/* theme.css: Route Summary. "Calm routing console": slate ink on paper, one teal accent, and amber
   for the only thing that needs a second look, the addresses a widened block adds.
   Loaded after styles.css, so these rules win. Structural template rules (.ad-slot height,
   .ads-off, footer, .consent) are restyled only, never resized. */

:root {
  color-scheme: light dark;

  /* Palette (every text pair below is WCAG AA or better) */
  --bg: #f6f7f5;
  --surface: #ffffff;
  --raised: #eef1ef;
  --text: #172124;          /* 15.9:1 on --bg */
  --muted: #4f5d61;         /* 6.6:1 on --bg, 7.0:1 on --surface */
  --border: #cfd6d4;
  --border-strong: #9aa6a4;
  --accent: #0d6b63;        /* white on it: 6.3:1 */
  --accent-hover: #0a5751;
  --accent-text: #0b5f58;   /* links: 7.0:1 on --bg */
  --accent-tint: #e2f1ee;
  --on-accent: #ffffff;
  --success: #1d6b3a;       /* 6.4:1 on --surface */
  --success-tint: #e6f3ea;
  --warning: #8a4a00;       /* 6.4:1 on --warning-tint */
  --warning-edge: #d98a1c;
  --warning-tint: #fff4e2;
  --danger: #b3261e;        /* 6.0:1 on --danger-tint */
  --danger-tint: #fdecea;
  --line: var(--border);

  /* Type */
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --text-xs: 0.8125rem;     /* 13px labels, caps */
  --text-sm: 0.9375rem;     /* 15px mono, table cells */
  --text-md: 1.0625rem;     /* 17px body */
  --text-lg: 1.25rem;       /* 20px h2 */
  --text-xl: 1.625rem;      /* 26px card CIDR */
  --text-2xl: clamp(1.75rem, 4.6vw, 2.5rem); /* h1 */

  /* Space */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;

  /* Shape */
  --r-s: 6px;
  --r-m: 10px;
  --r-l: 14px;
  --shadow-1: 0 1px 2px rgb(23 33 36 / 0.06), 0 1px 1px rgb(23 33 36 / 0.04);
  --shadow-2: 0 8px 24px rgb(23 33 36 / 0.10), 0 2px 6px rgb(23 33 36 / 0.06);
  --ring: 0 0 0 3px var(--bg), 0 0 0 5px var(--accent);

  --ease: cubic-bezier(.2, .7, .2, 1);
  --fast: 160ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1517;
    --surface: #161e21;
    --raised: #1d272b;
    --text: #e4ebec;        /* 14.6:1 on --bg */
    --muted: #a5b3b6;       /* 8.0:1 on --bg */
    --border: #2d3a3e;
    --border-strong: #4b5b60;
    --accent: #5cc8b8;      /* --on-accent on it: 9.1:1 */
    --accent-hover: #7dd6c9;
    --accent-text: #7dd6c9;
    --accent-tint: #173431;
    --on-accent: #06231f;
    --success: #7fd49a;
    --success-tint: #15291d;
    --warning: #f3c27a;     /* 9.6:1 on --warning-tint */
    --warning-edge: #e09a35;
    --warning-tint: #2a2114;
    --danger: #ff9b92;      /* 7.9:1 on --danger-tint */
    --danger-tint: #33191a;
    --shadow-1: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-2: 0 10px 28px rgb(0 0 0 / 0.45);
  }
}

