/* theme.css: Sudoers Plain. "Audit binder": warm paper, near-black ink, one ledger-green accent,
   monospace for every account, host, filename and command. Signature: the reference tab (S1, S2…)
   hanging off each capture card's left edge, repeated in the source appendix. Loaded after
   styles.css; the builder adds layout only. Contrast ratios (WCAG 2.x) beside each text pair. */

:root {
  color-scheme: light dark;

  /* Palette (light) */
  --bg: #f6f4ef;
  --surface: #ffffff;
  --raised: #efece5;
  --text: #1d2125;            /* 14.9:1 on --bg, 16.2:1 on --surface */
  --muted: #555d66;           /* 6.1:1 on --bg, 6.7:1 on --surface, 5.6:1 on --raised */
  --border: #dcd7cc;
  --border-strong: #8a8478;   /* 3.7:1 on --surface: input and drop-zone outlines (non-text) */
  --accent: #1f6b52;          /* 6.4:1 with --on-accent; 6.4:1 as text on --surface */
  --accent-hover: #185a45;
  --accent-active: #134a39;
  --accent-tint: #e3efe9;     /* --text on it 14:1, --accent on it 5.5:1 */
  --on-accent: #ffffff;
  --success: #22693f;         /* 6.6:1 on --surface, 5.9:1 on --success-tint */
  --success-tint: #e4f2e8;
  --warning: #8a5300;         /* 6.3:1 on --surface, 5.6:1 on --warning-tint */
  --warning-tint: #fbf0dc;
  --danger: #b42318;          /* 6.4:1 on --surface, 5.7:1 on --danger-tint */
  --danger-tint: #fdecea;

  /* Type */
  --font-ui: 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;
  --text-xs: 0.8125rem;   /* 13px caps labels, tabs */
  --text-sm: 0.9375rem;   /* 15px tables, notes, errors */
  --text-md: 1.0625rem;   /* 17px body */
  --text-lg: 1.25rem;     /* 20px h3, host names */
  --text-xl: 1.5rem;      /* 24px report title */
  --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;

  /* Radii and shadows */
  --r-s: 6px;
  --r-m: 10px;
  --r-l: 14px;
  --shadow-1: 0 1px 2px rgb(29 33 37 / 0.06), 0 2px 10px rgb(29 33 37 / 0.05);
  --shadow-2: 0 10px 30px rgb(29 33 37 / 0.18);
  --ring: 0 0 0 4px var(--accent-tint);

  /* Motion */
  --fast: 160ms;
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);

  /* Template variables, mapped so its own rules follow the theme */
  --line: var(--border);
  --accent-text: var(--accent);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181b;
    --surface: #1d2125;
    --raised: #252a2f;
    --text: #e9e6df;          /* 14.6:1 on --bg, 12.9:1 on --surface */
    --muted: #aab1b8;         /* 8.6:1 on --bg, 7.6:1 on --surface, 6.6:1 on --raised */
    --border: #343a40;
    --border-strong: #6e767e; /* 3.4:1 on --surface (non-text) */
    --accent: #6fcfa6;        /* 9.1:1 with --on-accent; 9.0:1 as text on --surface */
    --accent-hover: #86dab5;
    --accent-active: #5bbf95;
    --accent-tint: #1f3a2f;   /* --text on it 10.9:1 */
    --on-accent: #0d1f17;
    --success: #7fd49b;       /* 9.4:1 on --surface */
    --success-tint: #1d3526;
    --warning: #f0b75a;       /* 9.0:1 on --surface */
    --warning-tint: #3a2e18;
    --danger: #ff8f84;        /* 6.9:1 on --surface, 5.9:1 on --danger-tint */
    --danger-tint: #3d2220;
    --shadow-1: 0 1px 2px rgb(0 0 0 / 0.4), 0 2px 10px rgb(0 0 0 / 0.25);
    --shadow-2: 0 10px 30px rgb(0 0 0 / 0.5);
  }
}

