/* panel.ai.id console, design system v2 (ADR-0075, docs/design/design-system-v2.md). The one stylesheet of the
   console: tokens.css carries every value, this file the components; there is no second layer (skin.css is gone).
   Principles: calm surfaces, one accent for what acts (primary buttons, the current page, focus, links), status
   colours that mean the same everywhere and never stand alone (a dot or a word goes with them), one radius scale,
   a 4 px grid, 13-15 px working text, tabular numbers. Server-rendered, no framework, no inline style or script;
   everything works without JavaScript (fx.js only adds the theme switch, copy buttons and the 3D map).
   Motion: transitions answer the viewer (hover, press, focus, open) within --dur-1/--dur-2; page parts enter once
   with --dur-3; every duration collapses under prefers-reduced-motion or data-motion="reduced" (tokens.css).
   Breakpoints: > 1600 px wide content up to --max; <= 1100 px the sidebar becomes a rail; <= 860 px it hides behind
   "Menu"; <= 600 px phone spacing.
   Fonts: Geist and Geist Mono (SIL OFL 1.1, static/fonts/OFL-Geist.txt), served by the panel (font-src 'self'). */
@font-face { font-family: "Geist"; src: url("/static/fonts/Geist-Variable.woff2") format("woff2"); font-weight: 100 900; font-style: normal; font-display: swap; }
@font-face { font-family: "Geist Mono"; src: url("/static/fonts/GeistMono-Variable.woff2") format("woff2"); font-weight: 100 900; font-style: normal; font-display: swap; }

/* === base ======================================================================================================= */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: var(--weight-regular) var(--text-md)/var(--leading) var(--font);
  overflow-wrap: break-word; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
p a, dd a, li a, td a, .page-lead a { text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--link) 35%, transparent); text-underline-offset: 3px; }
p a:hover, dd a:hover, li a:hover, td a:hover { text-decoration-color: currentColor; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }
::selection { background: var(--accent-soft); }
h1, h2, h3, h4 { color: var(--text); font-weight: var(--weight-strong); letter-spacing: var(--tracking-tight); line-height: var(--leading-tight); }
h1 { font-size: var(--text-xl); margin: 0; }
h2 { font-size: var(--text-lg); margin: 0 0 var(--space-3); }
h3 { font-size: var(--text-md); margin: var(--space-4) 0 var(--space-2); }
p { margin: 0 0 var(--space-3); }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-5) 0; }
code, kbd, .mono { font-family: var(--mono); font-size: 0.86em; }
.mono { overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -9999px; top: var(--space-2); z-index: 50; background: var(--surface-raised); color: var(--text); padding: var(--space-2) var(--space-4); border-radius: var(--radius-sm); box-shadow: var(--shadow-2); }
.skip:focus { left: var(--space-4); }
.eyebrow { margin: 0 0 var(--space-1); color: var(--muted); font: var(--weight-medium) var(--text-2xs)/1.4 var(--font); text-transform: uppercase; letter-spacing: .08em; }
.eyebrow .mono { text-transform: none; letter-spacing: 0; }
.tone-ok { color: var(--ok-fg); } .tone-warn { color: var(--warn-fg); } .tone-bad { color: var(--bad-fg); } .tone-info { color: var(--info-fg); }
.plain { list-style: none; margin: 0; padding: 0; }
.plain li { padding: var(--space-1) 0; }

/* === icons (icons.svg, {{icon "name"}}): 16 px line drawings in currentColor ===================================== */
.icon { width: 16px; height: 16px; flex: none; display: inline-block; vertical-align: -3px; fill: none; stroke: currentColor;
  stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-lg { width: 20px; height: 20px; }

/* === app shell: sidebar + top bar ================================================================================ */
body.app { min-height: 100vh; }
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.main-col { display: flex; flex-direction: column; min-width: 0; }
.nav-toggle, .rail-toggle { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }

/* --- sidebar */
.side { position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: var(--space-1);
  padding: var(--space-3) var(--space-3) var(--space-4); background: var(--bg-2); border-right: 1px solid var(--border); scrollbar-width: thin; }
.side-brand { display: flex; align-items: center; gap: var(--space-2); min-height: var(--topbar); margin: calc(-1 * var(--space-3)) calc(-1 * var(--space-3)) var(--space-2);
  padding: 0 var(--space-4); border-bottom: 1px solid var(--border); }
.brand, .lockup { display: inline-flex; align-items: center; gap: 10px; min-width: 0; font-weight: 680; letter-spacing: -0.02em; font-size: 0.98rem; color: var(--text); text-decoration: none; }
.brand { min-height: var(--touch); overflow-wrap: anywhere; }
.brand:hover, .lockup:hover { text-decoration: none; }
.brand-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rackp { width: 17px; height: 21px; flex: none; display: block; }
.rackp-dot { fill: var(--ember); }
.brand-mark { width: 18px; height: 18px; flex: none; border-radius: var(--radius-xs); background: var(--accent); box-shadow: inset 0 0 0 1px rgb(255 255 255 / 20%); }
.brand-logo { height: 26px; width: auto; max-width: 120px; object-fit: contain; flex: none; border-radius: var(--radius-xs); }
.side-label { margin: 0 0 var(--space-1); padding: 0 var(--space-2); color: var(--faint); font: var(--weight-medium) var(--text-2xs)/1.6 var(--font); text-transform: uppercase; letter-spacing: .08em; }
.side-group { margin: var(--space-4) 0 var(--space-1); padding: 0 var(--space-2); color: var(--faint); font: var(--weight-medium) var(--text-2xs)/1.6 var(--font); text-transform: uppercase; letter-spacing: .08em; }
.side ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.side a { position: relative; display: flex; align-items: center; gap: 10px; min-height: 34px; padding: 0 var(--space-2); border-radius: var(--radius-sm);
  color: var(--text-2); font-size: var(--text-sm); font-weight: var(--weight-medium); text-decoration: none;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease); }
