/* Foundation and shared components: the shell, cards, controls, tables,
   overlays and feedback. Values come from tokens.css. */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--page);
  color: var(--ink-1);
  font: var(--fs-md) / var(--lh-normal) var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; line-height: var(--lh-tight); }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
code, pre, kbd, .mono { font-family: var(--font-mono); font-size: 0.92em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent-wash-strong); }

.muted { color: var(--ink-3); }
.secondary { color: var(--ink-2); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack.tight { gap: var(--sp-2); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4); }
.icon { width: 18px; height: 18px; flex: none; }
.icon.sm { width: 16px; height: 16px; }
.icon.xs { width: 14px; height: 14px; }

/* ---- the shell: a sidebar and the page */
.app {
  display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100vh; min-height: 100dvh;
  /* The sidebar's plane runs the full height of a long page. */
  background: linear-gradient(to right, var(--sidebar) calc(var(--sidebar-width) - 1px), var(--line) 0 var(--sidebar-width), var(--page) 0);
}
.sidebar {
  position: sticky; top: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column;
  background: var(--sidebar); border-right: 1px solid var(--line); padding: var(--sp-4) var(--sp-3) var(--sp-3);
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-1) var(--sp-2) var(--sp-5); min-width: 0; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; flex: none; display: grid; place-items: center; color: #fff;
  background: linear-gradient(140deg, var(--brand-a), var(--brand-b));
  box-shadow: 0 6px 14px -6px rgba(42, 120, 214, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.brand-mark .icon { width: 19px; height: 19px; }
.brand-name { font-weight: 600; font-size: 15px; line-height: 1.25; }
.brand-sub { color: var(--ink-3); font-size: var(--fs-xs); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  color: var(--ink-3); font-size: var(--fs-xs); font-weight: 500; letter-spacing: 0.04em;
  padding: var(--sp-4) var(--sp-3) var(--sp-1);
}
.nav-item {
  position: relative; display: flex; align-items: center; gap: var(--sp-3); padding: 7px var(--sp-3);
  border-radius: var(--r-md); color: var(--ink-2); font-weight: 450;
  transition: background var(--t-fast), color var(--t-fast);
}
.nav-item:hover { background: var(--hover); color: var(--ink-1); text-decoration: none; }
.nav-item .icon { color: var(--ink-3); transition: color var(--t-fast); }
.nav-item[aria-current="page"] { background: var(--accent-wash); color: var(--ink-1); font-weight: 600; }
.nav-item[aria-current="page"] .icon { color: var(--accent); }
.nav-item[aria-current="page"]::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.sidebar-foot { margin-top: auto; padding-top: var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-2); }
.upstream-pill {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px var(--sp-2); padding: var(--sp-2) var(--sp-3); border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--surface); font-size: var(--fs-sm); color: var(--ink-2);
}
.upstream-pill > span:not(.status) { white-space: nowrap; }
.upstream-pill:hover { text-decoration: none; background: var(--hover); }
.upstream-pill .status { margin-left: auto; }
.me-button {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%; padding: var(--sp-2); border: 0; background: none;
  border-radius: var(--r-md); cursor: pointer; text-align: left; border-top: 1px solid var(--line);
}
.me-button:hover, .me-button[aria-expanded="true"] { background: var(--hover); }
.me-button .who { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; flex: 1; }
.me-button .who .name { font-weight: 550; }
.me-button .who .role { color: var(--ink-3); font-size: var(--fs-xs); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 600; font-size: 13px; color: var(--accent-ink); background: var(--accent-wash-strong);
}
.avatar.lg { width: 48px; height: 48px; font-size: 18px; }
.avatar.sm { width: 24px; height: 24px; font-size: 11px; }