/* ---------- Page shell ---------- */
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
header, main, footer { max-width: 58rem; padding-left: var(--s5); padding-right: var(--s5); }
body > header { border-bottom: 1px solid var(--border); max-width: none; padding-left: max(var(--s5), calc((100% - 58rem) / 2 + var(--s5))); padding-right: max(var(--s5), calc((100% - 58rem) / 2 + var(--s5))); }
.brand { display: inline-flex; align-items: center; gap: var(--s2); font-size: var(--text-md); letter-spacing: -0.01em; }
.brand::before {
  content: ""; width: 22px; height: 26px; flex: none;
  border: 2px solid currentColor; border-radius: 3px;
  background: linear-gradient(var(--accent), var(--accent)) left 0 top 5px / 6px 8px no-repeat;
}
header nav a { padding: 0 var(--s2); color: var(--text); text-decoration: none; border-radius: var(--r-s); transition: background-color var(--fast) var(--ease); }
header nav a:hover { background: var(--raised); }

a { color: var(--accent); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }

h1 { font-size: var(--text-2xl); font-weight: 750; letter-spacing: -0.02em; margin: var(--s6) 0 var(--s3); }
h2 { font-size: var(--text-lg); font-weight: 700; margin: var(--s7) 0 var(--s3); letter-spacing: -0.01em; }
h3 { font-size: var(--text-md); font-weight: 650; margin: var(--s5) 0 var(--s1); }
main p, main li { max-width: 68ch; }
.lede { font-size: 1.125rem; color: var(--muted); max-width: 62ch; margin: 0 0 var(--s5); }
code, .mono, .file, kbd { font-family: var(--font-mono); font-size: 0.92em; }
p code, li code { background: var(--raised); padding: 1px 5px; border-radius: 4px; }
main ol, main ul { padding-left: 1.3em; }
main li { margin: var(--s1) 0; }

/* ---------- Tool panel ---------- */
.tool {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-1);
  padding: var(--s5);
}

/* Drop zone */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  gap: var(--s2);
  min-height: 168px;
  padding: var(--s5) var(--s4);
  border: 2px dashed var(--border-strong);
  border-radius: var(--r-m);
  background: var(--bg);
  transition: border-color var(--fast) var(--ease), background-color var(--fast) var(--ease);
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.over { border-color: var(--accent); border-style: solid; background: var(--accent-tint); }
.drop-icon { width: 40px; height: 40px; color: var(--accent); }
.drop-title { margin: 0; font-size: var(--text-lg); font-weight: 650; }
.drop-title code { background: none; padding: 0; }
.drop-hint { margin: 0 0 var(--s2); color: var(--muted); font-size: var(--text-sm); }
.field-label, .date-field label, .report-kicker, .label, .appendix-note-label {
  font-size: var(--text-xs); font-weight: 650; text-transform: uppercase; letter-spacing: 0.08em;
}
.dropzone .field-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.dropzone input[type="file"] {
  max-width: 100%;
  font: inherit; font-size: var(--text-sm); color: var(--muted);
}

/* Buttons: one primary (filled) per screen */
button, input[type="file"]::file-selector-button {
  font: inherit; font-weight: 600;
  min-height: 44px; padding: 0 var(--s4);
  border-radius: var(--r-m);
  cursor: pointer;
  transition: background-color var(--fast) var(--ease), border-color var(--fast) var(--ease), color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
button:active:not(:disabled), input[type="file"]::file-selector-button:active { transform: translateY(1px); }

button.primary, .tool:not(.has-report) input[type="file"]::file-selector-button {
  min-height: 48px; padding: 0 var(--s5);
  background: var(--accent); color: var(--on-accent);
  border: 1px solid var(--accent);
  box-shadow: var(--shadow-1);
}
button.primary:hover:not(:disabled), .tool:not(.has-report) input[type="file"]::file-selector-button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.primary:active:not(:disabled) { background: var(--accent-active); }

button.secondary, .tool.has-report input[type="file"]::file-selector-button {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong);
}
button.secondary:hover, .tool.has-report input[type="file"]::file-selector-button:hover { background: var(--raised); border-color: var(--text); }

button.quiet { background: transparent; color: var(--text); border: 1px solid transparent; }
button.quiet:hover { background: var(--raised); }