.side a .icon { color: var(--muted); transition: color var(--dur-1) var(--ease); }
.side a:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.side a:hover .icon { color: var(--text); }
.side a[aria-current="page"] { background: var(--accent-soft); color: var(--text); }
.side a[aria-current="page"] .icon { color: var(--link); }
.side a[aria-current="page"]::before { content: ""; position: absolute; left: calc(-1 * var(--space-3)); top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.side-label-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot { margin-top: auto; padding-top: var(--space-4); }
.rail-button { display: inline-flex; align-items: center; gap: 10px; min-height: 34px; width: 100%; padding: 0 var(--space-2); border-radius: var(--radius-sm);
  color: var(--muted); font-size: var(--text-sm); cursor: pointer; }
.rail-button:hover { background: var(--hover); color: var(--text); }
.rail-toggle:focus-visible ~ .shell .rail-button { box-shadow: var(--focus-ring); }
.side-account { display: none; }

/* collapsed rail (the viewer's choice, a checkbox, no script): icons only, names as tooltips via the title */
@media (min-width: 861px) {
  .rail-toggle:checked ~ .shell { grid-template-columns: 64px minmax(0, 1fr); }
  .rail-toggle:checked ~ .shell .side-label, .rail-toggle:checked ~ .shell .side-group,
  .rail-toggle:checked ~ .shell .side-label-text, .rail-toggle:checked ~ .shell .brand-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .rail-toggle:checked ~ .shell .side a, .rail-toggle:checked ~ .shell .rail-button { justify-content: center; padding: 0; }
  .rail-toggle:checked ~ .shell .side ul + .side-group-sep { display: block; }
  .rail-toggle:checked ~ .shell .side-brand { justify-content: center; padding: 0; }
  .rail-toggle:checked ~ .shell .rail-button .icon { transform: scaleX(-1); }
}

/* --- top bar */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: var(--space-3); min-height: var(--topbar); padding: 0 var(--space-6);
  background: color-mix(in srgb, var(--bg) 82%, transparent); -webkit-backdrop-filter: saturate(160%) blur(var(--blur)); backdrop-filter: saturate(160%) blur(var(--blur));
  border-bottom: 1px solid var(--border); }
.nav-button { display: none; }
.top-search { flex: 1 1 auto; max-width: 420px; margin: 0; }
.top-search input { width: 100%; min-height: 34px; padding-left: 34px; background: var(--surface-2); border-color: var(--border); }
.top-search label { position: relative; display: block; }
.top-search .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.top-tools { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }
.who { font-size: var(--text-xs); color: var(--muted); overflow-wrap: anywhere; }
.who-name { font-weight: var(--weight-strong); color: var(--text); }
.signout, .lang-switch { margin: 0; }
.lang-short { display: none; font-family: var(--mono); text-transform: uppercase; }

/* --- account menu: <details class="menu"> works without script */
.menu { position: relative; }
.menu > summary { list-style: none; display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--touch); padding: 0 var(--space-2); border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text); font-size: var(--text-sm); }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary:hover { background: var(--hover); }
.avatar { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: var(--radius-pill); background: var(--accent-soft); color: var(--link);
  font: var(--weight-strong) var(--text-xs)/1 var(--font); text-transform: uppercase; border: 1px solid var(--accent-line); }
.menu-panel { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 240px; padding: var(--space-2); border-radius: var(--radius);
  background: var(--surface-raised); border: 1px solid var(--border-strong); box-shadow: var(--shadow-3); animation: pop-in var(--dur-2) var(--ease-out); }
.menu-panel p { margin: 0; padding: var(--space-2) var(--space-3); font-size: var(--text-sm); }
.menu-panel hr { margin: var(--space-2) 0; }
.menu-panel .btn-quiet, .menu-panel button { width: 100%; justify-content: flex-start; }

/* --- viewer's switches (fx.js shows them; without script the console follows the system theme) */
.fx-switches { display: none; gap: var(--space-1); align-items: center; }
html.js .fx-switches { display: inline-flex; }
.fx-switch { display: inline-flex; align-items: center; gap: 6px; min-height: var(--touch); min-width: var(--touch); padding: 0 var(--space-3); border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; color: var(--muted); font: var(--weight-medium) var(--text-sm)/1 var(--font); cursor: pointer;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease); }
.fx-switch:hover { background: var(--hover); color: var(--text); }
.fx-switch[aria-pressed="true"] { color: var(--text); background: var(--accent-soft); border-color: var(--accent-line); }

/* --- main column */
main { width: 100%; max-width: 1240px; min-width: 0; margin: 0 auto; padding: var(--space-6) var(--space-6) var(--space-7); animation: page-in var(--dur-3) var(--ease-out); }
.foot { padding: var(--space-4) var(--space-6); font: var(--text-xs) var(--mono); color: var(--faint); border-top: 1px solid var(--border); }
.actas { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-6);
  background: var(--warn-bg); color: var(--warn-fg); border-bottom: 1px solid var(--warn-line); font-size: var(--text-sm); }
.actas form { margin: 0 0 0 auto; }

/* --- signed-out pages: a quiet grid and one soft accent light; the form is ready at the first paint */
body.bare-page { min-height: 100vh; display: flex; flex-direction: column; position: relative; isolation: isolate;
  background: radial-gradient(ellipse 70% 50% at 50% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 70%), var(--bg); }
body.bare-page::before { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px), linear-gradient(90deg, var(--grid-line) 1px, transparent 1px); background-size: 40px 40px;
  -webkit-mask-image: radial-gradient(ellipse 60% 50% at 50% 25%, #000, transparent 75%); mask-image: radial-gradient(ellipse 60% 50% at 50% 25%, #000, transparent 75%); }
body.bare-page > main { flex: 1 0 auto; }
body.bare-page > .foot { border-top: 0; text-align: center; }
.bare-top { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-4) 0; }
main.bare { max-width: 440px; padding: max(8vh, var(--space-6)) var(--space-4) var(--space-6); }

/* === page header and breadcrumbs ================================================================================= */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1); margin: 0 0 var(--space-3); font-size: var(--text-sm); color: var(--muted); }
.crumbs a { display: inline-flex; align-items: center; min-height: 28px; color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--text); }
.crumbs .icon { width: 12px; height: 12px; color: var(--faint); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: var(--space-3) var(--space-5);
  margin: 0 0 var(--space-6); padding-bottom: var(--space-5); border-bottom: 1px solid var(--border); }
.page-head > div { min-width: 0; }
.page-lead { margin: var(--space-2) 0 0; max-width: 68ch; color: var(--muted); font-size: var(--text-md); }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.section-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--space-2) var(--space-4); margin: 0 0 var(--space-4); }
.section-head h2 { margin: 0; }
.links { display: flex; flex-wrap: wrap; gap: 0 var(--space-4); }
.links > a, .section-head > a, .section-head > span > a, .section-head h2 > a, a.tile-label, .empty a, .alert-list li > a { display: inline-flex; align-items: center; min-height: var(--touch); }

