/* Legal Inbox — theme via [data-theme] on <html>, set by theme.js before paint. */

:root[data-theme="light"] {
  --bg: #f6f7f9; --panel: #ffffff; --ink: #1a2130; --muted: #5c6675;
  --line: #dde2e9; --accent: #2456c4; --accent-ink: #ffffff;
  --red: #c02b2b; --red-bg: #fdf1f1; --yellow: #a06a00; --yellow-bg: #fdf7ea;
  --gap: #6b46a8; --gap-bg: #f6f1fc; --ok: #1d7a4a;
  --code-bg: #f0f2f5; --shadow: 0 1px 3px rgba(20, 30, 50, 0.08);
}
:root[data-theme="dark"] {
  --bg: #12151b; --panel: #1a1f28; --ink: #e6eaf1; --muted: #98a2b3;
  --line: #2a3140; --accent: #6c96f0; --accent-ink: #0e1320;
  --red: #f08080; --red-bg: #2a1c1e; --yellow: #e0b45c; --yellow-bg: #282215;
  --gap: #b79ae0; --gap-bg: #221c2e; --ok: #6fce9e;
  --code-bg: #232936; --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { 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;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.82em; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hidden { display: none !important; }

/* --- Header ------------------------------------------------------------ */
header {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.9rem 1.4rem; border-bottom: 1px solid var(--line); background: var(--panel);
  flex-wrap: wrap;
}
.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; }
.tagline { margin: 0; font-size: 0.82rem; color: var(--muted); }
.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); }
.credits { color: var(--ok); font-weight: 600; }
.topup { color: var(--accent); font-size: 0.85rem; }

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.55; cursor: default; }
.big { padding: 0.65rem 1.5rem; font-size: 1rem; border-radius: 10px; }
button.big:not(.primary) { background: var(--panel); border: 1px solid var(--line); color: var(--ink); }
.linkish { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; font-size: inherit; }

/* --- Layout ------------------------------------------------------------ */
main { max-width: 980px; margin: 0 auto; padding: 1.5rem 1.2rem 3rem; }
.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.4rem; flex-wrap: wrap; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
textarea, input[type="text"], select {
  width: 100%; font: inherit; color: var(--ink); background: transparent;
  border: none; outline: none; padding: 0.8rem 0.9rem;
}
textarea { resize: vertical; min-height: 10rem; display: block; }
.options { margin-top: 1rem; }
.options summary { cursor: pointer; }
.row.three { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 0.9rem; margin-top: 0.7rem; }
.row.three label { display: block; font-size: 0.85rem; margin-bottom: 0.25rem; color: var(--muted); }
.row.three select, .row.three input { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 0.5rem 0.6rem; }
@media (max-width: 720px) { .row.three { grid-template-columns: 1fr; } }
.actions { display: flex; align-items: center; gap: 0.9rem; margin-top: 1.2rem; flex-wrap: wrap; }
.meter { font-size: 0.8rem; color: var(--muted); }

/* --- Prescan ------------------------------------------------------------ */
.prescan { margin-top: 1.1rem; }
.prescan-body { display: grid; gap: 0.55rem; margin-top: 0.3rem; }
.ps-item { border: 1px solid var(--line); border-left-width: 4px; border-radius: 8px; padding: 0.55rem 0.8rem; background: var(--panel); }
.ps-item.red { border-left-color: var(--red); background: var(--red-bg); }
.ps-item.yellow { border-left-color: var(--yellow); background: var(--yellow-bg); }
.ps-item.gap { border-left-color: var(--gap); background: var(--gap-bg); }
.ps-label { font-weight: 700; font-size: 0.9rem; }
.ps-excerpt { margin: 0.3rem 0; padding: 0.35rem 0.5rem; background: var(--code-bg); border-radius: 6px; overflow-x: auto; white-space: nowrap; }
.ps-why { font-size: 0.85rem; color: var(--muted); }
.ps-item.gap ul { margin: 0.3rem 0 0; padding-left: 1.2rem; font-size: 0.88rem; }
.ps-item.gap li { margin: 0.2rem 0; }

/* --- Progress ------------------------------------------------------------ */
.progress-panel { margin-top: 1.4rem; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.2rem; }
.pp-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.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.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); } }

