/* demo-shell base: tokens, shared parts, dock, mobile. Demos override tokens in css/theme.css. */
:root {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --bg: #f6f7f9; --surface: #ffffff; --fg: #15191e; --muted: #4f5966; --line: #d9dee5;
  --accent: #0f5f8c; --accent-fg: #ffffff; --accent-soft: #e3f0f7;
  --ok: #1d6b3a; --ok-soft: #e2f3e8; --warn: #8a5300; --warn-soft: #fff1d6; --late: #a3261b; --late-soft: #fde6e3;
  --radius: 14px; --gap: 16px; --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 6px 20px rgb(0 0 0 / .06);
  --dock-h: 64px; --dock-space: calc(var(--dock-h) + 24px);
}
body.is-dark {
  --bg: #0e1217; --surface: #171d25; --fg: #eef2f6; --muted: #a7b1bd; --line: #2b3440;
  --accent: #63b3e3; --accent-fg: #0b1620; --accent-soft: #16303f;
  --ok: #6fd28f; --ok-soft: #133222; --warn: #f2bb5b; --warn-soft: #3a2b10; --late: #ff8b7e; --late-soft: #421a16;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.5 var(--font); background: var(--bg); color: var(--fg); padding-bottom: var(--dock-space); overflow-x: hidden; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: clamp(1.5rem, 4vw, 2.2rem); }
h2 { font-size: 1.25rem; }
p { margin: 0; }
a { color: var(--accent); }
img { max-width: 100%; height: auto; display: block; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
#app:focus { outline: none; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; }

/* layout */
.page { max-width: 1100px; margin: 0 auto; padding: 24px 16px; display: grid; gap: var(--gap); }
.page.narrow { max-width: 520px; }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* parts */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn--small { min-height: 36px; padding: 0 12px; font-size: .9rem; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .85rem; font-weight: 600; background: var(--accent-soft); color: var(--fg); }
.kpi { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.field { display: grid; gap: 6px; font-weight: 600; }
.field input, .field select { font: inherit; min-height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--muted); background: var(--surface); color: var(--fg); width: 100%; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table-wrap { overflow-x: auto; }

/* health: [data-health] gets data-state from the 1 s tick */
[data-state="ok"] { --h: var(--ok); --h-soft: var(--ok-soft); }
[data-state="warn"] { --h: var(--warn); --h-soft: var(--warn-soft); }
[data-state="late"] { --h: var(--late); --h-soft: var(--late-soft); }
[data-state] { border-left: 6px solid var(--h, var(--line)); }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; background: var(--h, var(--accent)); transition: width .9s linear; }

/* toggle. Bug 2: the real checkbox sits ABOVE the drawn track, so the click lands on it. */
.toggle { position: relative; display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.toggle input { position: absolute; left: 0; top: 50%; width: 48px; height: 28px; margin: -14px 0 0; opacity: 0; z-index: 1; cursor: pointer; }
.toggle .track { position: relative; width: 48px; height: 28px; border-radius: 14px; background: var(--muted); flex: none; transition: background .2s; }
.toggle .track::after { content: ""; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; }
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track::after { transform: translateX(20px); }
.toggle input:focus-visible + .track { outline: 3px solid var(--accent); outline-offset: 2px; }

/* modal. Bug 1: backdrop carries data-self, so clicks on the form never close it. */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgb(10 14 20 / .55); display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); color: var(--fg); border-radius: var(--radius); padding: 20px; width: min(100%, 440px); max-height: calc(100vh - 32px); overflow: auto; }

/* dock: full-width tab bar on phones, floating centred pill from 768 px */
.dock { position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); }
.dock ul { list-style: none; margin: 0; padding: 0; display: flex; height: var(--dock-h); }
.dock li { flex: 1 1 0; min-width: 0; display: flex; }
.dock a, .dock button { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; padding: 4px 6px; min-width: 0;
  font: inherit; font-size: .8rem; font-weight: 600; line-height: 1.15; color: var(--muted); text-decoration: none; background: none; border: 0; cursor: pointer; }
.dock a[aria-current="page"] { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }
.dock--dark { --surface: #171d25; --line: #2b3440; --muted: #a7b1bd; --accent: #63b3e3; }
@media (min-width: 768px) {
  :root { --dock-h: 56px; }
  .dock { left: 50%; right: auto; bottom: 16px; transform: translateX(-50%); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow); padding: 0 8px; }
  .dock li { flex: none; }
  .dock a, .dock button { font-size: .9rem; padding: 0 16px; }
  .dock a[aria-current="page"] { box-shadow: inset 0 -3px 0 var(--accent); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