/* === card / panel ================================================================================================ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-5); margin: 0 0 var(--space-5);
  box-shadow: var(--shadow-1); min-width: 0; }
.card > h2:first-child, .card > .section-head:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin: calc(-1 * var(--space-5)) calc(-1 * var(--space-5)) var(--space-4);
  padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); }
.card-head h2 { margin: 0; font-size: var(--text-md); }
.card-foot { display: flex; justify-content: flex-end; gap: var(--space-2); margin: var(--space-4) calc(-1 * var(--space-5)) calc(-1 * var(--space-5));
  padding: var(--space-3) var(--space-5); border-top: 1px solid var(--border); background: var(--bg-2); border-radius: 0 0 var(--radius) var(--radius); }
.card.danger { border-color: var(--bad-line); }
.card.card-warn { border-color: var(--warn-line); background: var(--warn-bg); }
.hint-card, .wizard-card { border-color: var(--accent-line); box-shadow: inset 3px 0 0 var(--accent), var(--shadow-1); }
.hint-card .section-head { margin-bottom: var(--space-2); }
.hint-card p:last-child { margin-bottom: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: var(--space-5); align-items: start; }
.grid-2 > .card { margin: 0; }
.facts { display: grid; grid-template-columns: minmax(140px, max-content) minmax(0, 1fr); gap: var(--space-3) var(--space-6); margin: 0; font-size: var(--text-sm); }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; min-width: 0; color: var(--text); }

/* === stat tiles ================================================================================================== */
.tiles { list-style: none; padding: 0; margin: 0 0 var(--space-5); display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--space-3); }
.tile { display: flex; flex-direction: column; gap: var(--space-1); padding: var(--space-4); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-1); min-width: 0; transition: border-color var(--dur-1) var(--ease); }
.tile:hover, .tile:focus-within { border-color: var(--border-strong); }
.tile-label { color: var(--muted); font: var(--weight-medium) var(--text-xs)/1.4 var(--font); }
.stat { font-size: 1.75rem; font-weight: var(--weight-strong); letter-spacing: -0.03em; line-height: 1.1; font-variant-numeric: tabular-nums; color: var(--text); }
.stat-bad { color: var(--bad-fg); } .stat-warn { color: var(--warn-fg); } .stat-ok { color: var(--ok-fg); }
.stat-note { margin: 0; color: var(--muted); font-size: var(--text-xs); }
.stats .tile { align-items: flex-start; }

/* === tables ====================================================================================================== */
.table-wrap { position: relative; max-width: 100%; overflow: auto; max-height: min(70vh, 900px); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.card .table-wrap { margin: 0 0 var(--space-3); }
.table-wrap:focus-visible { border-radius: var(--radius); }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 10px var(--space-4); border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); color: var(--muted); font: var(--weight-medium) var(--text-2xs)/1.4 var(--font);
  text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; padding-top: var(--space-2); padding-bottom: var(--space-2); }
tbody tr { transition: background var(--dur-1) var(--ease); }
tbody tr:hover { background: var(--hover); }
tbody tr:last-child > * { border-bottom: 0; }
tbody th { font-weight: var(--weight-medium); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.detail { max-width: 440px; color: var(--text-2); }
.actions, .row-actions { white-space: nowrap; text-align: right; }
.row-actions { display: flex; justify-content: flex-end; gap: var(--space-1); opacity: .7; transition: opacity var(--dur-1) var(--ease); }
tr:hover .row-actions, tr:focus-within .row-actions { opacity: 1; }
td > a { display: inline-flex; align-items: center; min-height: var(--touch); }
td .inline-details { margin: 0 0 0 var(--space-3); vertical-align: top; }
td .inline-details > summary { display: inline-flex; align-items: center; min-height: var(--touch); margin: 0; color: var(--bad-fg); font-weight: var(--weight-medium); }
td .inline-details[open] { display: block; margin: var(--space-2) 0 0; }
.table-empty td { padding: var(--space-6); text-align: center; color: var(--muted); }
table.data td { white-space: pre-wrap; overflow-wrap: anywhere; max-width: 28rem; vertical-align: top; }
table.data th a { display: inline-flex; align-items: center; min-height: var(--touch); }
table.cron input { width: 100%; min-width: 120px; }
table.cron input.wide { min-width: 240px; }
.null { color: var(--muted); font-style: italic; }
.meter-cell { width: 140px; }
meter { width: 120px; height: 6px; vertical-align: middle; }
meter::-webkit-meter-bar { background: var(--muted-bg); border: 0; border-radius: var(--radius-pill); height: 6px; }
meter::-webkit-meter-optimum-value { background: var(--ok); border-radius: var(--radius-pill); }
meter::-webkit-meter-suboptimum-value { background: var(--warn); border-radius: var(--radius-pill); }
meter::-webkit-meter-even-less-good-value { background: var(--bad); border-radius: var(--radius-pill); }
.quota { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); }
.quota meter { width: 80px; }
.quota-text { white-space: nowrap; }
tr.quota-near > :first-child { box-shadow: inset 3px 0 0 var(--warn); }
tr.quota-full > :first-child { box-shadow: inset 3px 0 0 var(--bad); }
.usage { font-size: var(--text-sm); color: var(--muted); }
.limit-note { display: block; font-weight: var(--weight-regular); font-size: var(--text-xs); color: var(--muted); }
.pager { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; margin-top: var(--space-3); }
.pager a { display: inline-flex; align-items: center; min-height: var(--touch); }
.alert-list { list-style: none; padding: 0; margin: 0; }
.alert-list li { padding: var(--space-3) 0; border-bottom: 1px solid var(--border); }
.alert-list li:last-child { border-bottom: 0; }