/* ---------- Page ---------- */
html { background: var(--bg); }
body {
  background: var(--bg);
  color: var(--text);
  font: var(--text-md)/1.55 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
header, main, footer { max-width: 46rem; padding-inline: var(--s5); }
@media (max-width: 30rem) { header, main, footer { padding-inline: var(--s4); } }

header { border-bottom: 1px solid var(--border); padding-block: var(--s2); }
.brand {
  display: inline-flex; align-items: center; gap: var(--s2);
  font-weight: 700; letter-spacing: -0.01em; color: var(--text);
}
.brand::before {
  content: ""; width: 22px; height: 22px; flex: none;
  border-radius: var(--r-s);
  background:
    linear-gradient(var(--on-accent), var(--on-accent)) 5px 6px / 4px 10px no-repeat,
    linear-gradient(var(--on-accent), var(--on-accent)) 13px 6px / 4px 10px no-repeat,
    linear-gradient(var(--warning-edge), var(--warning-edge)) 9px 9px / 4px 4px no-repeat,
    var(--accent);
}
header nav a { color: var(--muted); text-decoration: none; padding-inline: var(--s2); border-radius: var(--r-s); }
header nav a:hover { color: var(--text); background: var(--raised); }

h1 {
  font-size: var(--text-2xl); line-height: 1.12; letter-spacing: -0.02em;
  font-weight: 750; margin: var(--s6) 0 var(--s3);
}
h2 { font-size: var(--text-lg); line-height: 1.3; letter-spacing: -0.01em; margin: var(--s7) 0 var(--s3); }
h3 { font-size: var(--text-md); line-height: 1.35; margin: var(--s5) 0 var(--s1); }
main p, main li { max-width: 68ch; }
.lede { font-size: 1.125rem; color: var(--muted); margin: 0 0 var(--s5); }
main ol, main ul { padding-left: 1.3em; }
main li + li { margin-top: var(--s2); }

a { color: var(--accent-text); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
code, kbd, samp, pre { font-family: var(--font-mono); }

:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-s); }

/* ---------- The tool panel ---------- */
.tool {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-1);
  padding: var(--s5);
  margin: var(--s5) 0 var(--s6);
  display: grid;
  gap: var(--s4);
}
@media (max-width: 30rem) { .tool { padding: var(--s4); margin-inline: calc(var(--s2) * -1); } }
.tool > p { margin: 0; }

/* Labels: weight and caps set them apart, not grey alone */
.tool label, .tool legend, .field-label {
  display: block;
  font-size: var(--text-xs); font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text);
  margin-bottom: var(--s2);
}

/* List box and drop target */
.drop { margin: 0; display: block; }
.drop textarea {
  display: block; width: 100%; min-height: 13rem;
  padding: var(--s3) var(--s4);
  font: var(--text-sm)/1.6 var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--bg);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-m);
  resize: vertical;
}
.drop textarea::placeholder { color: var(--muted); opacity: 1; }
.drop textarea:hover { border-color: var(--accent); }
.drop textarea:focus-visible { border-style: solid; border-color: var(--accent); box-shadow: var(--ring); }
.drop.over textarea { background: var(--accent-tint); border-color: var(--accent); border-style: solid; }

/* File picker row */
.file { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); margin: 0; }
.file label { margin: 0; }
.file input[type="file"] { font: inherit; font-size: var(--text-sm); color: var(--muted); max-width: 100%; min-height: 44px; }
.file input[type="file"]::file-selector-button {
  font: inherit; font-weight: 600; font-size: var(--text-sm);
  min-height: 44px; padding: 0 var(--s4); margin-right: var(--s3);
  color: var(--text); background: var(--raised);
  border: 1px solid var(--border); border-radius: var(--r-s);
  cursor: pointer;
}
.file input[type="file"]::file-selector-button:hover { border-color: var(--border-strong); background: var(--surface); }

/* Limit + mode row */
.settings { display: grid; grid-template-columns: minmax(0, 14rem) 1fr; gap: var(--s4) var(--s5); align-items: end; }
@media (max-width: 34rem) { .settings { grid-template-columns: 1fr; } }
.field { margin: 0; }
#limit, .tool input[type="text"], .tool input[type="number"] {
  display: block; width: 100%; min-height: 48px;
  padding: 0 var(--s4);
  font: 600 1.25rem/1 var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--text); background: var(--bg);
  border: 1.5px solid var(--border-strong); border-radius: var(--r-m);
}
#limit:hover { border-color: var(--accent); }
#limit:focus-visible { border-color: var(--accent); }

