/* NCR Workbench - one stylesheet, themed via [data-theme] set by theme.js. */

:root, [data-theme="light"] {
  --bg: #f4f5f8;
  --bg2: #ffffff;
  --ink: #171c26;
  --muted: #5f6a7c;
  --line: #dbdfe8;
  --accent: #1f6f6b;
  --accent-ink: #ffffff;
  --good: #2c7a44;
  --mid: #a06a10;
  --bad: #b03434;
  --quote-bg: #eef0f4;
  --shadow: 0 1px 2px rgba(23, 28, 38, 0.06), 0 8px 24px rgba(23, 28, 38, 0.05);
}
[data-theme="dark"] {
  --bg: #101318;
  --bg2: #171c24;
  --ink: #e6e9ee;
  --muted: #96a0b0;
  --line: #2a3140;
  --accent: #7cc6c0;
  --accent-ink: #101520;
  --good: #6cc389;
  --mid: #d9a94a;
  --bad: #e08484;
  --quote-bg: #1f2530;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.82em; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.hidden { display: none !important; }
.good { color: var(--good); }
.mid { color: var(--mid); }
.bad { color: var(--bad); }
button { font: inherit; cursor: pointer; }
a { color: var(--accent); }

/* --- Header ------------------------------------------------------------- */
header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  flex-wrap: wrap;
  padding: 18px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  background: var(--bg2);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .mark { width: 38px; height: 38px; color: var(--accent); flex: none; }
.brand h1 { margin: 0; font-size: 1.25rem; letter-spacing: -0.01em; }
.tagline { margin: 2px 0 0; font-size: 0.82rem; color: var(--muted); }
.session { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.home-link {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--muted); text-decoration: none; font-size: 0.85rem;
}
.home-link svg { width: 14px; height: 14px; }
.home-link:hover { color: var(--ink); }
.ghost {
  background: none; border: 1px solid var(--line); color: var(--ink);
  border-radius: 8px; padding: 6px 12px; font-size: 0.85rem;
}
.ghost:hover { border-color: var(--muted); }
.theme-toggle::before { content: "\2600"; }
[data-theme="dark"] .theme-toggle::before { content: "\263D"; }
.credits { font-size: 0.85rem; color: var(--muted); }
.topup { font-size: 0.85rem; }

/* --- Layout ------------------------------------------------------------- */
main { max-width: 1000px; margin: 0 auto; padding: 28px clamp(16px, 4vw, 40px) 60px; }
.klabel {
  display: inline-block;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 8px;
}
.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.doc-field { margin-bottom: 4px; }
.ctx-field { margin-top: 22px; }

.card { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
textarea, input[type="text"], select {
  width: 100%; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg2); color: var(--ink);
  padding: 10px 12px; font: inherit;
}
textarea {
  border: none; resize: vertical; display: block; border-radius: 12px;
  font-size: 0.92rem; white-space: pre-wrap; overflow-wrap: break-word;
}
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.actions { display: flex; align-items: center; gap: 14px; margin-top: 22px; flex-wrap: wrap; }
.primary {
  background: var(--accent); color: var(--accent-ink);
  border: none; border-radius: 10px; padding: 10px 18px; font-weight: 600;
}
.primary:hover { filter: brightness(1.08); }
.primary:disabled { opacity: 0.55; cursor: default; }
.big { padding: 12px 22px; font-size: 1rem; border-radius: 12px; }
button.big:not(.primary) { background: none; border: 1px solid var(--line); color: var(--ink); }
.meter { font-size: 0.8rem; color: var(--muted); }
.linkish { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; }

/* --- Number scan (free lane) ---------------------------------------------- */
.scan-panel {
  margin-top: 22px; padding: 16px 18px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
}
.lint-list { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 7px; }
.lint { font-size: 0.85rem; padding-left: 18px; position: relative; }
.lint::before { position: absolute; left: 0; top: 0; }
.lint.good::before { content: "\2713"; }
.lint.mid::before { content: "\26A0"; }
.lint.bad::before { content: "\2717"; }
.lint .lint-detail { display: block; color: var(--muted); font-size: 0.8rem; }
.lint .lint-where { color: var(--muted); font-size: 0.78rem; margin-left: 6px; }
.quick-note { margin: 14px 0 0; }

/* --- Progress -------------------------------------------------------------- */
.progress-panel { margin-top: 26px; padding: 18px; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; }
.pp-top { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.pp-bar { flex: 1; min-width: 120px; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.pp-fill { height: 100%; width: 40%; background: var(--accent); border-radius: 2px; animation: slide 1.4s ease-in-out infinite; }
.finished .pp-fill { animation: none; width: 100%; }
@keyframes slide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }
.live-output {
  margin: 14px 0 0; padding: 12px 14px; max-height: 340px; overflow-y: auto;
  background: var(--quote-bg); border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted);
}

/* --- Result ---------------------------------------------------------------- */
.result { margin-top: 30px; display: grid; gap: 18px; }
.verdict-zone { padding: 20px; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.verdict-top { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.verdict-badge {
  display: inline-block; padding: 4px 14px; border-radius: 999px;
  font-size: 0.9rem; font-weight: 700; letter-spacing: 0.01em;
  border: 1.5px solid currentColor;
}
.verdict-badge.good { color: var(--good); }
.verdict-badge.mid { color: var(--mid); }
.verdict-badge.bad { color: var(--bad); }
.conf-badge { font-size: 0.82rem; }
.tally { font-size: 0.8rem; color: var(--muted); }
.summary { margin: 14px 0 0; font-size: 1rem; overflow-wrap: anywhere; }
.consistency-note {
  margin-top: 12px; padding: 10px 14px; border-radius: 8px; font-size: 0.85rem;
  border: 1px solid var(--mid); color: var(--mid);
}
.dl-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.trunc-note {
  margin-top: 14px; padding: 10px 14px; border-radius: 8px; font-size: 0.88rem;
  border: 1px solid var(--bad); color: var(--bad);
}
.trunc-note a { color: inherit; font-weight: 700; margin-left: 6px; }

.paper {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: clamp(18px, 4vw, 34px);
  font-size: 0.97rem; overflow-wrap: anywhere;
}
.paper > :first-child { margin-top: 0; }
.paper-h { margin: 0 0 14px; font-size: 1.02rem; line-height: 1.3; }
.paper code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.86em;
  background: var(--quote-bg); border-radius: 4px; padding: 1px 5px;
}
.markdown-paper {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem; white-space: pre-wrap; margin: 0;
  max-height: 620px; overflow-y: auto;
}

/* Pitfall grid (rendered by report.js) */
.pf-grid { display: grid; gap: 12px; }
.pf-row { display: flex; gap: 12px; align-items: baseline; }
.pf-status {
  flex: none; display: inline-block; min-width: 64px; text-align: center;
  padding: 2px 8px; border-radius: 999px;
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.05em;
  border: 1px solid currentColor;
}
.pf-status.good { color: var(--good); }
.pf-status.mid { color: var(--mid); }
.pf-status.bad { color: var(--bad); }
.pf-body { min-width: 0; }
.pf-name { font-weight: 600; font-size: 0.95rem; }
.pf-evidence { color: var(--muted); font-size: 0.88rem; margin-top: 2px; }

/* Prose sections (rendered by report.js) */
.rsec { margin: 0 0 6px; }
.rsec h3 { margin: 1.3em 0 0.5em; font-size: 1.02rem; line-height: 1.3; }
.rsec:first-child h3 { margin-top: 0; }
.rsec-list { margin: 0.5em 0; padding-left: 1.3em; }
.rsec-list li { margin: 0.35em 0; }
.calc-list { list-style: none; margin: 0.5em 0; padding: 0; display: grid; gap: 8px; }
.calc { display: flex; gap: 10px; align-items: baseline; }
.calc-status {
  flex: none; display: inline-block; min-width: 44px; text-align: center;
  padding: 1px 7px; border-radius: 999px;
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.05em;
  border: 1px solid currentColor;
}
.calc-text { min-width: 0; font-size: 0.92rem; }

.run-meta { font-size: 0.78rem; color: var(--muted); }

.raw-result { margin-top: 26px; }
.raw-output {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px; white-space: pre-wrap; font-family: ui-monospace, Menlo, monospace;
  font-size: 0.82rem; overflow-x: auto;
}

/* --- How it works ---------------------------------------------------------- */
.how { margin-top: 44px; }
.how-lead { color: var(--muted); }
.how-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 780px) { .how-grid { grid-template-columns: 1fr; } }
.how-step { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
.step-n {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 0.85rem;
}
.how-step h3 { margin: 10px 0 6px; font-size: 1rem; }
.how-step p { margin: 0; font-size: 0.88rem; color: var(--muted); }

/* --- Footer / toasts -------------------------------------------------------- */
footer {
  max-width: 1000px; margin: 0 auto; padding: 22px clamp(16px, 4vw, 40px) 40px;
  font-size: 0.82rem; color: var(--muted);
  display: flex; gap: 10px; flex-wrap: wrap;
}
footer a { color: var(--muted); }
footer a:hover { color: var(--ink); }
.foot-sep { user-select: none; }

.toasts { position: fixed; bottom: 20px; right: 20px; display: grid; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 40px)); }
.toast {
  background: var(--ink); color: var(--bg); border-radius: 10px;
  padding: 10px 14px; font-size: 0.88rem; box-shadow: var(--shadow);
  transition: opacity 0.5s, transform 0.5s;
}
.toast a { color: inherit; font-weight: 700; margin-left: 8px; }
.toast.err { background: var(--bad); color: #fff; }
.toast.gone { opacity: 0; transform: translateY(6px); }

/* --- NCR Workbench additions ------------------------------------------------ */
.spec-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-top: 10px;
}
.spec-row input[type="text"] {
  width: 110px; flex: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85rem;
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
}
.verdict-badge + .verdict-badge { margin-left: 0; }

