/* Tokens: the devboard's palette and scale (builder/web/static/style.css). See DESIGN.md#style */
:root {
  --bg: #0b1020; --panel: #121a2b; --panel-2: #182236; --panel-3: #1f2b44; --line: #223049; --line-2: #2d3d5c;
  --fg: #e6eaf2; --fg-2: #c3cad8; --muted: #8a94a8;
  --accent: #f59e0b; --accent-fg: #ffd27a; --accent-soft: rgba(245, 158, 11, .14);
  --ok: #3fcf8e; --ok-soft: rgba(63, 207, 142, .14); --warn: #e3b341; --warn-soft: rgba(227, 179, 65, .14); --bad: #f0566a; --bad-soft: rgba(240, 86, 106, .14);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs-title: 20px; --fs-panel: 14px; --fs-body: 13px; --fs-label: 11px; --fs-mono: 12.5px; --fs-big: 22px;
  --sp-1: .25rem; --sp-2: .5rem; --sp-3: .75rem; --sp-4: 1rem; --sp-5: 1.5rem;
  --radius: 8px; --radius-sm: 5px; --topbar: 48px; --sidebar: 200px;
}

/* Base */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--fg); font: var(--fs-body)/1.5 var(--sans); font-variant-numeric: tabular-nums; display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); grid-template-rows: var(--topbar) 1fr; }
body.bare { grid-template-columns: minmax(0, 1fr); }
a { color: var(--accent-fg); text-decoration: none; }
a:hover { text-decoration: underline; }
b { font-weight: 600; }
h1, h2 { margin: 0; font-weight: 600; line-height: 1.3; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
code { font: var(--fs-mono) var(--mono); }
.muted { color: var(--muted); font-weight: 400; }
.mono { font-family: var(--mono); font-size: var(--fs-mono); }
.num { text-align: right; }
.nowrap { white-space: nowrap; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.icon { width: 16px; height: 16px; flex: none; }
input, button { font: inherit; color: var(--fg); background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: .35rem .6rem; }
input { width: 100%; padding: .5rem .65rem; font-size: 14px; }
input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
button { cursor: pointer; white-space: nowrap; }
button:hover { border-color: var(--muted); }
button:disabled { opacity: .55; cursor: progress; }
button.primary { padding: .5rem .9rem; font-weight: 600; color: #1a1205; background: var(--accent); border-color: var(--accent); }
button.primary:hover { background: var(--accent-fg); border-color: var(--accent-fg); }
button.danger { color: var(--bad); border-color: rgba(240, 86, 106, .45); }
button.danger:hover { background: var(--bad-soft); border-color: var(--bad); }
button.link { padding: 0; border: none; background: none; color: var(--accent-fg); }
button.link:hover { text-decoration: underline; }

/* Top bar */
.topbar { grid-column: 1 / -1; position: sticky; top: 0; z-index: 3; display: flex; align-items: center; gap: var(--sp-3); height: var(--topbar); padding: 0 var(--sp-4); background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: var(--sp-2); font-weight: 700; font-size: 15px; color: var(--fg); }
.brand .icon { width: 20px; height: 20px; color: var(--accent); }
.brand:hover { text-decoration: none; color: var(--accent-fg); }
.brand .section { padding-left: var(--sp-2); border-left: 1px solid var(--line-2); color: var(--muted); font-weight: 500; }
.topspace { flex: 1; }
.who { color: var(--fg-2); font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 14rem; }
.toplink { display: inline-flex; align-items: center; gap: .35rem; color: var(--muted); font-size: 12px; padding: .2rem .6rem; border: 1px solid var(--line); border-radius: 999px; background: none; }
.toplink:hover { color: var(--fg); border-color: var(--muted); text-decoration: none; }
.toplink .icon { width: 14px; height: 14px; }

/* Sidebar */
.sidebar { position: sticky; top: var(--topbar); align-self: start; height: calc(100vh - var(--topbar)); display: flex; flex-direction: column; gap: 2px; padding: var(--sp-3); background: var(--panel); border-right: 1px solid var(--line); }
.navlink { display: flex; align-items: center; gap: var(--sp-2); padding: .45rem var(--sp-2); border-radius: var(--radius-sm); color: var(--fg-2); border-left: 2px solid transparent; }
.navlink:hover { background: var(--panel-2); color: var(--fg); text-decoration: none; }
.navlink[aria-current="page"] { background: var(--accent-soft); color: var(--accent-fg); border-left-color: var(--accent); font-weight: 600; }
.navlink .icon { color: var(--muted); }
.navlink[aria-current="page"] .icon, .navlink:hover .icon { color: inherit; }
.navlink .ext { margin-left: auto; color: var(--muted); font-size: 11px; }

/* Main */
main { min-width: 0; width: 100%; max-width: 1280px; padding: var(--sp-5); }
body.bare main { display: flex; flex-direction: column; align-items: center; padding-top: 12vh; }
.pagehead { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.pagehead h1 { font-size: var(--fs-title); }
.pagehead h1 .mono { font-size: 16px; }
.back { margin-left: auto; font-size: 12px; }
.error, .form-error { margin: 0 0 var(--sp-4); padding: var(--sp-2) var(--sp-3); border: 1px solid rgba(240, 86, 106, .5); border-left-width: 3px; border-radius: var(--radius-sm); background: var(--bad-soft); color: var(--bad); }
.form-error { margin: var(--sp-3) 0 0; }
.notice { margin: 0; padding: var(--sp-2) var(--sp-3); border: 1px solid rgba(245, 158, 11, .45); border-left-width: 3px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--fg); }
.notice p { margin: 0; }
.noscript { position: fixed; bottom: var(--sp-4); left: 50%; transform: translateX(-50%); margin: 0; padding: var(--sp-2) var(--sp-4); border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn); }
.meta { margin: var(--sp-2) 0 0; color: var(--muted); font-size: 12px; }
.meta span + span::before { content: "·"; margin: 0 .5em; }
.meta b { color: var(--fg-2); }
.label { color: var(--muted); font-size: var(--fs-label); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }

/* Cards: login and messages */
.card { width: 100%; max-width: 420px; padding: var(--sp-5); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 12px 40px rgba(0, 0, 0, .35); }
.card h1 { font-size: var(--fs-title); margin-bottom: var(--sp-3); }
.card p { margin: 0 0 var(--sp-3); }
.card.message { max-width: 520px; margin: 8vh auto 0; }
.stack { display: flex; flex-direction: column; gap: var(--sp-3); }
.stack p { margin: 0; }
.stack label { display: flex; flex-direction: column; gap: var(--sp-1); color: var(--fg-2); font-size: 12px; font-weight: 600; }
.stack .link { align-self: flex-start; font-size: 12px; }

/* Panels and KPIs */
.panel { min-width: 0; margin-bottom: var(--sp-4); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-head { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: var(--fs-panel); }
.panel-head p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.panel-head code { color: var(--fg-2); }
.panel-pad { display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-4); }
.panel-body { overflow: auto; border-radius: 0 0 var(--radius) var(--radius); }
.panel-body:first-child { border-radius: var(--radius); }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-3); margin-bottom: var(--sp-4); }
.kpi { display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0; padding: var(--sp-3) var(--sp-4); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.kpi .big { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-big); font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; }
.sub { font-size: 12px; }
.links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
.linkcard { display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-4); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); color: var(--fg); }
.linkcard:hover { text-decoration: none; border-color: var(--accent); }
.linkcard .icon { width: 20px; height: 20px; color: var(--accent); }
.linkcard small { display: block; color: var(--muted); font-size: 12px; }