/* === forms ======================================================================================================= */
form { margin: 0; }
.stack { display: flex; flex-direction: column; gap: var(--space-4); margin-top: var(--space-3); }
.stack > .btn, .stack > button, .stack > .btn-quiet { align-self: flex-start; }
.row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3); margin-top: var(--space-3); border: 0; padding: 0; min-width: 0; }
.grid-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-4); }
.filter-form, .search-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3); margin: 0 0 var(--space-4); }
.search-form label { flex: 1 1 220px; }
.cron-when { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-end; }
.cron-when label { flex: 0 1 auto; }
label, .field { display: flex; flex-direction: column; gap: 6px; font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text); }
label .muted, .field-hint { font-weight: var(--weight-regular); font-size: var(--text-xs); color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: var(--space-2); font-weight: var(--weight-regular); min-height: var(--touch); }
label.choice { flex-direction: row; align-items: flex-start; gap: var(--space-3); padding: var(--space-3) var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-weight: var(--weight-regular); cursor: pointer; transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease); }
label.choice:hover { border-color: var(--border-strong); }
label.choice:has(input:checked) { border-color: var(--accent-line); background: var(--accent-soft); }
label.choice input { margin-top: 2px; flex: none; }
fieldset { min-width: 0; margin: 0; padding: var(--space-3) var(--space-4) var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-sm); }
legend { font-size: var(--text-sm); font-weight: var(--weight-medium); padding: 0 var(--space-1); }
input, select, textarea { font: inherit; font-size: var(--text-sm); color: var(--text); background: var(--field-bg); border: 1px solid var(--field-border);
  border-radius: var(--radius-sm); padding: 0 var(--space-3); min-height: var(--touch); max-width: 100%; box-shadow: var(--shadow-1);
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease); }
textarea { padding: var(--space-2) var(--space-3); line-height: 1.5; }
select { padding-right: var(--space-6); }
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: var(--faint); }
input[type=checkbox], input[type=radio] { min-height: 0; width: 16px; height: 16px; padding: 0; box-shadow: none; accent-color: var(--accent); }
input[type=file] { padding: var(--space-2); }
input[readonly] { background: var(--surface-2); }
input:user-invalid, select:user-invalid, textarea:user-invalid,
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); }
.field-error { display: flex; align-items: center; gap: 6px; color: var(--bad-fg); font-size: var(--text-xs); font-weight: var(--weight-medium); }
.field-ok { color: var(--ok-fg); font-size: var(--text-xs); }
input.copy { width: 100%; font-family: var(--mono); font-size: var(--text-xs); }
.copyval { user-select: all; }
textarea.code { font-family: var(--mono); font-size: var(--text-xs); width: 100%; resize: vertical; white-space: pre; overflow-x: auto; }

/* === buttons: primary = accent; secondary; quiet; danger; icon; sizes; loading =================================== */
.btn, .btn-secondary, .btn-quiet, .btn-danger, .btn-icon {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: var(--control); padding: 0 var(--space-4);
  font: var(--weight-medium) var(--text-sm)/1 var(--font); letter-spacing: -0.005em; white-space: nowrap; text-decoration: none; cursor: pointer;
  border-radius: var(--radius-sm); border: 1px solid transparent; position: relative;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease), transform var(--dur-1) var(--ease); }
/* a 36 px button keeps a 44 px target: the hit area grows, the drawing does not */
.btn::after, .btn-secondary::after, .btn-quiet::after, .btn-danger::after, .btn-icon::after { content: ""; position: absolute; inset: -4px 0; }
.btn:hover, .btn-secondary:hover, .btn-quiet:hover, .btn-danger:hover, .btn-icon:hover { text-decoration: none; }
.btn:active, .btn-secondary:active, .btn-quiet:active, .btn-danger:active, .btn-icon:active { transform: translateY(1px); }
.btn { background: var(--btn-bg); color: var(--btn-fg); border-color: color-mix(in srgb, var(--accent) 80%, #000); box-shadow: inset 0 1px 0 rgb(255 255 255 / 16%), var(--shadow-1); }
.btn:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-1); }
.btn-secondary:hover { background: var(--surface-3); }
.btn-quiet { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-quiet:hover { background: var(--hover); color: var(--text); border-color: var(--border-strong); }
.btn-danger, .btn.btn-danger { background: var(--danger); border-color: color-mix(in srgb, var(--danger) 80%, #000); color: #fff; box-shadow: inset 0 1px 0 rgb(255 255 255 / 14%); }
.btn-danger:hover, .btn.btn-danger:hover { background: color-mix(in srgb, var(--danger) 88%, #fff); }
.btn-icon { width: var(--control); padding: 0; background: transparent; color: var(--muted); border-color: transparent; }
.btn-icon:hover { background: var(--hover); color: var(--text); }
.btn-sm { min-height: 28px; padding: 0 var(--space-3); font-size: var(--text-xs); }
.btn-sm::after { inset: -8px 0; }
.btn-lg { min-height: var(--touch); padding: 0 var(--space-5); font-size: var(--text-md); }
.btn.btn-wide, .btn-wide, .stack > .btn.btn-wide { align-self: stretch; width: 100%; min-height: var(--touch); }
button[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn[aria-busy="true"], .is-loading { color: transparent !important; pointer-events: none; }
.btn[aria-busy="true"]::before, .is-loading::before { content: ""; position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%;
  border: 2px solid var(--btn-fg); border-right-color: transparent; animation: spin 700ms linear infinite; }
.btn-secondary.is-loading::before, .btn-quiet.is-loading::before { border-color: var(--text); border-right-color: transparent; }
.inline-form, .inline-details { display: inline-block; margin-right: var(--space-2); vertical-align: top; }
.inline-details > summary { margin: 0; }
.inline-details[open] { display: block; margin: var(--space-2) 0; }

/* === badge / status pill: one class per state kind (badgeFor in templates.go picks it) ============================ */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 0 var(--space-2); min-height: 22px; border-radius: var(--radius-pill);
  font: var(--weight-medium) var(--text-xs)/1 var(--font); white-space: nowrap; vertical-align: middle; text-decoration: none;
  color: var(--text-2); background: var(--muted-bg); border: 1px solid var(--border); }
.badge::before { content: ""; width: 6px; height: 6px; flex: none; border-radius: 50%; background: currentColor; }
a.badge:hover { text-decoration: none; border-color: currentColor; }
.badge-ok { color: var(--ok-fg); background: var(--ok-bg); border-color: var(--ok-line); }
.badge-warn { color: var(--warn-fg); background: var(--warn-bg); border-color: var(--warn-line); }
.badge-bad { color: var(--bad-fg); background: var(--bad-bg); border-color: var(--bad-line); }
.badge-info { color: var(--info-fg); background: var(--info-bg); border-color: var(--info-line); }
.badge-muted { color: var(--muted); background: var(--muted-bg); border-color: var(--border); }
.badge-busy::before { animation: pulse 1.4s var(--ease) infinite; }

/* === tabs (and the older .filters, the same component) ============================================================ */
.tabs, .filters { display: flex; flex-wrap: wrap; gap: var(--space-1); margin: 0 0 var(--space-5); border-bottom: 1px solid var(--border); }
.tabs a, .filters a { position: relative; display: inline-flex; align-items: center; gap: 6px; min-height: var(--touch); padding: 0 var(--space-3);
  color: var(--muted); font-size: var(--text-sm); font-weight: var(--weight-medium); text-decoration: none; transition: color var(--dur-1) var(--ease); }
.tabs a:hover, .filters a:hover { color: var(--text); text-decoration: none; }
.tabs a[aria-current], .filters a[aria-current] { color: var(--text); }
.tabs a[aria-current]::after, .filters a[aria-current]::after { content: ""; position: absolute; left: var(--space-2); right: var(--space-2); bottom: -1px; height: 2px;
  border-radius: 2px 2px 0 0; background: var(--accent); }

/* === flash and toast ============================================================================================= */
.flash { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-3) var(--space-4); margin: 0 0 var(--space-4); border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: var(--text-sm); animation: page-in var(--dur-3) var(--ease-out); }
.flash > .icon { margin-top: 2px; }
.flash-ok { background: var(--ok-bg); color: var(--ok-fg); border-color: var(--ok-line); }
.flash-error { background: var(--bad-bg); color: var(--bad-fg); border-color: var(--bad-line); }
.flash-warn { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-line); }
.flash-info { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-line); }
.flash p { margin: 0; }
.flash .facts { margin-top: var(--space-2); color: var(--text); }
.toast { position: fixed; right: var(--space-5); bottom: var(--space-5); z-index: 40; max-width: min(420px, calc(100vw - 2 * var(--space-5))); margin: 0;
  background: var(--surface-raised); color: var(--text); border: 1px solid var(--border-strong); box-shadow: var(--shadow-3); animation: toast-in var(--dur-3) var(--ease-out); }
.toast-demo { position: static; animation: none; }

/* === confirm dialog: <details class="dialog"> opens a centred panel over a scrim, no script ======================= */
.confirm { border: 1px solid var(--warn-line); background: var(--warn-bg); border-radius: var(--radius-sm); padding: var(--space-4); margin: var(--space-3) 0; }
.confirm h3 { margin-top: 0; }
.confirm p { margin: 0 0 var(--space-2); }
.dialog { display: inline-block; }
.dialog > summary { list-style: none; }
.dialog > summary::-webkit-details-marker { display: none; }
.dialog[open] > summary::before { content: ""; position: fixed; inset: 0; z-index: 60; background: var(--scrim); cursor: default; animation: fade-in var(--dur-2) var(--ease); }
.dialog-panel { position: fixed; z-index: 61; left: 50%; top: 18vh; width: min(460px, calc(100vw - 2 * var(--space-4))); transform: translateX(-50%);
  padding: var(--space-5); border-radius: var(--radius-lg); background: var(--surface-raised); border: 1px solid var(--border-strong); box-shadow: var(--shadow-3);
  animation: dialog-in var(--dur-3) var(--ease-out); }
.dialog-panel h2 { font-size: var(--text-lg); }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-5); }