/* Raise Ready additions */
.asset-card { padding: 10px 12px; }
.asset-card select { width: 100%; border: none; background: transparent; }
.asset-card select:focus { outline: none; }
.asset-h { margin: 1.2em 0 0.4em; font-size: 1.02rem; line-height: 1.3; }
h4.asset-h { font-size: 0.94rem; }
.paper > h3.asset-h:first-child { margin-top: 0; }
.asset-p { margin: 0.55em 0; font-size: 0.95rem; overflow-wrap: anywhere; }

/* --- Credit preflight -------------------------------------------------------- */
.shortfall {
  margin-top: 10px; padding: 10px 14px; border-radius: 10px;
  background: color-mix(in srgb, var(--bad) 12%, var(--bg2));
  border: 1px solid color-mix(in srgb, var(--bad) 40%, var(--line));
  font-size: 0.88rem; color: var(--ink);
}
.shortfall a { color: var(--bad); font-weight: 700; }

/* --- Staged progress --------------------------------------------------------- */
.elapsed { color: var(--muted); font-size: 0.82rem; min-width: 3.5em; text-align: right; }
.stage-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; }
.stage { display: flex; align-items: center; gap: 10px; font-size: 0.86rem; color: var(--muted); }
.stage-dot {
  width: 9px; height: 9px; border-radius: 50%; flex: none;
  border: 1.5px solid var(--line); background: transparent;
}
.stage.active { color: var(--ink); font-weight: 600; }
.stage.active .stage-dot { border-color: var(--accent); background: var(--accent); }
.stage.done { color: var(--ink); }
.stage.done .stage-dot { border-color: var(--good); background: var(--good); }
.stage.failed .stage-dot { border-color: var(--bad); background: var(--bad); }
.stage.failed { color: var(--bad); }