/* --- Result ------------------------------------------------------------ */
.result { margin-top: 1.6rem; display: grid; gap: 1.3rem; }
.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; }
.parties { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.party-chip { font-size: 0.85rem; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 0.2rem 0.7rem; }
.party-note { color: var(--muted); font-size: 0.9rem; margin: 0.5rem 0 0; }
.dl-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.summary-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.2rem; box-shadow: var(--shadow); }
.summary-card p { margin: 0.5rem 0 0; }

.flag-zone { }
.flag-head { display: flex; align-items: center; gap: 0.55rem; margin-bottom: 0.6rem; }
.flag-head h3 { margin: 0; font-size: 1.02rem; }
.flag-dot { width: 0.75rem; height: 0.75rem; border-radius: 50%; flex: none; }
.flag-head.red .flag-dot { background: var(--red); }
.flag-head.yellow .flag-dot { background: var(--yellow); }
.flag-head.missing .flag-dot { background: var(--gap); }
.count { color: var(--muted); }
.flag-list { display: grid; gap: 0.7rem; }
.flag-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 0.8rem 1rem; box-shadow: var(--shadow); }
.fc-head { display: flex; justify-content: space-between; gap: 0.8rem; align-items: baseline; flex-wrap: wrap; }
.fc-cat { font-weight: 700; font-size: 0.9rem; }
.fc-loc { color: var(--muted); }
.fc-clause {
  margin: 0.55rem 0; padding: 0.5rem 0.8rem; border-left: 3px solid var(--line);
  background: var(--code-bg); border-radius: 0 8px 8px 0; font-size: 0.88rem; font-style: italic;
  overflow-wrap: break-word;
}
.fc-problem { margin: 0.4rem 0; font-size: 0.93rem; }
.fc-suggestion { margin: 0.4rem 0 0; font-size: 0.9rem; color: var(--ok); }
.fc-suggestion strong { color: inherit; }

.missing-list { display: grid; gap: 0.45rem; }
.missing-item { background: var(--gap-bg); border: 1px solid var(--line); border-left: 4px solid var(--gap); border-radius: 8px; padding: 0.5rem 0.8rem; font-size: 0.9rem; }

