/* Spec Desk — one stylesheet, both themes, no external fonts.
 *
 * The theme is set on <html> by theme.js before first paint (the app CSP has no
 * 'unsafe-inline' for scripts, so it cannot be an inline tag). Light is the bare
 * :root default so a document rendered before theme.js runs is still legible;
 * [data-theme="dark"] is the override.
 *
 * The accent is a single indigo family in both themes, and every state that
 * matters — a readiness verdict, a placement bucket, a reconciliation note —
 * carries a word as well as a colour, so nothing here depends on hue alone. */

:root,
:root[data-theme="light"] {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel2: #eef2f8;
  --ink: #161d2b;
  --muted: #5a6478;
  --line: #dde3ee;
  --accent: #4338ca;
  --accent-ink: #ffffff;
  --ok: #1c7a4d;
  --ok-bg: #edf8f2;
  --warn: #96650a;
  --warn-bg: #fdf7e9;
  --red: #c02b34;
  --red-bg: #fdf1f2;
  --code-bg: #eef1f7;
  --shadow: 0 1px 3px rgba(18, 30, 50, 0.08);
  --mono-font: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg: #0d111c;
  --panel: #161d2c;
  --panel2: #1d2637;
  --ink: #e6ecf7;
  --muted: #96a2b8;
  --line: #28324a;
  --accent: #a5b4fc;
  --accent-ink: #12162a;
  --ok: #6fce9e;
  --ok-bg: #142520;
  --warn: #e2b662;
  --warn-bg: #272115;
  --red: #f08c8c;
  --red-bg: #291b1d;
  --code-bg: #202a3d;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html { font-size: 16px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.55;
}

code, pre, .mono { font-family: var(--mono-font); }
.mono { font-size: 0.85em; }
.small { font-size: 0.85rem; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

a { color: var(--accent); }
a:hover { text-decoration: underline; }

/* --- Header --------------------------------------------------------------- */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.9rem 1.4rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand .mark { width: 34px; height: 34px; color: var(--accent); flex: none; }
.brand h1 { font-size: 1.15rem; margin: 0; }
.brandlink { color: inherit; text-decoration: none; }
.tagline { margin: 0; font-size: 0.82rem; color: var(--muted); max-width: 44ch; }

.session { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.home-link {
  display: inline-flex; align-items: center; gap: 0.3rem;
  color: var(--muted); text-decoration: none; font-size: 0.85rem;
}
.home-link svg { width: 14px; height: 14px; }
.home-link:hover { color: var(--ink); text-decoration: none; }
.credits { color: var(--ok); font-weight: 600; }
.topup { color: var(--accent); font-size: 0.85rem; text-decoration: none; }

/* --- Buttons -------------------------------------------------------------- */

button { font: inherit; cursor: pointer; border-radius: 8px; }
.ghost {
  background: transparent; border: 1px solid var(--line); color: var(--ink);
  padding: 0.35rem 0.8rem; font-size: 0.85rem;
}
.ghost:hover { border-color: var(--accent); }
.ghost.theme-toggle { width: 2.1rem; height: 2.1rem; padding: 0; position: relative; }
.ghost.theme-toggle::after {
  content: "\2600"; font-size: 1rem; position: absolute; inset: 0;
  display: grid; place-items: center;
}
:root[data-theme="dark"] .ghost.theme-toggle::after { content: "\263D"; }

.primary {
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent);
  padding: 0.45rem 1.1rem; font-weight: 600;
}
.primary:hover { filter: brightness(1.08); }
.primary:disabled { opacity: 0.5; cursor: default; filter: none; }
.big { padding: 0.65rem 1.4rem; font-size: 1rem; border-radius: 10px; }
button.big:not(.primary) { background: var(--panel); border: 1px solid var(--line); color: var(--ink); }
button.big:not(.primary):hover { border-color: var(--accent); }
.linkish {
  background: none; border: none; padding: 0; color: var(--accent);
  text-decoration: underline; font-size: inherit;
}

/* --- The lane switcher: this app is a pipeline, so it reads as one --------- */

.lanes {
  border-bottom: 1px solid var(--line);
  background: var(--panel2);
  padding: 0.6rem 1.4rem;
}
.lanes-in {
  max-width: 980px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 0.6rem; flex-wrap: wrap;
}
.lane-stage { display: flex; flex-direction: column; gap: 0.2rem; }
.stage-label {
  font-size: 0.66rem; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted);
}
.lane {
  background: var(--panel); border: 1px solid var(--line); color: var(--ink);
  padding: 0.4rem 1.1rem; font-size: 0.95rem; font-weight: 600;
}
.lane:hover { border-color: var(--accent); }
.lane.active {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}
.lane-arrow { color: var(--muted); padding-bottom: 0.4rem; font-size: 1.05rem; }