.topbar { display: none; }
.main { min-width: 0; }
.page { max-width: var(--content-width); margin: 0 auto; padding: var(--sp-7) var(--sp-8) var(--sp-9); }
.page-body { animation: page-in var(--t-med) var(--ease); }
@keyframes page-in { from { opacity: 0; transform: translateY(4px); } }
.page-head { display: flex; align-items: flex-end; gap: var(--sp-4); margin-bottom: var(--sp-6); flex-wrap: wrap; }
.page-head .titles { min-width: 0; flex: 1 1 320px; }
.page-head h1 { font-size: var(--fs-2xl); letter-spacing: -0.02em; }
.page-head .description { color: var(--ink-2); margin-top: 6px; }
.page-head .actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }

/* ---- cards */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-1);
  min-width: 0;
}
.card-head {
  display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); min-height: 56px; flex-wrap: wrap;
}
.card-head h2 { font-size: var(--fs-lg); }
.card-head .hint { color: var(--ink-3); font-size: var(--fs-sm); }
.card-head + .card-body { padding-top: 0; }
.card-body { padding: var(--sp-5); }
.card-body.flush { padding: 0; }
.section-title { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); margin-bottom: var(--sp-3); }

/* ---- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px;
  border: 1px solid var(--line-strong); background: var(--raised); color: var(--ink-1); border-radius: var(--r-md);
  font-weight: 500; font-size: var(--fs-md); cursor: pointer; white-space: nowrap; -webkit-user-select: none; user-select: none;
  box-shadow: 0 1px 1px rgba(11, 11, 11, 0.04);
  transition: background var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast), color var(--t-fast);
}
.btn:hover { background: var(--hover); text-decoration: none; }
.btn:active { background: var(--press); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn .icon { width: 16px; height: 16px; }
.btn.primary { background: var(--accent-fill); border-color: transparent; color: var(--ink-on-accent); }
.btn.primary:hover { background: var(--accent-fill-hover); }
.btn.danger { color: var(--bad-ink); }
.btn.danger:hover { background: var(--bad-wash); border-color: transparent; }
.btn.danger-fill { background: var(--bad); color: #fff; border-color: transparent; }
.btn.danger-fill:hover { background: var(--bad-ink); }
.btn.ghost { background: none; border-color: transparent; box-shadow: none; color: var(--ink-2); }
.btn.ghost:hover { background: var(--hover); color: var(--ink-1); }
.btn.sm { height: 28px; padding: 0 10px; font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn.lg { height: 40px; padding: 0 18px; }
.btn.icon-only { width: 34px; padding: 0; }
.btn.sm.icon-only { width: 28px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn[aria-busy="true"] { cursor: progress; }
.btn[aria-busy="true"] > .icon { display: none; }
.btn[aria-busy="true"]::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- form controls: every control is the same height, so a row lines up */
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="email"],
input[type="search"], select, textarea {
  height: 34px; width: 100%; min-width: 0; padding: 0 10px; border: 1px solid var(--control-border);
  border-radius: var(--r-md); background: var(--raised); color: var(--ink-1);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
textarea { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--ink-3); opacity: 0.85; }
input:hover, select:hover, textarea:hover { border-color: var(--ink-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
input[aria-invalid="true"] { border-color: var(--bad); }
input:disabled, select:disabled { background: var(--sunken); color: var(--ink-3); cursor: not-allowed; }
select {
  appearance: none; -webkit-appearance: none; padding-right: 30px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%; background-size: 5px 5px; background-repeat: no-repeat;
}
input[type="date"] { padding-right: 6px; }
/* No spin buttons: Safari and Firefox always draw them, in the middle of a
   field that has a unit after it, and nobody steps to 50,000 by ones. */
input[type="number"] { font-variant-numeric: tabular-nums; -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > .label { font-size: var(--fs-sm); font-weight: 500; color: var(--ink-2); }
.field > .help { font-size: var(--fs-xs); color: var(--ink-3); }
.field > .error { font-size: var(--fs-xs); color: var(--bad-ink); }
.input-affix { position: relative; display: flex; align-items: center; }
.input-affix > input { padding-right: 64px; }
.input-affix > .suffix { position: absolute; right: 10px; color: var(--ink-3); font-size: var(--fs-sm); pointer-events: none; }
.input-affix > .reveal { position: absolute; right: 3px; }
.input-affix > input.has-reveal { padding-right: 40px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4) var(--sp-4); }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-section { display: flex; flex-direction: column; gap: var(--sp-4); }
.form-section + .form-section { border-top: 1px solid var(--line); padding-top: var(--sp-5); margin-top: var(--sp-5); }
.form-section > h3 { font-size: var(--fs-md); }
.form-section > .lead { color: var(--ink-3); font-size: var(--fs-sm); margin-top: -10px; }
.check { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; color: var(--ink-2); }

/* A switch is a checkbox drawn as a track and a knob. */
.switch { display: inline-flex; align-items: center; gap: var(--sp-3); cursor: pointer; }
.switch input { appearance: none; -webkit-appearance: none; width: 34px; height: 20px; border-radius: 10px; margin: 0;
  background: var(--axis); position: relative; cursor: pointer; transition: background var(--t-fast); flex: none; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: transform var(--t-fast) var(--ease); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(14px); }
.switch input:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.switch input:disabled { opacity: 0.45; cursor: not-allowed; }
.switch:has(input:disabled) { cursor: not-allowed; }

/* A segmented control: radio-like buttons in one pill. */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--r-md); background: var(--sunken); border: 1px solid var(--line); flex-wrap: wrap; }
.seg button {
  height: 26px; padding: 0 10px; border: 0; border-radius: var(--r-sm); background: none; color: var(--ink-2);
  font-size: var(--fs-sm); font-weight: 500; cursor: pointer; white-space: nowrap;
}
.seg button:hover { color: var(--ink-1); }
.seg button[aria-pressed="true"], .seg button[aria-selected="true"] { background: var(--raised); color: var(--ink-1); box-shadow: var(--shadow-1); }
.seg button:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* The filter row: one line above what it scopes. */
.filters { display: flex; align-items: flex-end; gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-4); }
.filters .field { width: 176px; }
.filters .field.wide { width: 240px; }
.filters .field.date { width: 150px; }
.filters .field.narrow { width: 140px; }
.filters .field.auto { width: auto; }
.filters .check { height: 34px; }