input[type="file"]::file-selector-button { margin-right: var(--s3); }

/* Template's generic button rule is overridden by the classes above; disabled stays readable. */
.actions button:disabled, button:disabled {
  cursor: not-allowed; box-shadow: none;
  background: var(--raised); color: var(--muted); border: 1px solid var(--border);
}
.tool:not(.has-report) .actions button.primary { background: var(--raised); color: var(--muted); border-color: var(--border); box-shadow: none; }
.tool.has-report .actions button.primary:disabled { background: var(--raised); color: var(--muted); border-color: var(--border); }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin: var(--s4) 0 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; box-shadow: var(--ring); }
input[type="file"]:focus-visible { border-radius: var(--r-m); }

/* Progress */
.progress { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); margin-top: var(--s4); }
.progress[hidden] { display: none; }
.progress progress {
  flex: 1 1 12rem; height: 8px; appearance: none; -webkit-appearance: none;
  border: 0; border-radius: 99px; background: var(--raised); overflow: hidden;
}
.progress progress::-webkit-progress-bar { background: var(--raised); border-radius: 99px; }
.progress progress::-webkit-progress-value { background: var(--accent); border-radius: 99px; }
.progress progress::-moz-progress-bar { background: var(--accent); border-radius: 99px; }
.progress-text { font-size: var(--text-sm); font-variant-numeric: tabular-nums; min-width: 11ch; }

/* Status */
#status { min-height: 1.6em; margin: var(--s3) 0 0; font-size: var(--text-sm); font-weight: 600; font-variant-numeric: tabular-nums; }
#status.ok { color: var(--success); }
#status.error { color: var(--danger); }

