/* theme.css: Fix First. Direction: "triage work order", a calm field-service ticket in steel
   teal on cool paper. Signature: the ticket stub, each fix card opens with a monospace rank
   numeral in a stub column torn off by a dashed perforation, edged in the fix's highest-risk colour.
   Loaded after styles.css, so these rules win. The builder adds layout only if it must: no
   colours, radii, shadows or font sizes. Contrast ratios (WCAG 2.x) are noted beside each pair. */

:root {
  color-scheme: light dark;

  /* Palette, light */
  --bg: #f5f6f3;            /* page */
  --surface: #ffffff;       /* panels and cards */
  --raised: #eceeea;        /* stub column, chips, hover fills */
  --text: #16201c;          /* 15.9:1 on --surface, 14.7:1 on --bg */
  --muted: #55615c;         /* 6.4:1 on --surface, 6.0:1 on --bg, 5.6:1 on --raised */
  --border: #d5d9d4;        /* edges only, never text */
  --border-strong: #7d8882; /* drop zone dash, control edges: 3.39:1 on --bg, 3.67:1 on --surface */
  --accent: #0b5f78;        /* 7.2:1 with --on-accent; 6.6:1 as text on --bg */
  --accent-hover: #094f64;
  --accent-active: #073f50;
  --accent-tint: #e3f0f3;   /* --accent text on it 6.3:1 */
  --on-accent: #ffffff;
  --success: #1f6b3a;       /* 6.4:1 on --surface, 5.7:1 on --success-tint */
  --success-tint: #e6f2e9;
  --warning: #7a5a00;       /* 6.4:1 on --surface, 5.6:1 on --warning-tint */
  --warning-tint: #f8f0d8;
  --danger: #b42318;        /* 6.5:1 on --surface, 5.7:1 on --danger-tint */
  --danger-tint: #fbeae8;

  /* Risk ink (text and the stub edge) and its chip tint. Each ink is AA on its tint and on --surface. */
  --risk-critical: #a3161b; /* 7.8:1 on --surface, 6.7:1 on tint */
  --risk-critical-tint: #fbe7e6;
  --risk-high: #a8430a;     /* 5.8:1 on --surface, 5.1:1 on tint */
  --risk-high-tint: #fcede2;
  --risk-medium: #7a5a00;   /* 6.4:1 on --surface, 5.6:1 on tint */
  --risk-medium-tint: #f8f0d8;
  --risk-low: #3d5566;      /* 7.8:1 on --surface, 6.9:1 on tint */
  --risk-low-tint: #e8eef2;
  --risk-unknown: var(--muted);
  --risk-unknown-tint: var(--raised);

  /* Type */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --fs-label: 0.8125rem;    /* 13px caps labels, 700, tracked */
  --fs-small: 0.9375rem;    /* 15px hints, host chips, meta */
  --fs-body: 1.0625rem;     /* 17px */
  --fs-lead: 1.25rem;       /* 20px lede, fix solution text */
  --fs-h2: 1.625rem;        /* 26px results title */
  --fs-rank: 2.25rem;       /* 36px rank numeral */
  --fs-h1: clamp(2rem, 5.5vw, 2.75rem);

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

  /* Radii, shadows, motion */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-pill: 999px;
  --shadow-1: 0 1px 2px rgb(22 32 28 / 0.06), 0 2px 8px rgb(22 32 28 / 0.05);
  --shadow-2: 0 4px 12px rgb(22 32 28 / 0.08), 0 12px 32px rgb(22 32 28 / 0.08);
  --ring: 0 0 0 4px var(--accent-tint);
  --t: 160ms ease-out;

  --stub: 5.5rem;           /* width of the ticket stub column */
  --column: 56rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1513;
    --surface: #161e1b;
    --raised: #1f2925;
    --text: #e6ebe8;          /* 14.6:1 on --surface */
    --muted: #a3aea9;         /* 7.4:1 on --surface, 6.4:1 on --raised */
    --border: #2e3a35;
    --border-strong: #5f6d67; /* 3.1:1 on --surface (non-text UI) */
    --accent: #5cc4dc;        /* 8.0:1 with --on-accent; 8.6:1 as text on --surface */
    --accent-hover: #7dd2e5;
    --accent-active: #9bdeec;
    --accent-tint: #123540;   /* --accent text on it 6.5:1 */
    --on-accent: #062630;
    --success: #7fd49a;       /* 9.4:1 on --surface */
    --success-tint: #15301f;
    --warning: #e8c25a;       /* 10.2:1 on --surface */
    --warning-tint: #33290f;
    --danger: #ff9b92;        /* 8.2:1 on --surface, 6.6:1 on tint */
    --danger-tint: #3a1a18;
    --risk-critical: #ff8f8a; /* 7.6:1 on --surface, 6.2:1 on tint */
    --risk-critical-tint: #3a1a19;
    --risk-high: #ffad70;     /* 9.1:1 on --surface, 7.4:1 on tint */
    --risk-high-tint: #382211;
    --risk-medium: #e8c25a;   /* 10.2:1 on --surface, 8.2:1 on tint */
    --risk-medium-tint: #33290f;
    --risk-low: #a7c0d2;      /* 9.5:1 on --surface, 7.9:1 on tint */
    --risk-low-tint: #1c2830;
    --shadow-1: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-2: 0 8px 28px rgb(0 0 0 / 0.5);
  }
}