/* --- Layout --------------------------------------------------------------- */

main { max-width: 980px; margin: 0 auto; padding: 1.5rem 1.2rem 3rem; }

.hero h1 { font-size: 1.7rem; line-height: 1.25; margin: 0.6rem 0 0.5rem; }
.lede { font-size: 1rem; color: var(--muted); max-width: 74ch; margin: 0 0 0.4rem; }

.klabel {
  display: inline-block; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted);
}
.label-row {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; margin-bottom: 0.35rem; flex-wrap: wrap;
}

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 1.1rem 1.2rem; margin: 1.2rem 0;
}

.field { margin-bottom: 1rem; }
.field > label { display: block; margin-bottom: 0.3rem; }
.hint { margin: 0.35rem 0 0; }

textarea, input[type="text"], input[type="search"], select {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 0.6rem 0.75rem;
}
textarea { resize: vertical; font-size: 0.93rem; line-height: 1.55; display: block; }
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
select { font-size: 0.92rem; }

.dropzone { border: 1px dashed transparent; border-radius: 10px; transition: border-color 0.15s, background 0.15s; }
.dropzone.dragging { border-color: var(--accent); background: var(--panel2); }

.clip-note {
  margin: 0.5rem 0 0; padding: 0.5rem 0.75rem; font-size: 0.87rem;
  border: 1px solid var(--warn); border-left-width: 3px; border-radius: 0 8px 8px 0;
  background: var(--warn-bg); color: var(--ink);
}

.row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }
.row.two label { display: block; font-size: 0.85rem; margin-bottom: 0.25rem; color: var(--muted); }
@media (max-width: 620px) { .row.two { grid-template-columns: 1fr; } }

.actions { display: flex; align-items: center; gap: 0.9rem; margin-top: 1.1rem; flex-wrap: wrap; }
.meter { font-size: 0.8rem; color: var(--muted); flex: 1 1 16rem; }

.run-gate:not(.hidden) {
  display: flex; align-items: center; flex-wrap: wrap; gap: 0.7rem;
  margin-top: 0.8rem; padding: 0.6rem 0.9rem; border-radius: 10px;
  border: 1px solid var(--warn); background: var(--warn-bg); font-size: 0.9rem;
}

/* --- The free in-browser scan --------------------------------------------- */

.prescan {
  margin-top: 1.3rem; padding: 1rem 1.2rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow);
}
.free {
  font-size: 0.66rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ok); background: var(--ok-bg); border: 1px solid var(--ok);
  border-radius: 999px; padding: 0.05rem 0.5rem; margin-left: 0.4rem;
}
.empty { color: var(--muted); font-size: 0.92rem; margin: 0.4rem 0 0; }
.prescan-body { margin-top: 0.6rem; }

.score-head { display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.7rem; }
.score-num { font-size: 2rem; font-weight: 700; line-height: 1; color: var(--accent); }
.score-of { color: var(--muted); font-size: 0.9rem; }

.ps-grid { display: grid; gap: 0.4rem; }
.ps-item {
  display: grid; grid-template-columns: 3rem 13rem 1fr; align-items: baseline; gap: 0.6rem;
  border: 1px solid var(--line); border-left-width: 4px; border-radius: 8px;
  padding: 0.45rem 0.75rem; background: var(--panel2);
}
@media (max-width: 700px) { .ps-item { grid-template-columns: 3rem 1fr; } .ps-item .ps-why { grid-column: 1 / -1; } }
.ps-item.sig-on { border-left-color: var(--ok); }
.ps-item.sig-off { border-left-color: var(--warn); }
.ps-mark {
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
}
.ps-item.sig-on .ps-mark { color: var(--ok); }
.ps-item.sig-off .ps-mark { color: var(--warn); }
.ps-label { font-weight: 600; font-size: 0.92rem; }
.ps-why { color: var(--muted); font-size: 0.86rem; }
.ps-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.5rem 0 0.4rem; }
.ps-sections { font-size: 0.88rem; color: var(--muted); margin: 0.7rem 0 0; }