/* Batch summary */
.batch-summary { margin-top: var(--s4); padding-top: var(--s4); border-top: 1px solid var(--border); }
.counts { display: flex; flex-wrap: wrap; gap: var(--s2); margin: 0 0 var(--s3); }
.count {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: var(--s1) var(--s3); border-radius: 99px;
  background: var(--raised); color: var(--text); font-size: var(--text-sm);
}
.count b { font-variant-numeric: tabular-nums; font-size: var(--text-md); }
.count.ok { background: var(--success-tint); color: var(--success); }
.count.bad { background: var(--danger-tint); color: var(--danger); }
.rejects { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.rejects li {
  max-width: none; margin: 0;
  display: grid; gap: 2px;
  padding: var(--s3) var(--s4);
  border-radius: var(--r-m);
  background: var(--danger-tint);
  border-left: 4px solid var(--danger);
}
.rejects .file { font-weight: 600; overflow-wrap: anywhere; }
.rejects .reason { color: var(--danger); font-weight: 600; font-size: var(--text-sm); }
.rejects .fix { font-size: var(--text-sm); color: var(--text); }

/* Empty state */
.empty-state {
  margin-top: var(--s4);
  padding: var(--s5);
  border-radius: var(--r-m);
  background: var(--bg);
  color: var(--muted);
}
.empty-state strong { display: block; color: var(--text); font-size: var(--text-md); margin-bottom: var(--s1); }
.empty-state p { margin: 0; font-size: var(--text-sm); }

/* ---------- Report ---------- */
#output:focus { outline: none; }
.report { margin-top: var(--s5); animation: report-in 180ms var(--ease) both; }
@keyframes report-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.report-head { padding-bottom: var(--s4); border-bottom: 2px solid var(--text); }
.report-kicker { margin: 0; color: var(--accent); }
.report h2 { font-size: var(--text-xl); margin: var(--s1) 0 var(--s2); }
.report-meta { margin: 0; display: flex; flex-wrap: wrap; gap: var(--s1) var(--s4); font-size: var(--text-sm); color: var(--muted); font-variant-numeric: tabular-nums; }
.report-meta time { font-family: var(--font-mono); color: var(--text); }
.coverage { margin: var(--s3) 0 0; font-weight: 600; }

.report-rejects {
  margin-top: var(--s5); padding: var(--s3) var(--s4);
  border-radius: var(--r-m); background: var(--warning-tint);
  border-left: 4px solid var(--warning);
}
.report-rejects h3 { margin: 0 0 var(--s1); color: var(--warning); font-size: var(--text-sm); text-transform: uppercase; letter-spacing: 0.08em; }
.report-rejects ul { margin: 0; padding: 0; list-style: none; font-size: var(--text-sm); }
.report-rejects li { margin: 2px 0; max-width: none; }
.report-rejects .file { font-weight: 600; margin-right: var(--s2); overflow-wrap: anywhere; }

.host { margin-top: var(--s6); }
.host-name {
  display: flex; align-items: baseline; gap: var(--s3); flex-wrap: wrap;
  margin: 0 0 var(--s3); padding-bottom: var(--s2);
  border-bottom: 1px solid var(--border);
  font-size: var(--text-lg);
}
.account { margin: var(--s4) 0 0; padding-left: var(--s4); }
.account-name { display: flex; align-items: baseline; gap: var(--s3); flex-wrap: wrap; margin: 0 0 var(--s3); font-size: var(--text-md); font-weight: 650; }
.host-name .label, .account-name .label { color: var(--muted); font-family: var(--font-ui); }
.host-name .mono, .account-name .mono { overflow-wrap: anywhere; }

/* Capture card with the signature reference tab */
.capture {
  position: relative;
  margin: 0 0 var(--s4) var(--s5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 var(--r-m) var(--r-m) var(--r-m);
}
.capture-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s4);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--border);
  background: var(--raised);
  border-radius: 0 var(--r-m) 0 0;
}
.ref {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2.6em; padding: 2px var(--s2);
  font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 700;
  background: var(--accent); color: var(--on-accent);
  font-variant-numeric: tabular-nums;
}
.capture > .capture-head > .ref {
  position: absolute; top: -1px; right: 100%;
  min-height: 32px; border-radius: var(--r-s) 0 0 var(--r-s);
}
.capture-head .file { flex: 1 1 14rem; font-weight: 600; overflow-wrap: anywhere; }
.date-field { display: grid; gap: 2px; flex: 0 1 13rem; }
.date-field label { color: var(--muted); }
.date-field input {
  font: inherit; font-family: var(--font-mono); font-size: var(--text-sm);
  min-height: 44px; width: 100%; padding: 0 var(--s3);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-s);
  font-variant-numeric: tabular-nums;
  transition: border-color var(--fast) var(--ease);
}
.date-field input:hover { border-color: var(--text); }
.date-field input::placeholder { color: var(--muted); opacity: 1; }
.date-error:empty { min-height: 0; }
.date-error { min-height: 1.4em; margin: 0; font-size: var(--text-xs); color: var(--danger); font-weight: 600; max-width: 26ch; }
.date-field.invalid input { border: 2px solid var(--danger); background: var(--danger-tint); }
.date-value { display: none; margin: 0; }

.privs { width: 100%; border-collapse: collapse; font-size: var(--text-sm); table-layout: fixed; }
.privs th {
  text-align: left; padding: var(--s2) var(--s4);
  font-size: var(--text-xs); font-weight: 650; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); border-bottom: 1px solid var(--border);
}
.privs th:first-child { width: 30%; }
.privs td {
  padding: var(--s2) var(--s4); vertical-align: top;
  font-family: var(--font-mono); line-height: 1.5;
  white-space: pre-wrap; overflow-wrap: anywhere;
  border-bottom: 1px solid var(--border);
}
.privs tr:last-child td { border-bottom: 0; }
.privs tbody tr:nth-child(even) td { background: var(--bg); }

/* Source appendix */
.appendix { margin-top: var(--s7); padding-top: var(--s4); border-top: 2px solid var(--text); }
.appendix h3 { font-size: var(--text-lg); margin: 0; }
.appendix-note { margin: var(--s1) 0 var(--s4); color: var(--muted); font-size: var(--text-sm); }
.source { margin: 0 0 var(--s4); border: 1px solid var(--border); border-radius: var(--r-m); overflow: hidden; background: var(--surface); }
.source figcaption { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s4) var(--s2) 0; background: var(--raised); border-bottom: 1px solid var(--border); }
.source figcaption .ref { min-height: 28px; border-radius: 0 var(--r-s) var(--r-s) 0; }
.source figcaption .file { font-weight: 600; overflow-wrap: anywhere; }
.source pre {
  margin: 0; padding: var(--s3) var(--s4);
  font-family: var(--font-mono); font-size: 0.875rem; line-height: 1.55;
  white-space: pre-wrap; overflow-wrap: anywhere; tab-size: 8;
}

