/* theoryforge interactive apps: shared styles.
   Brand-consistent with the documentation landing page: navy/teal identity,
   R-blue and Python-blue accents, light/dark via CSS variables and the shared
   `tf-theme` localStorage key. */

:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-2: #eef2f4;
  --ink: #1b2733;
  --ink-soft: #4a5a68;
  --line: #d8e0e5;
  --teal: #2fa392;
  --teal-soft: #4cc2b0;
  --amber: #d98a14;
  --accent: #2fa392;        /* overridden per app (R / Python) */
  --accent-ink: #ffffff;
  --danger: #c5413a;
  --warn: #d98a14;
  --ok: #3a9d4e;
  --shadow: 0 1px 2px rgba(16, 27, 39, .06), 0 6px 20px rgba(16, 27, 39, .07);
  --mono: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg: #0f1822;
  --panel: #18242f;
  --panel-2: #13202b;
  --ink: #e7eef2;
  --ink-soft: #9fb3c0;
  --line: #283744;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1822; --panel: #18242f; --panel-2: #13202b; --ink: #e7eef2;
    --ink-soft: #9fb3c0; --line: #283744;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--sans); color: var(--ink); background: var(--bg);
  font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; }

/* ---- header ---- */
header.app {
  display: flex; align-items: center; gap: 14px; padding: 12px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
header.app .logo { width: 36px; height: auto; flex: 0 0 auto; }
header.app .titles { display: flex; flex-direction: column; line-height: 1.15; }
header.app .titles .t { margin: 0; font-weight: 700; font-size: 1.02rem; }
header.app .titles .s { font-size: .82rem; color: var(--ink-soft); }
header.app .grow { flex: 1 1 auto; }
header.app .navlinks { display: flex; gap: 10px; align-items: center; }
.badge {
  font-size: .72rem; font-weight: 700; letter-spacing: .02em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 999px; color: var(--accent-ink); background: var(--accent);
}
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--ink); cursor: pointer; font-size: 1.05rem;
}
.icon-btn:hover { border-color: var(--accent); }
header.app .doclink {
  font-size: .85rem; padding: 7px 12px; border: 1px solid var(--line);
  border-radius: 9px; color: var(--ink-soft);
}
header.app .doclink:hover { border-color: var(--accent); color: var(--ink); text-decoration: none; }

/* The guide is the main onboarding affordance, so it reads as an accent-ringed
   call to action rather than another grey icon button. */
.help-cta {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font: inherit;
  font-weight: 600; font-size: .85rem; padding: 7px 13px; border-radius: 9px;
  border: 1.5px solid var(--accent); color: var(--ink);
  background: color-mix(in srgb, var(--accent) 13%, var(--panel));
}
.help-cta:hover { background: color-mix(in srgb, var(--accent) 22%, var(--panel)); }
/* The accent fill stays on the border and the ? badge (accent-ink on accent,
   the same high-contrast pairing as the primary button), while the label uses
   --ink so it meets WCAG AA on the tinted fill in both themes. */
.help-cta .hq {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%; font-weight: 800; font-size: .72rem;
  color: var(--accent-ink); background: var(--accent);
}

/* ---- layout ---- */
main {
  display: grid; grid-template-columns: 360px 1fr; gap: 18px;
  padding: 18px 20px 40px; max-width: 1380px; margin: 0 auto; align-items: start;
}
main > * { min-width: 0; }   /* let grid children shrink instead of overflowing */
@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
  .sidebar { position: static; }
}
@media (max-width: 620px) {
  main { padding: 14px 14px 34px; }
  .ops { grid-template-columns: 1fr; }
  header.app { gap: 8px; padding: 10px 14px; }
  header.app .titles .s { display: none; }   /* drop the decorative subtitle to keep the toolbar reachable */
  .help-cta .ht { display: none; }           /* keep only the ? badge so the toolbar stays compact */
  .help-cta { padding: 7px 9px; }
}

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 16px;
}
.panel + .panel { margin-top: 16px; }
.panel > h2 {
  margin: 0 0 12px; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-soft);
}
.sidebar { position: sticky; top: 76px; }

label.field { display: block; margin: 0 0 12px; }
label.field > span { display: block; font-size: .82rem; color: var(--ink-soft); margin-bottom: 4px; }
select, input[type="text"], input[type="number"] {
  width: 100%; padding: 9px 10px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--ink); font: inherit;
}
select:focus, input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* visible focus for every custom control (WCAG 2.4.7); --ink reads against the
   accent-filled primary button and the panel surfaces in both themes */
