/* Shared design system for the astro tools (same tokens as LRD Zoo).
   Layout: one 1100px column; the tool's input panel is the only raised surface, results sit flat below. */
:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #eceef3;
  --ink: #131824;
  --ink-2: #485266;
  --muted: #6e788b;
  --line: #dce0e8;
  --grid: #e8ebf0;
  --accent: #b3262e;
  --accent-ink: #ffffff;
  --accent-soft: #f8e4e5;
  --dot-core: #ffe9d6;
  --focus: #2a78d6;
  --warn-ink: #8a5600;
  --warn-soft: #fbefd6;
  --ok-ink: #0b6b2b;
  --ok-soft: #dff3e5;
  /* categorical series (validated slots 1-3 of the dataviz reference palette) */
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --shadow: 0 1px 2px rgba(19, 24, 36, 0.06), 0 8px 24px rgba(19, 24, 36, 0.06);
  --f-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --f-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --step--1: 0.8125rem;
  --step-0: 0.9375rem;
  --step-1: 1.125rem;
  --step-2: 1.5rem;
  --step-3: 2.1rem;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0f15; --surface: #151a23; --surface-2: #1d232e; --ink: #e8ebf1; --ink-2: #b6bdcb; --muted: #8a94a7;
    --line: #2a313e; --grid: #222936; --accent: #f0646b; --accent-ink: #1b0a0c; --accent-soft: #3b1d22; --dot-core: #fff1e6;
    --focus: #6aa5ec; --warn-ink: #f2c46b; --warn-soft: #3a2e14; --ok-ink: #7fd89a; --ok-soft: #16301f;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c0f15; --surface: #151a23; --surface-2: #1d232e; --ink: #e8ebf1; --ink-2: #b6bdcb; --muted: #8a94a7;
  --line: #2a313e; --grid: #222936; --accent: #f0646b; --accent-ink: #1b0a0c; --accent-soft: #3b1d22; --dot-core: #fff1e6;
  --focus: #6aa5ec; --warn-ink: #f2c46b; --warn-soft: #3a2e14; --ok-ink: #7fd89a; --ok-soft: #16301f;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 var(--step-0)/1.55 var(--f-body); }
img { max-width: 100%; }
[hidden] { display: none !important; }
a { color: var(--accent); text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
code, .mono { font-family: var(--f-mono); font-size: 0.92em; }
.muted { color: var(--muted); }
.small { font-size: var(--step--1); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h1, h2, h3 { font-family: var(--f-display); text-wrap: balance; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: var(--step-2); font-weight: 700; }
h3 { font-size: var(--step-1); font-weight: 700; }
.wrap { width: 100%; max-width: 1100px; margin-inline: auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }

/* top bar shared by all tools */
.topbar { border-bottom: 1px solid var(--line); background: var(--surface); }
.topbar .wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; padding-block: 8px; }
.topbar .suite { font-family: var(--f-display); font-weight: 700; color: var(--ink); text-decoration: none; margin-right: 6px; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 2px; flex: 1; }
.topbar nav a { color: var(--ink-2); text-decoration: none; padding: 4px 10px; border-radius: 6px; font-size: var(--step--1); font-weight: 500; }
.topbar nav a:hover { background: var(--surface-2); color: var(--ink); }
.topbar nav a[aria-current="page"] { color: var(--ink); background: var(--surface-2); }

.masthead { padding-block: 26px 18px; }
.masthead h1 { font-size: var(--step-3); font-weight: 700; line-height: 1.05; }
.masthead p { margin: 6px 0 0; color: var(--ink-2); max-width: 70ch; }

/* controls */
button, select, input, textarea { font: inherit; color: inherit; }
.primary-btn, .ghost-btn, .link-btn { display: inline-flex; align-items: center; gap: 6px; border-radius: 8px; padding: 7px 14px; cursor: pointer; font-size: var(--step--1); font-weight: 500; text-decoration: none; line-height: 1.3; }
.primary-btn { background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); font-weight: 600; }
.primary-btn:hover { filter: brightness(1.08); }
.ghost-btn { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.ghost-btn:hover { background: var(--surface-2); }
.link-btn { background: none; border: 0; color: var(--accent); padding: 4px 2px; }
input[type="number"], input[type="text"], input[type="search"], select, textarea {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 9px; font-size: var(--step-0); min-width: 0;
}
textarea { font-family: var(--f-mono); font-size: 0.875rem; background: var(--bg); width: 100%; resize: vertical; }
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field > span { font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.field input, .field select { width: 100%; }
.unit, .field .unit { text-transform: none; letter-spacing: 0; font-weight: 400; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 6px 12px; cursor: pointer; font-size: var(--step--1); font-weight: 500; color: var(--ink-2); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 18px 20px; display: grid; gap: 14px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; align-items: end; }

/* results */
.section { padding-block: 22px 8px; display: grid; gap: 12px; min-width: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.kpi { padding: 12px 14px; border-right: 1px solid var(--grid); border-bottom: 1px solid var(--grid); min-width: 0; }
.kpi .label { font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.kpi .value { font-family: var(--f-display); font-size: 1.45rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi .value small { font-family: var(--f-body); font-size: 0.8rem; font-weight: 500; color: var(--ink-2); }
.kpi .sub { font-size: var(--step--1); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.table-scroll { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: var(--step--1); }
table.data th, table.data td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--grid); vertical-align: top; }
table.data thead th { background: var(--surface-2); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-2); white-space: nowrap; position: sticky; top: 0; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 500; line-height: 1.6; white-space: nowrap; border: 1px solid transparent; }
.pill-accent { background: var(--accent-soft); color: var(--accent); }
.pill-ok { background: var(--ok-soft); color: var(--ok-ink); }
.pill-warn { background: var(--warn-soft); color: var(--warn-ink); }
.pill-plain { background: var(--surface-2); color: var(--ink-2); }
.note { font-size: var(--step--1); color: var(--ink-2); max-width: 80ch; }
.note-box { font-size: var(--step--1); color: var(--ink-2); border-left: 3px solid var(--line); padding: 4px 0 4px 12px; }

/* charts */
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
svg text { fill: var(--muted); font-family: var(--f-body); font-size: 11px; }
svg .axis-line { stroke: var(--line); }
svg .grid-line { stroke: var(--grid); }
svg .frame { fill: var(--surface); stroke: var(--line); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: var(--step--1); color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; flex: none; }
.tooltip { position: fixed; z-index: 50; pointer-events: none; max-width: 300px; background: var(--ink); color: var(--bg); padding: 6px 9px; border-radius: 6px; font-size: 0.75rem; line-height: 1.45; box-shadow: var(--shadow); }

.footer { padding-block: 10px 32px; border-top: 1px solid var(--line); margin-top: 28px; }
.footer p { margin: 12px 0 0; font-size: var(--step--1); color: var(--muted); max-width: 90ch; }

@media (max-width: 640px) {
  .topbar nav { order: 3; flex-basis: 100%; margin-left: -10px; }
  .topbar .suite { flex: 1; }
  .masthead h1 { font-size: 1.75rem; }
  .panel { padding: 14px; }
}