/* ---------- Page ---------- */
html { background: var(--bg); }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 var(--fs-body)/1.55 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}
header, main, footer { max-width: var(--column); padding-inline: var(--s5); }
/* Full-width hairline under the header; its contents stay on the page column. */
header {
  max-width: none; padding-block: var(--s3); border-bottom: 1px solid var(--border);
  padding-inline: max(var(--s5), calc((100% - var(--column)) / 2 + var(--s5)));
}
.brand {
  display: inline-flex; align-items: center; gap: var(--s3);
  font-weight: 750; letter-spacing: -0.01em; color: var(--text);
}
.brand::before {
  content: ""; width: 28px; height: 28px; flex: none;
  background: url("icons/favicon.svg") center / contain no-repeat;
}
header nav a {
  padding-inline: var(--s3); border-radius: var(--r-sm);
  color: var(--muted); font-weight: 600; text-decoration: none;
  transition: background-color var(--t), color var(--t);
}
header nav a:hover { color: var(--text); background: var(--raised); }

main { padding-top: var(--s6); }
main > p, main > ol, main > ul, main > h3 { max-width: 68ch; }
h1 {
  font-size: var(--fs-h1); font-weight: 800; letter-spacing: -0.025em;
  line-height: 1.1; margin: 0 0 var(--s3);
}
h2 { font-size: var(--fs-lead); font-weight: 750; letter-spacing: -0.01em; margin: var(--s7) 0 var(--s3); }
h3 { font-size: var(--fs-body); font-weight: 700; margin: var(--s5) 0 var(--s1); }
.lede { font-size: var(--fs-lead); color: var(--muted); line-height: 1.45; margin: 0 0 var(--s6); }
main li { margin-block: var(--s1); }
a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
code, kbd { font-family: var(--font-mono); font-size: 0.92em; background: var(--raised); padding: 1px var(--s1); border-radius: var(--r-sm); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; box-shadow: var(--ring); }

/* ---------- The tool panel ---------- */
.tool {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  padding: var(--s5);
}
.panel-label {
  margin: 0 0 var(--s3);
  font-size: var(--fs-label); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted);
}

/* Drop zone */
.drop {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--s2);
  min-height: 15rem; margin: 0;
  padding: var(--s2) var(--s5);
  text-align: center;
  background: var(--bg);
  border: 2px dashed var(--border-strong);
  border-radius: var(--r-md);
  transition: background-color var(--t), border-color var(--t);
}
.drop-icon { width: 44px; height: 44px; color: var(--accent); }
.drop-title { display: block; font-size: var(--fs-lead); font-weight: 700; color: var(--text); }
.drop-sub { display: block; font-size: var(--fs-small); color: var(--muted); }
.drop-hint { margin: 0; max-width: 64ch; font-size: var(--fs-small); color: var(--muted); }
.drop.over { border-style: solid; border-color: var(--accent); background: var(--accent-tint); }
.drop.over .drop-icon { transform: translateY(-3px); }
.drop-icon { transition: transform var(--t); }
.drop.invalid { border-color: var(--danger); background: var(--danger-tint); }
.drop:focus-within {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: var(--ring);
}
.drop.locked { opacity: 0.55; pointer-events: none; }
.file-input {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Compact file bar (replaces the drop zone while working and once there is a result) */
.file-bar {
  display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap;
  min-height: 56px; padding: var(--s2) var(--s2) var(--s2) var(--s4);
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-md);
}
.file-bar svg { width: 22px; height: 22px; flex: none; color: var(--accent); }
.file-name {
  flex: 1 1 12rem; min-width: 0;
  font-family: var(--font-mono); font-size: var(--fs-small); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.file-size { font-family: var(--font-mono); font-size: var(--fs-small); color: var(--muted); font-variant-numeric: tabular-nums; }
.file-bar .local {
  display: inline-flex; align-items: center; gap: var(--s1);
  font-size: var(--fs-label); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--success);
}
.file-bar .local svg { width: 16px; height: 16px; color: var(--success); }