/* ---- status: a symbol and a word, never colour alone */
.status {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-size: var(--fs-sm); font-weight: 500;
  padding: 1px 8px 1px 7px; border-radius: var(--r-full); line-height: 20px;
}
.status::before { font-size: 9px; line-height: 1; }
.status.good { color: var(--good-ink); background: var(--good-wash); }
.status.good::before { content: "●"; color: var(--good); }
.status.warn { color: var(--warn-ink); background: var(--warn-wash); }
.status.warn::before { content: "▲"; color: var(--warn); }
.status.bad { color: var(--bad-ink); background: var(--bad-wash); }
.status.bad::before { content: "■"; color: var(--bad); }
.status.off { color: var(--ink-2); background: var(--off-wash); }
.status.off::before { content: "○"; color: var(--off); }
.status.plain { background: none; padding: 0; }
.tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 0 8px; border-radius: var(--r-full); line-height: 22px;
  font-size: var(--fs-xs); font-weight: 500; color: var(--ink-2); background: var(--off-wash); white-space: nowrap;
}
.tag.accent { color: var(--accent-ink); background: var(--accent-wash); }
.tag .icon { width: 13px; height: 13px; }
code.chip {
  padding: 1px 6px; border-radius: var(--r-xs); background: var(--sunken); border: 1px solid var(--line); font-size: 12px; white-space: nowrap;
}

