/* =========================================================================
 * QUANT–DESK Terminal — shell layout + shared components
 *
 * Layout (DESIGN.md §2): one fixed viewport. Top bar · [left drawing rail |
 * chart | side panel | right icon rail] · bottom panel (resizable) · status
 * bar. The page NEVER scrolls; regions scroll inside themselves.
 *
 * Tiers (set by shell.js as data-tier on #t-app):
 *   1  >= 1280  full layout, side panel docked (pushes the chart)
 *   2  900–1279 side panel overlays the chart; drawing rail -> top-bar menu
 *   3  <  900   chart on top, one bottom sheet with tabs; top bar shrinks to
 *               symbol · price · STOP. STOP is visible at every width.
 *
 * Component classes (use these; do not restyle per feature):
 *   .t-btn [--primary --danger --ghost --icon --sm]   .t-seg / .t-seg-btn
 *   .t-input .t-select .t-textarea .t-field .t-field-label .t-field-hint .t-check
 *   .t-table [--plain --dense] (sticky header; td.num / th.num right-aligned tabular)
 *   .t-badge--{pass fail warn info neutral paper live stale up down}
 *   .t-chip  .t-pill  .t-dot--{ok warn crit info mute}  .t-kbd
 *   .t-up .t-down .t-flat  .t-num (tabular mono)  .t-muted  .t-flash-up/-down
 *   .t-panel-section .t-panel-heading  .t-scroll (a region that scrolls)
 *   .t-empty  .t-modal .t-drawer .t-menu .t-toast .t-tip  (built by ui.js)
 * ========================================================================= */

/* ---------------------------------------------------------------- base -- */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;                         /* no page scroll, ever */
  overscroll-behavior: none;
}
body {
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: var(--lh);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: var(--c-accent); text-underline-offset: 2px; }
h1, h2, h3, h4 { margin: 0; font-weight: var(--fw-semibold); }
p { margin: 0 0 var(--sp-2); }
code, kbd, pre, .t-num { font-family: var(--font-mono); }
.t-num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 1px; border-radius: var(--r-1); }
[hidden] { display: none !important; }
::selection { background: var(--c-accent-soft); color: var(--c-text); }

.t-icon { width: var(--icon); height: var(--icon); flex: none; display: block; }
.t-skip {
  position: absolute; left: -9999px; top: 0; z-index: var(--z-tip);
  background: var(--c-raised); color: var(--c-text); padding: var(--sp-2) var(--sp-3);
}
.t-skip:focus { left: var(--sp-2); top: var(--sp-2); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* thin, calm scrollbars inside regions */
* { scrollbar-width: thin; scrollbar-color: var(--c-border-strong) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--c-border-strong); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ============================================================== layout == */
.t-app {
  --bottom-h: var(--bottom-default);
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: var(--h-topbar) minmax(0, 1fr) var(--bottom-h) var(--h-status);
  grid-template-columns: minmax(0, 1fr);
  gap: var(--gutter);
  background: var(--c-bg);
  overflow: hidden;
}
.t-app.t-resizing, .t-app.t-resizing * { cursor: row-resize !important; user-select: none; }

/* ---- top bar ---------------------------------------------------------- */
.t-topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
  padding: 0 var(--sp-2) 0 var(--sp-3);
  background: var(--c-surface);
  overflow: hidden;
}
.t-brand {
  display: flex; align-items: center; gap: var(--sp-2);
  flex: none;
  padding-right: var(--sp-3);
  margin-right: var(--sp-1);
  border-right: 1px solid var(--c-border);
  height: 28px;
  color: var(--c-text);
  user-select: none;
}
.t-brand-mark { width: 16px; height: 16px; color: var(--c-accent); }
.t-brand-name { font-size: var(--fs-sm); font-weight: var(--fw-bold); letter-spacing: 0.08em; white-space: nowrap; }
.t-topbar-zone { display: flex; align-items: center; gap: var(--sp-1); min-width: 0; }
.t-topbar-left { flex: 0 1 auto; overflow: hidden; }
.t-topbar-spacer { flex: 1 1 0; min-width: var(--sp-2); }
.t-topbar-right { flex: 0 0 auto; }
.t-slot { display: flex; align-items: center; gap: var(--sp-1); min-width: 0; flex: none; }
.t-slot + .t-slot { padding-left: var(--sp-1); }
.t-slot[data-divider]::before, .t-topbar-left .t-slot + .t-slot::before {
  content: ""; width: 1px; height: 20px; background: var(--c-border); margin-right: var(--sp-1);
}
.t-only-compact { display: none !important; }
.t-slot[data-overflow] { display: none; }
.t-topbar .t-btn:not(.t-btn--icon) { padding: 0 var(--sp-2); }
@media (max-width: 1439px) { .t-topbar .t-label-wide { display: none; } }