.rm-facts { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: 0.8rem; }
.rm-items { list-style: none; margin: 0.5rem 0 0; padding: 0; display: grid; gap: 0.25rem; }
.rm-items li { font-size: 0.88rem; }
.rm-bucket {
  display: inline-block; min-width: 5.2rem; font-family: var(--mono-font); font-size: 0.75rem;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em;
}

.chip {
  display: inline-block; border: 1px solid var(--line); background: var(--panel);
  border-radius: 999px; padding: 0.08rem 0.6rem; font-size: 0.78rem; white-space: nowrap;
}
.chip-ok, .chip-pass { color: var(--ok); border-color: var(--ok); background: var(--ok-bg); }
.chip-warn { color: var(--warn); border-color: var(--warn); background: var(--warn-bg); }
.chip-bad { color: var(--red); border-color: var(--red); background: var(--red-bg); }

/* --- Staged progress ------------------------------------------------------ */

.progress-panel {
  margin-top: 1.4rem; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 1rem 1.2rem; box-shadow: var(--shadow);
}
.pp-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.steps { list-style: none; margin: 0.8rem 0 0; padding: 0; display: grid; gap: 0.45rem; }
.step { display: flex; align-items: center; gap: 0.6rem; font-size: 0.92rem; color: var(--muted); }
.step-ic { width: 0.85rem; height: 0.85rem; border-radius: 50%; border: 2px solid var(--line); flex: none; }
.step-label { flex: 1 1 auto; }
.step-time { color: var(--muted); font-size: 0.78rem; }
.step.live { color: var(--ink); }
.step.live .step-ic { border-color: var(--accent); animation: pulse 1.2s infinite; }
.step.done { color: var(--ink); }
.step.done .step-ic { background: var(--ok); border-color: var(--ok); }
@keyframes pulse { 50% { transform: scale(1.25); } }

/* --- The result ----------------------------------------------------------- */

.result { margin-top: 1.6rem; display: grid; gap: 1.1rem; }
.res-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.res-head h2 { margin: 0.15rem 0 0.3rem; font-size: 1.35rem; }
.res-meta { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.verdict { margin: 0.3rem 0 0; color: var(--muted); max-width: 60ch; }
.verdict-line { margin: 0 0 0.5rem; display: flex; gap: 0.4rem; flex-wrap: wrap; }

.partial:not(.hidden), .reconcile:not(.hidden) {
  display: block; padding: 0.7rem 0.95rem; border-radius: 10px; font-size: 0.92rem;
}
.partial:not(.hidden) { border: 1px solid var(--warn); background: var(--warn-bg); }
.reconcile:not(.hidden) { border: 1px solid var(--red); background: var(--red-bg); }
.reconcile ul { margin: 0.5rem 0 0.5rem; padding-left: 1.2rem; }
.reconcile li { margin: 0.2rem 0; }
.reconcile .ps-why { margin: 0; }

.summary-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 0.9rem 1.1rem; box-shadow: var(--shadow); margin-bottom: 0.9rem;
}
.summary-card p { margin: 0.5rem 0 0; }
.summary-card > .klabel + * { margin-top: 0.45rem; }

.plain-list { margin: 0.4rem 0 0; padding-left: 1.2rem; display: grid; gap: 0.3rem; }
.plain-list li { font-size: 0.94rem; }
.ac-ref { color: var(--accent); font-weight: 700; }