/* === empty state ================================================================================================= */
.empty { margin: 0; padding: var(--space-6) var(--space-4); border: 1px dashed var(--border-strong); border-radius: var(--radius); text-align: center; color: var(--muted); font-size: var(--text-sm); }
.empty p { margin: 0 0 var(--space-3); }
.empty p:last-child { margin-bottom: 0; }
.empty .btn { margin: 0 auto; }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); padding: var(--space-7) var(--space-4); text-align: center; }
.empty-art { display: grid; place-items: center; width: 56px; height: 56px; margin-bottom: var(--space-2); border-radius: var(--radius); background: var(--accent-soft); color: var(--link);
  border: 1px solid var(--accent-line); }
.empty-art .icon { width: 24px; height: 24px; }
.empty-state h3 { margin: 0; color: var(--text); }
.empty-state p { max-width: 46ch; }

/* === skeleton ==================================================================================================== */
.skeleton { display: grid; gap: var(--space-2); }
.skeleton-line { height: 12px; border-radius: var(--radius-xs); background: linear-gradient(90deg, var(--muted-bg) 25%, var(--hover) 50%, var(--muted-bg) 75%) 0 0 / 300% 100%;
  animation: shimmer 1.6s linear infinite; }
.skeleton-line:nth-child(2) { width: 80%; } .skeleton-line:nth-child(3) { width: 60%; }

/* === progress and steps (wizard) ================================================================================= */
.steps { list-style: none; counter-reset: step; padding: 0; margin: 0 0 var(--space-5); display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-2); }
.steps li { display: flex; flex-direction: column; gap: 2px; padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); }
.steps li[aria-current] { border-color: var(--accent-line); box-shadow: inset 0 2px 0 var(--accent); }
.steps .step-done { color: var(--ok-fg); }
.steps a, .steps strong { display: inline-flex; align-items: center; min-height: var(--touch); font-weight: var(--weight-strong); }
.step-num { font: var(--weight-medium) var(--text-2xs)/1.4 var(--font); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
progress, progress.wizard { width: 100%; height: 6px; border: 0; border-radius: var(--radius-pill); background: var(--muted-bg); accent-color: var(--accent); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--muted-bg); }
progress::-webkit-progress-value { background: var(--accent); border-radius: var(--radius-pill); }
progress::-moz-progress-bar { background: var(--accent); }

/* === code and secret block ======================================================================================= */
.codeblock { position: relative; display: flex; align-items: flex-start; gap: var(--space-2); margin: var(--space-2) 0 var(--space-3); padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm); background: var(--bg-2); border: 1px solid var(--border); font: var(--text-xs)/1.6 var(--mono); }
.codeblock pre, .codeblock code { flex: 1 1 auto; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; background: none; border: 0; padding: 0; }
.codeblock .btn-icon { flex: none; margin: -6px -8px -6px 0; }
.secret { filter: blur(5px); transition: filter var(--dur-2) var(--ease); }
.codeblock:hover .secret, .codeblock:focus-within .secret { filter: none; }
html:not(.js) [data-copy] { display: none; }
[data-copy][data-done]::after { content: attr(data-done); position: absolute; right: 0; bottom: calc(100% + 4px); inset: auto 0 calc(100% + 4px) auto; padding: 2px 8px;
  border-radius: var(--radius-xs); background: var(--surface-raised); border: 1px solid var(--border); color: var(--text); font: var(--text-xs) var(--font); white-space: nowrap; }
pre.log { font: var(--text-xs)/1.65 var(--mono); background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4); margin: var(--space-3) 0; max-height: 70vh; overflow: auto; white-space: pre; max-width: 100%; color: var(--text); }
pre.mono { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg-2); padding: var(--space-3); border-radius: var(--radius-sm); border: 1px solid var(--border); }