/* the STOP button — the one loud thing on the screen */
.t-stop {
  flex: none;
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px;
  margin-left: var(--sp-2);
  padding: 0 14px 0 11px;
  border: 0;
  border-radius: var(--r-2);
  background: var(--c-stop-bg);
  color: var(--c-stop-fg);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  letter-spacing: 0.1em;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.18);
}
.t-stop .t-icon { width: 14px; height: 14px; }
.t-stop:hover { background: var(--c-stop-bg-hover); }
.t-stop:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 2px; }
.t-stop:active { transform: translateY(1px); }
.t-stop:disabled { opacity: 0.5; cursor: not-allowed; }

/* account chip */
.t-account {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  height: 30px; padding: 0 var(--sp-2);
  border: 1px solid transparent; border-radius: var(--r-2);
  background: transparent; color: var(--c-text);
  white-space: nowrap;
}
.t-account:hover { background: var(--c-hover); }
.t-account[data-state="off"] { color: var(--c-text-3); }
.t-account[data-state="signin"] { border-color: var(--c-control-border); }
.t-account-fig { display: inline-flex; align-items: baseline; gap: 5px; }
.t-account-label { font-size: var(--fs-xs); color: var(--c-text-3); }
.t-account-fig .t-num { font-size: var(--fs-md); font-weight: var(--fw-medium); }
.t-account-note { font-size: var(--fs-sm); }
.t-account .t-icon { width: 16px; height: 16px; }
/* 900–1279 px: the chip keeps its three facts (PAPER/LIVE, equity, open P&L with its
   sign and arrow) and drops the words, so the symbol and its price keep their room.
   The full wording stays in the chip's aria-label and its menu. */
.t-app[data-tier="2"] .t-account { gap: 6px; padding: 0 6px; }
.t-app[data-tier="2"] .t-account-open .t-account-label { display: none; }
.t-app[data-tier="2"] .t-account-fig .t-num { font-size: var(--fs-sm); }
.t-app[data-tier="2"] .t-account .t-badge { padding: 0 4px; }
/* ... and at the narrow end of that band the wordmark yields too (the mark stays) */
@media (max-width: 1023px) { .t-app[data-tier="2"] .t-brand-name { display: none; } }

.t-haltchip {
  display: inline-flex; align-items: center; gap: 5px;
  height: 26px; padding: 0 var(--sp-2);
  border-radius: var(--r-2); border: 1px solid currentColor;
  font-size: var(--fs-xs); font-weight: var(--fw-bold); letter-spacing: var(--tracking-caps);
  background: transparent;
}
.t-haltchip .t-icon { width: 14px; height: 14px; }
.t-haltchip--warn { color: var(--c-warn); background: var(--c-warn-bg); }
.t-haltchip--crit { color: var(--c-crit); background: var(--c-crit-bg); }

/* ---- main row --------------------------------------------------------- */
.t-main {
  position: relative;
  display: grid;
  grid-template-columns: var(--w-rail) minmax(0, 1fr) var(--w-rail);
  gap: var(--gutter);
  min-height: 0;
  background: var(--c-bg);
}
.t-app[data-tier="1"][data-side="open"] .t-main {
  grid-template-columns: var(--w-rail) minmax(0, 1fr) var(--w-side) var(--w-rail);
}
.t-app[data-no-tools] .t-lrail { display: none; }
.t-app[data-tier="1"][data-no-tools] .t-main { grid-template-columns: minmax(0, 1fr) var(--w-rail); }
.t-app[data-tier="1"][data-no-tools][data-side="open"] .t-main {
  grid-template-columns: minmax(0, 1fr) var(--w-side) var(--w-rail);
}