/* --- Per-chunk copy ---------------------------------------------------------- */
.asset-chunk { margin: 0 0 0.4em; }
.chunk-head { display: flex; align-items: baseline; gap: 10px; justify-content: space-between; }
.chunk-head h3 { flex: 1; min-width: 0; }
.chunk-copy {
  flex: none; font-size: 0.72rem; padding: 3px 9px; border-radius: 7px;
  opacity: 0; transition: opacity 0.15s;
}
.chunk-head:hover .chunk-copy, .chunk-copy:focus { opacity: 1; }
@media (hover: none) { .chunk-copy { opacity: 1; } }

/* --- Checklists -------------------------------------------------------------- */
.checklist { list-style: none; padding-left: 0; }
.check-item { display: flex; gap: 10px; align-items: flex-start; margin: 0.35em 0; }
.check-box { margin-top: 0.25em; flex: none; accent-color: var(--accent); }
.check-text { flex: 1; min-width: 0; }
.check-item.done .check-text { text-decoration: line-through; color: var(--muted); }

/* --- Placeholders ------------------------------------------------------------ */
.ph-panel {
  margin: 16px 0; padding: 14px 16px; border-radius: 12px;
  background: var(--bg2); border: 1px solid color-mix(in srgb, var(--mid) 35%, var(--line));
  box-shadow: var(--shadow);
}
.ph-list { list-style: none; margin: 10px 0; padding: 0; display: grid; gap: 12px; }
.ph-item { display: grid; gap: 5px; padding-left: 12px; border-left: 3px solid var(--mid); }
.ph-item.filled { border-left-color: var(--good); }
.ph-token { font-size: 0.85rem; color: var(--mid); font-weight: 700; }
.ph-item.filled .ph-token { color: var(--good); }
.ph-context { margin: 0; }
.ph-input {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
  font-size: 0.88rem; background: var(--bg); color: var(--ink); max-width: 460px;
}
.ph-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.ok-text { color: var(--good); }
.warn-text { color: var(--mid); }

