/* Base, layout and components for the dashboard. Colors and sizes come from tokens.css only. Page-specific
   rules go in css/pages/<area>.css; chart rules in charts.css. Class names are documented in js/README.md. */

/* ---------- Reset and base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--text-body);
  line-height: var(--leading);
  overflow-wrap: break-word;
}

h1, h2, h3, h4, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
img, svg { display: block; }
svg { flex: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

a { color: var(--accent-text); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }
/* Headings take focus on route changes; the ring would only distract there */
h1[tabindex="-1"]:focus, main[tabindex="-1"]:focus { outline: none; }

code, kbd, samp, .mono { font-family: var(--mono); font-size: 0.92em; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.secondary { color: var(--ink-2); }
.meta { font-size: var(--text-meta); color: var(--ink-3); }
.small { font-size: var(--text-secondary); }
.nowrap { white-space: nowrap; }
.wrap-anywhere { overflow-wrap: anywhere; }
.strong { font-weight: 600; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* Icons from the inline sprite: 16 px by default */
.icon { width: 16px; height: 16px; }
.icon-20 { width: 20px; height: 20px; }
.icon-24 { width: 24px; height: 24px; }

/* ---------- Skip link ---------- */

.skip-link {
  position: absolute;
  left: var(--space-2); top: var(--space-2);
  z-index: calc(var(--z-header) + 10);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-control);
  background: var(--button); color: var(--button-ink);
  text-decoration: none; font-weight: 600;
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

/* ---------- Header ---------- */

.app-header {
  position: sticky; top: 0;
  z-index: var(--z-header);
  background: var(--page);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: var(--max-width);
  height: var(--header-height);
  margin: 0 auto;
  padding: 0 var(--gutter);
  display: flex; align-items: center; gap: var(--space-3);
}
.brand {
  display: inline-flex; align-items: center; gap: var(--space-2);
  color: var(--ink); text-decoration: none;
  font-weight: 600; font-size: 15px; white-space: nowrap;
}
.brand-mark { width: 24px; height: 24px; }

.main-nav { display: flex; align-items: stretch; gap: var(--space-1); margin-left: var(--space-4); height: 100%; }
.main-nav a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 var(--space-3);
  color: var(--ink-2); text-decoration: none; font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.main-nav a:hover { color: var(--ink); }
.main-nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

.header-tools { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.updated { font-size: var(--text-meta); color: var(--ink-3); white-space: nowrap; }

.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 28px; padding: 2px 10px 2px 8px;
  border: 1px solid var(--border); border-radius: var(--radius-tag);
  background: var(--surface); color: var(--ink);
  font-size: var(--text-secondary); text-decoration: none; white-space: nowrap;
}
.status-pill:hover { border-color: var(--border-strong); }
/* On a narrow phone the pill gives way first: its label shortens instead of pushing the page wider */
.status-pill { min-width: 0; }
.status-pill-icon { flex: none; display: inline-flex; }
.status-pill-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.nav-status { display: inline-flex; }

/* Phone bottom tab bar */
.bottom-bar { display: none; }

/* Session and connectivity notices under the header */
.shell-notices:empty { display: none; }
.shell-notices .notice { border-radius: 0; border-left: 0; border-right: 0; border-top: 0; }
.shell-notices .notice-inner { max-width: var(--max-width); margin: 0 auto; }

/* ---------- Main and pages ---------- */

.view {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-6) var(--gutter) var(--space-12);
}
.view.is-dimmed > * { opacity: 0.6; transition: opacity var(--fade); }

.page { display: flex; flex-direction: column; gap: var(--section-gap); }

.page-header { display: flex; flex-direction: column; gap: var(--space-1); }
.page-title-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); }
.page-title-row h1 { font-size: var(--text-page); font-weight: 600; line-height: 1.3; margin-right: auto; }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.page-meta { color: var(--ink-2); font-size: var(--text-secondary); }

.breadcrumb { font-size: var(--text-secondary); color: var(--ink-3); }
.breadcrumb ol { display: flex; flex-wrap: wrap; gap: 6px; }
.breadcrumb li + li::before { content: "/"; margin-right: 6px; color: var(--ink-3); }
.breadcrumb a { color: var(--ink-2); }