/* ---- tables */
.table-wrap { overflow-x: auto; }
table.data { border-collapse: separate; border-spacing: 0; width: 100%; font-size: var(--fs-md); }
table.data th, table.data td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data th:first-child, table.data td:first-child { padding-left: var(--sp-5); }
table.data th:last-child, table.data td:last-child { padding-right: var(--sp-5); }
table.data thead th {
  position: sticky; top: 0; z-index: 1; background: var(--surface); color: var(--ink-3); font-weight: 500;
  font-size: var(--fs-xs); letter-spacing: 0.02em; white-space: nowrap; padding-top: 8px; padding-bottom: 8px;
}
table.data th.num, table.data td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data th.actions, table.data td.actions { text-align: right; white-space: nowrap; width: 1%; }
table.data tbody tr { transition: background var(--t-fast); }
@media (hover: hover) { table.data tbody tr:hover { background: var(--hover); } }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
table.data tr.muted-row td { color: var(--ink-3); }
table.data tfoot td { font-weight: 600; border-top: 1px solid var(--line-strong); border-bottom: 0; background: var(--sunken); }
table.data .sub { display: block; color: var(--ink-3); font-size: var(--fs-xs); margin-top: 1px; }
table.data th button.sort {
  border: 0; background: none; padding: 0; color: inherit; font: inherit; cursor: pointer; display: inline-flex; gap: 4px; align-items: center;
}
table.data th button.sort:hover { color: var(--ink-1); }
table.data th[aria-sort] { color: var(--ink-1); }
table.data th .arrow { font-size: 10px; }
.cell-main { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.cell-main .text { min-width: 0; }

/* ---- feedback: toasts */
.toasts {
  position: fixed; right: var(--sp-5); bottom: var(--sp-5); z-index: 100; display: flex; flex-direction: column; gap: var(--sp-2);
  width: min(380px, calc(100vw - 32px)); pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4);
  background: var(--raised); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-2);
  animation: toast-in var(--t-med) var(--ease);
}
.toast .glyph { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; flex: none; margin-top: 1px; }
.toast .glyph .icon { width: 13px; height: 13px; }
.toast.good .glyph { background: var(--good-wash); color: var(--good-ink); }
.toast.bad .glyph { background: var(--bad-wash); color: var(--bad-ink); }
.toast .body { flex: 1; min-width: 0; }
.toast .title { font-weight: 600; }
.toast .detail { color: var(--ink-2); font-size: var(--fs-sm); word-break: break-word; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity var(--t-med), transform var(--t-med); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---- overlays: dialogs (centred) and drawers (from the right). Heights
   use the dynamic viewport (dvh) where there is one, so a phone's browser
   bars do not cover a dialog's buttons; vh is the fallback. Older Safari and
   Chrome do not pass custom properties to ::backdrop, hence the fallback
   colour there. */
dialog {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-1); padding: 0; box-shadow: var(--shadow-3);
  max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px); overflow: hidden;
}
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: var(--overlay, rgba(20, 20, 18, 0.38)); -webkit-backdrop-filter: blur(1.5px); backdrop-filter: blur(1.5px); }
dialog.modal { width: min(560px, calc(100vw - 32px)); border-radius: var(--r-xl); margin: auto; }
dialog.modal.wide { width: min(720px, calc(100vw - 32px)); }
dialog.modal.narrow { width: min(440px, calc(100vw - 32px)); }
dialog.modal[open] { animation: modal-in var(--t-med) var(--ease); }
dialog.drawer {
  margin: 0 0 0 auto; height: 100vh; height: 100dvh; max-height: 100vh; max-height: 100dvh; width: min(720px, 100vw); border-radius: var(--r-xl) 0 0 var(--r-xl);
  border-right: 0;
}
dialog.drawer.wide { width: min(960px, 100vw); }
dialog.drawer[open] { animation: drawer-in 240ms var(--ease); }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.985); } }
@keyframes drawer-in { from { opacity: 0.4; transform: translateX(48px); } }
.dialog-head {
  display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-5) var(--sp-6) var(--sp-4); border-bottom: 1px solid var(--line); flex: none;
}
.dialog-head .titles { flex: 1; min-width: 0; }
.dialog-head h2 { font-size: var(--fs-lg); }
.dialog-head .sub { color: var(--ink-3); font-size: var(--fs-sm); margin-top: 4px; }
/* The body takes the height of what is in it, and gives way when the dialog
   reaches its greatest height. Its basis must be auto: with a basis of zero
   Safari gives a dialog that has no height of its own a body of no height. */