/* Bundle key */
.panel.key { max-width: 880px; }
.keyrow { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.token { flex: 1 1 18rem; min-width: 0; padding: .5rem .7rem; background: var(--bg); border: 1px solid var(--line-2); border-radius: var(--radius-sm); color: var(--fg); overflow-wrap: anywhere; user-select: all; }
.token.revealed { border-color: var(--accent); }
.keybuttons { display: flex; gap: var(--sp-2); }
.keybuttons button { min-width: 4.5rem; }
.delivery { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); }
.delivery ul { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-3); margin: 0; padding: 0; list-style: none; }
.delivery li { display: inline-flex; align-items: center; gap: .35rem; }
.region { font-weight: 600; color: var(--fg-2); }
.hint { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 12px; }

/* Tags */
.tag { display: inline-block; padding: 0 .5rem; border: 1px solid var(--line-2); border-radius: var(--radius-sm); font-size: 12px; line-height: 1.4; color: var(--muted); white-space: nowrap; }
.tag.ok { color: var(--ok); border-color: rgba(63, 207, 142, .5); background: var(--ok-soft); }
.tag.warn { color: var(--warn); border-color: rgba(227, 179, 65, .5); background: var(--warn-soft); }
.tag.bad { color: var(--bad); border-color: rgba(240, 86, 106, .5); background: var(--bad-soft); }
.tag.accent { color: var(--accent-fg); border-color: rgba(245, 158, 11, .5); background: var(--accent-soft); }

/* Tables */
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { padding: .4rem .7rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
td { overflow-wrap: anywhere; }
th { white-space: nowrap; }
thead th { position: sticky; top: 0; z-index: 1; font-size: var(--fs-label); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: var(--panel-2); }
thead th .muted { text-transform: none; letter-spacing: 0; }
tbody tr:nth-child(even) > td { background: rgba(255, 255, 255, .02); }
tbody tr:hover > td { background: rgba(255, 255, 255, .045); }
tbody:last-child tr:last-child > * { border-bottom: none; }
.empty { color: var(--muted); font-style: italic; padding: var(--sp-4) var(--sp-3); }
.bundles td, .txs td, .timeline td:first-child { white-space: nowrap; }
.bundles { min-width: 900px; }
.txs { min-width: 640px; }
.compare { table-layout: fixed; }
.compare col.field { width: 9rem; }
.compare tbody th { font-weight: 500; color: var(--muted); }
.compare tbody + tbody tr:first-child > * { border-top: 1px solid var(--line); }
.compare tr.group th { font-size: var(--fs-label); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; background: var(--panel-2); }
.pager { display: flex; justify-content: space-between; padding: var(--sp-2) var(--sp-4); border-top: 1px solid var(--line); font-size: 12px; }
.pager a:only-child { margin-left: auto; }

/* Narrow screens: the sidebar becomes a row under the top bar, grids stack. */
@media (max-width: 900px) {
  body { grid-template-columns: minmax(0, 1fr); grid-template-rows: var(--topbar) auto 1fr; }
  body.bare { grid-template-rows: var(--topbar) 1fr; }
  .sidebar { height: auto; z-index: 2; flex-direction: row; overflow-x: auto; padding: var(--sp-2) var(--sp-3); border-right: none; border-bottom: 1px solid var(--line); }
  .navlink { flex: none; padding: .3rem .5rem; border-left: none; border-bottom: 2px solid transparent; border-radius: 0; }
  .navlink[aria-current="page"] { background: none; border-bottom-color: var(--accent); }
  .brand .section { display: none; }
  main { padding: var(--sp-3); }
  body.bare main { padding-top: 6vh; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .links { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 480px) {
  .who { display: none; }
  .keybuttons { flex: 1; }
  .keybuttons button { flex: 1; }
}