/* Allowlist / Blocklist: a two-part segmented switch built on real radios */
fieldset.mode { border: 0; padding: 0; margin: 0; min-inline-size: 0; }
fieldset.mode legend { padding: 0; }
.segmented {
  display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  gap: var(--s1); padding: var(--s1);
  background: var(--raised); border: 1px solid var(--border); border-radius: var(--r-m);
  width: 100%; max-width: 22rem;
}
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmented label {
  margin: 0; display: flex; align-items: center; justify-content: center; min-height: 40px;
  padding: 0 var(--s4); border-radius: calc(var(--r-m) - 3px);
  font-size: var(--text-sm); font-weight: 600; letter-spacing: 0; text-transform: none;
  color: var(--muted); cursor: pointer;
}
.segmented label:hover { color: var(--text); }
.segmented input:checked + label { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }
.segmented input:focus-visible + label { box-shadow: var(--ring); }

/* Buttons: one filled (Fit), one outline (Cancel), one quiet (Clear) */
.actions { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s3); align-items: center; margin: 0; }
.actions button, .tool button, #output button {
  min-height: 44px; min-width: 44px;
  padding: 0 var(--s5);
  font: 600 var(--text-md)/1 var(--font-ui);
  border-radius: var(--r-m);
  cursor: pointer;
  border: 1.5px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  transition: transform var(--fast) var(--ease);
}
.actions button:hover, .tool button:hover, #output button:hover { border-color: var(--accent); color: var(--accent-text); }
.actions button:active, .tool button:active, #output button:active { transform: translateY(1px); }

#run, .tool button.primary {
  min-width: 8.5rem; min-height: 48px;
  background: var(--accent); color: var(--on-accent); border-color: var(--accent);
  box-shadow: var(--shadow-1);
}
#run:hover, .tool button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }

#clear, .tool button.quiet {
  background: transparent; border-color: transparent; color: var(--muted);
  padding-inline: var(--s4);
}
#clear:hover, .tool button.quiet:hover { color: var(--text); background: var(--raised); border-color: transparent; }

.tool button:disabled, #output button:disabled {
  opacity: 0.45; cursor: not-allowed; transform: none;
  border-color: var(--border); color: var(--muted); background: transparent; box-shadow: none;
}
#run:disabled { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

/* ---------- Status line ---------- */
#status {
  min-height: 1.6em; margin: 0;
  font-weight: 600; font-variant-numeric: tabular-nums;
  color: var(--text);
}
#status:empty { min-height: 1.6em; }
#status.busy::before {
  content: ""; display: inline-block; width: 0.7em; height: 0.7em; margin-right: var(--s2);
  border-radius: 50%; background: var(--accent); vertical-align: 0.05em;
  animation: rs-pulse 900ms ease-in-out infinite alternate;
}
#status.error {
  color: var(--danger); background: var(--danger-tint);
  border-left: 4px solid var(--danger); border-radius: var(--r-s);
  padding: var(--s3) var(--s4);
}
#status.ok { color: var(--text); }

/* ---------- Output ---------- */
#output { min-height: 0; }
#output:not(:empty) { border-top: 1px solid var(--border); padding-top: var(--s2); animation: rs-in 180ms var(--ease) both; }
#output h2 { font-size: var(--text-lg); margin: var(--s5) 0 var(--s3); }
#output h2:first-child { margin-top: var(--s3); }

/* Problem list on error */
#output ul.problems { list-style: none; padding: 0; margin: var(--s3) 0 0; font: var(--text-sm)/1.5 var(--font-mono); }
#output ul.problems li { padding: var(--s2) var(--s3); border-bottom: 1px solid var(--border); max-width: none; overflow-wrap: anywhere; }
#output ul.problems li + li { margin-top: 0; }

/* Warnings and notices */
#output .warning {
  margin: var(--s3) 0 0; padding: var(--s3) var(--s4);
  color: var(--warning); background: var(--warning-tint);
  border-left: 4px solid var(--warning-edge); border-radius: var(--r-s);
  font-weight: 600; max-width: none;
}
#output .notices { margin: var(--s3) 0 0; padding: 0; list-style: none; font-size: var(--text-sm); color: var(--muted); }
#output .notices li { margin: var(--s1) 0 0; }
#output .more { font-size: var(--text-sm); color: var(--muted); font-style: italic; }