.dialog-body { padding: var(--sp-5) var(--sp-6); overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.dialog-foot {
  display: flex; justify-content: flex-end; align-items: center; gap: var(--sp-2); padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--line); background: var(--sunken); flex: none; flex-wrap: wrap;
}
.dialog-foot .left { margin-right: auto; color: var(--ink-3); font-size: var(--fs-sm); }
dialog.confirm .dialog-head { border-bottom: 0; padding-bottom: 0; }
dialog.confirm .dialog-body { color: var(--ink-2); padding-top: var(--sp-3); }
dialog.confirm .dialog-foot { background: none; border-top: 0; padding-top: 0; }
.confirm-glyph { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.confirm-glyph.bad { background: var(--bad-wash); color: var(--bad-ink); }
.confirm-glyph.warn { background: var(--warn-wash); color: var(--warn-ink); }
.confirm-glyph.info { background: var(--accent-wash); color: var(--accent-ink); }

/* ---- menus (a popover list of actions) */
.menu {
  position: fixed; z-index: 60; min-width: 200px; padding: var(--sp-1); background: var(--raised); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-2); animation: modal-in var(--t-fast) var(--ease);
}
.menu [role="menuitem"], .menu [role="menuitemradio"] {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%; padding: 7px var(--sp-3); border: 0; background: none;
  border-radius: var(--r-sm); text-align: left; cursor: pointer; color: var(--ink-1); font-size: var(--fs-md);
}
.menu [role^="menuitem"]:hover, .menu [role^="menuitem"]:focus { background: var(--hover); outline: none; }
.menu [role^="menuitem"] .icon { color: var(--ink-3); width: 16px; height: 16px; }
.menu [role^="menuitem"].danger { color: var(--bad-ink); }
.menu [role^="menuitem"].danger .icon { color: var(--bad-ink); }
.menu [role="menuitemradio"] .check-mark { margin-left: auto; color: var(--accent); visibility: hidden; }
.menu [role="menuitemradio"][aria-checked="true"] .check-mark { visibility: visible; }
.menu .sep { height: 1px; background: var(--line); margin: var(--sp-1) 0; }
.menu .menu-label { padding: 6px var(--sp-3) 2px; color: var(--ink-3); font-size: var(--fs-xs); }

/* ---- states: empty, error, loading */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--sp-2);
  padding: var(--sp-9) var(--sp-5); color: var(--ink-2);
}
.empty .glyph {
  width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; margin-bottom: var(--sp-2);
  background: var(--sunken); border: 1px solid var(--line); color: var(--ink-3);
}
.empty .glyph .icon { width: 22px; height: 22px; }
.empty .title { font-weight: 600; color: var(--ink-1); font-size: var(--fs-lg); }
.empty .text { max-width: 420px; color: var(--ink-3); }
.empty .actions { margin-top: var(--sp-3); display: flex; gap: var(--sp-2); }
.empty.compact { padding: var(--sp-7) var(--sp-4); }
.empty.bad .glyph { background: var(--bad-wash); color: var(--bad-ink); border-color: transparent; }
.notice {
  display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md);
  background: var(--accent-wash); color: var(--ink-1); font-size: var(--fs-sm); border: 1px solid transparent;
}
.notice .icon { color: var(--accent-ink); margin-top: 1px; width: 16px; height: 16px; }
.notice.warn { background: var(--warn-wash); }
.notice.warn .icon { color: var(--warn-ink); }
.notice.bad { background: var(--bad-wash); }
.notice.bad .icon { color: var(--bad-ink); }
.skeleton {
  display: block; border-radius: var(--r-sm); background: var(--sunken); position: relative; overflow: hidden;
}
.skeleton::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--hover), transparent); animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }
.skeleton-rows { display: flex; flex-direction: column; gap: 14px; padding: var(--sp-5); }
.skeleton-rows .skeleton { height: 14px; }
.loading-frame { opacity: 0.55; transition: opacity var(--t-med); pointer-events: none; }

