:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef4f2;
  --line: #d8dee6;
  --ink: #18212b;
  --muted: #667385;
  --teal: #007a78;
  --teal-dark: #005f5d;
  --amber: #b96f16;
  --coral: #bd4b45;
  --green: #387a43;
  --shadow: 0 18px 42px rgba(20, 31, 45, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 20px clamp(16px, 3vw, 36px);
  background: #17202a;
  color: #fff;
  border-bottom: 5px solid var(--teal);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 8px;
  background: #f1b84b;
  color: #15212d;
  font-weight: 800;
}

.brand h1,
.brand p,
.section-title h2,
.section-title h3,
.results-header h2,
.tool-panel h3 {
  margin: 0;
}

.brand h1 {
  font-size: clamp(1.35rem, 3vw, 1.9rem);
  line-height: 1.1;
}

.brand p {
  margin-top: 4px;
  color: #c9d3df;
  font-size: 0.92rem;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, 1fr));
  gap: 10px;
  min-width: min(420px, 100%);
}

.summary-strip div {
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.summary-strip span {
  display: block;
  font-size: 1.25rem;
  font-weight: 800;
}

.summary-strip small {
  color: #c9d3df;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(0, 1fr) minmax(250px, 320px);
  gap: 18px;
  padding: 18px clamp(12px, 2.5vw, 28px) 28px;
}

.query-surface,
.tool-panel,
.plain-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.query-surface,
.tool-panel {
  padding: 18px;
}

.plain-panel {
  padding: 16px;
}

.results-area {
  min-width: 0;
}

.results-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 4px 2px;
}

.results-header h2 {
  font-size: 1.35rem;
}

.results-header p,
.section-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.section-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.section-title.compact {
  margin-bottom: 10px;
}

.section-title h2 {
  font-size: 1.12rem;
}

.section-title h3,
.tool-panel h3 {
  font-size: 1rem;
}

.query-form {
  display: grid;
  gap: 12px;
}

.advanced-box {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.checkline {
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
}

.checkline input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--teal);
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(0, 122, 120, 0.14);
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding-top: 6px;
}

.primary-button,
.secondary-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 9px 12px;
  font-weight: 800;
}

.primary-button {
  background: var(--teal);
  color: #fff;
}

.primary-button:hover {
  background: var(--teal-dark);
}

.secondary-button {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.secondary-button:hover {
  border-color: var(--teal);
  color: var(--teal-dark);
}

.full {
  width: 100%;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.adc-profile-panel {
  margin-bottom: 14px;
}

.adr-ranking-panel {
  margin-bottom: 14px;
}

#adr-ranking-table tbody tr {
  cursor: pointer;
}

.adc-profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.profile-card {
  min-height: 120px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.profile-card strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 0.95rem;
}

.profile-card dl {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 5px 8px;
  margin: 0;
  font-size: 0.82rem;
}

.profile-card dt {
  color: var(--muted);
  font-weight: 800;
}

.profile-card dd {
  margin: 0;
  color: var(--ink);
}

.metric-card {
  min-height: 92px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric-card strong {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.metric-card span {
  display: block;
  margin-top: 10px;
  font-size: clamp(1.2rem, 2vw, 1.65rem);
  line-height: 1;
  font-weight: 850;
}

.metric-card.accent {
  border-color: rgba(0, 122, 120, 0.45);
  background: var(--surface-2);
}

.flag-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.flag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  background: #e7f2ee;
  color: var(--green);
  border: 1px solid #bcd9cc;
  font-size: 0.78rem;
  font-weight: 800;
}

.flag.neutral {
  background: #f7f0e4;
  color: var(--amber);
  border-color: #e3cda8;
}

.analysis-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(320px, 1.2fr);
  gap: 14px;
  margin-bottom: 14px;
}

.table-scroll {
  width: 100%;
  overflow: auto;
}

.table-scroll.wide {
  max-height: 420px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 420px;
}

.data-table th,
.data-table td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 0.88rem;
}

.data-table th {
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  background: #f8fafc;
}

.data-table tbody tr:hover td,
.data-table tbody tr:hover th {
  background: #fbf7ef;
}

.side-tools {
  display: grid;
  align-content: start;
  gap: 14px;
}

.saved-list {
  display: grid;
  gap: 8px;
}

.registry-list {
  display: grid;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
  padding-right: 2px;
}

.registry-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.registry-item strong {
  display: block;
  color: var(--ink);
}

.registry-item span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.saved-item {
  width: 100%;
  padding: 10px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.saved-item strong {
  display: block;
  color: var(--ink);
}

.saved-item span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.file-control input {
  padding: 7px;
}

.status-line {
  min-height: 18px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.tool-panel.caution {
  border-left: 5px solid var(--coral);
}

.tool-panel.caution p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(260px, 350px) minmax(0, 1fr);
  }

  .side-tools {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .topbar,
  .results-header,
  .section-title {
    display: grid;
  }

  .summary-strip {
    min-width: 0;
    width: 100%;
  }

  .workspace,
  .analysis-grid,
  .side-tools {
    grid-template-columns: 1fr;
  }

  .query-surface {
    position: static;
  }
}

@media (max-width: 520px) {
  .topbar {
    padding: 16px 12px;
  }

  .brand {
    align-items: flex-start;
  }

  .summary-strip {
    grid-template-columns: 1fr;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-card {
    min-height: 86px;
    padding: 12px;
  }
}