/* The fitted list: the biggest thing once a result exists */
#output pre {
  margin: 0; padding: var(--s4) var(--s5);
  font: 600 1.125rem/1.7 var(--font-mono); font-variant-numeric: tabular-nums;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: var(--r-m);
  overflow-x: auto; white-space: pre;
}
#output .actions { margin-top: var(--s3); }
#output .actions button:first-child {
  background: var(--accent); color: var(--on-accent); border-color: var(--accent);
}
#output .actions button:first-child:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
#output button.copy { min-width: 8rem; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-m); background: var(--surface); }
#output table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
#output th, #output td { padding: var(--s2) var(--s4); text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
#output th {
  font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  background: var(--raised); color: var(--text);
}
#output tbody tr:last-child td { border-bottom: 0; }
#output td:first-child { font-family: var(--font-mono); font-weight: 600; }
#output td.num, #output th.num { text-align: right; }
#output tr.widened td:first-child { box-shadow: inset 4px 0 0 var(--warning-edge); }
#output td.extra-pos { color: var(--warning); font-weight: 700; }
#output td.extra-zero { color: var(--muted); }
#output tr.current td { background: var(--accent-tint); font-weight: 700; }

/* Signature: the widened-block card. Amber edge, the CIDR as a large mono readout, and the
   "+64" it costs pinned to the right. */
#output .widened-list { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s3); }
#output .widened-list > li { margin: 0; max-width: none; }
.widened-card {
  background: var(--surface);
  border: 1px solid var(--border); border-left: 6px solid var(--warning-edge);
  border-radius: var(--r-m);
  padding: var(--s4) var(--s5);
  box-shadow: var(--shadow-1);
}
.widened-card h3 {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--s1) var(--s4);
  margin: 0 0 var(--s3);
  font: 700 var(--text-xl)/1.15 var(--font-mono); letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
.widened-card .cost {
  font: 700 var(--text-sm)/1 var(--font-mono); font-variant-numeric: tabular-nums;
  color: var(--warning); background: var(--warning-tint);
  padding: var(--s1) var(--s2); border-radius: var(--r-s); white-space: nowrap;
}
.widened-card .group-label {
  margin: var(--s3) 0 var(--s1);
  font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
}
.widened-card ul { list-style: none; padding: 0; margin: 0; font: var(--text-sm)/1.6 var(--font-mono); font-variant-numeric: tabular-nums; }
.widened-card ul li { margin: 0; padding: 2px 0; overflow-wrap: anywhere; }
.widened-card ul.sources li { color: var(--muted); }
.widened-card ul.added li { color: var(--warning); font-weight: 600; }
.widened-card ul.added li::before { content: "+ "; }

/* Success with nothing widened */
#output .all-clear {
  margin: var(--s3) 0 0; padding: var(--s3) var(--s4);
  color: var(--success); background: var(--success-tint);
  border-left: 4px solid var(--success); border-radius: var(--r-s); font-weight: 600; max-width: none;
}

/* ---------- Reading section, template parts ---------- */
main > h3 { margin-top: var(--s5); }
main > h3 + p { margin-top: var(--s1); color: var(--text); }
.ad-slot { background: var(--raised); border: 1px solid var(--border); }
.ad-label { color: var(--muted); opacity: 1; }
.house-card { background: var(--surface); border: 1px solid var(--border); }
.house-card strong { color: var(--accent-text); }
.consent { background: var(--surface); color: var(--text); border-color: var(--border); box-shadow: var(--shadow-2); }
.consent button { border-color: var(--accent); color: var(--text); }
.consent button:hover { background: var(--accent-tint); }
footer { color: var(--muted); opacity: 1; border-top: 1px solid var(--border); margin-top: var(--s7); padding-block: var(--s5); }

/* ---------- Motion ---------- */
@keyframes rs-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes rs-pulse { from { opacity: 0.35; transform: scale(0.85); } to { opacity: 1; transform: scale(1); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
