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

:root, [data-theme="light"] {
  --bg: #f4f5f7;
  --bg2: #ffffff;
  --ink: #1a2130;
  --muted: #5e6b80;
  --line: #dde2ea;
  --accent: #3b5fa0;
  --accent-ink: #ffffff;
  --good: #2c7a44;
  --mid: #a06a10;
  --bad: #b03434;
  --quote-bg: #eef1f5;
  --shadow: 0 1px 2px rgba(26, 33, 48, 0.06), 0 8px 24px rgba(26, 33, 48, 0.05);
}
[data-theme="dark"] {
  --bg: #10131a;
  --bg2: #171c26;
  --ink: #e6eaf1;
  --muted: #94a0b4;
  --line: #2a3140;
  --accent: #8fb0e8;
  --accent-ink: #0e1a2e;
  --good: #6cc389;
  --mid: #d9a94a;
  --bad: #e08484;
  --quote-bg: #1f2532;
  --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); }
.small-btn { padding: 4px 10px; font-size: 0.78rem; }
.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: 1080px; 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; }
.grid2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; margin-top: 22px; align-items: start; }
@media (max-width: 780px) { .grid2 { grid-template-columns: 1fr; } }

.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; }
.type-hint {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 14px 16px;
}
.type-hint .quick-note { margin-top: 10px; }
.quick-note { margin: 14px 0 0; }
.code-input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.8rem; line-height: 1.5; }

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

/* --- Free lane: profile + spec check ---------------------------------------- */
.guess-panel {
  margin-top: 22px; padding: 16px 18px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
}
.lint-list { display: flex; flex-direction: column; gap: 5px; margin-top: 6px; }
.prof-grid { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.prof-chip {
  border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px;
  background: var(--quote-bg); display: flex; flex-direction: column; gap: 1px;
  max-width: 300px;
}
.prof-chip.number { border-left: 3px solid var(--accent); }
.prof-chip.date { border-left: 3px solid var(--good); }
.prof-chip.string { border-left: 3px solid var(--mid); }
.prof-name { font-weight: 700; font-size: 0.84rem; overflow-wrap: anywhere; }
.prof-detail { overflow-wrap: anywhere; }
.prof-missing { color: var(--mid); }

/* --- 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; }
.issue-title { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.badge {
  display: inline-block; padding: 1px 9px; border-radius: 999px;
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  border: 1px solid currentColor;
}
.badge.verdict.grounded { color: var(--good); }
.badge.verdict.checkasm { color: var(--mid); }
.badge.verdict.notenough { color: var(--bad); }
.badge.verdict.local { color: var(--accent); }
.result-summary { margin: 10px 0 0; font-size: 0.92rem; }
.conf-badge { margin-top: 12px; font-size: 0.82rem; }
.consistency-note {
  margin-top: 12px; padding: 8px 12px; border-radius: 8px; font-size: 0.84rem;
  border: 1px solid var(--mid); color: var(--mid);
}
.dl-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.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; }

/* --- Dashboard ---------------------------------------------------------------- */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.kpi-card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 14px 18px;
}
.kpi-label { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
.kpi-value { font-size: 1.7rem; font-weight: 700; margin-top: 2px; }
.kpi-sub { margin-top: 1px; }

.filter-bar {
  display: flex; gap: 14px; align-items: end; flex-wrap: wrap;
  padding: 12px 16px; background: var(--bg2); border: 1px solid var(--line);
  border-radius: 12px;
}
.filter-item { display: flex; flex-direction: column; gap: 3px; }
.filter-item select { width: auto; min-width: 130px; font-size: 0.88rem; padding: 6px 10px; }

.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(430px, 100%), 1fr)); gap: 16px; }
.chart-card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 14px 16px; min-width: 0;
}
.chart-title { margin: 0 0 8px; font-size: 0.95rem; }
.chart-body { overflow-x: auto; }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.ch-grid { stroke: var(--line); stroke-width: 1; }
.ch-rect:hover, .ch-slice:hover { opacity: 0.82; }
.ch-legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.78rem; color: var(--muted); margin-top: 6px; }
.ch-leg-item { display: inline-flex; align-items: center; gap: 5px; }
.ch-leg-dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }

.table-wrap {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 14px 16px; overflow-x: auto;
}
.data-table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
.data-table th {
  text-align: left; padding: 7px 10px; border-bottom: 2px solid var(--line);
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
  cursor: pointer; user-select: none; white-space: nowrap;
}
.data-table th:hover { color: var(--ink); }
.data-table td { padding: 6px 10px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.data-table td.num { text-align: right; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: nowrap; }

.result-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 900px) { .result-grid { grid-template-columns: 1fr; } }

.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 p { margin: 0.8em 0; }
.paper ul, .paper ol { margin: 0.8em 0; padding-left: 1.4em; }
.paper li { margin: 0.3em 0; }
.paper h3, .paper h4, .paper h5, .paper h6 { line-height: 1.3; margin: 1.2em 0 0.4em; font-size: 1rem; }
.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;
}
.side-paper { font-size: 0.88rem; padding: 16px 18px; }
.notes-label { margin-top: 18px; }
.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;
}

.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: 1080px; 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); }

/* --- staged progress: a determinate bar replaces the indeterminate slide --- */
.pp-fill.staged { animation: none; margin-left: 0; transition: width .3s ease; }

/* --- partial-result banner --- */
.consistency-note.partial {
  border-color: var(--warn, #b8860b);
  color: var(--warn, #b8860b);
  background: var(--quote-bg);
}

/* --- run history --- */
.hist-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.hist-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--quote-bg);
}
.hist-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hist-title { font-weight: 600; font-size: 0.9rem; overflow-wrap: anywhere; }
.hist-meta { font-size: 0.78rem; }
.hist-acts { display: flex; gap: 8px; flex-wrap: wrap; }