/* ---------- Reading section, ad slot, consent, footer ---------- */
main > h2 { padding-top: var(--s2); }
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); border-radius: var(--r-l); }
.ad-label { color: var(--muted); opacity: 1; font-size: var(--text-xs); letter-spacing: 0.06em; text-transform: uppercase; }
.house-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-m); transition: border-color var(--fast) var(--ease); }
.house-card:hover { border-color: var(--accent); }
.house-card strong { color: var(--accent); }
.consent { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--r-l); box-shadow: var(--shadow-2); }
.consent button { border-color: var(--border-strong); color: var(--text); background: var(--surface); }
.consent button:hover { background: var(--raised); }
footer { opacity: 1; color: var(--muted); border-top: 1px solid var(--border); padding-top: var(--s5); padding-bottom: var(--s6); }
footer a { color: var(--muted); }
footer a:hover { color: var(--text); }

/* ---------- Phone ---------- */
@media (max-width: 40rem) {
  header, main, footer { padding-left: var(--s4); padding-right: var(--s4); }
  .tool { padding: var(--s4); border-radius: var(--r-m); }
  .drop-title { font-size: var(--text-md); }
  .dropzone input[type="file"] { width: 100%; }
  .actions { flex-direction: column; align-items: stretch; }
  .actions button { width: 100%; }
  .account { padding-left: 0; }
  .capture { margin-left: 34px; }
  .date-field { flex-basis: 100%; }
  .date-error { max-width: none; }
  .privs th:first-child { width: 34%; }
  .privs th, .privs td { padding-left: var(--s3); padding-right: var(--s3); }
}

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

/* ---------- Print: the report only ---------- */
@media print {
  @page { margin: 16mm; }
  :root {
    --bg: #ffffff; --surface: #ffffff; --raised: #ffffff;
    --text: #000000; --muted: #333333; --border: #999999;
    --accent: #000000; --on-accent: #000000;
    --warning: #000000; --warning-tint: #ffffff;
  }
  body { background: #fff; color: #000; font-size: 10.5pt; line-height: 1.4; }
  /* Tracked text prints as separate letters in a PDF, which breaks search and copy. */
  *, *::before, *::after { letter-spacing: 0 !important; }
  body > header, footer, .consent, .ad-slot,
  main > :not(.tool),
  .dropzone, .progress, .actions, #status, #batch, .empty-state,
  .date-field { display: none !important; }
  main { max-width: none; padding: 0; margin: 0; }
  .tool { border: 0; box-shadow: none; padding: 0; background: none; }
  .report { margin: 0; animation: none; }
  .report h2 { font-size: 18pt; }
  .report-meta, .report-meta time { color: #000; }
  .date-value { display: block; flex: 0 0 auto; padding-top: 10px; }
  .capture { border-color: #999; margin-left: 0; break-inside: auto; border-radius: 0; }
  .capture-head { background: none; break-inside: avoid; break-after: avoid; border-radius: 0; }
  .capture > .capture-head > .ref, .ref {
    position: static; background: #fff; color: #000; border: 1.5px solid #000; border-radius: 0; min-height: 0;
  }
  .host-name, .account-name { break-after: avoid; }
  .privs tr { break-inside: avoid; }
  .privs tbody tr:nth-child(even) td { background: none; }
  .report-rejects { border: 1px solid #000; border-left-width: 4px; break-inside: avoid; }
  .appendix { break-before: page; margin-top: 0; }
  .source { border-color: #999; border-radius: 0; break-inside: auto; }
  .source figcaption { background: none; padding-left: var(--s2); break-after: avoid; }
  .source pre { font-size: 9pt; white-space: pre-wrap; overflow-wrap: anywhere; }
  a { color: #000; }
}