/* --- Diff -------------------------------------------------------------------- */
.diff-panel {
  margin: 16px 0; padding: 14px 16px; border-radius: 12px;
  background: var(--bg2); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.diff-summary { margin: 8px 0 12px; font-size: 0.9rem; }
.diff-lines {
  font-size: 0.78rem; line-height: 1.55; border-radius: 8px;
  background: var(--quote-bg); padding: 10px 12px;
  max-height: 340px; overflow: auto;
}
.diff-line { white-space: pre-wrap; overflow-wrap: anywhere; padding: 0 4px; border-radius: 3px; }
.d-add { background: color-mix(in srgb, var(--good) 20%, transparent); color: var(--ink); }
.d-del { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--ink); }
.d-ctx { color: var(--muted); }
.d-skip { color: var(--muted); font-style: italic; opacity: 0.75; }

/* --- History ----------------------------------------------------------------- */
.hist-panel {
  margin: 16px 0; padding: 14px 16px; border-radius: 12px;
  background: var(--bg2); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.hist-list { list-style: none; margin: 10px 0; padding: 0; display: grid; gap: 6px; }
.hist-item { display: flex; gap: 8px; align-items: center; }
.hist-item.current .hist-open { border-color: var(--accent); }
.hist-open {
  flex: 1; min-width: 0; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap;
  text-align: left; padding: 8px 12px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  cursor: pointer; font: inherit; font-size: 0.86rem;
}
.hist-open:hover { border-color: var(--accent); }
.hist-asset { font-weight: 700; }
.hist-verdict { font-size: 0.76rem; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); }
.hist-verdict.good { color: var(--good); border-color: var(--good); }
.hist-verdict.mid { color: var(--mid); border-color: var(--mid); }
.hist-verdict.bad { color: var(--bad); border-color: var(--bad); }
.hist-label { color: var(--muted); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-when { color: var(--muted); font-size: 0.74rem; }
.hist-del { flex: none; font-size: 0.74rem; padding: 4px 9px; }
button.small { font-size: 0.74rem; padding: 4px 9px; }

/* --- Print: the asset alone, which is what actually gets sent ---------------- */
@media print {
  header, footer, form, #historyPanel, #progressPanel, #factPanel,
  #sectionsWrap, #phPanel, #crossPanel, #diffPanel, #rawResult, .how,
  .dl-actions, .toasts, .verdict-zone, #runMeta, #reportSource, .chunk-copy {
    display: none !important;
  }
  html, body { background: #fff; color: #000; }
  main { max-width: none; padding: 0; margin: 0; }
  #result { display: block !important; }
  #assetWrap {
    display: block !important; box-shadow: none; border: none;
    padding: 0; margin: 0; background: #fff; color: #000;
    font-size: 11pt; line-height: 1.45;
  }
  .asset-h { page-break-after: avoid; break-after: avoid; color: #000; }
  .asset-chunk { page-break-inside: avoid; break-inside: avoid; }
  .asset-p, .rsec-list li { orphans: 3; widows: 3; }
  a[href]::after { content: ""; }
  @page { margin: 18mm; }
}