.t-lrail, .t-rrail {
  display: flex; flex-direction: column; align-items: center;
  gap: 2px;
  padding: var(--sp-1) 0;
  background: var(--c-surface);
  min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  scrollbar-width: none;
}
.t-lrail::-webkit-scrollbar, .t-rrail::-webkit-scrollbar { display: none; }
.t-rrail { justify-content: space-between; }
.t-rrail-top, .t-rrail-foot { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.t-rail-btn {
  position: relative;
  display: grid; place-items: center;
  width: 36px; height: 36px;
  border: 0; border-radius: var(--r-2);
  background: transparent;
  color: var(--c-text-2);
}
.t-rail-btn .t-icon { width: 20px; height: 20px; }
.t-rail-btn:hover { background: var(--c-hover); color: var(--c-text); }
.t-rail-btn[aria-pressed="true"] { background: var(--c-selected); color: var(--c-accent); }
.t-rrail .t-rail-btn[aria-pressed="true"]::before {
  content: ""; position: absolute; left: -4px; top: 8px; bottom: 8px; width: 2px;
  border-radius: 2px; background: var(--c-accent);
}
.t-lrail .t-rail-btn[aria-pressed="true"]::before {
  content: ""; position: absolute; right: -4px; top: 8px; bottom: 8px; width: 2px;
  border-radius: 2px; background: var(--c-accent);
}
.t-rail-badge {
  position: absolute; top: 2px; right: 1px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: var(--r-pill);
  background: var(--c-accent-bg); color: var(--c-accent-fg);
  font-size: var(--fs-2xs); font-weight: var(--fw-bold); line-height: 16px; text-align: center;
  font-family: var(--font-mono);
}
.t-rail-sep { width: 20px; height: 1px; background: var(--c-border); margin: var(--sp-1) 0; flex: none; }

/* ---- chart region ----------------------------------------------------- */
.t-chart {
  position: relative;
  min-width: 0; min-height: 0;
  background: var(--c-chart);
  overflow: hidden;
}
.t-chart > .t-empty { position: absolute; inset: 0; }
.t-boot-msg {
  position: absolute; inset: 0; display: grid; place-items: center; padding: var(--sp-5);
  color: var(--c-text-3); font-size: var(--fs-sm); text-align: center;
}

/* ---- side panel ------------------------------------------------------- */
.t-side {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  background: var(--c-surface);
}
.t-side-head {
  display: flex; align-items: center; gap: var(--sp-1);
  height: 36px; flex: none;
  padding: 0 var(--sp-1) 0 var(--sp-3);
  border-bottom: 1px solid var(--c-border);
}
.t-side-title {
  flex: 1 1 auto; min-width: 0;
  font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--c-text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.t-side-actions { display: flex; align-items: center; gap: 2px; }
.t-side-body { flex: 1 1 auto; min-height: 0; overflow: auto; position: relative; }

/* tier 2: the side panel overlays the chart */
.t-app[data-tier="2"] .t-main { grid-template-columns: minmax(0, 1fr) var(--w-rail); }
.t-app[data-tier="2"] .t-lrail { display: none; }
.t-app[data-tier="2"] .t-side {
  position: absolute;
  top: 0; bottom: 0;
  right: calc(var(--w-rail) + var(--gutter));
  width: min(var(--w-side-overlay), calc(100% - var(--w-rail) - 48px));
  z-index: var(--z-overlay-panel);
  box-shadow: var(--shadow-2);
  border-left: 1px solid var(--c-border-strong);
}
.t-app[data-tier="2"] .t-main > .t-chart { grid-column: 1; grid-row: 1; }
.t-app[data-tier="2"] .t-main > .t-rrail { grid-column: 2; grid-row: 1; }
.t-draw-menu { flex: none; }

/* ---- bottom panel ----------------------------------------------------- */
.t-bottom {
  position: relative;
  display: grid;
  grid-template-rows: var(--h-tabs) minmax(0, 1fr);
  min-height: 0;
  background: var(--c-surface);
}
.t-bottom-grip {
  position: absolute; left: 0; right: 0; top: -4px; height: 8px;
  z-index: 5;
  cursor: row-resize;
  touch-action: none;
}
.t-bottom-grip::after {
  content: ""; position: absolute; left: 50%; top: 3px; width: 32px; height: 2px;
  margin-left: -16px; border-radius: 2px; background: transparent;
  transition: background var(--t-fast);
}
.t-bottom-grip:hover::after, .t-bottom-grip:focus-visible::after { background: var(--c-accent); }
.t-bottom-grip:focus-visible { outline: none; }
.t-bottom-head {
  display: flex; align-items: stretch;
  min-width: 0;
  padding-right: var(--sp-1);
  border-bottom: 1px solid var(--c-border);
}
.t-app[data-bottom="collapsed"] .t-bottom-head { border-bottom-color: transparent; }
.t-bottom-head > .t-btn { align-self: center; }
.t-tabs {
  flex: 1 1 auto; min-width: 0;
  display: flex; align-items: stretch;
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: none;
}
.t-tabs::-webkit-scrollbar { display: none; }
.t-tab {
  position: relative;
  display: inline-flex; align-items: center; gap: 6px;
  flex: none;
  padding: 0 var(--sp-3);
  border: 0; background: transparent;
  color: var(--c-text-2);
  font-size: var(--fs-sm); font-weight: var(--fw-medium);
  white-space: nowrap;
}
.t-tab:hover { color: var(--c-text); background: var(--c-hover); }
.t-tab[aria-selected="true"] { color: var(--c-text); }
.t-tab[aria-selected="true"]::after {
  content: ""; position: absolute; left: var(--sp-2); right: var(--sp-2); bottom: 0; height: 2px;
  background: var(--c-accent); border-radius: 2px 2px 0 0;
}
.t-app[data-bottom="collapsed"] .t-tab[aria-selected="true"]::after { display: none; }
.t-tab-icon { width: 15px; height: 15px; }
.t-tab-badge {
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: var(--r-pill);
  background: var(--c-accent-soft); color: var(--c-accent);
  font-family: var(--font-mono); font-size: var(--fs-2xs); font-weight: var(--fw-bold); line-height: 16px; text-align: center;
}
.t-tabs-empty { align-self: center; padding: 0 var(--sp-3); font-size: var(--fs-sm); color: var(--c-text-3); white-space: nowrap; }
.t-bottom-body { min-height: 0; overflow: auto; position: relative; }
.t-app[data-bottom="collapsed"] .t-bottom-body { display: none; }

/* ---- status bar ------------------------------------------------------- */
.t-status {
  display: flex; align-items: stretch;
  min-width: 0;
  background: var(--c-surface);
  font-size: var(--fs-xs);
  color: var(--c-text-2);
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: none;
}
.t-status::-webkit-scrollbar { display: none; }
.t-status-zone { display: flex; align-items: stretch; flex: none; }
.t-status-left > .t-status-item { order: 0; }
.t-status-right { margin-left: auto; }
.t-status-item { display: flex; align-items: stretch; flex: none; }
.t-status-item + .t-status-item, .t-status-right { border-left: 1px solid var(--c-border); }
.t-sbtn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 0 var(--sp-2);
  border: 0; background: transparent;
  color: var(--c-text-2); font-size: var(--fs-xs);
  white-space: nowrap;
}
.t-sbtn:hover { background: var(--c-hover); color: var(--c-text); }
.t-status-text { display: inline-flex; align-items: center; padding: 0 var(--sp-2); white-space: nowrap; }
.t-clocks { display: flex; align-items: stretch; }
.t-clock + .t-clock { border-left: 1px solid var(--c-border); }
.t-clock-name { font-weight: var(--fw-semibold); color: var(--c-text); }
.t-clock-state { letter-spacing: 0.02em; }
.t-clock-next { color: var(--c-text-3); }
.t-clock-short { display: none; }
.t-app[data-tier="2"] .t-clock-state, .t-app[data-tier="3"] .t-clock-state { display: none; }
.t-app[data-tier="2"] .t-clock-short, .t-app[data-tier="3"] .t-clock-short { display: inline; }
.t-app[data-tier="2"] .t-clock-next { display: none; }
/* on a phone the two facts that matter most come first */
.t-app[data-tier="3"] .t-status-item[data-slot="halt"],
.t-app[data-tier="3"] .t-status-item[data-slot="api"] { order: -1; }

/* ---- tier 3: phone / small tablet ------------------------------------- */
.t-app[data-tier="3"] {
  grid-template-rows: var(--h-topbar-compact) minmax(0, 1fr) var(--bottom-h) var(--h-status);
}
.t-app[data-tier="3"] .t-main { grid-template-columns: minmax(0, 1fr); }
.t-app[data-tier="3"] .t-lrail,
.t-app[data-tier="3"] .t-rrail,
.t-app[data-tier="3"] .t-side,
.t-app[data-tier="3"] .t-draw-menu { display: none !important; }
.t-app[data-tier="3"] .t-topbar { padding: 0 var(--sp-2); gap: var(--sp-1); }
.t-app[data-tier="3"] .t-brand { padding-right: var(--sp-2); margin-right: 0; }
.t-app[data-tier="3"] .t-brand-name { display: none; }
.t-app[data-tier="3"] .t-slot:not([data-compact]) { display: none; }
.t-app[data-tier="3"] .t-only-compact { display: flex !important; }
.t-app[data-tier="3"] .t-stop { margin-left: var(--sp-1); padding: 0 12px 0 10px; }
.t-app[data-tier="3"] .t-bottom { border-top: 1px solid var(--c-border-strong); }
.t-app[data-tier="3"] .t-bottom-grip { top: -6px; height: 14px; }
.t-app[data-tier="3"] .t-bottom-grip::after { background: var(--c-border-strong); top: 8px; }
.t-app[data-tier="3"] .t-tab { padding: 0 var(--sp-2); }
.t-app[data-tier="3"] .t-tabs {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
          mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
}

/* ============================================================ controls == */
.t-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--h-control);
  padding: 0 var(--sp-3);
  border: 1px solid var(--c-control-border);
  border-radius: var(--r-2);
  background: var(--c-surface);
  color: var(--c-text);
  font-size: var(--fs-sm); font-weight: var(--fw-medium);
  white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.t-btn .t-icon { width: 16px; height: 16px; }
