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

:root, [data-theme="light"] {
  --bg: #f5f4f1;
  --bg2: #ffffff;
  --ink: #1c1a16;
  --muted: #6b655a;
  --line: #e0dcd3;
  --accent: #8a5a24;
  --accent-ink: #ffffff;
  --good: #2c7a44;
  --mid: #a06a10;
  --bad: #b03434;
  --quote-bg: #f0eee9;
  --shadow: 0 1px 2px rgba(28, 26, 22, 0.06), 0 8px 24px rgba(28, 26, 22, 0.05);
}
[data-theme="dark"] {
  --bg: #14120f;
  --bg2: #1c1915;
  --ink: #ece8e1;
  --muted: #a89f91;
  --line: #353027;
  --accent: #d9a45f;
  --accent-ink: #1a1206;
  --good: #6cc389;
  --mid: #d9a94a;
  --bad: #e08484;
  --quote-bg: #262019;
  --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; }

.opt-row { display: flex; gap: 18px; flex-wrap: wrap; }
.opt-item { flex: 1; min-width: 220px; display: block; }
.opt-item select { font-size: 0.9rem; }

.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; }

/* --- Material 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.ok::before { content: "\2713"; color: var(--good); }
.lint.warn::before { content: "\26A0"; color: var(--mid); }
.lint.bad::before { content: "\2717"; color: var(--bad); }
.lint .lint-detail { display: block; color: var(--muted); font-size: 0.8rem; }
.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; }
.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 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;
}

/* The article itself (rendered by report.js) */
.article-title { margin: 0 0 0.7em; font-size: 1.55rem; line-height: 1.25; letter-spacing: -0.01em; }
.article-h { margin: 1.5em 0 0.5em; line-height: 1.3; }
h3.article-h { font-size: 1.14rem; }
h4.article-h { font-size: 1.02rem; }
h5.article-h, h6.article-h { font-size: 0.95rem; }
#articleWrap p { margin: 0.8em 0; }
.article-list { margin: 0.6em 0; padding-left: 1.4em; }
.article-list li { margin: 0.3em 0; }
.article-code {
  margin: 0.9em 0; padding: 12px 14px;
  background: var(--quote-bg); border-radius: 8px;
  font-size: 0.82rem; overflow-x: auto;
}
.article-code code { background: none; padding: 0; font-size: inherit; }
.article-quote {
  margin: 0.9em 0; padding: 6px 16px;
  border-left: 3px solid var(--accent);
  background: var(--quote-bg); border-radius: 0 8px 8px 0;
  color: var(--muted); font-style: italic;
}
mark.placeholder {
  background: none; color: var(--mid); font-weight: 600;
  border: 1px dashed var(--mid); border-radius: 5px; padding: 0 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85em;
}

/* 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; }

.output-lint { margin-top: 14px; }
.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); }

/* --- Credit preflight ------------------------------------------------------ */
.credit-note {
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--mid);
  border-radius: 8px;
  background: var(--quote-bg);
  font-size: 0.88rem;
}
.credit-note a { margin-left: 6px; }

/* --- Staged progress ------------------------------------------------------- */
.elapsed { margin-left: 10px; color: var(--muted); }
.stage-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
}
.stage { display: flex; align-items: center; gap: 7px; font-size: 0.84rem; color: var(--muted); }
.stage-dot {
  width: 9px; height: 9px; border-radius: 50%;
  border: 1px solid var(--line); background: transparent;
  flex: none;
}
.stage.active { color: var(--ink); }
.stage.active .stage-dot { background: var(--accent); border-color: var(--accent); }
.stage.done { color: var(--muted); }
.stage.done .stage-dot { background: var(--good); border-color: var(--good); }

/* --- Grounding, staleness, the second run ---------------------------------- */
.ground-block { margin-top: 14px; }
.stale-note {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-left: 3px solid var(--mid);
  background: var(--quote-bg);
  border-radius: 0 8px 8px 0;
  font-size: 0.88rem;
}
.diff-note {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  background: var(--quote-bg);
  border-radius: 0 8px 8px 0;
  font-size: 0.9rem;
}
.diff-resolved { margin: 6px 0 0; padding-left: 20px; color: var(--good); }
.diff-added { margin: 6px 0 0; padding-left: 20px; color: var(--bad); }
.diff-note p { margin: 8px 0 0; }

/* --- Filling the gaps ------------------------------------------------------ */
.gap-panel {
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg2);
}
.gap-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 10px; }
.gap-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.gap-label {
  font: 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--mid);
  flex: 0 0 auto;
  min-width: 10rem;
}
.gap-input {
  flex: 1 1 14rem;
  font: inherit;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
}
.gap-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.gap-btn {
  font: inherit;
  border: 1px dashed currentColor;
  border-radius: 5px;
  padding: 0 4px;
  background: transparent;
  cursor: pointer;
}
mark.placeholder.filled { background: transparent; color: inherit; border-bottom: 2px solid var(--good); }

/* --- Past articles --------------------------------------------------------- */
.history-panel {
  margin: 30px 0 0;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.hist-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }
.hist-open {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  text-align: left;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
}
.hist-open:hover:not(:disabled) { border-color: var(--accent); }
.hist-open:disabled { cursor: default; opacity: 0.72; }
.hist-title { font-weight: 600; }
.hist-counts { color: var(--muted); font-size: 0.85rem; }
.hist-when { margin-left: auto; color: var(--muted); }

/* --- Questions ------------------------------------------------------------- */
.faq { margin: 40px 0 0; }
.faq-list { margin-top: 12px; display: grid; gap: 14px; }
.faq-item {
  padding: 14px 16px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.faq-item h3 { margin: 0 0 6px; font-size: 0.98rem; }
.faq-item p { margin: 0; font-size: 0.88rem; color: var(--muted); line-height: 1.65; }

/* --- Language tabs (api.html) ---------------------------------------------- */
.lang-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.lang-tabs button {
  font: inherit;
  font-size: 0.8rem;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.lang-tabs button.active { border-color: var(--accent); color: var(--ink); }