/* Layout helpers: stacks of sections, never nested cards */
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.stack-tight { display: flex; flex-direction: column; gap: var(--space-2); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.grid { display: grid; gap: var(--space-4); }
.grid-auto { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); }
.grid-2 { display: grid; gap: var(--section-gap); grid-template-columns: minmax(0, 1fr); }
.grid-4 { display: grid; gap: var(--space-4); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 640px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* One filter row above everything it scopes */
.filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); }
.filter-row .range-dates { font-size: var(--text-secondary); color: var(--ink-2); }

/* ---------- Section ---------- */

.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-section);
  padding: var(--space-4);
  min-width: 0;
}
@media (min-width: 768px) { .section { padding: var(--space-5); } }
.section-plain { background: none; border: 0; padding: 0; border-radius: 0; }

.section-header {
  display: flex; flex-wrap: wrap; align-items: baseline;
  gap: var(--space-1) var(--space-4);
  margin-bottom: var(--space-3);
}
.section-title { font-size: var(--text-section); font-weight: 600; line-height: 1.35; }
.section-source { margin-left: auto; font-size: var(--text-meta); color: var(--ink-3); }
.section-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.section-description { color: var(--ink-2); font-size: var(--text-secondary); margin: calc(-1 * var(--space-2)) 0 var(--space-3); }
.section-stale {
  display: flex; align-items: flex-start; gap: var(--space-2);
  margin-bottom: var(--space-3);
  font-size: var(--text-secondary); color: var(--ink-2);
}
.section-body { min-width: 0; transition: opacity var(--fade); }
.section-body.is-refreshing { opacity: 0.6; }
.section-body.is-stale { opacity: 0.6; }
.subsection-title { font-size: 14px; font-weight: 600; margin-bottom: var(--space-2); }

/* ---------- States ---------- */

.state {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-4) 0;
}
.state-icon { margin-top: 2px; }
.state-content { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.state-title { font-weight: 600; }
.state-text { color: var(--ink-2); }
.state-source { font-size: var(--text-meta); color: var(--ink-3); }
.state-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.state-compact { padding: var(--space-2) 0; }
.state-loading { min-height: var(--state-min-height, 96px); align-items: center; justify-content: center; color: var(--ink-3); }
.state-loading .state-text { opacity: 0; transition: opacity var(--fade); }
.state-loading.is-visible .state-text { opacity: 1; }
.state-page { padding: var(--space-8) 0; }

/* ---------- Notices ---------- */

.notice {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border); border-radius: var(--radius-control);
  background: var(--surface); color: var(--ink);
  font-size: var(--text-secondary);
}
.notice-inner { display: flex; gap: var(--space-3); align-items: flex-start; flex: 1; min-width: 0; }
.notice-content { flex: 1; min-width: 0; }
.notice-title { font-weight: 600; }
.notice-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-left: auto; }
.notice-critical { background: var(--critical-wash); }
.notice-warning { background: var(--warning-wash); }
.notice-info { background: var(--info-wash); }

/* ---------- Stat tiles and hero ---------- */

.stats { display: grid; gap: var(--space-4); grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 768px) { .stats { grid-template-columns: repeat(var(--stat-count, 4), minmax(0, 1fr)); } }
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-label { font-size: var(--text-secondary); color: var(--ink-2); }
.stat-value { font-size: var(--text-stat); font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; }
.stat-delta, .hero-delta { font-size: var(--text-secondary); color: var(--ink-2); }
.stat-note, .hero-detail { font-size: var(--text-meta); color: var(--ink-3); }
.is-good { color: var(--delta-good); }
.is-bad { color: var(--delta-bad); }
.is-neutral { color: var(--ink-2); }

.hero { display: flex; flex-direction: column; gap: var(--space-1); }
.hero-label { font-size: var(--text-secondary); color: var(--ink-2); }
.hero-value { font-size: var(--text-hero); font-weight: 600; line-height: 1.05; letter-spacing: -0.02em; }
.hero-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2) var(--space-4); }
@media (max-width: 479px) { .hero-value { font-size: 44px; } }

/* ---------- Meter ---------- */