.t-btn:hover:not(:disabled) { background: var(--c-hover); }
.t-btn:disabled { opacity: 0.5; }
.t-btn--primary { background: var(--c-accent-bg); border-color: var(--c-accent-bg); color: var(--c-accent-fg); }
.t-btn--primary:hover:not(:disabled) { background: var(--c-accent-bg-hover); border-color: var(--c-accent-bg-hover); }
.t-btn--danger { background: var(--c-stop-bg); border-color: var(--c-stop-bg); color: var(--c-stop-fg); }
.t-btn--danger:hover:not(:disabled) { background: var(--c-stop-bg-hover); border-color: var(--c-stop-bg-hover); }
.t-btn--ghost { background: transparent; border-color: transparent; color: var(--c-text-2); }
.t-btn--ghost:hover:not(:disabled) { color: var(--c-text); background: var(--c-hover); }
.t-btn--icon { width: var(--h-control); padding: 0; }
.t-btn--icon .t-icon { width: 18px; height: 18px; }
.t-btn--sm { height: var(--h-control-sm); padding: 0 var(--sp-2); font-size: var(--fs-xs); }
.t-btn--icon.t-btn--sm { width: var(--h-control-sm); padding: 0; }
.t-btn--icon.t-btn--sm .t-icon { width: 15px; height: 15px; }
.t-btn--block { width: 100%; }