/* ---------- Buttons ---------- */
.btn, .actions button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px; padding: var(--s2) var(--s4);
  border-radius: var(--r-sm); border: 1px solid transparent;
  font: 600 var(--fs-body)/1.2 var(--font-sans);
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background-color var(--t), border-color var(--t), color var(--t), transform var(--t);
}
.btn svg { width: 18px; height: 18px; flex: none; }
.btn:active, .actions button:active { transform: translateY(1px); }
.btn.primary, .actions .btn.primary {
  min-height: 48px; padding-inline: var(--s5);
  background: var(--accent); color: var(--on-accent); border-color: var(--accent);
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.primary:active { background: var(--accent-active); border-color: var(--accent-active); }
.btn.secondary, .actions .btn.secondary, .actions button:not(.btn) {
  background: var(--surface); color: var(--text); border-color: var(--border-strong);
}
.btn.secondary:hover, .actions button:not(.btn):hover { background: var(--raised); border-color: var(--text); }
.btn.secondary:active { background: var(--border); }
.btn.quiet, .actions .btn.quiet {
  background: transparent; color: var(--accent); border-color: transparent; padding-inline: var(--s3);
}
.btn.quiet:hover { background: var(--accent-tint); }
.btn.quiet:active { background: var(--border); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }
/* Copy buttons keep their width when the label becomes "Copied" */
#copy-text { min-width: 12.5rem; }
#copy-csv { min-width: 10.5rem; }
.actions .btn.secondary.copied { color: var(--success); border-color: var(--success); background: var(--success-tint); }
.btn.primary.copied { background: var(--success); border-color: var(--success); color: var(--surface); }

.actions { display: flex; flex-wrap: wrap; align-items: stretch; gap: var(--s2); margin: 0; }
.actions .btn, .actions button { min-height: 48px; }
[tabindex="-1"]:focus, [tabindex="-1"]:focus-visible { outline: none; box-shadow: none; }
.actions .push { margin-left: auto; }

/* ---------- Status line (space reserved) ---------- */
#status {
  min-height: 1.6em; margin: var(--s4) 0 0;
  font-size: var(--fs-small); font-weight: 600; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
#status.ok { color: var(--success); }
#status.error { color: var(--danger); }
#output { min-height: 6rem; }

/* ---------- Empty state ---------- */
.empty-state {
  display: flex; gap: var(--s4); align-items: flex-start;
  margin-top: var(--s4); padding: var(--s4) var(--s5);
  border: 1px dashed var(--border); border-radius: var(--r-md);
  color: var(--muted); font-size: var(--fs-small);
}
#status:empty + #output .empty-state { margin-top: 0; }
.empty-state svg { width: 40px; height: 40px; flex: none; color: var(--border-strong); }
.empty-state strong { display: block; color: var(--text); font-size: var(--fs-body); margin-bottom: var(--s1); }
.empty-state p { margin: 0; max-width: 68ch; }

/* ---------- Working ---------- */
.working { margin-top: var(--s4); }
.progress-row { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; }
.progress-text { flex: 1 1 14rem; margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.progress-text .num { font-family: var(--font-mono); }
.progress {
  height: 8px; margin-top: var(--s3);
  background: var(--raised); border-radius: var(--r-pill); overflow: hidden;
}
.progress-bar {
  height: 100%; width: 100%;
  background: var(--accent); border-radius: inherit;
  transform-origin: left center; transform: scaleX(var(--p, 0));
  transition: transform var(--t);
}

/* ---------- Error notice ---------- */
.notice {
  display: flex; gap: var(--s3); align-items: flex-start;
  margin-top: var(--s4); padding: var(--s4);
  border-radius: var(--r-md); border: 1px solid currentColor;
}
.notice svg { width: 22px; height: 22px; flex: none; margin-top: 2px; }
.notice strong { display: block; font-size: var(--fs-body); }
.notice p { margin: var(--s1) 0 0; color: var(--text); }
.notice .btn { margin-top: var(--s3); }
.notice.error { color: var(--danger); background: var(--danger-tint); }
.notice.warn { color: var(--warning); background: var(--warning-tint); }

/* ---------- Results ---------- */
.results { margin-top: var(--s5); animation: rise 180ms ease-out both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.results-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: var(--s4); padding-bottom: var(--s4); border-bottom: 1px solid var(--border);
}
.results-title {
  margin: 0; font-size: var(--fs-h2); font-weight: 800; letter-spacing: -0.02em; line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.results-title .count-group { white-space: nowrap; }
#status.ok .num, .results-title .num, .summary-skips .num { font-family: var(--font-mono); }
.summary-skips { margin: var(--s1) 0 0; font-size: var(--fs-small); color: var(--muted); font-variant-numeric: tabular-nums; }

.fixes { list-style: none; margin: var(--s5) 0 0; padding: 0; display: grid; gap: var(--s3); }
.fixes > li { margin: 0; }

/* The signature: the ticket stub */
.fix {
  --edge: var(--risk-unknown);
  --edge-tint: var(--risk-unknown-tint);
  display: grid; grid-template-columns: var(--stub) 1fr;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 5px solid var(--edge);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.fix[data-risk="critical"] { --edge: var(--risk-critical); --edge-tint: var(--risk-critical-tint); }
.fix[data-risk="high"]     { --edge: var(--risk-high);     --edge-tint: var(--risk-high-tint); }
.fix[data-risk="medium"]   { --edge: var(--risk-medium);   --edge-tint: var(--risk-medium-tint); }
.fix[data-risk="low"]      { --edge: var(--risk-low);      --edge-tint: var(--risk-low-tint); }
.fix-rank {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding: var(--s4) var(--s2);
  background: var(--raised);
  border-right: 2px dashed var(--border-strong);
  text-align: center;
}
.rank-label {
  font-size: var(--fs-label); font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted);
}
.rank-num {
  font-family: var(--font-mono); font-size: var(--fs-rank); font-weight: 700; line-height: 1.1;
  color: var(--text); font-variant-numeric: tabular-nums;
}
.fix:first-child .rank-num { color: var(--edge); }
.fix-body { min-width: 0; padding: var(--s4) var(--s5) var(--s4); }
.fix-solution {
  margin: 0; font-size: var(--fs-lead); font-weight: 650; line-height: 1.35;
  overflow-wrap: anywhere; white-space: pre-line;
}
.fix-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3);
  margin: var(--s2) 0 0; font-size: var(--fs-small); color: var(--muted);
}
.fix-count { font-variant-numeric: tabular-nums; }
.fix-count b { font-family: var(--font-mono); color: var(--text); font-weight: 700; }
.risk {
  display: inline-flex; align-items: center; gap: var(--s1);
  padding: 2px var(--s2); border-radius: var(--r-sm);
  font-size: var(--fs-label); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--edge); background: var(--edge-tint);
}
.risk::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: currentColor; }
.fix-names {
  margin: var(--s2) 0 0; font-size: var(--fs-small); color: var(--muted);
  max-width: 68ch;
  overflow-wrap: anywhere;
}
.fix-names b { color: var(--text); font-weight: 600; }
.hosts-label {
  margin: var(--s3) 0 var(--s1);
  font-size: var(--fs-label); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted);
}
.hosts { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s1) var(--s2); }
.hosts li {
  margin: 0; padding: 2px var(--s2);
  font-family: var(--font-mono); font-size: var(--fs-small); font-variant-numeric: tabular-nums;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-sm);
  max-width: 100%; overflow-wrap: anywhere;
}
.show-all { margin-top: var(--s2); margin-left: calc(var(--s3) * -1); }