.btn:focus-visible, .icon-btn:focus-visible, .op:focus-visible, .doclink:focus-visible,
.help-cta:focus-visible, .linklike:focus-visible {
  outline: 2px solid var(--ink); outline-offset: 2px;
}
.skip-link {
  position: absolute; left: 8px; top: -48px; z-index: 300;
  background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: 8px;
  transition: top .15s;
}
.skip-link:focus { top: 8px; }

.filewrap { display: flex; gap: 8px; align-items: center; }
.filewrap input[type="file"] { font-size: .8rem; color: var(--ink-soft); }

button.btn {
  appearance: none; border: 1px solid var(--accent); background: var(--accent);
  color: var(--accent-ink); font: inherit; font-weight: 600; padding: 9px 16px;
  border-radius: 9px; cursor: pointer;
}
button.btn:hover { filter: brightness(1.06); }
button.btn:disabled { opacity: .5; cursor: not-allowed; }
button.btn.ghost { background: var(--panel-2); color: var(--ink); border-color: var(--line); font-weight: 500; }
button.btn.ghost:hover { border-color: var(--accent); filter: none; }
button.btn.sm { padding: 5px 11px; font-size: .82rem; }

/* theory summary */
.summary { font-size: .88rem; }
.summary .ttl { font-weight: 700; font-size: .98rem; margin-bottom: 2px; }
.summary .meta { color: var(--ink-soft); margin-bottom: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: .76rem; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 9px; color: var(--ink-soft);
}
.chip b { color: var(--ink); font-weight: 700; }

/* operations */
.ops { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.op {
  text-align: left; border: 1px solid var(--line); background: var(--panel-2);
  border-radius: 10px; padding: 9px 11px; cursor: pointer; color: var(--ink);
}
.op:hover { border-color: var(--accent); }
/* active op also carries a structural left bar so selection is not colour-only */
.op.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--panel)); box-shadow: inset 3px 0 0 var(--accent); }
.op.active .on { color: var(--accent); }
.op .on { display: block; font-weight: 600; font-size: .9rem; }
.op .od { display: block; font-size: .76rem; color: var(--ink-soft); margin-top: 3px; line-height: 1.3; }
.params { margin-top: 12px; }
.params .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* output */
.outhead { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.outhead h2 { margin: 0; font-size: 1.05rem; }
.outhead .grow { flex: 1; }
/* Each result section is delimited by a separator and generous spacing, so its
   header (title + export buttons) reads as belonging to the box beneath it. */
.section { margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--line); }
.section:first-child { margin-top: 4px; padding-top: 0; border-top: none; }
.section .sh {
  display: flex; align-items: center; gap: 10px; margin-bottom: 8px;
  font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft);
}
.section .sh .grow { flex: 1; }
.section .sh .btn.ghost.sm { text-transform: none; letter-spacing: 0; }

/* First-run welcome: rationale and steps shown before any operation is run. */
.welcome h3 { margin: 2px 0 8px; font-size: 1.06rem; }
.welcome p { margin: 0 0 10px; }
.welcome .welcome-steps { margin: 0 0 10px; padding-left: 1.2rem; }
.welcome .welcome-steps li { margin-bottom: 5px; }
.linklike {
  background: none; border: none; padding: 0; font: inherit; color: var(--accent);
  cursor: pointer; text-decoration: underline;
}
.linklike:hover { filter: brightness(1.1); }

/* Per-result guidance: a general "how to read" line and a result-specific
   interpretation, set off by an accent rule so they read as orientation rather
   than as another data section. */
.result-intro {
  border-left: 3px solid var(--accent); border-radius: 0 10px 10px 0;
  background: color-mix(in srgb, var(--accent) 7%, var(--panel));
  padding: 11px 14px; margin: 2px 0 4px; font-size: .88rem;
}
.result-intro p { margin: 0; }
.result-intro .ri-about { color: var(--ink-soft); }
.result-intro .ri-interp { margin-top: 7px; color: var(--ink); font-weight: 500; }
/* The intro is not itself a .section, so the first real section that follows it
   should be spaced like a first section, not carry a mid-list divider. */
.result-intro + .section { margin-top: 14px; padding-top: 0; border-top: none; }

/* Figures sit on a light "paper" canvas in both themes so the package's
   black-text SVGs stay legible. In dark mode a brighter frame and a drop
   shadow make the white inset read as intentional rather than a flash. */
.figure {
  background: #ffffff; border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; overflow: auto; text-align: center;
}
.figure svg { max-width: 100%; height: auto; }
html[data-theme="dark"] .figure { border-color: #5a6b7c; box-shadow: 0 2px 12px rgba(0, 0, 0, .4); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .figure { border-color: #5a6b7c; box-shadow: 0 2px 12px rgba(0, 0, 0, .4); }
}