/* === disclosure ================================================================================================== */
details > summary { cursor: pointer; color: var(--link); margin-top: var(--space-3); min-height: var(--touch); display: flex; align-items: center; gap: var(--space-2); font-weight: var(--weight-medium); font-size: var(--text-sm); }
details.create > summary, details.more > summary { list-style: none; margin: 0; color: var(--text); flex-wrap: wrap; }
details.create > summary::-webkit-details-marker, details.more > summary::-webkit-details-marker { display: none; }
details.create > summary h2, details.more > summary h2 { display: inline; margin: 0; }
details.create > summary::before, details.more > summary::before { content: "+"; display: inline-grid; place-items: center; width: 22px; height: 22px; flex: none;
  border-radius: var(--radius-xs); border: 1px solid var(--border-strong); font-weight: var(--weight-strong); color: var(--text); }
details.more[open] > summary { margin-bottom: var(--space-3); }
details.more[open] > summary::before, details.create[open] > summary::before { content: "\2212"; }

/* === dashboard task cards ======================================================================================== */
.tasks-block { margin: 0 0 var(--space-6); }
.tasks-head { font-size: var(--text-sm); color: var(--muted); font-weight: var(--weight-medium); text-transform: uppercase; letter-spacing: .06em; }
.tasks { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); gap: var(--space-3); }
.task { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; padding: var(--space-4); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-1); transition: border-color var(--dur-1) var(--ease), transform var(--dur-2) var(--ease); }
.task:hover, .task:focus-within { border-color: var(--accent-line); }
.task-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--link); }
.task-title { margin: 0; font-size: var(--text-md); }
.task-stat { margin: 0; font-weight: var(--weight-medium); font-size: var(--text-sm); overflow-wrap: anywhere; }
.task-text { margin: 0 0 auto; color: var(--muted); font-size: var(--text-sm); }
.task > .btn, .task > .btn-secondary { align-self: stretch; margin-top: var(--space-2); }
.task-later { background: transparent; border-style: dashed; box-shadow: none; }
.task-later .task-stat { color: var(--muted); }

/* === the sign-in card ============================================================================================ */
.card.login { padding: var(--space-6); border-radius: var(--radius-lg); background: var(--surface); border-color: var(--border-strong); box-shadow: var(--shadow-3);
  animation: dialog-rise var(--dur-3) var(--ease-out); }
.login .lockup { margin: 0 0 var(--space-6); }
.login h1 { font-size: var(--text-xl); margin: 0 0 var(--space-1); }
.login .tagline { margin: 0 0 var(--space-5); }
.login .brand-logo { height: 44px; max-width: 200px; }
.login-foot { margin: var(--space-5) 0 0; text-align: center; font-size: var(--text-xs); color: var(--faint); }