.caveat {
  display: flex; gap: var(--s3); align-items: flex-start;
  margin: var(--s5) 0 0; padding: var(--s3) var(--s4);
  background: var(--warning-tint); color: var(--text);
  border-radius: var(--r-md); font-size: var(--fs-small); max-width: none;
}
.caveat svg { width: 20px; height: 20px; flex: none; margin-top: 2px; color: var(--warning); }

/* ---------- Template pieces, restyled, structure untouched ---------- */
.ad-slot { background: var(--raised); border: 1px solid var(--border); }
.ad-label { opacity: 1; color: var(--muted); font-size: var(--fs-label); letter-spacing: 0.06em; text-transform: uppercase; }
.house-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); }
.house-card strong { color: var(--accent); }
.consent {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-2);
}
.consent button { border-color: var(--border-strong); border-radius: var(--r-sm); transition: background-color var(--t); }
.consent button:hover { background: var(--raised); }
footer {
  opacity: 1; color: var(--muted); font-size: var(--fs-small);
  margin-top: var(--s8); padding-block: var(--s5) var(--s6);
  border-top: 1px solid var(--border);
}
footer a { color: var(--accent); }

/* ---------- Phone ---------- */
@media (max-width: 46rem) {
  header, main, footer { padding-inline: var(--s4); }
  header { padding-inline: var(--s4); }
  main { padding-top: var(--s5); }
  .tool { padding: var(--s4); border-radius: var(--r-md); }
  .drop { min-height: 12rem; padding: var(--s4); }
  .drop .btn.primary { width: 100%; }
  .empty-state { gap: var(--s2); padding-inline: var(--s4); }
  .empty-state svg { width: var(--s5); height: var(--s5); }
  .results-head .actions { width: 100%; }
  .results-head .actions .btn { flex: 1 1 10rem; min-width: 0; }
  :root { --stub: 3.5rem; --fs-rank: 1.625rem; }
  .fix-body { padding: var(--s3) var(--s4); }
  .fix-solution { font-size: var(--fs-body); }
  .rank-label { letter-spacing: 0.04em; }
}

/* ---------- Motion off ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .drop.over .drop-icon, .btn:active, .actions button:active { transform: none; }
}