.meter { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.meter-head { display: flex; justify-content: space-between; gap: var(--space-3); font-size: var(--text-secondary); }
.meter-label { color: var(--ink-2); }
.meter-value { font-variant-numeric: tabular-nums; white-space: nowrap; }
.meter-track { height: 8px; border-radius: var(--radius-tag); background: var(--accent-track); overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--accent); border-radius: var(--radius-tag); }
.meter.is-warning .meter-track { background: var(--warning-wash); }
.meter.is-warning .meter-fill { background: var(--warning); }
.meter.is-critical .meter-track { background: var(--critical-wash); }
.meter.is-critical .meter-fill { background: var(--critical); }
.meter.is-muted .meter-fill { background: var(--mark-muted); }
.meter.is-muted .meter-track { background: var(--hover); }

/* ---------- Status ---------- */

.status { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.status-word { color: var(--ink); }
.status-icon { width: 16px; height: 16px; }
.status-icon.icon-20 { width: 20px; height: 20px; }
.status-shape { color: var(--neutral); }
.status-glyph { color: var(--glyph-on-status); }
.tone-good .status-shape { color: var(--good); }
.tone-warning .status-shape { color: var(--warning); }
.tone-warning .status-glyph { color: var(--glyph-on-warning); }
.tone-serious .status-shape { color: var(--serious); }
.tone-serious .status-glyph { color: var(--glyph-on-warning); }
.tone-critical .status-shape { color: var(--critical); }
.tone-info .status-shape { color: var(--info); }
.tone-muted .status-shape, .tone-muted .status-glyph,
.tone-neutral .status-shape, .tone-neutral .status-glyph { color: var(--ink-3); }

/* ---------- Tags ---------- */

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 0 8px; min-height: 20px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-tag);
  font-size: var(--text-meta); line-height: 18px; font-weight: 500;
  color: var(--ink-2); white-space: nowrap; vertical-align: middle;
}
.tag-v2 { border-color: var(--v2); color: var(--accent-text); }
.tag-v1 { border-color: var(--border-strong); color: var(--ink-2); }
.tag-local { border-color: var(--warning); color: var(--ink); background: var(--warning-wash); }
.tag-strong { border-color: var(--accent); color: var(--accent-text); background: var(--selected); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--control-height); padding: 0 var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-control);
  background: var(--control); color: var(--ink);
  font-weight: 500; line-height: 1.2; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--button); border-color: var(--button); color: var(--button-ink); }
.btn-primary:hover { background: var(--button); filter: brightness(1.08); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--accent-text); }
.btn-quiet:hover { background: var(--hover); }
.btn-danger { background: var(--control); border-color: var(--critical); color: var(--delta-bad); }
.btn-danger.btn-solid { background: var(--critical); color: #ffffff; }
.btn-icon { width: var(--control-height); padding: 0; color: var(--ink-2); }
.btn-small { min-height: 28px; padding: 0 var(--space-2); font-size: var(--text-secondary); }
.btn-block { width: 100%; }
.btn.is-busy { cursor: progress; }
.link-button { padding: 0; border: 0; background: none; color: var(--accent-text); text-decoration: underline; text-underline-offset: 2px; }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-weight: 500; font-size: var(--text-secondary); }
.field-hint { font-size: var(--text-meta); color: var(--ink-3); }
.field-error { font-size: var(--text-secondary); color: var(--delta-bad); }
.field-error:empty { display: none; }
.input, .select, .textarea {
  width: 100%; min-height: var(--control-height);
  padding: 6px 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-control);
  background: var(--control); color: var(--ink);
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-3); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--critical); }
.input[readonly] { background: var(--page); }
.textarea { min-height: 72px; resize: vertical; }
.select { appearance: none; padding-right: 30px; background-image: none; }
.select-wrap { position: relative; display: inline-flex; }
.select-wrap .icon { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); pointer-events: none; color: var(--ink-3); }
.input-row { display: flex; gap: var(--space-2); }
.input-row .input { flex: 1; min-width: 0; }
.form { display: flex; flex-direction: column; gap: var(--space-4); }
.form-error { font-size: var(--text-secondary); color: var(--delta-bad); }
.form-error:empty { display: none; }
.checkbox { display: inline-flex; align-items: center; gap: var(--space-2); }

/* Segmented control: 2-4 options, aria-pressed */
.segmented {
  display: inline-flex; padding: 2px; gap: 2px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-control);
  background: var(--control);
}
.segmented button {
  min-height: calc(var(--control-height) - 6px); padding: 0 var(--space-3);
  border: 0; border-radius: 6px; background: none;
  color: var(--ink-2); font-weight: 500; white-space: nowrap;
}
.segmented button:hover { background: var(--hover); color: var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--selected); color: var(--accent-text); font-weight: 600; }
.segmented-label { font-size: var(--text-secondary); color: var(--ink-2); }