/* ---- small parts */
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 10px var(--sp-5); font-size: var(--fs-md); }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; min-width: 0; word-break: break-word; display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.code {
  position: relative; background: var(--sunken); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4); padding-right: 48px; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.65;
  white-space: pre-wrap; word-break: break-all; margin: 0; color: var(--ink-1);
}
.code .copy { position: absolute; top: 6px; right: 6px; }
.secret {
  display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-3) var(--sp-3) var(--sp-4);
  border: 1px dashed var(--accent); border-radius: var(--r-md); background: var(--accent-wash);
}
.secret code { flex: 1; min-width: 0; word-break: break-all; font-size: 13.5px; -webkit-user-select: all; user-select: all; }
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--line); margin-bottom: var(--sp-4); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 0; background: none; padding: 8px 12px; color: var(--ink-2); font-weight: 500; cursor: pointer; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button:hover { color: var(--ink-1); }
.tabs button[aria-selected="true"] { color: var(--ink-1); border-bottom-color: var(--accent); }
.tabs button:focus-visible { outline: none; box-shadow: inset var(--focus-ring); border-radius: var(--r-sm); }
.tabs .count { color: var(--ink-3); font-weight: 400; margin-left: 4px; }
.meter { height: 6px; border-radius: 3px; background: var(--accent-wash-strong); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.meter.warn > i { background: var(--warn); }
.meter.bad > i { background: var(--bad); }
.phone-only { display: none; }
.btn .count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent-fill); color: var(--ink-on-accent); font-size: 11px; display: inline-grid; place-items: center; }
.pager { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--line); color: var(--ink-3); font-size: var(--fs-sm); }
.pager .spacer { flex: 1; }
kbd {
  padding: 0 5px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: var(--r-xs);
  font-size: 11px; color: var(--ink-2); background: var(--raised);
}
time { white-space: nowrap; }

/* ---- narrow screens: the sidebar becomes a drawer behind a top bar,
   wide tables become cards, dialogs become full-screen sheets. */