.fix-list { margin: 0.5rem 0 0; padding-left: 0; list-style: none; display: grid; gap: 0.4rem; }
.fix-list li {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
  padding: 0.5rem 0.8rem; font-size: 0.92rem;
}
.fix-list li.muted { background: transparent; border-style: dashed; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; margin-top: 0.5rem; }
.data-table { width: 100%; border-collapse: collapse; min-width: 34rem; font-size: 0.9rem; }
.data-table thead th {
  text-align: left; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted); padding: 0.55rem 0.8rem;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.data-table td { padding: 0.5rem 0.8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table tbody tr:last-child td { border-bottom: none; }

.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.7rem; margin-top: 0.5rem; }
@media (max-width: 760px) { .board { grid-template-columns: 1fr; } }
.board-col { border: 1px solid var(--line); border-radius: 10px; padding: 0.6rem 0.8rem; background: var(--panel2); }
.board-head {
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 0.35rem;
}
.board-col .plain-list { padding-left: 1.1rem; }

.subject-line { font-size: 1.05rem; font-weight: 600; margin: 0.3rem 0 0; }
.update-body {
  margin: 0.5rem 0 0; padding: 0.9rem 1rem; background: var(--code-bg);
  border: 1px solid var(--line); border-radius: 10px;
  font-family: var(--mono-font); font-size: 0.85rem; line-height: 1.65;
  white-space: pre-wrap; word-break: break-word; max-height: 34rem; overflow: auto;
}

.handoffs { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.dl-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.raw-result {
  margin-top: 1.4rem; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 1rem 1.2rem; box-shadow: var(--shadow);
}
.raw-output {
  margin: 0.5rem 0; padding: 0.8rem; background: var(--code-bg); border: 1px solid var(--line);
  border-radius: 8px; font-size: 0.78rem; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word; max-height: 28rem; overflow: auto;
}

/* --- History and the explainer sections ----------------------------------- */

.how { margin-top: 2.2rem; }
.how-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; margin-top: 0.8rem; }
@media (max-width: 720px) { .how-grid { grid-template-columns: 1fr; } }
.how-step { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.1rem; }
.how-step h3 { margin: 0 0 0.35rem; font-size: 0.98rem; }
.how-step p { margin: 0; font-size: 0.88rem; color: var(--muted); }

.history-tools { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin: 0.6rem 0; }
.history-tools input[type="search"] { flex: 1 1 20rem; }
.history-tools select { flex: 0 0 auto; width: auto; }
.history-list { list-style: none; margin: 0.6rem 0 0; padding: 0; display: grid; gap: 0.5rem; }
.hist-item {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 0.6rem 0.85rem;
}
.hist-head { display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }
.hist-title { font-weight: 600; }
.hist-meta { margin-top: 0.15rem; }
.hist-restore { margin-top: 0.5rem; }

/* --- Footer and toasts ---------------------------------------------------- */

footer {
  border-top: 1px solid var(--line); padding: 1.2rem 1.4rem;
  text-align: center; font-size: 0.85rem; color: var(--muted);
}
footer a { color: var(--muted); }
footer span { display: inline; }
.foot-sep { margin: 0 0.5rem; }

.toasts {
  position: fixed; bottom: 1rem; right: 1rem; display: grid; gap: 0.5rem;
  z-index: 50; max-width: min(420px, 90vw);
}
.toast {
  background: var(--panel); border: 1px solid var(--line); border-left-width: 4px;
  border-radius: 10px; padding: 0.6rem 0.9rem; box-shadow: 0 6px 22px rgba(0, 0, 0, 0.25);
  font-size: 0.9rem; transition: opacity 0.5s;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--red); }
.toast.gone { opacity: 0; }
.toast a { color: var(--accent); margin-left: 0.4rem; }

/* --- Small screens and print ---------------------------------------------- */

@media (max-width: 620px) {
  .hero h1 { font-size: 1.4rem; }
  main { padding: 1.1rem 0.9rem 2.5rem; }
  header { padding: 0.7rem 0.9rem; }
  .lanes { padding: 0.5rem 0.9rem; }
  .lane-arrow { display: none; }
}

@media print {
  header, .lanes, form, .prescan, .progress-panel, .how, .toasts, .dl-actions, .handoffs, footer {
    display: none !important;
  }
  body { background: #fff; color: #000; }
  .result { display: grid !important; }
  .summary-card, .table-wrap { break-inside: avoid; box-shadow: none; }
}