/* Switch: role=switch */
.switch {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: 0; border: 0; background: none; color: var(--ink); text-align: left;
  min-height: var(--control-height);
}
.switch-track {
  position: relative; width: 36px; height: 20px; flex: none;
  border-radius: var(--radius-tag); background: var(--baseline);
  transition: background var(--fade);
}
.switch-thumb {
  position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #ffffff;
  transition: transform var(--fade);
}
.switch[aria-checked="true"] .switch-track { background: var(--accent); }
.switch[aria-checked="true"] .switch-thumb { transform: translateX(16px); }
.switch:disabled { opacity: 0.55; cursor: not-allowed; }
.switch-state { font-size: var(--text-secondary); color: var(--ink-2); }

/* Disclosure: native details */
.disclosure > summary {
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer; color: var(--accent-text); list-style: none;
  min-height: 28px;
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary .icon { transition: transform var(--fade); }
.disclosure[open] > summary .icon { transform: rotate(90deg); }
.disclosure-body { padding-top: var(--space-2); }

/* Combobox: ARIA 1.2 pattern */
.combobox { position: relative; }
.combobox-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  z-index: var(--z-menu);
  max-height: 280px; overflow-y: auto;
  padding: 4px; border: 1px solid var(--border-strong); border-radius: var(--radius-control);
  background: var(--surface);
}
.combobox-option { display: flex; gap: var(--space-2); align-items: baseline; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.combobox-option[aria-selected="true"] { background: var(--selected); }
.combobox-option:hover { background: var(--hover); }
.combobox-option mark { background: none; color: inherit; font-weight: 700; }
.combobox-hint { font-size: var(--text-meta); color: var(--ink-3); margin-left: auto; }

/* ---------- Menus ---------- */

.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px);
  z-index: var(--z-menu);
  min-width: 220px; padding: 4px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-control);
  background: var(--surface);
}
.menu-item {
  display: flex; align-items: center; gap: var(--space-2);
  width: 100%; min-height: 36px; padding: 0 var(--space-2);
  border: 0; border-radius: 6px; background: none;
  color: var(--ink); text-align: left; text-decoration: none;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--hover); }
.menu-item .menu-check { width: 16px; height: 16px; visibility: hidden; color: var(--accent-text); }
.menu-item[aria-checked="true"] .menu-check { visibility: visible; }
.menu-item[aria-checked="true"] { font-weight: 600; }
.menu-info { padding: var(--space-2); font-size: var(--text-secondary); color: var(--ink-2); }
.menu-info strong { display: block; color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }
.menu-separator { height: 1px; margin: 4px 0; background: var(--border); }
.menu-item-detail { margin-left: auto; font-size: var(--text-meta); color: var(--ink-3); }

/* ---------- Key-value lists ---------- */

.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px var(--space-4); font-size: var(--text-secondary); }
.kv dt { color: var(--ink-2); }
.kv dd { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 479px) { .kv { grid-template-columns: minmax(0, 1fr); gap: 0; } .kv dd { margin-bottom: var(--space-2); } }

/* Rows separated by hairlines (events, attention items) */
.rows > * + * { border-top: 1px solid var(--border); }
.rows > * { padding: var(--space-3) 0; }
.rows > *:first-child { padding-top: 0; }
.rows > *:last-child { padding-bottom: 0; }

/* ---------- Route tabs (System) ---------- */