/* === charts (internal/web/chart.go) =============================================================================== */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: var(--space-4); }
.chart-fig { margin: 0; min-width: 0; }
.chart-fig figcaption { font-weight: var(--weight-strong); font-size: var(--text-sm); margin-bottom: var(--space-1); }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart-axis { stroke: var(--border-strong); stroke-width: 1; }
.chart-grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 2 4; }
.chart-tick { fill: var(--muted); font-size: 17px; font-family: var(--font); }
.chart-line { fill: none; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.chart-bar { fill: var(--link); opacity: .85; transition: opacity var(--dur-1) var(--ease); }
.chart-bar:hover { opacity: 1; }
.chart-line.s0 { stroke: var(--accent); } .chart-dot.s0, .swatch.s0 { fill: var(--accent); background: var(--accent); }
.chart-line.s1 { stroke: var(--ember); } .chart-dot.s1, .swatch.s1 { fill: var(--ember); background: var(--ember); }
.chart-line.s2 { stroke: #2cc5d6; } .chart-dot.s2, .swatch.s2 { fill: #2cc5d6; background: #2cc5d6; }
.chart-line.s3 { stroke: #a78bfa; } .chart-dot.s3, .swatch.s3 { fill: #a78bfa; background: #a78bfa; }
.chart-line.s4 { stroke: #8fa3c7; } .chart-dot.s4, .swatch.s4 { fill: #8fa3c7; background: #8fa3c7; }
.chart-line.s5 { stroke: #f472b6; } .chart-dot.s5, .swatch.s5 { fill: #f472b6; background: #f472b6; }
.legend { list-style: none; padding: 0; margin: var(--space-1) 0 0; font-size: var(--text-sm); color: var(--muted); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: var(--space-1); vertical-align: middle; }
.load-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: var(--space-4); }

/* === the wizard's success mark: a check in a hexagon that draws itself once (decoration only) ===================== */
.success-mark { display: block; width: 72px; height: 72px; margin: 0 0 var(--space-4); }
.success-mark .hex { fill: var(--ok-bg); stroke: var(--ok-fg); stroke-width: 2; }
.success-mark .tick { fill: none; stroke: var(--ok-fg); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 48; stroke-dashoffset: 48;
  animation: draw var(--dur-4) var(--ease-out) var(--dur-2) forwards; }
.success-mark .spark { fill: var(--honey); opacity: 0; animation: fade-in var(--dur-3) var(--ease) var(--dur-4) forwards; }

/* === the 3D cluster map (fx.js, gl.js): optional; hidden without script and in light mode; the tiles say the same == */
.scene3d { position: relative; overflow: hidden; border-radius: var(--radius); }
.scene3d canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; opacity: 0; transition: opacity var(--dur-3) var(--ease-out); }
.scene3d.is-ready canvas { opacity: 1; }
.cluster3d { min-height: 340px; margin: 0 0 var(--space-5); background: radial-gradient(ellipse 80% 70% at 50% 0%, var(--glow-cool), transparent 70%), var(--bg-2); border: 1px solid var(--border); }
.cluster3d .scene-legend { position: absolute; left: var(--space-4); bottom: var(--space-3); z-index: 1; margin: 0; padding: 3px 10px; border-radius: var(--radius-pill);
  background: var(--surface-raised); border: 1px solid var(--border); color: var(--muted); font-size: var(--text-xs); }
.cluster3d .scene-labels { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.cluster3d .scene-label { position: absolute; transform: translate(-50%, -100%); padding: 2px 8px; border-radius: var(--radius-pill); background: var(--surface-raised);
  border: 1px solid var(--border); color: var(--text); font: var(--text-xs) var(--mono); white-space: nowrap; }
html:not(.js) .cluster3d, :root[data-fx="lite"] .cluster3d { display: none; }

/* === the file manager ============================================================================================ */
#files .crumbs { padding: var(--space-2) var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-2); font-family: var(--mono); }
#files .crumbs a { padding: 2px 6px; border-radius: var(--radius-xs); min-height: 0; }
#files .crumbs a:hover { background: var(--hover); }
#files td.mono a { text-decoration: none; color: var(--text); font-weight: var(--weight-medium); }
#files td.mono a:hover { color: var(--link); text-decoration: underline; }
#files td.mono a[href*="/files?path="]::before { content: ""; display: inline-block; width: 14px; height: 11px; margin-right: 8px; vertical-align: -1px; border-radius: 2px 3px 3px 3px; background: var(--honey); }
#files td.mono a[href*="/files/item?path="]::before { content: ""; display: inline-block; width: 10px; height: 13px; margin: 0 10px 0 2px; vertical-align: -2px; border-radius: 2px; border: 1.5px solid var(--muted); }
#files tbody tr:has(input:checked) { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
#upload input[type="file"] { padding: var(--space-4); border: 1.5px dashed var(--border-strong); border-radius: var(--radius); background: var(--bg-2); width: 100%; }
#upload input[type="file"]:hover, #upload input[type="file"]:focus { border-color: var(--accent-line); background: var(--accent-soft); }

/* === the style guide page (styleguide.html) ======================================================================= */
.sg-section { scroll-margin-top: calc(var(--topbar) + var(--space-4)); }
.sg-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin: 0 0 var(--space-4); }
.sg-swatches { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: var(--space-2); }
.sg-swatches li { display: flex; flex-direction: column; gap: var(--space-1); font-size: var(--text-xs); color: var(--muted); }
.sg-chip { height: 44px; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.sg-c-bg { background: var(--bg); } .sg-c-surface { background: var(--surface); } .sg-c-surface-2 { background: var(--surface-2); } .sg-c-raised { background: var(--surface-raised); }
.sg-c-text { background: var(--text); } .sg-c-muted { background: var(--muted); } .sg-c-accent { background: var(--accent); } .sg-c-ok { background: var(--ok); }
.sg-c-warn { background: var(--warn); } .sg-c-bad { background: var(--bad); } .sg-c-info { background: var(--info); } .sg-c-border { background: var(--border-strong); }
.sg-theme { padding: var(--space-5); border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.sg-type p { margin: 0 0 var(--space-2); }
.sg-t-xl { font-size: var(--text-xl); font-weight: var(--weight-strong); letter-spacing: var(--tracking-tight); }
.sg-t-lg { font-size: var(--text-lg); font-weight: var(--weight-strong); }
.sg-t-md { font-size: var(--text-md); } .sg-t-sm { font-size: var(--text-sm); } .sg-t-xs { font-size: var(--text-xs); color: var(--muted); }
.sg-icons { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--space-2); }
.sg-icons li { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); padding: var(--space-3) var(--space-1); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font: var(--text-2xs) var(--mono); color: var(--muted); }
.sg-icons .icon { color: var(--text); width: 20px; height: 20px; }

/* === keyframes (every duration is a token, so reduced motion stops them) ========================================== */
@keyframes page-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes dialog-in { from { opacity: 0; transform: translate(-50%, 8px) scale(.98); } to { opacity: 1; transform: translateX(-50%); } }
@keyframes dialog-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes shimmer { to { background-position: -150% 0; } }
@keyframes draw { to { stroke-dashoffset: 0; } }

/* === responsive ================================================================================================== */
@media (min-width: 1601px) { main { max-width: var(--max); } }
@media (max-width: 1100px) and (min-width: 861px) {
  .shell { grid-template-columns: 64px minmax(0, 1fr); }
  .side-label, .side-group, .side-label-text, .brand-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .side a, .rail-button, .side-brand { justify-content: center; padding: 0; }
  .rail-button { display: none; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; z-index: 45; left: 0; top: 0; bottom: 0; width: min(300px, 86vw); height: auto; transform: translateX(-102%);
    box-shadow: var(--shadow-3); transition: transform var(--dur-3) var(--ease-out); visibility: hidden; }
  .nav-toggle:checked ~ .shell .side { transform: none; visibility: visible; }
  .nav-scrim { display: none; }
  .nav-toggle:checked ~ .shell .nav-scrim { display: block; position: fixed; inset: 0; z-index: 44; background: var(--scrim); animation: fade-in var(--dur-2) var(--ease); }
  .nav-button { display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--touch); padding: 0 var(--space-3); border: 1px solid var(--border);
    border-radius: var(--radius-sm); cursor: pointer; font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text); }
  .nav-toggle:focus-visible ~ .shell .nav-button { box-shadow: var(--focus-ring); }
  .rail-button { display: none; }
  .top { padding: 0 var(--space-4); }
  .top-search { display: none; }
  main { padding: var(--space-5) var(--space-4) var(--space-6); }
  .actas { padding: var(--space-2) var(--space-4); }
  .card { padding: var(--space-4); }
  .card-head { margin: calc(-1 * var(--space-4)) calc(-1 * var(--space-4)) var(--space-4); padding: var(--space-3) var(--space-4); }
  .detail { max-width: none; }
  .foot { padding: var(--space-4); }
}
@media (max-width: 600px) {
  :root { --text-xl: 1.3rem; }
  .top .who, .top .lang-long, .fx-switch .fx-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .top .lang-short { display: inline; }
  main { padding: var(--space-4) var(--space-3) var(--space-6); }
  .page-head { align-items: flex-start; margin-bottom: var(--space-5); padding-bottom: var(--space-4); }
  .card { padding: var(--space-3) var(--space-4); margin-bottom: var(--space-4); }
  .facts { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .facts dt { margin-top: var(--space-3); }
  .meter-cell { display: none; }
  .row > label, .row > input, .row > select { flex: 1 1 100%; }
  .grid-fields { grid-template-columns: minmax(0, 1fr); }
  th, td { padding: var(--space-2) var(--space-3); }
  .tasks { grid-template-columns: minmax(0, 1fr); }
  .card.login { padding: var(--space-5) var(--space-4); }
  main.bare { padding-left: var(--space-3); padding-right: var(--space-3); }
  .chart-tick { font-size: 22px; }
  .toast { left: var(--space-3); right: var(--space-3); bottom: var(--space-3); }
}

/* === accessibility fallbacks ===================================================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-iteration-count: 1 !important; }
  .skeleton-line, .badge-busy::before { animation: none; }
}
:root[data-motion="reduced"] .skeleton-line, :root[data-motion="reduced"] .badge-busy::before { animation: none; }
:root[data-motion="reduced"] * { animation-iteration-count: 1 !important; }
@media (forced-colors: active) {
  .side a[aria-current="page"], .tabs a[aria-current], .filters a[aria-current] { outline: 2px solid CanvasText; outline-offset: -2px; }
  .badge::before { forced-color-adjust: none; }
  body.bare-page::before { display: none; }
  :focus-visible { outline: 2px solid Highlight; }
}
@media print {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .side, .top, .actas, .scene3d, .fx-switches, .skip, body.bare-page::before { display: none !important; }
  .shell { display: block; }
  .card, .tile, .task, .table-wrap { box-shadow: none; max-height: none; overflow: visible; }
}

/* === design system v2, second pass (ds-2): sidebar sub-items, confirm forms, task status, stepper, chip, ========= */
/* === unavailable state, copy field. Tokens only, so both themes and every brand accent follow. ================== */

/* sidebar sub-items (navItem.Sub): indented under the open item, the current one marked like a top-level row */
.side .side-sub { margin: 2px 0 var(--space-1) 17px; padding-left: var(--space-2); border-left: 1px solid var(--border); }
.side .side-sub a { min-height: 30px; padding: 0 var(--space-2); color: var(--muted); font-size: var(--text-xs); }
.side .side-sub a:hover { color: var(--text); }
.side .side-sub a[aria-current="page"] { background: var(--accent-soft); color: var(--text); font-weight: var(--weight-medium); }
.side .side-sub a[aria-current="page"]::before { left: calc(-1 * var(--space-2) - 1px); top: 6px; bottom: 6px; width: 2px; border-radius: 2px; }
@media (min-width: 861px) { .rail-toggle:checked ~ .shell .side-sub { display: none; } }
@media (max-width: 1100px) and (min-width: 861px) { .side .side-sub { display: none; } }

/* confirmForm and confirmName: the dialog panel scrolls on a short screen; fields stack under the sentence */
.dialog-panel { max-height: 78vh; overflow-y: auto; }
.dialog-list { margin: var(--space-3) 0 0; padding-left: var(--space-5); color: var(--text-2); font-size: var(--text-sm); }
.dialog-list li { padding: 2px 0; }
.dialog-form { margin: 0; }
.dialog-fields { display: grid; gap: var(--space-3); margin-top: var(--space-4); }
.dialog-check { display: flex; align-items: flex-start; gap: var(--space-2); font-size: var(--text-sm); }
.dialog-check input { margin-top: 3px; }
.confirm-name .dialog-fields input[name="confirm"] { width: 100%; font-family: var(--mono); }

/* taskStatus: one operation, a coloured edge and a mark; the state is also a badge, so colour is never alone */
.task-status { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--space-3); align-items: start; margin: 0 0 var(--space-4); padding: var(--space-4);
  border: 1px solid var(--border); border-left-width: 3px; border-radius: var(--radius-sm); background: var(--surface); box-shadow: var(--shadow-1); }
.task-status-queued { border-left-color: var(--border-strong); }
.task-status-running { border-left-color: var(--info-line); }
.task-status-done { border-left-color: var(--ok-line); }
.task-status-failed { border-left-color: var(--bad-line); }
.task-status-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius-pill); background: var(--muted-bg); color: var(--muted); }
.task-status-running .task-status-mark { background: var(--info-bg); color: var(--info-fg); }
.task-status-done .task-status-mark { background: var(--ok-bg); color: var(--ok-fg); }
.task-status-failed .task-status-mark { background: var(--bad-bg); color: var(--bad-fg); }
.task-status-body > p { margin: 0 0 var(--space-2); }
.task-status-body > :last-child { margin-bottom: 0; }
.task-status-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.task-status-meta { color: var(--muted); font-size: var(--text-xs); }
.task-status-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }
.task-status progress { display: block; margin: var(--space-2) 0; }
.task-details { margin-top: var(--space-3); font-size: var(--text-xs); color: var(--muted); }
.task-details summary { cursor: pointer; }
.task-details p { margin: var(--space-1) 0 0; overflow-wrap: anywhere; }