@media (max-width: 960px) {
  .page { padding: var(--sp-6) var(--sp-5) var(--sp-8); }
}
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); background: var(--page); }
  .topbar {
    display: flex; align-items: center; gap: var(--sp-2); position: sticky; top: 0; z-index: 20; height: 56px;
    padding: 0 var(--sp-3); background: var(--sidebar); border-bottom: 1px solid var(--line);
  }
  .topbar .brand { padding: 0; flex: 1; }
  .topbar .brand-sub { display: none; }
  .sidebar {
    position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; width: min(300px, 86vw); transform: translateX(-100%);
    transition: transform var(--t-med) var(--ease); box-shadow: var(--shadow-3); visibility: hidden;
  }
  .app.nav-open .sidebar { transform: none; visibility: visible; }
  .scrim { position: fixed; inset: 0; z-index: 40; background: var(--overlay); }
  .page { padding: var(--sp-5) var(--sp-4) var(--sp-8); }
  .page-head { margin-bottom: var(--sp-5); align-items: flex-start; }
  .page-head h1 { font-size: var(--fs-xl); }
  .page-head .description { font-size: var(--fs-sm); }
  .card-head, .card-body { padding-left: var(--sp-4); padding-right: var(--sp-4); }
  .grid-2, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .filters { gap: var(--sp-2); }
  .filters .field, .filters .field.wide, .filters .field.date, .filters .field.narrow { width: calc(50% - 4px); }
  .filters .field.auto { width: 100%; }
  .filters .seg { display: flex; }
  .filters .seg button { flex: 1; }
  .filters .field.full { width: 100%; }
  dialog.modal, dialog.modal.wide, dialog.modal.narrow, dialog.drawer, dialog.drawer.wide {
    width: 100vw; max-width: 100vw; height: 100%; max-height: 100%; margin: 0; border-radius: 0; border: 0;
  }
  dialog.confirm { height: auto; margin: auto 0 0; border-radius: var(--r-xl) var(--r-xl) 0 0; }
  .dialog-head, .dialog-body, .dialog-foot { padding-left: var(--sp-4); padding-right: var(--sp-4); }
  .toasts { left: 16px; right: 16px; bottom: 16px; width: auto; }
  /* A table marked to reflow shows each row as a card of label: value lines. */
  table.data.reflow thead { display: none; }
  table.data.reflow, table.data.reflow tbody, table.data.reflow tr, table.data.reflow td { display: block; width: 100%; }
  table.data.reflow tr { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line); }
  table.data.reflow tbody tr:last-child { border-bottom: 0; }
  table.data.reflow td { border: 0; padding: 3px 0 !important; text-align: left; display: flex; gap: var(--sp-3); justify-content: space-between; align-items: center; }
  table.data.reflow td.num { text-align: right; }
  table.data.reflow td::before { content: attr(data-label); color: var(--ink-3); font-size: var(--fs-sm); flex: none; font-weight: 400; }
  table.data.reflow tr { position: relative; }
  table.data.reflow td.lead { font-weight: 600; padding: 0 40px 4px 0 !important; }
  table.data.reflow td.lead::before, table.data.reflow td.actions::before,
  table.data.reflow td.p-meta::before, table.data.reflow td.p-plain::before { content: none; }
  table.data.reflow td.actions { position: absolute; top: 8px; right: 8px; width: auto; padding: 0 !important; }
  table.data.reflow td.p-meta { display: inline-flex; width: auto; margin-right: 10px; color: var(--ink-2); font-size: var(--fs-sm); vertical-align: middle; }
  table.data.reflow td.p-plain { display: block; color: var(--ink-2); font-size: var(--fs-sm); }
  table.data.reflow td.p-figure { display: inline-flex; width: auto; margin-right: 14px; gap: 6px; font-size: var(--fs-sm); }
  table.data.reflow td.p-figure::before { font-size: var(--fs-xs); }
  table.data.reflow td.p-figure .sub { display: none; }
  table.data.reflow td.p-hide { display: none; }
  table.data.reflow .sub { display: inline; margin: 0 0 0 6px; }
  table.data.reflow .cell-main .sub { display: block; margin: 1px 0 0; }
  .filters:not(.open) { display: none; }
  .phone-only { display: inline-flex; }
  table.data.reflow td > * { min-width: 0; }
  table.data.reflow tfoot { display: block; }
  .kv { gap: 8px var(--sp-4); }
  /* Fingers need larger targets than a pointer: 36px at least, 40px for the
     main controls. Fields take 16px type, below which Safari on a phone
     zooms the page into a field when it is focused. */
  .btn, input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="email"],
  input[type="search"], select { height: 40px; }
  input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="email"],
  input[type="search"], select, textarea { font-size: 16px; }
  .btn.icon-only { width: 40px; }
  .btn.sm { height: 36px; }
  .btn.sm.icon-only { width: 36px; }
  .seg button { height: 36px; }
  .switch, .check, .fold > summary { min-height: 36px; }
  table.data.reflow td a:not(.btn), .thread-meta a { display: inline-flex; align-items: center; justify-content: flex-end; min-height: 36px; min-width: 36px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .skeleton::after { display: none; }
}
@media (forced-colors: active) {
  .status::before, .nav-item[aria-current="page"]::before { forced-color-adjust: none; }
}