/* segmented control (timeframes, chart type, filters) */
.t-seg {
  display: inline-flex; align-items: stretch;
  height: var(--h-control);
  padding: 2px; gap: 1px;
  border-radius: var(--r-2);
  background: var(--c-sunken);
  border: 1px solid var(--c-border);
}
.t-seg--sm { height: var(--h-control-sm); }
.t-seg-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 0 var(--sp-2);
  border: 0; border-radius: var(--r-1);
  background: transparent; color: var(--c-text-2);
  font-size: var(--fs-sm); font-weight: var(--fw-medium);
  white-space: nowrap;
}
.t-seg--sm .t-seg-btn { font-size: var(--fs-xs); padding: 0 6px; }
.t-seg-btn .t-icon { width: 16px; height: 16px; }
.t-seg-btn:hover:not(:disabled) { color: var(--c-text); background: var(--c-hover); }
.t-seg-btn[aria-pressed="true"], .t-seg-btn[aria-checked="true"] {
  background: var(--c-accent-soft); color: var(--c-accent); font-weight: var(--fw-semibold);
}
.t-seg-btn:disabled { opacity: 0.45; }

/* inputs */
.t-input, .t-select, .t-textarea {
  width: 100%;
  height: var(--h-control);
  padding: 0 var(--sp-2);
  border: 1px solid var(--c-control-border);
  border-radius: var(--r-2);
  background: var(--c-sunken);
  color: var(--c-text);
  font-size: var(--fs-md);
}
.t-textarea { height: auto; min-height: 72px; padding: 6px var(--sp-2); resize: vertical; }
.t-input::placeholder, .t-textarea::placeholder { color: var(--c-text-3); }
.t-input:focus, .t-select:focus, .t-textarea:focus { border-color: var(--c-focus); outline: 1px solid var(--c-focus); outline-offset: 0; }
.t-input--mono { font-family: var(--font-mono); }
.t-input[aria-invalid="true"] { border-color: var(--c-crit); }
.t-select { appearance: none; padding-right: 26px;
  background-image: linear-gradient(45deg, transparent 50%, var(--c-text-2) 50%), linear-gradient(135deg, var(--c-text-2) 50%, transparent 50%);
  background-position: calc(100% - 13px) 50%, calc(100% - 9px) 50%;
  background-size: 4px 4px; background-repeat: no-repeat; }
.t-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: var(--sp-3); }
.t-field-label { font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--c-text-2); letter-spacing: 0.02em; }
.t-field-hint { font-size: var(--fs-xs); color: var(--c-text-3); margin-top: 4px; }
.t-field-hint--warn { color: var(--c-warn); }
.t-field-error { font-size: var(--fs-xs); color: var(--c-crit); }
.t-check { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--c-text); }
.t-check input { accent-color: var(--c-accent-bg); width: 14px; height: 14px; margin: 0; }