pre.code, pre.text {
  margin: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; overflow: auto; font-family: var(--mono); font-size: .82rem;
  line-height: 1.5; color: var(--ink); white-space: pre; tab-size: 2;
}
.codewrap { position: relative; }

/* Data grids size to their content (small columns hug left, a designated
   `.grow` column takes the remaining width and wraps) rather than stretching
   every column to fill the panel. */
table.grid { border-collapse: collapse; width: auto; max-width: 100%; font-size: .85rem; }
table.grid th, table.grid td {
  text-align: left; padding: 5px 16px 5px 0; border-bottom: 1px solid var(--line);
  white-space: nowrap; vertical-align: top;
}
table.grid th:last-child, table.grid td:last-child { padding-right: 0; }
table.grid th { color: var(--ink-soft); font-weight: 600; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; }
table.grid td { font-size: .85rem; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); padding-left: 20px; }
table.grid .grow { white-space: normal; width: 100%; }
table.grid td.kvk { color: var(--ink-soft); }
table.grid tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--ink) 4%, transparent); }
table.grid tbody tr:hover td { background: color-mix(in srgb, var(--accent) 9%, transparent); }
/* Solid, theme-independent pills so the pass/warn/fail verdicts meet WCAG
   contrast (≈4.5:1) regardless of the surrounding panel tint. */
.pill { padding: 2px 9px; border-radius: 999px; font-size: .74rem; font-weight: 700; white-space: nowrap; }
.pill.pass, .pill.ok, .pill.covered, .pill.progressive { background: #2e7d46; color: #ffffff; }
.pill.warn, .pill.advisory, .pill.review, .pill.neutral, .pill.crowded { background: #e8a33d; color: #3a2600; }
.pill.fail, .pill.blocked, .pill.degenerating, .pill.under_theorised { background: #b5392f; color: #ffffff; }

.note { font-size: .85rem; color: var(--ink-soft); }
.error {
  background: color-mix(in srgb, var(--danger) 12%, var(--panel)); border: 1px solid var(--danger);
  color: var(--ink); border-radius: 10px; padding: 12px 14px; font-size: .88rem;
}
.error .et { font-weight: 700; color: var(--danger); margin-bottom: 4px; }
.err-list { margin: 6px 0 0; padding-left: 1.2rem; }
.err-list li { margin-bottom: 3px; }
.valid-ok {
  background: color-mix(in srgb, var(--ok) 14%, var(--panel)); border: 1px solid var(--ok);
  color: var(--ink); border-radius: 10px; padding: 12px 14px; font-weight: 600;
}
.boot-error { text-align: center; max-width: 440px; }
.boot-error .btn { margin-top: 14px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 999px;
  font-size: .85rem; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50;
}
.toast.show { opacity: .96; }

/* boot overlay */
#boot {
  position: fixed; inset: 0; z-index: 100; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
}
#boot .logo { width: 84px; height: auto; }
#boot .bt { font-weight: 700; font-size: 1.1rem; }
#boot .spinner {
  width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--line);
  border-top-color: var(--accent); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#boot .blog {
  font-family: var(--mono); font-size: .8rem; color: var(--ink-soft);
  max-width: 480px; min-height: 3.2em; text-align: center;
}
#boot.hidden { display: none; }

footer.app {
  text-align: center; color: var(--ink-soft); font-size: .8rem; padding: 8px 20px 28px;
}

/* example description + operation help + view-source row */
.exdesc { font-size: .8rem; color: var(--ink-soft); margin: -6px 0 12px; }
.ophelp { font-size: .8rem; color: var(--ink-soft); margin: 10px 0 0; min-height: 1px; }
.srcrow { margin-top: 12px; }

/* modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200; background: rgba(8, 14, 20, .55);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  width: 100%; max-width: 560px; max-height: 86vh; display: flex; flex-direction: column;
}
.modal.wide { max-width: 820px; }
.modal > header { display: flex; align-items: center; gap: 10px; padding: 13px 18px; border-bottom: 1px solid var(--line); }
.modal > header h3 { margin: 0; font-size: 1rem; }
.modal > header .close { margin-left: auto; font-size: 1.3rem; line-height: 1; }
.modal .body { padding: 16px 18px; overflow: auto; }
.modal .body pre.text { max-height: 62vh; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 10px; }

/* help content */
.help h4 { margin: 18px 0 6px; font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); }
.help p { margin: 0 0 8px; }
.help ol.steps { margin: 0; padding-left: 1.2rem; }
.help ol.steps li { margin-bottom: 5px; }
.help ul.help-ops { margin: 0; padding-left: 1.1rem; }
.help ul.help-ops li { margin-bottom: 5px; }
.help ul.help-ops b { color: var(--ink); }