.tabs { display: flex; gap: var(--space-1); overflow-x: auto; border-bottom: 1px solid var(--border); scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: var(--space-2) var(--space-3); min-height: 40px;
  color: var(--ink-2); text-decoration: none; white-space: nowrap; font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------- Tables ---------- */

.table-wrap { min-width: 0; }
.data-table { width: 100%; border-collapse: collapse; font-size: var(--text-secondary); }
.data-table th, .data-table td { padding: 8px 10px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.data-table th:first-child, .data-table td:first-child { padding-left: 0; }
.data-table th:last-child, .data-table td:last-child { padding-right: 0; }
.data-table thead th { font-weight: 500; color: var(--ink-2); font-size: var(--text-meta); white-space: nowrap; vertical-align: bottom; }
.data-table .is-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table tbody tr:last-child > * { border-bottom: 0; }
.data-table tbody + tbody tr:first-child > * { border-top: 1px solid var(--border); }
.sort-button {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 0; border: 0; background: none;
  color: inherit; font: inherit; font-weight: 500; text-align: inherit;
}
.sort-button:hover { color: var(--ink); }
.is-num .sort-button { flex-direction: row-reverse; }
.sort-icon { width: 12px; height: 12px; opacity: 0; }
th[aria-sort="ascending"] .sort-icon, th[aria-sort="descending"] .sort-icon { opacity: 1; }
th[aria-sort="ascending"] .sort-icon { transform: rotate(180deg); }
.expand-button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; margin: -2px 4px -2px -4px; padding: 0;
  border: 0; border-radius: 6px; background: none; color: var(--ink-2); vertical-align: middle;
}
.expand-button:hover { background: var(--hover); }
.expand-button .icon { transition: transform var(--fade); }
.expand-button[aria-expanded="true"] .icon { transform: rotate(90deg); }
.row-detail > td { background: var(--page); padding: var(--space-3) !important; }
.group-header > th { padding-top: var(--space-4); font-size: var(--text-secondary); color: var(--ink); font-weight: 600; text-align: left; }
.group-note { font-weight: 400; color: var(--ink-3); margin-left: var(--space-2); }
.table-footer { display: flex; justify-content: flex-start; padding-top: var(--space-2); }
.table-empty { padding: var(--space-4) 0; color: var(--ink-2); }

/* Card mode below 640 px: every row becomes a card, so no table scrolls sideways */
@media (max-width: 639px) {
  .data-table[data-cards] thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .data-table[data-cards], .data-table[data-cards] tbody, .data-table[data-cards] tr,
  .data-table[data-cards] td, .data-table[data-cards] th { display: block; }
  .data-table[data-cards] tbody tr:not(.row-detail):not(.group-header) {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2) var(--space-3);
    padding: var(--space-3) 0; border-bottom: 1px solid var(--border);
  }
  .data-table[data-cards] td { padding: 0 !important; border: 0; text-align: left; white-space: normal; }
  .data-table[data-cards] td::before { content: attr(data-label); display: block; font-size: var(--text-meta); color: var(--ink-3); }
  .data-table[data-cards] td.cell-title { grid-column: 1 / -1; font-size: var(--text-body); font-weight: 600; }
  .data-table[data-cards] td.cell-title::before, .data-table[data-cards] td.cell-wide::before { content: none; }
  .data-table[data-cards] td.cell-wide, .data-table[data-cards] td.cell-actions { grid-column: 1 / -1; }
  .data-table[data-cards] td.cell-actions .btn { width: 100%; min-height: var(--touch); }
  .data-table[data-cards] .expand-button { width: var(--touch); height: var(--touch); }
  .data-table[data-cards] td:empty { display: none; }
  .data-table[data-cards] .row-detail > td { margin-bottom: var(--space-2); }
  .data-table[data-cards] .group-header > th { padding: var(--space-4) 0 0 !important; border: 0; }
}

/* ---------- Code and raw JSON: scrolls inside its own box ---------- */

.code-block {
  margin: 0; padding: var(--space-3);
  max-height: 420px; overflow: auto;
  border: 1px solid var(--border); border-radius: var(--radius-control);
  background: var(--page);
  font-family: var(--mono); font-size: 12px; line-height: 1.5;
  white-space: pre; tab-size: 2;
}

/* ---------- Dialogs and sheets (native dialog) ---------- */

.dialog {
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--border-strong); border-radius: var(--radius-section);
  background: var(--surface); color: var(--ink);
}
.dialog[open] { display: flex; flex-direction: column; animation: fade-in var(--fade) ease-out; }
.dialog::backdrop { background: var(--backdrop); }
.dialog-wide { width: min(640px, calc(100vw - 32px)); }
.dialog-header { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-4) var(--space-4) var(--space-2); }
.dialog-title { font-size: var(--text-section); font-weight: 600; line-height: 1.35; margin-right: auto; }
.dialog-header h2:focus { outline: none; }
.dialog-close { margin: -4px -6px 0 0; }
.dialog-body { padding: var(--space-2) var(--space-4) var(--space-4); overflow-y: auto; display: flex; flex-direction: column; gap: var(--space-4); }
.dialog-body > p { color: var(--ink-2); }
.dialog-footer {
  position: sticky; bottom: 0;
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border); background: var(--surface);
}
.dialog-footer:empty { display: none; }