/* ============================================================== tables == */
.t-table {
  width: 100%;
  border-collapse: separate; border-spacing: 0;
  font-size: var(--fs-sm);
}
.t-table th {
  position: sticky; top: 0; z-index: 1;
  height: 28px; padding: 0 var(--sp-2);
  background: var(--c-surface-2);
  border-bottom: 1px solid var(--c-border-strong);
  color: var(--c-text-3);
  font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  text-align: left; white-space: nowrap;
  letter-spacing: 0.02em;
}
.t-table td {
  height: var(--h-row);
  padding: 0 var(--sp-2);
  border-bottom: 1px solid var(--c-border);
  white-space: nowrap;
  vertical-align: middle;
}
.t-table th.num, .t-table td.num {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.t-table th.num { font-family: var(--font-ui); }
.t-table tbody tr:hover td { background: var(--c-hover); }
.t-table tbody tr[aria-selected="true"] td { background: var(--c-selected); }
.t-table tbody tr.t-clickable { cursor: pointer; }
.t-table--dense td { height: 22px; }
.t-table--plain th { position: static; background: transparent; }
.t-table--plain td { border-bottom-color: var(--c-border); }
.t-table--plain tbody tr:hover td { background: transparent; }
.t-table td.t-wrap { white-space: normal; }
.t-table caption { caption-side: bottom; text-align: left; padding: var(--sp-2); color: var(--c-text-3); font-size: var(--fs-xs); }

/* ============================================================== badges == */
.t-badge {
  display: inline-flex; align-items: center; gap: 3px;
  height: 18px; padding: 0 6px;
  border-radius: var(--r-1);
  border: 1px solid transparent;
  font-size: var(--fs-2xs); font-weight: var(--fw-bold);
  letter-spacing: 0.05em; text-transform: uppercase;
  white-space: nowrap; line-height: 1;
  font-family: var(--font-ui);
}
.t-badge .t-icon { width: 11px; height: 11px; }
.t-badge--pass { color: var(--c-ok); background: var(--c-ok-bg); }
.t-badge--fail { color: var(--c-crit); background: var(--c-crit-bg); }
.t-badge--warn { color: var(--c-warn); background: var(--c-warn-bg); }
.t-badge--info { color: var(--c-accent); background: var(--c-accent-soft); }
.t-badge--neutral { color: var(--c-text-2); background: var(--c-surface-2); border-color: var(--c-border); }
.t-badge--paper { color: var(--c-paper-fg); border-color: var(--c-control-border); background: transparent; }
.t-badge--live { color: var(--c-live-fg); background: var(--c-live-bg); }
.t-badge--stale { color: var(--c-warn); border-color: currentColor; border-style: dashed; background: transparent; }
.t-badge--up { color: var(--c-up); background: var(--c-up-soft); }
.t-badge--down { color: var(--c-down); background: var(--c-down-soft); }

.t-chip {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 var(--sp-2);
  border: 1px solid var(--c-border-strong); border-radius: var(--r-pill);
  background: transparent; color: var(--c-text-2);
  font-size: var(--fs-xs); white-space: nowrap;
}
.t-chip[aria-pressed="true"] { background: var(--c-accent-soft); border-color: var(--c-accent); color: var(--c-accent); }
.t-chip .t-icon { width: 12px; height: 12px; }

.t-pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px 0 8px;
  border: 1px solid var(--c-control-border); border-radius: var(--r-pill);
  background: transparent; color: var(--c-text);
  font-size: var(--fs-sm); font-weight: var(--fw-medium); white-space: nowrap;
}
.t-pill .t-icon { width: 14px; height: 14px; }
.t-pill:hover { background: var(--c-hover); }
.t-pill--muted { color: var(--c-text-2); }
.t-pill--warn { border-color: var(--c-warn); color: var(--c-warn); }
.t-pill--ok { border-color: var(--c-ok); color: var(--c-ok); }

.t-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--c-text-3); }
.t-dot--ok { background: var(--c-ok); }
.t-dot--warn { background: var(--c-warn); }
.t-dot--crit { background: var(--c-crit); }
.t-dot--info { background: var(--c-accent); }
.t-dot--mute { background: transparent; box-shadow: inset 0 0 0 1.5px var(--c-text-3); }

.t-kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 5px;
  border: 1px solid var(--c-border-strong); border-bottom-width: 2px; border-radius: var(--r-1);
  background: var(--c-surface-2); color: var(--c-text-2);
  font-family: var(--font-mono); font-size: var(--fs-xs); line-height: 1;
}

/* values */
.t-up { color: var(--c-up); }
.t-down { color: var(--c-down); }
.t-flat { color: var(--c-text-2); }
.t-muted { color: var(--c-text-3); }
.t-strong { font-weight: var(--fw-semibold); }
.t-ok { color: var(--c-ok); }
.t-warn { color: var(--c-warn); }
.t-crit { color: var(--c-crit); }
@keyframes t-flash-up { from { background-color: var(--c-up-soft); } to { background-color: transparent; } }
@keyframes t-flash-down { from { background-color: var(--c-down-soft); } to { background-color: transparent; } }
.t-flash-up { animation: t-flash-up var(--flash) ease-out; }
.t-flash-down { animation: t-flash-down var(--flash) ease-out; }