.terms-zone { }
.terms-table { width: 100%; border-collapse: collapse; margin-top: 0.5rem; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.terms-table th, .terms-table td { text-align: left; padding: 0.5rem 0.9rem; border-bottom: 1px solid var(--line); font-size: 0.9rem; vertical-align: top; }
.terms-table th { width: 32%; color: var(--muted); font-weight: 600; }
.terms-table tr:last-child th, .terms-table tr:last-child td { border-bottom: none; }

.playbook-list { display: grid; gap: 0.7rem; margin-top: 0.5rem; }
.pb-item { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 0.75rem 1rem; }
.pb-flag { font-weight: 700; margin-bottom: 0.3rem; }
.pb-item p { margin: 0.25rem 0; font-size: 0.9rem; }

.disclaimer { font-size: 0.82rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 0.8rem; }
.standing-notice { font-size: 0.86rem; line-height: 1.5; color: var(--fg); background: var(--code-bg); border: 1px solid var(--line); border-left: 3px solid var(--accent, #b45309); border-radius: 8px; padding: 0.75rem 0.9rem; margin: 0 0 1.1rem; }
.run-meta { color: var(--muted); font-size: 0.8rem; }

.raw-result { margin-top: 1.4rem; }
.raw-output { background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px; padding: 1rem; overflow-x: auto; font-size: 0.82rem; white-space: pre-wrap; }

/* --- How it works ------------------------------------------------------- */
.how { margin-top: 2.2rem; }
.how-lead { color: var(--muted); }
.how-grid { display: grid; grid-template-columns: repeat(3, 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; }
.step-n { display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 0.9rem; }
.how-step h3 { margin: 0.6rem 0 0.3rem; font-size: 0.98rem; }
.how-step p { margin: 0; font-size: 0.88rem; color: var(--muted); }
.how-credit { margin-top: 1rem; font-size: 0.82rem; color: var(--muted); }
.how-credit a { color: var(--accent); }

/* --- Footer & toasts ------------------------------------------------------ */
footer { border-top: 1px solid var(--line); padding: 1rem 1.4rem; text-align: center; font-size: 0.85rem; color: var(--muted); }
footer a { color: var(--muted); }
.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: 4px solid var(--ok);
  border-radius: 10px; padding: 0.6rem 0.9rem; font-size: 0.88rem; box-shadow: var(--shadow);
  transition: opacity 0.5s;
}
.toast.err { border-left-color: var(--red); }
.toast.gone { opacity: 0; }
.toast a { color: var(--accent); margin-left: 0.4rem; }

/* --- Print: just the review -------------------------------------------------- */
@media print {
  header, footer, form, .prescan, .how, .toasts, .dl-actions, .progress-panel, .history, .short-warn, .copy-actions { display: none !important; }
  body { background: #fff; color: #000; }
  .result { display: grid !important; }
  .flag-card, .summary-card, .pb-item { break-inside: avoid; box-shadow: none; }
}

/* --- Legal Inbox additions ------------------------------------------------ */
.rec-badge {
  display: inline-block; margin-top: 0.45rem; padding: 0.25rem 0.8rem; border-radius: 999px;
  font-size: 0.85rem; font-weight: 700; border: 1px solid var(--line);
}
.rec-badge.ok { color: var(--ok); border-color: var(--ok); background: transparent; }
.rec-badge.esc { color: var(--red); border-color: var(--red); background: var(--red-bg); }
.response-zone { }
.response-text {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 1rem 1.2rem; box-shadow: var(--shadow); white-space: pre-wrap;
  font-family: inherit; font-size: 0.93rem; margin: 0.4rem 0 0; overflow-wrap: break-word;
}
.plain-list { margin: 0.5rem 0 0; padding-left: 1.4rem; display: grid; gap: 0.35rem; font-size: 0.92rem; }
.ph-status { font-size: 0.78rem; font-weight: 700; padding: 0.12rem 0.55rem; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; }
.ph-status.filled { color: var(--ok); border-color: var(--ok); }
.ph-status.needs { color: var(--yellow); border-color: var(--yellow); }
.terms-table code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.82em; }

/* --- Placeholder fill-in worksheet ---------------------------------------- */
.copy-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.copy-actions .ghost:disabled { opacity: 0.5; cursor: not-allowed; }
.ph-mark {
  background: var(--yellow-bg); color: var(--yellow); border: 1px dashed var(--yellow);
  border-radius: 5px; padding: 0 0.25rem; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em; font-style: normal;
}
.ph-fill { display: grid; gap: 0.3rem; }
.ph-input {
  width: 100%; font: inherit; font-size: 0.9rem; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 0.4rem 0.6rem; outline: none;
}
.ph-input:focus { border-color: var(--accent); }
.ph-note { line-height: 1.4; }

/* --- Short-inquiry warning -------------------------------------------------- */
.short-warn {
  display: flex; align-items: center; justify-content: space-between; gap: 0.9rem;
  flex-wrap: wrap; margin-top: 0.6rem; padding: 0.55rem 0.8rem;
  background: var(--yellow-bg); border: 1px solid var(--yellow); border-left-width: 4px;
  border-radius: 8px; font-size: 0.88rem;
}

/* --- Recent runs (history) --------------------------------------------------- */
.history { margin-top: 2rem; }
.hist-list { display: grid; gap: 0.5rem; margin-top: 0.4rem; }
.hist-empty { color: var(--muted); font-size: 0.9rem; padding: 0.6rem 0.2rem; }
.hist-row {
  display: flex; align-items: center; gap: 0.8rem; width: 100%; text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 0.6rem 0.9rem; color: var(--ink); font: inherit; box-shadow: var(--shadow);
}
.hist-row:hover { border-color: var(--accent); }
.hist-verdict {
  flex: none; font-size: 0.75rem; font-weight: 700; padding: 0.15rem 0.6rem;
  border-radius: 999px; border: 1px solid var(--line);
}
.hist-verdict.ok { color: var(--ok); border-color: var(--ok); }
.hist-verdict.esc { color: var(--red); border-color: var(--red); background: var(--red-bg); }
.hist-main { flex: 1 1 auto; min-width: 0; display: grid; gap: 0.1rem; }
.hist-label { font-weight: 600; font-size: 0.92rem; }
.hist-summary {
  color: var(--muted); font-size: 0.82rem; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.hist-when { flex: none; color: var(--muted); font-size: 0.8rem; }