/* flashOk: the next step sits at the end of the sentence */
.flash-next { display: inline-flex; align-items: center; gap: 4px; margin-left: var(--space-1); font-weight: var(--weight-medium); color: inherit; text-decoration: underline; white-space: nowrap; }

/* stepper: numbered steps; done shows a tick, the current one the accent */
.stepper { list-style: none; counter-reset: stepper; display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-5); margin: 0 0 var(--space-5); padding: 0; }
.stepper li { counter-increment: stepper; display: inline-flex; align-items: center; gap: var(--space-2); color: var(--muted); font-size: var(--text-sm); }
.stepper li::before { content: counter(stepper); display: grid; place-items: center; width: 24px; height: 24px; flex: none; border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--muted); font-size: var(--text-xs); font-weight: var(--weight-medium); font-variant-numeric: tabular-nums; }
.stepper .step-done { color: var(--text-2); }
.stepper .step-done::before { content: "\2713"; background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok-fg); }
.stepper [aria-current="step"] { color: var(--text); font-weight: var(--weight-strong); }
.stepper [aria-current="step"]::before { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* chip: a small neutral pill (a count, a validity); not a status, so no dot and no colour */
.chip { display: inline-flex; align-items: center; min-height: 20px; padding: 0 var(--space-2); border: 1px solid var(--border); border-radius: var(--radius-pill);
  background: var(--muted-bg); color: var(--text-2); font-size: var(--text-xs); font-weight: var(--weight-medium); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* unavailable: calm, dashed, no alarm colour */
.state { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-4); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm);
  color: var(--text-2); font-size: var(--text-sm); }
.state > .icon { margin-top: 2px; color: var(--muted); }
.state p { margin: 0 0 var(--space-1); }
.state p:last-child { margin-bottom: 0; }
.state-unavailable strong { color: var(--text); }

/* copyField: label above, value and copy button in one bordered row (the button needs fx.js and hides without it) */
.copyfield { display: grid; gap: var(--space-1); margin: 0 0 var(--space-3); }
.copyfield-label { color: var(--muted); font-size: var(--text-xs); font-weight: var(--weight-medium); }
.copyfield-row { position: relative; display: flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-2) 0 var(--space-3); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--bg-2); }
.copyfield-row code { flex: 1 1 auto; min-width: 0; margin: 0; padding: var(--space-2) 0; border: 0; background: none; overflow-wrap: anywhere; font: var(--text-xs)/1.5 var(--mono); }
.copyfield-row:hover .secret, .copyfield-row:focus-within .secret { filter: none; }
.copyfield .field-hint { margin: 0; }

/* style guide: a sample of the sidebar inside a card (the real one is sticky and full height) */
.sg-side { max-width: 280px; }
.sg-side .side { position: static; height: auto; overflow: visible; border: 1px solid var(--border); border-radius: var(--radius); }