/* panel building blocks */
.t-scroll { overflow: auto; min-height: 0; }
.t-panel-section { padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--c-border); }
.t-panel-heading {
  display: flex; align-items: center; gap: var(--sp-2);
  margin: 0 0 var(--sp-2);
  font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--c-text-3);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.t-toolbar { display: flex; align-items: center; gap: var(--sp-1); padding: var(--sp-1) var(--sp-2); border-bottom: 1px solid var(--c-border); background: var(--c-surface-2); }
.t-note { font-size: var(--fs-xs); color: var(--c-text-3); }

/* =========================================================== empty state == */
.t-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-2);
  height: 100%; min-height: 120px;
  padding: var(--sp-5) var(--sp-4);
  text-align: center;
  color: var(--c-text-2);
}
.t-empty-icon { width: 28px; height: 28px; color: var(--c-text-3); }
.t-empty-title { font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--c-text); }
.t-empty-text { max-width: 380px; font-size: var(--fs-sm); color: var(--c-text-2); }
.t-empty--compact { min-height: 0; height: auto; padding: var(--sp-4) var(--sp-3); gap: 6px; }
.t-empty--compact .t-empty-icon { width: 20px; height: 20px; }

/* ================================================== modal / drawer / scrim == */
.t-scrim {
  /* starts BELOW the top bar: STOP stays reachable while any modal or drawer is open */
  position: fixed; inset: 0; top: var(--scrim-top, 0px);
  z-index: var(--z-modal);
  display: grid; place-items: center;
  padding: var(--sp-4);
  background: var(--c-scrim);
  animation: t-fade var(--t-med) ease-out;
}
.t-scrim--drawer { z-index: var(--z-drawer); display: block; padding: 0; }
@keyframes t-fade { from { opacity: 0; } to { opacity: 1; } }
.t-modal {
  display: flex; flex-direction: column;
  width: 100%; max-width: 560px;
  max-height: calc(100vh - 32px - var(--scrim-top, 0px)); max-height: calc(100dvh - 32px - var(--scrim-top, 0px));
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-4);
  background: var(--c-raised);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
.t-modal--sm { max-width: 420px; }
.t-modal--lg { max-width: 880px; }
.t-modal--xl { max-width: 1120px; height: min(760px, calc(100vh - 32px - var(--scrim-top, 0px))); }
.t-modal:focus-visible, .t-drawer:focus-visible, .t-menu:focus-visible { outline: none; }
.t-modal-head, .t-drawer-head {
  display: flex; align-items: center; gap: var(--sp-2);
  height: 44px; flex: none;
  padding: 0 var(--sp-2) 0 var(--sp-4);
  border-bottom: 1px solid var(--c-border);
}
.t-modal-title, .t-drawer-title { flex: 1 1 auto; font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.t-modal-body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: var(--sp-4); }
/* a bottom tab / side panel shown as a modal on a phone (shell.openOffSheet) */
.t-offsheet-modal .t-modal-body { padding: 0; display: flex; flex-direction: column; }
.t-offsheet { flex: 1 1 auto; min-height: 0; overflow: auto; }
.t-modal-foot, .t-drawer-foot {
  display: flex; justify-content: flex-end; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--c-border);
  background: var(--c-surface-2);
}
.t-modal-text { color: var(--c-text); }
.t-modal-note { font-size: var(--fs-xs); color: var(--c-text-3); margin-top: var(--sp-3); }
.t-phrase {
  display: inline-block; padding: 1px 6px; border-radius: var(--r-1);
  background: var(--c-sunken); border: 1px solid var(--c-border-strong);
  font-weight: var(--fw-semibold); color: var(--c-text); user-select: all;
}
.t-pre { font-family: var(--font-mono); font-size: var(--fs-xs); background: var(--c-sunken); border: 1px solid var(--c-border); border-radius: var(--r-2); padding: var(--sp-2); white-space: pre-wrap; }
.t-drawer {
  position: absolute; top: 0; bottom: 0;
  display: flex; flex-direction: column;
  width: min(420px, 100vw);
  background: var(--c-raised);
  box-shadow: var(--shadow-2);
  border-left: 1px solid var(--c-border-strong);
  animation: t-slide-in var(--t-med) ease-out;
}
.t-drawer--right { right: 0; }
.t-drawer--left { left: 0; border-left: 0; border-right: 1px solid var(--c-border-strong); }
@keyframes t-slide-in { from { transform: translateX(12px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.t-drawer-body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: var(--sp-3) var(--sp-4); }

/* auth */
.t-auth .t-auth-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-2); }
.t-auth-msg { min-height: 18px; font-size: var(--fs-sm); color: var(--c-warn); }