/* Side sheet (the Food sheet): 560 px on desktop */
.sheet {
  margin: 0 0 0 auto;
  width: min(560px, 100vw); max-width: 100vw;
  height: 100dvh; max-height: 100dvh;
  border-radius: 0; border-top: 0; border-bottom: 0; border-right: 0;
}
.sheet .dialog-body { flex: 1; }

@media (max-width: 639px) {
  .dialog, .dialog-wide, .sheet {
    width: 100vw; max-width: 100vw;
    height: 100dvh; max-height: 100dvh;
    margin: 0; border: 0; border-radius: 0;
  }
  .dialog-body { flex: 1; }
  .dialog-footer { padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom)); }
  .dialog-footer .btn { flex: 1; min-height: var(--touch); }
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Copy feedback ---------- */

.copy-button[data-copied="true"] { color: var(--delta-good); }

/* ---------- Sign in ---------- */

.signin { min-height: calc(100vh - var(--header-height) - 96px); display: grid; place-items: center; }
.signin-card {
  width: min(360px, 100%);
  padding: var(--space-6);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-section);
  display: flex; flex-direction: column; gap: var(--space-4);
}
.signin-card h1 { font-size: var(--text-page); font-weight: 600; }
.signin-fineprint { font-size: var(--text-meta); color: var(--ink-3); }

/* ---------- Shell states ---------- */

body.is-booting .main-nav, body.is-booting .header-tools > :not(#theme-menu), body.is-booting .bottom-bar,
body.is-signed-out .main-nav, body.is-signed-out .header-tools > :not(#theme-menu), body.is-signed-out .bottom-bar { display: none !important; }

/* ---------- Phones ---------- */

@media (max-width: 767px) {
  .main-nav, .updated, #refresh { display: none; }
  .header-inner { gap: var(--space-2); }
  .header-tools { gap: var(--space-1); }
  .header-tools .btn-icon { width: var(--touch); min-height: var(--touch); }
  .bottom-bar {
    position: fixed; left: 0; right: 0; bottom: 0;
    z-index: var(--z-bottom-bar);
    display: grid; grid-template-columns: repeat(4, 1fr);
    height: calc(var(--bottom-bar-height) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--page); border-top: 1px solid var(--border);
  }
  .bottom-bar a {
    position: relative;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--ink-3); text-decoration: none; font-size: 11px; font-weight: 500;
  }
  .bottom-bar a[aria-current="page"] { color: var(--accent-text); }
  .bottom-bar .nav-status { position: absolute; top: 6px; left: calc(50% + 6px); }
  .view { padding-bottom: calc(var(--bottom-bar-height) + env(safe-area-inset-bottom) + var(--space-8)); }
  .page-actions .btn { min-height: var(--touch); }
  .segmented button { min-height: calc(var(--touch) - 6px); }
  .menu-item { min-height: var(--touch); }
  /* 44 px touch targets for the small controls, and 16 px text in fields so iOS doesn't zoom in on focus */
  .btn-small, .disclosure > summary, .link-button, .state-actions .btn { min-height: var(--touch); }
  .input, .select, .textarea { font-size: 16px; }
}
@media (max-width: 479px) {
  .brand-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .status-pill { padding: 2px 8px; }
}
/* shell.js sets is-typing while a text field has focus on a touch screen: the on-screen keyboard is up, and the
   bottom bar would sit on top of the field */
@media (max-width: 767px) { body.is-typing .bottom-bar { display: none; } }

/* ---------- Motion and forced colors ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media (forced-colors: active) {
  .status-shape, .status-glyph { color: CanvasText; }
  .meter-fill { background: Highlight; }
  .meter-track { background: Canvas; border: 1px solid CanvasText; }
  .switch-track { border: 1px solid ButtonText; }
  .switch[aria-checked="true"] .switch-track { background: Highlight; }
  .segmented button[aria-pressed="true"] { outline: 2px solid Highlight; }
  .main-nav a[aria-current="page"], .tab[aria-current="page"] { border-bottom-color: Highlight; }
  .btn-primary { border: 1px solid ButtonText; }
}