/* ================================================================ menu == */
.t-menu {
  position: fixed;
  z-index: var(--z-menu);
  min-width: 200px; max-width: min(360px, calc(100vw - 8px));
  max-height: calc(100vh - 16px); overflow: auto;
  padding: 4px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-3);
  background: var(--c-raised);
  box-shadow: var(--shadow-2);
}
.t-menu-item {
  display: flex; align-items: center; gap: var(--sp-2);
  width: 100%; min-height: 28px;
  padding: 3px var(--sp-2) 3px 4px;
  border: 0; border-radius: var(--r-2);
  background: transparent; color: var(--c-text);
  font-size: var(--fs-sm); text-align: left;
}
.t-menu-item:hover:not(:disabled), .t-menu-item:focus-visible { background: var(--c-hover); outline: none; }
.t-menu-item:disabled { color: var(--c-text-2); cursor: default; }
.t-menu-item--danger { color: var(--c-crit); }
.t-menu-check { width: 14px; flex: none; display: grid; place-items: center; color: var(--c-accent); }
.t-menu-check .t-icon { width: 14px; height: 14px; }
.t-menu-icon { width: 16px; height: 16px; flex: none; color: var(--c-text-2); }
.t-menu-label { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.t-menu-hint { font-size: var(--fs-xs); color: var(--c-text-3); }
.t-menu-kbd { margin-left: auto; font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--c-text-3); }
.t-menu-sep { height: 1px; margin: 4px 2px; background: var(--c-border); }
.t-menu-heading { padding: 6px var(--sp-2) 4px; font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--c-text-3); letter-spacing: 0.03em; }

/* =============================================================== toast == */
.t-toasts {
  position: fixed;
  right: var(--sp-3); bottom: calc(var(--h-status) + var(--sp-3));
  z-index: var(--z-toast);
  display: flex; flex-direction: column; align-items: flex-end; gap: var(--sp-2);
  max-width: min(440px, calc(100vw - 24px));
  pointer-events: none;
}
.t-toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: var(--sp-2);
  width: 100%;
  padding: var(--sp-2) var(--sp-1) var(--sp-2) var(--sp-3);
  border: 1px solid var(--c-border-strong);
  border-left: 3px solid var(--c-accent);
  border-radius: var(--r-3);
  background: var(--c-raised);
  box-shadow: var(--shadow-2);
  font-size: var(--fs-sm);
  animation: t-fade var(--t-med) ease-out;
}
.t-toast-icon { width: 16px; height: 16px; margin-top: 1px; color: var(--c-accent); }
.t-toast-body { flex: 1 1 auto; min-width: 0; padding-top: 1px; overflow-wrap: anywhere; }
.t-toast-code { display: inline-block; margin-right: 6px; font-family: var(--font-mono); font-size: var(--fs-xs); font-weight: var(--fw-bold); color: var(--c-text-2); }
.t-toast-action { flex: none; }
.t-toast--error { border-left-color: var(--c-crit); }
.t-toast--error .t-toast-icon, .t-toast--error .t-toast-code { color: var(--c-crit); }
.t-toast--warn { border-left-color: var(--c-warn); }
.t-toast--warn .t-toast-icon, .t-toast--warn .t-toast-code { color: var(--c-warn); }
.t-toast--ok { border-left-color: var(--c-ok); }
.t-toast--ok .t-toast-icon { color: var(--c-ok); }

/* ============================================================= tooltip == */
.t-tip {
  position: fixed;
  z-index: var(--z-tip);
  max-width: 320px;
  padding: 5px 8px;
  border-radius: var(--r-2);
  background: var(--c-text);
  color: var(--c-surface);
  font-size: var(--fs-xs); line-height: 1.35;
  pointer-events: none;
  white-space: pre-line;
  box-shadow: var(--shadow-1);
}

/* shortcut sheet */
.t-shortcuts td { height: 30px; }
.t-shortcut-keys { width: 40%; color: var(--c-text-2); }

.t-noscript { position: fixed; inset: 0; display: grid; place-items: center; background: var(--c-bg); color: var(--c-text); }

/* ================================================== motion + forced colours == */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
@media (forced-colors: active) {
  .t-stop { border: 2px solid ButtonText; }
  .t-rail-btn[aria-pressed="true"], .t-tab[aria-selected="true"], .t-seg-btn[aria-pressed="true"] { outline: 2px solid Highlight; }
  .t-dot { forced-color-adjust: none; border: 1px solid CanvasText; }
}
