/* ─────────────────────────────────────────────────────────────
   te.css — TE/R1-spirited design system for hud-web.

   Mirrors the palette, typography, and chrome of the Pi's CRT HUD +
   the reMarkable reports so every surface in the ecosystem feels
   like the same device.

   Palette:
     BG      #0A0A0A    near-black
     INK     #F0F0F0    near-white body text
     ACCENT  #FE7D01    amber / action
     DIMMER  #8A4400    dark amber / secondary accent
     MUTED   #5A5A5A    dividers, faint labels
     FAINT   #1E1E1E    row tint / chip bg
     OK      #00CC66    phosphor green (healthy)
     WARN    #FFA500
     ALERT   #FF3030

   Geometry:
     Corners are square. Viewfinder brackets mark framed regions.
     Rules are thin and often dashed.
     Headings are small-caps, letter-spaced, with a solid accent bar.
   ───────────────────────────────────────────────────────────── */

:root {
  --bg:        #0A0A0A;
  --bg-elev:  #141414;
  --ink:      #F0F0F0;
  --accent:   #FE7D01;
  --dimmer:  #8A4400;
  --muted:    #5A5A5A;
  --faint:    #1E1E1E;
  --rule:     #2A2A2A;
  --ok:       #00CC66;
  --warn:     #FFA500;
  --alert:   #FF3030;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", "IBM Plex Mono", "SF Mono", "Cascadia Code",
          "Consolas", ui-monospace, monospace;

  --top-h: 44px;
  --drawer-w: 260px;
  --bot-h: 28px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  height: 100%;
  overflow: hidden;
  overflow-x: hidden;       /* belt-and-braces: no stray horizontal scroll */
  max-width: 100vw;
  -webkit-text-size-adjust: 100%;  /* Safari/iOS: don't resize on orient */
}

body {
  display: grid;
  /* auto rows so topbar/bottombar breathe when the user zooms (125%+)
     — fixed 44/28px boxes clip their contents at that scale. Use
     min-height to keep the bars visually consistent at 100%. */
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "top"
    "main"
    "bot";
}

/* ─────────────────────── Top bar ─────────────────────── */
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  padding: 6px 12px;
  min-height: var(--top-h);
  border-bottom: 1px solid var(--accent);
  background: var(--bg);
  gap: 12px;
  position: relative;
  flex-wrap: wrap;
}
/* Thin amber accent rail just below the topbar (TE/R1 detail) */
.topbar::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  bottom: -3px;
  height: 2px;
  background: linear-gradient(
    90deg, transparent, var(--accent) 20%, var(--accent) 80%, transparent
  );
  opacity: 0.35;
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: inherit;
  padding: 0 4px;
  line-height: 1;
}
.topbar .brand:hover .brand-mark { color: var(--ink); }
.topbar .brand-mark {
  color: var(--accent);
  font-size: 10px;
  transition: color 0.15s;
}
.topbar .brand-name {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.22em;
  color: var(--ink);
}
.topbar .brand-sub {
  color: var(--accent);
  margin-left: 2px;
}
.topbar-divider {
  width: 1px;
  height: 22px;
  background: var(--rule);
  margin: 0 2px;
}
.topbar .title {
  flex: 1;
  font-family: var(--mono);
  font-weight: 500;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.topbar .clock {
  font-family: var(--mono);
  font-weight: 700;
  color: var(--ink);
  font-size: 13px;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border: 1px solid var(--rule);
}
.topbar .agent {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 6px;
}
.topbar .agent .pulse {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 5px var(--ok);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.3; }
  50%       { opacity: 1; }
}

/* ─── Animated hamburger → X ─── */
.hamburger {
  width: 30px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--rule);
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  position: relative;
  transition: border-color 0.15s;
}
.hamburger:hover { border-color: var(--accent); }
.hamburger span {
  display: block;
  width: 14px;
  height: 1.5px;
  background: var(--accent);
  transition: transform 0.18s ease-out, opacity 0.12s;
}
body.nav-open .hamburger {
  border-color: var(--accent);
  background: var(--faint);
}
body.nav-open .hamburger span:nth-child(1) {
  transform: translateY(5.5px) rotate(45deg);
}
body.nav-open .hamburger span:nth-child(2) { opacity: 0; }
body.nav-open .hamburger span:nth-child(3) {
  transform: translateY(-5.5px) rotate(-45deg);
}

/* ─────────────────────── Sidebar drawer ─────────────────────── */
.sidebar {
  position: fixed;
  top: var(--top-h);
  bottom: var(--bot-h);
  left: 0;
  width: var(--drawer-w);
  background: var(--bg);
  border-right: 1px solid var(--accent);
  overflow-y: auto;
  padding: 0;
  z-index: 500;
  transform: translateX(-101%);
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 24px rgba(0, 0, 0, 0.6);
}
body.nav-open .sidebar { transform: translateX(0); }

.sidebar-backdrop {
  position: fixed;
  inset: var(--top-h) 0 var(--bot-h) 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  z-index: 490;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease-out;
}
body.nav-open .sidebar-backdrop {
  opacity: 1;
  pointer-events: auto;
}

/* ─── Drawer brand header ─── */
.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 14px 12px 14px;
  border-bottom: 1px solid var(--accent);
  background: linear-gradient(
    180deg, rgba(254,125,1,0.06) 0%, transparent 100%
  );
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-brand .brand-mark {
  color: var(--accent);
  font-size: 14px;
  text-shadow: 0 0 8px rgba(254,125,1,0.4);
}
.sidebar-brand-name {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 11px;
  color: var(--ink);
  letter-spacing: 0.24em;
}
.sidebar-brand-sub {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.18em;
  margin-top: 1px;
}
.sidebar-close {
  width: 26px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--rule);
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.sidebar-close:hover { border-color: var(--accent); }
.sidebar-close span {
  position: absolute;
  width: 10px;
  height: 1.5px;
  background: var(--muted);
}
.sidebar-close:hover span { background: var(--accent); }
.sidebar-close span:nth-child(1) { transform: rotate(45deg); }
.sidebar-close span:nth-child(2) { transform: rotate(-45deg); }

/* ─── Drawer footer ─── */
.sidebar-foot {
  margin-top: auto;
  padding: 10px 14px 14px 14px;
  border-top: 1px dashed var(--rule);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.sidebar-foot-kbd {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.12em;
}
.sidebar-foot-kbd kbd {
  font-family: var(--mono);
  color: var(--accent);
  background: var(--faint);
  border: 1px solid var(--rule);
  padding: 1px 5px;
  font-size: 9px;
  margin: 0 2px;
}
.sidebar-foot-logout {
  font-family: var(--mono);
  color: var(--muted);
  text-decoration: none;
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  padding: 3px 8px;
  border: 1px solid var(--rule);
  transition: color 0.12s, border-color 0.12s;
}
.sidebar-foot-logout:hover {
  color: var(--alert);
  border-color: var(--alert);
}

/* ─── Nav groups ─── */
.nav-group + .nav-group { border-top: 1px solid var(--rule); }
.nav-group > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px 10px 14px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.28em;
  text-transform: uppercase;
  user-select: none;
  transition: color 0.12s, background 0.12s;
}
.nav-group > summary::-webkit-details-marker { display: none; }
.nav-group > summary:hover {
  background: var(--faint);
  color: var(--accent);
}
.nav-group[open] > summary {
  color: var(--ink);
  background: linear-gradient(
    180deg, rgba(254,125,1,0.05) 0%, transparent 100%
  );
}

.nav-group .caret {
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 4px solid var(--muted);
  border-top: 3px solid transparent;
  border-bottom: 3px solid transparent;
  transition: transform 0.18s ease-out, border-color 0.12s;
}
.nav-group[open] > summary .caret {
  transform: rotate(90deg);
  border-left-color: var(--accent);
}
.nav-group > summary:hover .caret {
  border-left-color: var(--accent);
}
.nav-group-label { flex: 1; }
.nav-group-count {
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  padding: 1px 7px;
  letter-spacing: 0.1em;
  border: 1px solid var(--rule);
  font-variant-numeric: tabular-nums;
}
.nav-group[open] > summary .nav-group-count {
  border-color: var(--dimmer);
  color: var(--accent);
}

.nav-group-body { padding: 2px 0 10px; }

.sidebar a.nav-item {
  display: grid;
  grid-template-columns: 20px 1fr;
  align-items: center;
  gap: 12px;
  padding: 8px 14px 8px 22px;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-left: 2px solid transparent;
  position: relative;
  transition: color 0.12s, background 0.12s;
}
.sidebar a.nav-item:hover {
  background: var(--faint);
  color: var(--accent);
}
.sidebar a.nav-item:hover .icon { text-shadow: 0 0 6px var(--accent); }
.sidebar a.nav-item.active {
  background: linear-gradient(
    90deg, rgba(254,125,1,0.16) 0%, transparent 70%
  );
  border-left-color: var(--accent);
  color: var(--accent);
}
.sidebar a.nav-item.active::after {
  content: "";
  position: absolute;
  right: 12px;
  width: 4px;
  height: 4px;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}
.sidebar a.nav-item .icon {
  color: var(--accent);
  font-weight: 700;
  text-align: center;
  font-size: 11px;
}

/* ─────────────────────── Main content ─────────────────────── */
.main {
  grid-area: main;
  position: relative;
  padding: 18px 22px;
  overflow-y: auto;
  min-height: 0;            /* allow the grid cell to shrink if needed */
  /* Flex column so any child with `flex: 1` (e.g. .chat-window) fills
     the available vertical space rather than relying on a brittle
     calc(100vh - Npx) that collapses at non-100% zoom. */
  display: flex;
  flex-direction: column;
}
/* Prevent flex-column squish: on tall pages (reports list, events
   feed, db tables) the default flex-shrink:1 was crushing subtitles
   and filter rows to near-zero height. Pin every direct child to its
   natural size; children that actually want to fill remaining space
   (.chat-window) opt in via `flex: 1` which overrides this. */
.main > * {
  flex-shrink: 0;
}

/* Viewfinder brackets: pinned to the viewport corners so they stay put
   when main content scrolls. Using position: fixed + CSS variable
   offsets lets them track whatever height the topbar/bottombar land at
   (after the zoom-safe auto sizing above). */
.vf-bl,
.vf-br {
  position: fixed;
  width: 14px;
  height: 14px;
  pointer-events: none;
  z-index: 1;
}
.main::before,
.main::after {
  content: "";
  position: fixed;
  width: 14px;
  height: 14px;
  pointer-events: none;
  z-index: 1;
}
.main::before {
  top: calc(var(--top-h) + 10px);
  left: 14px;
  border-top: 1px solid var(--accent);
  border-left: 1px solid var(--accent);
}
.main::after {
  top: calc(var(--top-h) + 10px);
  right: 14px;
  border-top: 1px solid var(--accent);
  border-right: 1px solid var(--accent);
}
.vf-bl {
  bottom: calc(var(--bot-h) + 10px);
  left: 14px;
  border-bottom: 1px solid var(--accent);
  border-left: 1px solid var(--accent);
}
.vf-br {
  bottom: calc(var(--bot-h) + 10px);
  right: 14px;
  border-bottom: 1px solid var(--accent);
  border-right: 1px solid var(--accent);
}

/* ─────────────────────── Bottom hint bar ─────────────────────── */
.bottombar {
  grid-area: bot;
  display: flex;
  align-items: center;
  padding: 4px 16px;
  min-height: var(--bot-h);
  gap: 16px;
  border-top: 1px solid var(--rule);
  background: var(--bg);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.08em;
  flex-wrap: wrap;
  row-gap: 2px;
}
.bottombar .hint {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.bottombar .hint .key {
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.bottombar .hint .lbl {
  color: var(--ink);
  text-transform: lowercase;
}
.bottombar .sep {
  color: var(--muted);
  opacity: 0.6;
}

/* ─────────────────────── Section headers ─────────────────────── */
h1.hero {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 26px;
  color: var(--ink);
  margin: 0 0 4px 0;
  letter-spacing: 0.02em;
  position: relative;
}
/* Page-title bloom — phosphor-amber gradient underline with a soft
   outer glow. Every .hero gets it by default; remove locally if a
   page wants a neutral heading. */
h1.hero::after {
  content: "";
  display: block;
  height: 2px;
  margin-top: 4px;
  background: linear-gradient(90deg,
    var(--accent) 0%,
    var(--ok) 60%,
    transparent 100%);
  box-shadow: 0 0 8px rgba(254, 125, 1, 0.35);
  width: min(220px, 40%);
}
.subtitle {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin: 0 0 14px 0;
}

h2.section {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 12px;
  color: var(--ink);
  margin: 18px 0 6px 0;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
h2.section::before {
  content: "";
  display: inline-block;
  width: 3px;
  height: 14px;
  background: var(--accent);
}
h2.section::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--rule);
  margin-left: 6px;
}

/* Dashed rule */
hr.dashed {
  border: 0;
  border-top: 1px dashed var(--rule);
  margin: 10px 0;
}
hr.thick {
  border: 0;
  border-top: 1px solid var(--accent);
  margin: 10px 0;
}

/* ─────────────────────── KPI tiles ─────────────────────── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin: 10px 0;
}
.kpi-tile {
  border: 1px solid var(--rule);
  padding: 10px 12px;
  background:
    linear-gradient(180deg,
      rgba(254, 125, 1, 0.04) 0%,
      rgba(254, 125, 1, 0) 60%),
    var(--bg);
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease-out, border-color 0.15s ease-out;
}
/* Phosphor-scanline overlay — near-invisible but gives every tile a
   subtle CRT texture. Below pointer events. */
.kpi-tile::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.015) 0px,
    rgba(255, 255, 255, 0.015) 1px,
    transparent 1px,
    transparent 3px);
  pointer-events: none;
  opacity: 0.6;
}
.kpi-tile:hover {
  transform: translateY(-1px);
  border-color: var(--dimmer);
}
.kpi-tile .label {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--accent);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.kpi-tile .value {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 22px;
  color: var(--ink);
  line-height: 1;
}
.kpi-tile .value.ok     {
  color: var(--ok);
  text-shadow: 0 0 4px rgba(0, 204, 102, 0.45),
               0 0 10px rgba(0, 204, 102, 0.2);
}
.kpi-tile .value.warn   {
  color: var(--warn);
  text-shadow: 0 0 4px rgba(255, 165, 0, 0.45),
               0 0 10px rgba(255, 165, 0, 0.2);
}
.kpi-tile .value.alert  {
  color: var(--alert);
  text-shadow: 0 0 4px rgba(255, 48, 48, 0.5),
               0 0 10px rgba(255, 48, 48, 0.2);
}
.kpi-tile .value.accent {
  color: var(--accent);
  text-shadow: 0 0 4px rgba(254, 125, 1, 0.55),
               0 0 10px rgba(254, 125, 1, 0.25);
}
.kpi-tile .caption {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--muted);
  margin-top: 4px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ─────────────────────── Status dots row ─────────────────────── */
.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 8px 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
/* Chip-style rows (unit picker, report filters, db tables) scroll
   horizontally rather than wrapping to multiple rows, especially on
   mobile where a wrapped row of 16 chips eats the viewport. */
.status-row--chips,
.status-row--compact {
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px 0;
  scrollbar-width: none;
}
.status-row--chips::-webkit-scrollbar,
.status-row--compact::-webkit-scrollbar { display: none; }
.status-row--chips > *,
.status-row--compact > * { flex-shrink: 0; }
.status-row--compact {
  gap: 10px;
  font-size: 10px;
  letter-spacing: 0.1em;
}
.status-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
}
.dot.ok    { background: var(--ok);    box-shadow: 0 0 4px var(--ok); }
.dot.warn  { background: var(--warn);  box-shadow: 0 0 4px var(--warn); }
.dot.alert { background: var(--alert); box-shadow: 0 0 4px var(--alert);
             animation: flash 1.0s ease-in-out infinite; }
@keyframes flash {
  0%, 100% { opacity: 0.4; }
  50%       { opacity: 1; }
}
.status-item .label { color: var(--ink); }
.status-item .state {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.18em;
}
.status-item.ok    .state { color: var(--ok); }
.status-item.warn  .state { color: var(--warn); }
.status-item.alert .state { color: var(--alert); }

/* ─── Live-data pulse dot (attach to page subtitles to signal polling) ─── */
.live-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 6px var(--ok);
  animation: pulse 2.4s ease-in-out infinite;
  flex-shrink: 0;
}

/* ─────────────────────── Badges / chips ─────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 9px;
  background: var(--ink);
  color: #000;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-right: 4px;
  vertical-align: baseline;
}
/* Coloured fills — always pin text to #000 so we never depend on
   cascading from whichever class name follows in the class list. */
.badge.accent { background: var(--accent);          color: #000; }
.badge.ok     { background: var(--ok);               color: #000; }
.badge.warn   { background: var(--warn);             color: #000; }
.badge.alert  { background: var(--alert);            color: #fff; }
.badge.muted  { background: var(--faint);            color: var(--muted); }

/* Outline badges — transparent bg, coloured ring + text */
.badge.outline {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--rule);
  padding: 2px 8px;
}
.badge.outline.accent { color: var(--accent); border-color: var(--accent); background: transparent; }
.badge.outline.ok     { color: var(--ok);     border-color: var(--ok);     background: transparent; }
.badge.outline.warn   { color: var(--warn);   border-color: var(--warn);   background: transparent; }
.badge.outline.alert  { color: var(--alert);  border-color: var(--alert);  background: transparent; }

/* ─────────────────────── Tables + KV rows ─────────────────────── */
table.meta {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 12px;
}
table.meta td {
  padding: 4px 8px 4px 0;
  vertical-align: top;
}
table.meta td:first-child {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--dimmer);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  width: 140px;
  padding-top: 6px;
}
table.meta td:nth-child(2) { color: var(--ink); }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 12px;
  margin: 10px 0;
}
table.data th {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid var(--accent);
}
table.data td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--faint);
  color: var(--ink);
}
table.data tr:hover td {
  background: var(--faint);
}
table.data td.num {
  font-family: var(--mono);
  text-align: right;
}

/* ─────────────────────── Event feed ─────────────────────── */
.feed {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink);
  display: flex;
  flex-direction: column;
}
.feed .row {
  display: grid;
  grid-template-columns: 48px 70px minmax(0, 1fr);
  gap: 10px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--faint);
  align-items: center;
}
.feed .row.new { background: rgba(254, 125, 1, 0.08); }
.feed .row .ts {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.1em;
}
.feed .row .src {
  font-weight: 700;
  color: var(--accent);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}
.feed .row .txt {
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.feed .row.warn  .src { color: var(--warn); }
.feed .row.alert .src { color: var(--alert); }

/* ─────────────────────── Cards / panels ─────────────────────── */
.panel {
  border: 1px solid var(--rule);
  padding: 12px 14px;
  background: var(--bg);
  position: relative;
}
.panel .corner {
  position: absolute;
  width: 10px; height: 10px;
  border-color: var(--accent);
  pointer-events: none;
}
.panel .corner.tl { top: -1px;    left: -1px;
  border-top: 1px solid; border-left: 1px solid; }
.panel .corner.tr { top: -1px;    right: -1px;
  border-top: 1px solid; border-right: 1px solid; }
.panel .corner.bl { bottom: -1px; left: -1px;
  border-bottom: 1px solid; border-left: 1px solid; }
.panel .corner.br { bottom: -1px; right: -1px;
  border-bottom: 1px solid; border-right: 1px solid; }

/* ─────────────────────── Layout helpers ─────────────────────── */
.col-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.col-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

/* ─── Split layout (triage / memory / workspace)
   Desktop: main + aside in a 2-col grid. Aside holds the nav list,
   main holds the selected detail.
   Mobile: stack with the MAIN content first so the selected detail
   dominates the viewport, with the list shrunk to a compact tail. */
.split {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 16px;
  height: calc(100vh - 200px);
}
.split-aside {
  order: 1;
  overflow-y: auto;
  padding-right: 10px;
}
.split-main {
  order: 2;
  overflow-y: auto;
  padding-right: 6px;
}
/* (Desktop order defaults to .split-aside=1, .split-main=2 from the
   generic .split-* rules above, so no .triage-split-specific reorder
   is needed. An explicit re-declaration would out-specify the mobile
   override and force queue-first on phones — which we don't want.) */

/* Triage-specific details */
.triage-cust {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
  margin-bottom: 4px;
}
.triage-badges { margin-bottom: 10px; }
.triage-summary {
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.55;
}
.triage-raw {
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
  white-space: pre-wrap;
}
.triage-hint {
  font-size: 10px;
  margin-top: 10px;
  letter-spacing: 0.12em;
}
.triage-row-link,
.memory-row-link,
.workspace-row-link {
  text-decoration: none;
  color: inherit;
  display: block;
}
.triage-row-link .row.is-selected,
.memory-row-link .row.is-selected,
.workspace-row-link .row.is-selected {
  background: rgba(254, 125, 1, 0.10);
}
.triage-row-link .row.is-selected .txt,
.memory-row-link .row.is-selected .txt,
.workspace-row-link .row.is-selected .txt {
  color: var(--accent);
}
.section--sub { font-size: 10px !important; }

/* Workspace: panels for each split half */
.workspace-split { height: 50vh; margin-bottom: 20px; }
.markdown-panel {
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.6;
}
.markdown-panel-head {
  font-family: var(--mono);
  color: var(--accent);
  letter-spacing: 0.22em;
  margin-bottom: 12px;
  font-size: 10px;
  text-transform: uppercase;
}

/* Reports list: direct-open links (click = open PDF in new tab). */
.report-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.report-list > li {
  border: 1px solid var(--rule);
  border-left: 2px solid var(--accent);
  margin: 0 0 6px 0;
}
.report-list > li.empty {
  border: 0;
  padding: 14px 8px;
  text-align: center;
}
.report-list > li > a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  text-decoration: none;
  color: var(--ink);
  transition: background 0.12s, color 0.12s;
}
.report-list > li > a:hover {
  background: var(--faint);
  color: var(--accent);
}
.report-list .report-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.report-list .report-meta {
  flex-shrink: 0;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.08em;
}

/* Scroll container for data-scroll tables (kept simple — just one
   overflow axis). */
.data-wrap {
  max-height: calc(100vh - 340px);
  overflow-y: auto;
}

/* ─────────────────────── Progress bar ─────────────────────── */
.progress {
  display: flex;
  gap: 2px;
  height: 10px;
  width: 100%;
  padding: 1px 0;
}
.progress .seg {
  flex: 1;
  background: transparent;
  border: 1px solid var(--rule);
}
.progress .seg.on { background: var(--accent); border-color: var(--accent); }
.progress.alert .seg.on { background: var(--alert); border-color: var(--alert); }
.progress.warn  .seg.on { background: var(--warn);  border-color: var(--warn); }

/* ─────────────────────── Scrollbar styling ─────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--rule); }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ─────────────────────── Typography utilities ─────────────────────── */
.mono { font-family: var(--mono); }
.caps { text-transform: uppercase; letter-spacing: 0.16em; }
.muted { color: var(--muted); }
.dim   { color: var(--dimmer); }
.accent { color: var(--accent); }

/* ─────────────────────── Chat (atlas / code) ─────────────────────── */
.chat-window {
  display: grid;
  grid-template-rows: 1fr auto;
  height: 100%;
  gap: 10px;
}
.chat-feed {
  overflow-y: auto;
  padding-right: 8px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  min-height: 0;           /* let feed shrink inside its grid cell */
}
.chat-msg {
  margin-bottom: 12px;
}
.chat-msg .who {
  font-weight: 700;
  font-size: 9px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}
.chat-msg.user .who { color: var(--ink); }
.chat-msg.atlas .who,
.chat-msg.claude .who { color: var(--accent); }
.chat-msg .body { margin-top: 2px; }

/* ─── Rendered markdown (shared: chat / workspace / customer notes) ─── */
/* Markdown base — long URLs, paths, and tokens break to wrap so
   narrow viewports never need a horizontal scrollbar. Code blocks
   (.markdown pre) still scroll internally via the rule below. */
.markdown {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.markdown code { word-break: break-all; white-space: normal; }
.markdown pre  { max-width: 100%; }
.markdown pre code { word-break: normal; white-space: pre; }
.markdown a { word-break: break-all; }

.markdown h1, .markdown h2, .markdown h3,
.markdown h4, .markdown h5, .markdown h6 {
  font-family: var(--mono);
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin: 0.9em 0 0.35em;
  line-height: 1.2;
}
.markdown h1 { font-size: 13px; }
.markdown h2 { font-size: 12px; }
.markdown h3 { font-size: 11px; color: var(--ink); }
.markdown h4, .markdown h5, .markdown h6 {
  font-size: 10px; color: var(--muted);
}
.markdown p { margin: 0.35em 0; }
.markdown ul, .markdown ol { margin: 0.35em 0; padding-left: 1.4em; }
.markdown li { margin: 0.15em 0; }
.markdown li > p { margin: 0; }
.markdown code {
  font-family: var(--mono);
  background: var(--faint);
  border: 1px solid var(--rule);
  padding: 0 4px;
  font-size: 0.92em;
  color: var(--accent);
}
.markdown pre {
  font-family: var(--mono);
  background: var(--faint);
  border: 1px solid var(--rule);
  border-left: 2px solid var(--accent);
  padding: 8px 10px;
  overflow-x: auto;
  font-size: 11px;
  margin: 0.5em 0;
  line-height: 1.45;
}
.markdown pre code {
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--ink);
  font-size: inherit;
}
.markdown blockquote {
  border-left: 2px solid var(--dimmer);
  padding-left: 10px;
  margin: 0.5em 0 0.5em 4px;
  color: var(--muted);
}
.markdown blockquote p { margin: 0.25em 0; }
.markdown a { color: var(--accent); text-decoration: underline dotted; }
.markdown a:hover { color: var(--ink); }
.markdown hr {
  border: 0;
  border-top: 1px dashed var(--rule);
  margin: 0.8em 0;
}
.markdown strong { color: var(--ink); }
.markdown em { color: inherit; font-style: italic; }
.markdown s { color: var(--muted); }

/* ─── Compact chat page head ─── */
.chat-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.chat-head .hero { margin-bottom: 0; }
.chat-head-meta {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-left: auto;
}
.chat-subtitle { margin-top: 2px; }

/* ─── Chat composer ─── */
.chat-window {
  display: grid;
  grid-template-rows: 1fr auto;
  flex: 1 1 auto;           /* fill .main's remaining height  */
  min-height: 240px;        /* degrade gracefully on tiny viewports */
  gap: 10px;
  overflow: hidden;         /* feed scrolls inside, not the page */
}

/* Two-row composer: (label + textarea) above, (hints + busy + send) below.
   The send button always lives on its own deterministic row — no way for
   narrow viewports to break the send label onto two lines. */
.composer {
  border: 1px solid var(--rule);
  border-left: 2px solid var(--accent);
  background: linear-gradient(
    180deg, rgba(254,125,1,0.04) 0%, transparent 70%
  );
  display: flex;
  flex-direction: column;
  transition: border-color 0.12s;
}
.composer:focus-within {
  border-color: var(--accent);
  border-left-color: var(--accent);
}

.composer-body {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px 4px 14px;
}
.composer-from {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 10px;
  color: var(--accent);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  padding-top: 6px;
  flex-shrink: 0;
  white-space: nowrap;
  user-select: none;
}
.composer-from::after {
  content: "›";
  color: var(--muted);
  margin-left: 6px;
  font-weight: 400;
}
.composer-input {
  flex: 1;
  min-width: 0;              /* critical — lets textarea shrink inside flex */
  background: transparent;
  color: var(--ink);
  border: 0;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  padding: 4px 2px;
  resize: none;
  outline: none;
  overflow-y: auto;
  min-height: 44px;
  max-height: 240px;
  width: 100%;
}
.composer-input::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

/* Bottom bar — hints left, busy middle, send right. Flex-wrap on narrow
   viewports so nothing overflows the container. */
.composer-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 10px 14px;
  border-top: 1px dashed var(--rule);
  flex-wrap: wrap;
}
.composer-hints {
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.14em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.composer-hints kbd {
  font-family: var(--mono);
  color: var(--accent);
  background: var(--faint);
  border: 1px solid var(--rule);
  padding: 1px 6px;
  font-size: 9px;
  letter-spacing: 0.08em;
  margin-right: 2px;
}

.composer-busy {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-size: 9px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  /* htmx toggles opacity via .htmx-indicator — 0 when idle, 1 during req */
}
.composer-busy-pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: pulse 0.9s ease-in-out infinite;
}

/* Send button — always-visible amber block pinned right. Using
   white-space:nowrap + flex-shrink:0 so "Send →" never wraps. */
.composer-send {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: var(--bg);
  border: 0;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  padding: 8px 16px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.12s, transform 0.08s;
}
.composer-send:hover { background: var(--ink); color: var(--accent); }
.composer-send:active { transform: scale(0.97); }
.composer-send:disabled {
  background: var(--faint);
  color: var(--muted);
  cursor: not-allowed;
}
.composer-send-arrow {
  font-size: 14px;
  line-height: 1;
  display: inline-block;
}

/* When htmx request is in flight, dim the textarea + tint the send button
   amber-dim so the user has obvious pending-state feedback. */
.composer.htmx-request .composer-input { opacity: 0.55; }
.composer.htmx-request .composer-send {
  background: var(--dimmer);
  color: var(--ink);
}

/* Use htmx's default indicator cadence — fades in/out smoothly. */
.composer-busy.htmx-indicator {
  opacity: 0;
  transition: opacity 0.2s ease-in;
}
.composer-busy.htmx-indicator.htmx-request,
.htmx-request .composer-busy.htmx-indicator {
  opacity: 1;
}

/* ─── Chat controls strip (thinking / session / model) ─── */
.chat-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 8px 0 10px 0;
  border-bottom: 1px dashed var(--rule);
  margin-bottom: 10px;
}
.chat-ctrl {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}
.chat-ctrl label {
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.2em;
}
.chat-ctrl select {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 11px;
  padding: 3px 6px;
  outline: none;
  cursor: pointer;
}
.chat-ctrl select:focus { border-color: var(--accent); }
.chat-ctrl input {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 11px;
  padding: 3px 6px;
  outline: none;
}
.chat-ctrl input:focus { border-color: var(--accent); }
.chat-ctrl--search {
  flex: 1 1 240px;
  min-width: 0;
}
.chat-ctrl--search input { flex: 1; min-width: 0; }

/* Table column width hint: Actions column. Narrow on phone, roomier
   on desktop. Set as a min-width so the buttons don't compress below
   their content. */
table.data th.col-actions,
table.data td.col-actions { min-width: 180px; }
/* ─── Button system — tight, uniform, TE-aware ──────────────────────
   Every button renders at the same 26px height. Icons and text share
   a single font-size so there's no baseline wobble between a word
   button and a glyph button sitting next to it.

     .btn              neutral base (ink text, rule ring)
     .btn--primary     amber fill, primary action per context
     .btn--ghost       amber outline, secondary verb
     .btn--ok          phosphor-green outline, positive state change
     .btn--alert       alert-red outline, destructive
     .btn--muted       low-emphasis tertiary (dismiss, clear)
     .btn--icon        square 26×26 — glyph only, tooltip labels it
     .btn--sm          smaller row action (text labels too but denser)

   `.btn-row` pairs them with a 1-px divider between the primary call
   and the utility cluster via a `::before` on `.btn-row__cluster`. */
.btn-row {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.btn-row > form { display: contents; }  /* inline <form> stays invisible */

.btn-row__cluster {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding-left: 8px;
  margin-left: 2px;
  border-left: 1px solid var(--rule);
}
.btn-row__cluster > form { display: contents; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 26px;
  padding: 0 11px;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--rule);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 10px;
  line-height: 1;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
  vertical-align: middle;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  user-select: none;
}
.btn:hover   { border-color: var(--ink); background: var(--faint); }
.btn:active  { transform: translateY(0.5px); }
.btn:focus-visible {
  outline: 1px dashed var(--accent);
  outline-offset: 2px;
}
.btn:disabled {
  color: var(--muted);
  border-color: var(--rule);
  cursor: not-allowed;
  opacity: 0.6;
}

.btn--primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}
.btn--primary:hover { background: var(--ink); color: var(--accent); border-color: var(--ink); }

.btn--ghost  { color: var(--accent); border-color: var(--accent); }
.btn--ghost:hover { background: var(--accent); color: #000; border-color: var(--accent); }

.btn--ok     { color: var(--ok); border-color: var(--ok); }
.btn--ok:hover { background: var(--ok); color: #000; border-color: var(--ok); }

.btn--alert  { color: var(--alert); border-color: var(--alert); }
.btn--alert:hover { background: var(--alert); color: #fff; border-color: var(--alert); }

.btn--muted  { color: var(--muted); border-color: var(--rule); }
.btn--muted:hover { color: var(--ink); border-color: var(--muted); background: var(--faint); }

/* Icon-only square — same height as text buttons so they line up. */
.btn--icon {
  width: 26px;
  padding: 0;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0;
}
.btn--icon svg { width: 12px; height: 12px; }

/* Smaller variant — use for per-detail action clusters where 26px
   feels outsized against the content. */
.btn--sm {
  height: 22px;
  padding: 0 8px;
  font-size: 9px;
}
.btn--sm.btn--icon {
  width: 22px;
  padding: 0;
  font-size: 11px;
}

/* .icon span inside a text button — sits naturally on the baseline */
.btn .icon {
  font-size: 11px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
}

/* ─── Customer detail edit controls ─── */
.field-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  padding: 6px 0 10px 0;
  border-bottom: 1px dashed var(--rule);
  margin-bottom: 10px;
  font-size: 11px;
}
.field-strip label {
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.18em;
}
.field-select {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 6px;
  outline: none;
  cursor: pointer;
}
.field-select:focus { border-color: var(--accent); }

.note-add {
  border: 1px dashed var(--rule);
  padding: 8px;
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.note-add .row-1 {
  display: flex;
  align-items: center;
  gap: 10px;
}
.note-add .note-pin {
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.18em;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.note-add textarea {
  width: 100%;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 8px;
  outline: none;
  resize: vertical;
  min-height: 44px;
}
.note-add textarea:focus { border-color: var(--accent); }
.note-add button[type="submit"] { margin-left: auto; }

/* ─── Form grids (cron add, etc.) ─── */
.cron-add {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px 16px;
  margin-top: 10px;
}
.cron-add .full { grid-column: 1 / -1; }
.cron-add label {
  display: block;
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.2em;
  margin-bottom: 4px;
}
.cron-add input,
.cron-add select,
.cron-add textarea {
  width: 100%;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 12px;
  padding: 6px 8px;
  outline: none;
}
.cron-add input:focus,
.cron-add select:focus,
.cron-add textarea:focus { border-color: var(--accent); }
.cron-add textarea { resize: vertical; }
@media (max-width: 900px) {
  .cron-add { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .cron-add { grid-template-columns: 1fr; }
}

/* ─────────────────────── Toasts ─────────────────────── */
.toast-stack {
  position: fixed;
  right: 16px;
  bottom: 42px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}
.toast {
  background: var(--bg-elev);
  border-left: 3px solid var(--accent);
  padding: 8px 14px;
  min-width: 260px;
  max-width: 420px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink);
  letter-spacing: 0.05em;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
  animation: toast-in 0.18s ease-out;
}
.toast.ok    { border-left-color: var(--ok); }
.toast.warn  { border-left-color: var(--warn); }
.toast.alert { border-left-color: var(--alert); }
.toast .tag {
  font-size: 9px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 2px;
  font-weight: 700;
}
.toast.ok    .tag { color: var(--ok); }
.toast.warn  .tag { color: var(--warn); }
.toast.alert .tag { color: var(--alert); }
@keyframes toast-in {
  0%   { opacity: 0; transform: translateX(30px); }
  100% { opacity: 1; transform: translateX(0); }
}
@keyframes toast-out {
  0%   { opacity: 1; transform: translateX(0); }
  100% { opacity: 0; transform: translateX(30px); }
}
.toast.leaving { animation: toast-out 0.18s ease-in forwards; }

/* ─────────────────────── Command palette ─────────────────────── */
.cmdp-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.64);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  z-index: 9998;
  backdrop-filter: blur(2px);
}
.cmdp-overlay.open { display: flex; }
.cmdp {
  width: min(640px, 92vw);
  background: var(--bg);
  border: 1px solid var(--accent);
  font-family: var(--mono);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  position: relative;
}
.cmdp::before,
.cmdp::after,
.cmdp-bl,
.cmdp-br {
  content: "";
  position: absolute;
  width: 10px; height: 10px;
  pointer-events: none;
}
.cmdp::before { top: -1px; left: -1px;
  border-top: 2px solid var(--accent); border-left: 2px solid var(--accent); }
.cmdp::after { top: -1px; right: -1px;
  border-top: 2px solid var(--accent); border-right: 2px solid var(--accent); }
.cmdp-bl { bottom: -1px; left: -1px;
  border-bottom: 2px solid var(--accent); border-left: 2px solid var(--accent); }
.cmdp-br { bottom: -1px; right: -1px;
  border-bottom: 2px solid var(--accent); border-right: 2px solid var(--accent); }

.cmdp input {
  background: var(--bg);
  color: var(--ink);
  border: 0;
  border-bottom: 1px solid var(--rule);
  padding: 14px 18px;
  font-family: var(--mono);
  font-size: 14px;
  outline: none;
  letter-spacing: 0.04em;
}
.cmdp-results {
  overflow-y: auto;
  max-height: 60vh;
}
.cmdp-section {
  padding: 6px 18px 2px;
  font-size: 9px;
  color: var(--accent);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  border-top: 1px dashed var(--rule);
  margin-top: 4px;
}
.cmdp-section:first-child { border-top: 0; margin-top: 0; }
.cmdp-item {
  display: grid;
  grid-template-columns: 60px 1fr auto;
  gap: 10px;
  padding: 7px 18px;
  cursor: pointer;
  color: var(--ink);
  text-decoration: none;
  font-size: 12px;
}
.cmdp-item:hover,
.cmdp-item.active {
  background: var(--faint);
  color: var(--accent);
}
.cmdp-item .kind {
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  align-self: center;
}
.cmdp-item .sub {
  font-size: 9px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  align-self: center;
}
.cmdp-empty {
  padding: 18px;
  color: var(--muted);
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.cmdp-foot {
  padding: 6px 18px;
  border-top: 1px solid var(--rule);
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  display: flex;
  gap: 14px;
}
.cmdp-foot b { color: var(--accent); font-weight: 700; }

/* ─────────────────────── Usage / metrics viz ───────────────────────
   Bars, sparklines, and tenant cards for /usage. Built on the existing
   KPI and panel primitives — nothing here fights them, just layers on
   viz-specific shapes. */

/* Phosphor glow — used on numeric accent values to sell the CRT vibe
   without hurting legibility. Cheap text-shadow, no filter. */
.glow {
  text-shadow:
    0 0 4px rgba(254, 125, 1, 0.55),
    0 0 10px rgba(254, 125, 1, 0.25);
}

/* Intensified KPI treatments — base .kpi-tile already carries the
   gradient wash + hover lift + scanline overlay (see the KPI block
   above). These modifiers layer extra heat on specific tiles. */
.kpi-tile--pulse .value {
  animation: kpi-pulse 4s ease-in-out infinite;
}
.kpi-tile--feature {
  background:
    linear-gradient(180deg,
      rgba(254, 125, 1, 0.12) 0%,
      rgba(254, 125, 1, 0) 70%),
    var(--bg);
  border-color: var(--dimmer);
}
@keyframes kpi-pulse {
  0%, 100% { text-shadow: 0 0 4px rgba(254, 125, 1, 0.45); }
  50%      { text-shadow: 0 0 10px rgba(254, 125, 1, 0.75),
                          0 0 18px rgba(254, 125, 1, 0.25); }
}

/* Delta pills inside KPI captions — tighter typography for the arrow. */
.delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  letter-spacing: 0;
}
.delta--up   { color: var(--ok); }
.delta--down { color: var(--alert); }

.usage-bars {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  margin: 8px 0 4px 0;
}
.usage-bar {
  display: grid;
  grid-template-columns: 1fr 48px;
  grid-template-areas: "label pct" "track pct";
  gap: 3px 10px;
  align-items: center;
}
.usage-bar__label {
  grid-area: label;
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--muted);
}
.usage-bar__label .num { color: var(--ink); letter-spacing: 0; }
.usage-bar__track {
  grid-area: track;
  height: 8px;
  background: var(--faint);
  position: relative;
  overflow: hidden;
}
.usage-bar__fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--dimmer) 0%, var(--accent) 100%);
  transition: width 0.4s ease-out;
  box-shadow: 0 0 6px rgba(254, 125, 1, 0.35);
}
.usage-bar__fill.ok {
  background: linear-gradient(90deg,
    rgba(0, 204, 102, 0.4) 0%, var(--ok) 100%);
  box-shadow: 0 0 6px rgba(0, 204, 102, 0.35);
}
.usage-bar__fill.warn {
  background: linear-gradient(90deg,
    rgba(255, 165, 0, 0.4) 0%, var(--warn) 100%);
  box-shadow: 0 0 6px rgba(255, 165, 0, 0.35);
}
.usage-bar__fill.alert {
  background: linear-gradient(90deg,
    rgba(255, 48, 48, 0.4) 0%, var(--alert) 100%);
  box-shadow: 0 0 6px rgba(255, 48, 48, 0.35);
}
.usage-bar__fill.muted   { background: var(--dimmer); box-shadow: none; }
.usage-bar__fill.outline { background: var(--rule);   box-shadow: none; }
.usage-bar__pct {
  grid-area: pct;
  text-align: right;
  font-size: 10px;
  align-self: center;
}

/* Tenant leaderboard cards — grid of up to 3 columns on desktop,
   stacks on mobile. Each card is a 4-up metric board with a PLG share
   bar and a 30-day sparkline. */
.tenant-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 10px;
  margin-top: 8px;
}
.tenant-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px 10px 14px;
  background:
    linear-gradient(180deg,
      rgba(254, 125, 1, 0.03) 0%,
      rgba(0, 0, 0, 0) 50%),
    var(--panel, #141414);
  border: 1px solid var(--rule);
  color: inherit;
  text-decoration: none;
  transition:
    transform 0.18s ease-out,
    border-color 0.18s ease-out,
    box-shadow 0.18s ease-out;
  position: relative;
  overflow: hidden;
}
/* CRT scanline overlay — near-invisible but gives phosphor texture.
   Sits above content but behind pointer events so links still click. */
.tenant-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.015) 0px,
    rgba(255, 255, 255, 0.015) 1px,
    transparent 1px,
    transparent 3px);
  pointer-events: none;
  opacity: 0.7;
}
.tenant-card:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  box-shadow:
    0 0 0 1px rgba(254, 125, 1, 0.15),
    0 6px 18px rgba(254, 125, 1, 0.08);
}
/* Trend-tinted left accent bar — subtle edge of color on healthy vs
   struggling tenants. */
.tenant-card--up   { border-left: 2px solid var(--ok); }
.tenant-card--down { border-left: 2px solid var(--alert); }
.tenant-card--flat { border-left: 2px solid var(--dimmer); }

/* Rank medallion — top-right corner number. Gold/silver/bronze for
   top 3, plain accent outline for the rest. */
.tenant-card__rank {
  position: absolute;
  top: 8px;
  right: 10px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  font-weight: 700;
  padding: 2px 6px;
  border: 1px solid var(--rule);
  color: var(--muted);
  z-index: 1;
}
.tenant-card__rank.rank--gold {
  color: #FFD84A;
  border-color: #FFD84A;
  box-shadow: 0 0 8px rgba(255, 216, 74, 0.35);
}
.tenant-card__rank.rank--silver {
  color: #D8D8D8;
  border-color: #D8D8D8;
  box-shadow: 0 0 6px rgba(216, 216, 216, 0.25);
}
.tenant-card__rank.rank--bronze {
  color: #E08B4F;
  border-color: #E08B4F;
  box-shadow: 0 0 6px rgba(224, 139, 79, 0.25);
}
.tenant-card__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  padding-right: 44px;  /* leave room for the rank medallion */
}
.tenant-card__name {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.tenant-card__status {
  font-size: 9px;
  letter-spacing: 0.22em;
  flex-shrink: 0;
  padding: 2px 6px;
  border: 1px solid currentColor;
  color: var(--muted);
}

/* Per-tier chip tints — so enterprise pops and churned tenants fade. */
.tier--enterprise { color: #FFD84A; border-color: rgba(255, 216, 74, 0.6); }
.tier--pro        { color: var(--accent); border-color: var(--dimmer); }
.tier--growth     { color: var(--ok); border-color: rgba(0, 204, 102, 0.5); }
.tier--starter    { color: var(--warn); border-color: rgba(255, 165, 0, 0.5); }
.tier--trial      { color: var(--warn); border-color: rgba(255, 165, 0, 0.5); }
.tier--demo       { color: #9FB3FF; border-color: rgba(159, 179, 255, 0.5); }
.tier--active     { color: var(--ok); border-color: rgba(0, 204, 102, 0.5); }
.tier--inactive   { color: var(--muted); border-color: var(--rule); }
.tenant-card__metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 4px 0 2px 0;
}
.tenant-card__metrics .caps { font-size: 8px; letter-spacing: 0.18em; }
.tenant-card__bar {
  height: 4px;
  background: var(--faint);
  overflow: hidden;
  position: relative;
}
.tenant-card__bar-fill {
  height: 100%;
  background: linear-gradient(90deg,
    var(--dimmer) 0%,
    var(--accent) 40%,
    var(--ok) 100%);
  box-shadow: 0 0 6px rgba(254, 125, 1, 0.5);
  transition: width 0.4s ease-out;
}
.tenant-card__spark {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}
.tenant-card__spark svg {
  flex: 1;
  height: 32px;
  display: block;
}
/* The `path:nth-of-type(2)` here is the stroked line; the first path
   is the filled area with the gradient. Stroke colors drive the vibe
   per trend. */
.spark path:last-of-type { stroke: var(--accent); }
.spark--up   path:last-of-type { stroke: var(--ok); filter: drop-shadow(0 0 3px rgba(0, 204, 102, 0.6)); }
.spark--down path:last-of-type { stroke: var(--alert); filter: drop-shadow(0 0 3px rgba(255, 48, 48, 0.5)); }
.spark--flat path:last-of-type { stroke: var(--dimmer); }

/* Inline tenant editor — shown on /db/customer. Sits above the field
   strip and calls the remote StartProto API before touching local DBs.
   Uses a grid so the number input + tier select line up with the
   existing field-strip aesthetic. */
.tenant-editor {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr auto;
  gap: 8px 10px;
  align-items: center;
  padding: 12px 14px;
  margin: 8px 0;
  background:
    linear-gradient(180deg,
      rgba(254, 125, 1, 0.05) 0%,
      rgba(254, 125, 1, 0) 80%),
    var(--faint);
  border: 1px solid var(--dimmer);
  position: relative;
}
/* Corner brackets — echoes the .panel "viewfinder" look from the rest
   of the app. Cheap ::before / ::after for the top corners only. */
.tenant-editor::before,
.tenant-editor::after {
  content: "";
  position: absolute;
  top: -1px;
  width: 12px;
  height: 12px;
  border: 1px solid var(--accent);
  pointer-events: none;
}
.tenant-editor::before { left: -1px; border-right: 0; border-bottom: 0; }
.tenant-editor::after  { right: -1px; border-left: 0; border-bottom: 0; }
.tenant-editor label {
  font-size: 9px;
  letter-spacing: 0.22em;
  color: var(--muted);
}
.tenant-editor input[type="number"],
.tenant-editor select {
  background: var(--bg);
  border: 1px solid var(--rule);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  padding: 4px 6px;
  width: 100%;
}
.tenant-editor input[type="number"]:focus,
.tenant-editor select:focus {
  outline: none;
  border-color: var(--accent);
}
.tenant-editor .btn { grid-column: 5; }
.tenant-editor__hint {
  grid-column: 1 / -1;
  font-size: 9px;
  color: var(--muted);
  font-family: var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.tenant-editor__flash {
  grid-column: 1 / -1;
  padding: 6px 8px;
  font-size: 11px;
  font-family: var(--mono);
  border-left: 2px solid var(--accent);
  background: var(--bg);
}
.tenant-editor__flash.err {
  border-color: var(--alert);
  color: var(--alert);
}
.tenant-editor__flash.ok {
  border-color: var(--ok);
  color: var(--ok);
}

/* ─────────────────────── Queue table ─────────────────────── */
/* Triage + tasks queues use `<table class="data">` like every other
   list in the app. Extras layered on: a clickable row pointer, an
   is-selected highlight, and a MULTI mode that reveals a checkbox
   column via `.multi-active` on the shell. */
table.data tbody tr.queue-tr { cursor: pointer; }
table.data tbody tr.queue-tr.is-selected td {
  background: rgba(254, 125, 1, 0.14);
}
table.data tbody tr.queue-tr.is-selected td:first-child {
  box-shadow: inset 2px 0 0 var(--accent);
}
table.data tbody tr.queue-tr.is-selected td.queue-title,
table.data tbody tr.queue-tr.is-selected td.queue-title strong {
  color: var(--accent);
}
table.data td.queue-title { font-weight: 600; }

/* Always-visible slim checkbox column at the left edge of queue tables. */
table.data th.col-check,
table.data td.col-check {
  width: 22px;
  padding: 4px 4px 4px 6px;
  text-align: center;
}

/* Leading row checkbox — slim, always visible at the left edge of
   queue tables. Unobtrusive at rest, lights up on check. */
.multi-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.multi-check input { position: absolute; opacity: 0; pointer-events: none; }
.multi-check-box {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1px solid var(--rule);
  background: transparent;
  position: relative;
}
.multi-check:hover .multi-check-box { border-color: var(--muted); }
.multi-check input:checked + .multi-check-box {
  background: var(--accent);
  border-color: var(--accent);
}
.multi-check input:checked + .multi-check-box::after {
  content: "";
  position: absolute;
  left: 2px; top: -2px;
  width: 3px; height: 7px;
  border-right: 1.5px solid var(--bg);
  border-bottom: 1.5px solid var(--bg);
  transform: rotate(45deg);
}

/* Bulk action footer — uses `.btn-row` with `.btn--sm` buttons; only
   surfaces when selection > 0. */
.multi-footer { margin-top: 8px; }
.multi-footer[hidden] { display: none; }
.multi-footer-count { color: var(--accent); font-size: 10px; }

/* ─────────────────────── Mobile layout ─────────────────────── */
/* Tablet / small laptop — first tier of responsive trims. */
@media (max-width: 820px) {
  :root {
    --top-h: 40px;
    --bot-h: 26px;
    --drawer-w: 260px;
  }
  .topbar { padding: 4px 10px; gap: 8px; }
  .topbar .title { font-size: 11px; letter-spacing: 0.12em; }
  .topbar-divider { display: none; }
  .topbar .agent { display: none; }
  .topbar .brand-sub { display: none; }
  .main { padding: 12px 14px; }
  h1.hero { font-size: 20px; }
  .kpi-tile { padding: 8px 10px; }
  .kpi-tile .value { font-size: 18px; }
  .col-2, .col-3 { grid-template-columns: 1fr; }
  table.data { font-size: 11px; }
  table.data th, table.data td { padding: 5px 6px; }
  .feed .row { grid-template-columns: 40px 60px minmax(0, 1fr); font-size: 10px; }
  .bottombar { font-size: 10px; padding: 2px 10px; gap: 10px; }
  /* Bracket offsets need to shrink so they don't clip page padding */
  .main::before, .main::after { top: calc(var(--top-h) + 6px); }
  .main::before { left: 8px; }
  .main::after  { right: 8px; }
  .vf-bl { bottom: calc(var(--bot-h) + 6px); left: 8px; }
  .vf-br { bottom: calc(var(--bot-h) + 6px); right: 8px; }
}

/* Phone. Everything tightens, the decorative chrome retreats, and every
   tap target hits at least ~40px. Input font-sizes pinned ≥16px so iOS
   Safari doesn't zoom the page on focus. */
@media (max-width: 560px) {
  :root {
    --top-h: 38px;
    --bot-h: 0px;               /* bottom hints row dropped on phones */
    --drawer-w: min(300px, 84vw);
  }

  /* Viewfinder chrome gets in the way at tiny widths — let the content
     have the whole frame. */
  .main::before, .main::after,
  .vf-bl, .vf-br { display: none; }

  /* Respect iOS notch + home-indicator. The safe-area insets are 0 on
     non-notched devices so this is a no-op there. */
  .topbar {
    padding: 4px calc(8px + env(safe-area-inset-right))
             4px calc(8px + env(safe-area-inset-left));
    gap: 8px;
    min-height: var(--top-h);
  }
  .main {
    padding: 10px calc(12px + env(safe-area-inset-right))
             calc(10px + env(safe-area-inset-bottom))
             calc(12px + env(safe-area-inset-left));
  }

  /* Topbar: hamburger + brand + title, that's it */
  .topbar .clock { display: none; }
  .topbar .agent { display: none; }
  .topbar .brand-name { font-size: 11px; letter-spacing: 0.18em; }
  .topbar .title {
    font-size: 9px;
    letter-spacing: 0.14em;
  }
  .hamburger { width: 34px; height: 30px; }
  .hamburger span { width: 16px; }

  /* No decorative bottom hints row — the drawer footer has them */
  .bottombar { display: none; }

  /* Radical chrome compression on phone.
     Page identity lives in the topbar's title — h1.hero just duplicates
     it. Subtitle carries status info; keep it but pin it as a tiny
     single line. Section headers shrink to 9px caps + minimal margins.
     Filter bars get their own tight treatment below.
     Target: from ~255px of chrome down to ~55px before content. */
  h1.hero { display: none; }

  .subtitle {
    font-size: 10px;
    line-height: 1.4;
    margin: 0 0 8px 0;
    color: var(--muted);
    max-height: 3em;               /* 2 lines max, silently clip beyond */
    overflow: hidden;
    /* Don't force white-space — some subtitles are flex containers with
       inline badges / live-dots that need to wrap naturally. */
  }

  h2.section {
    font-size: 9px;
    margin: 10px 0 4px 0;
    letter-spacing: 0.22em;
    gap: 6px;
  }
  h2.section::before { width: 2px; height: 9px; }
  /* When a section header is the very first content in the main area,
     it's visually redundant with the topbar title — collapse the
     top margin. */
  .main > h2.section:first-of-type,
  .main > .subtitle + h2.section {
    margin-top: 4px;
  }

  /* KPI — 2-per-row grid at phone widths, readable density */
  .kpi-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }
  .kpi-tile { padding: 8px 10px; }
  .kpi-tile .value { font-size: 17px; }
  .kpi-tile .label, .kpi-tile .caption { font-size: 9px; }

  .status-row { gap: 6px 10px; font-size: 10px; padding: 4px 0; }
  .feed .row { grid-template-columns: 38px 62px minmax(0, 1fr); font-size: 11px; }
  .feed .row .ts { font-size: 9px; }
  .feed .row .src { font-size: 10px; letter-spacing: 0.12em; }
  .feed .row .txt { white-space: normal; line-height: 1.4; }

  /* Default mobile table style: CARD STACK, not horizontal scroll.
     Every <tr> renders as a block card, every <td> flows vertically
     inside it. Column headers (thead) are dropped because the row's
     content is self-explanatory at card density.

     Rationale: horizontal-scrolling tables on phones are essentially
     unreadable on narrow Fold 7 / iPhone SE widths — the first
     column gets clipped off-screen and you can't see what the action
     buttons apply to. Stacked cards read like a feed.

     Tables that ARE inherently tabular (comparison grids in /db
     and /tokens) opt out with `.data-scroll` or `.data-grid` —
     see overrides below. */
  table.data,
  table.data thead,
  table.data tbody,
  table.data tr,
  table.data th,
  table.data td {
    display: block;
    width: auto;
  }
  table.data thead { display: none; }
  table.data tbody tr {
    position: relative;
    border: 1px solid var(--rule);
    border-left: 2px solid var(--accent);
    background: var(--bg);
    padding: 10px 12px;
    margin: 0 0 8px 0;
  }
  table.data tbody tr:hover td { background: transparent; }
  table.data td {
    padding: 3px 0;
    border: 0;
    font-size: 12px;
    line-height: 1.4;
    white-space: normal;
  }
  table.data td.num { text-align: left; }
  table.data td:empty { display: none; }
  /* Card-stacked tables lose their thead on mobile, so a cell like
     "3h ago" or "127.0.0.1" floats without context. Templates can opt
     into inline field labels by adding data-label="..." to any td; we
     render it as a small caps prefix so each stacked row reads as
     "Created · 3h ago". Cells without the attribute are unaffected. */
  table.data td[data-label]::before {
    content: attr(data-label);
    display: inline-block;
    min-width: 64px;
    margin-right: 8px;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
  }

  /* Action-cell buttons stay horizontal inside the card, with a bit
     of top air. */
  table.data td .btn-row {
    margin-top: 6px;
    flex-wrap: wrap;
    gap: 6px;
  }

  /* Colspan="7" empty-state rows ("no tasks", "no signals", etc.)
     read as a single muted line instead of a bordered card. */
  table.data tbody tr:has(td[colspan]) {
    border: 0;
    border-left: 0;
    padding: 10px 0;
    background: transparent;
    text-align: center;
  }

  /* Opt-out for tables that genuinely need the grid — /db browser +
     /tokens comparison tables. These wrap in a real horizontal-scroll
     container so columns stay aligned and comparable. */
  table.data.data-scroll,
  table.data.data-scroll thead,
  table.data.data-scroll tbody,
  table.data.data-scroll tr,
  table.data.data-scroll th,
  table.data.data-scroll td {
    display: revert;
  }
  table.data.data-scroll {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    max-width: 100%;
    font-size: 11px;
  }
  table.data.data-scroll thead,
  table.data.data-scroll tbody,
  table.data.data-scroll tr { width: max-content; min-width: 100%; }
  table.data.data-scroll th,
  table.data.data-scroll td {
    padding: 6px 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
  }

  /* Control strips on phone: single horizontal-scrollable row instead
     of stacking each form to full width. Labels drop; the select +
     value communicates enough.
     Vertical padding gives native select chrome (Android chevron,
     focus outlines) a buffer — overflow-x:auto pins overflow-y:auto
     per CSS spec, so a select that bleeds above its layout box gets
     its top clipped without the buffer. 6px top/bottom is the floor
     that keeps dropdowns whole without looking bulky. */
  .chat-controls {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 6px;
    padding: 6px 0;
    margin: 4px 0 8px 0;
    border-bottom: 1px dashed var(--rule);
    scrollbar-width: none;       /* Firefox */
  }
  .chat-controls::-webkit-scrollbar { display: none; }
  .chat-controls > form {
    width: auto;
    min-width: 0;
    flex-shrink: 0;
  }
  .chat-ctrl {
    width: auto;
    gap: 4px;
    flex-shrink: 0;
  }
  .chat-ctrl label {
    display: none;               /* tags are visible via the select itself */
  }
  .chat-ctrl select {
    font-size: 14px;
    padding: 5px 26px 5px 8px;   /* room for the native chevron on the right */
    min-width: 0;
    max-width: 44vw;
    flex: 0 1 auto;
  }
  .chat-ctrl input {
    font-size: 16px;
    padding: 6px 8px;
    min-width: 0 !important;     /* override any inline min-width */
    flex: 1 1 auto;
    max-width: 60vw;
  }
  /* …but the /db + /tasks search fields DO deserve full width */
  .chat-ctrl--search {
    flex: 1 1 100% !important;
    width: 100%;
  }
  .chat-ctrl--search input { max-width: none; }

  .field-strip { gap: 6px 10px; font-size: 10px; padding: 4px 0 8px 0; }
  .field-select { font-size: 14px; padding: 4px 8px; }

  /* Composer */
  .composer-body { padding: 10px 12px 4px 12px; gap: 10px; }
  .composer-from { font-size: 9px; letter-spacing: 0.16em; padding-top: 4px; }
  .composer-input {
    font-size: 16px;           /* iOS: no auto-zoom */
    min-height: 42px;
    max-height: 200px;
  }
  .composer-bar { padding: 6px 10px 10px 12px; gap: 8px; }
  .composer-hints { display: none; }   /* kbd hints not useful on touch */
  .composer-busy { font-size: 9px; }
  .composer-send { padding: 10px 16px; font-size: 11px; min-width: 76px; }

  /* Chat messages — tight on mobile so the feed holds more turns.
     Wrap behavior for long tokens lives at the base .markdown rule;
     we only override size + spacing here. */
  .chat-feed {
    font-size: 11px;
    padding-right: 2px;
    line-height: 1.5;
    min-width: 0;
  }
  .chat-msg { margin-bottom: 10px; min-width: 0; }
  .chat-msg .who { font-size: 8px; letter-spacing: 0.2em; }
  .chat-feed .markdown { font-size: 11px; line-height: 1.5; }
  .chat-feed .markdown p { margin: 0.25em 0; }
  .chat-feed .markdown h1,
  .chat-feed .markdown h2,
  .chat-feed .markdown h3 { font-size: 11px; margin: 0.5em 0 0.2em; }
  .chat-feed .markdown ul,
  .chat-feed .markdown ol { margin: 0.25em 0 0.25em 1.1em; padding: 0; }
  .chat-feed .markdown li { margin: 0.1em 0; }
  .chat-feed .markdown pre { font-size: 10px; }

  /* Toast stack — lift above the composer and span full width */
  .toast-stack {
    right: 10px;
    left: 10px;
    bottom: calc(14px + env(safe-area-inset-bottom));
  }
  .toast { max-width: none; width: 100%; }

  /* Row actions (Ticketed/Dismiss, Atlas/Start/Done) — full-width wrap
     so each button's 44px+ tap area is preserved. */
  .btn-row {
    flex-wrap: wrap;
    width: 100%;
    gap: 6px;
  }
  .btn-row__cluster {
    padding-left: 0;
    margin-left: 0;
    border-left: 0;
    gap: 6px;
  }
  .btn {
    height: 30px;              /* up from 26 — fingertip friendly */
    padding: 0 12px;
    font-size: 11px;
  }
  .btn--icon {
    width: 34px;
    height: 34px;
    font-size: 15px;
  }

  /* Sidebar drawer — close button easier to hit, nav items have more air */
  .sidebar-head { padding: 12px; }
  .sidebar-close { width: 32px; height: 28px; }
  .sidebar a.nav-item {
    padding: 12px 14px 12px 20px;
    font-size: 13px;
    grid-template-columns: 22px 1fr;
  }
  .sidebar a.nav-item.active::after {
    right: 14px;               /* nudge the glow dot in so it never clips */
  }
  .nav-group > summary { padding: 13px 14px; }
  .sidebar-foot {
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }

  /* Cmd palette stretches full-width on tiny screens */
  .cmdp { width: calc(100vw - 20px); max-width: 520px; }
  .cmdp input { font-size: 16px; padding: 14px 16px; }

  /* Chat page: the chat-head wraps nothing on phone since the hero
     is hidden — we keep just the meta chip (session/thinking) as a
     small strip. */
  .chat-head { gap: 6px; align-items: center; margin: 0 0 4px 0; }
  .chat-head .hero { display: none; }       /* phone: drop, match global */
  .chat-head-meta {
    font-size: 10px;
    letter-spacing: 0.08em;
    margin-left: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--muted);
  }
  .chat-head-meta .accent { font-size: 10px; }
  .chat-subtitle { display: none; }

  /* Chat message text — Tyler: "could be smaller". 12 → 11. */
  .chat-feed { font-size: 11px; padding-right: 2px; }
  .chat-msg { margin-bottom: 10px; }
  .chat-msg .who { font-size: 9px; }
  .markdown { font-size: 12px; line-height: 1.5; }
  .markdown pre { font-size: 10px; }
  .markdown h1, .markdown h2, .markdown h3 { font-size: 11px; }

  /* Split layouts (triage/memory/workspace) on phone.
     Stack with the DETAIL first and dominating the viewport; the list
     sits under it, capped at ~half-viewport. Tyler called out these
     specifically — triage buried the selected content under the queue;
     memory/workspace detail was too small. */
  .split {
    display: flex;
    flex-direction: column;
    height: auto;
    gap: 10px;
  }
  .split-main {
    order: 1;
    padding-right: 0;
    overflow: visible;
    max-height: none;
  }
  .split-aside {
    order: 2;
    padding-right: 0;
    max-height: 44vh;
    overflow-y: auto;
    border-top: 1px dashed var(--rule);
    padding-top: 8px;
  }
  .workspace-split { height: auto; margin-bottom: 14px; }
  .workspace-split .split-aside { max-height: 34vh; }

  /* Triage detail shrinks so the action bar stays above the fold */
  .triage-cust { font-size: 15px; }
  .triage-summary { font-size: 12px; }
  .triage-raw { font-size: 10px; }
  .triage-hint { font-size: 9px; }

  /* Events + System: status chips/dots scroll horizontally, single
     row. Unlike .chat-controls these have no native selects, so no
     chrome bleed — 3px vertical padding is plenty to keep chips from
     touching siblings without making the row bulky. */
  .status-row--compact {
    gap: 8px;
    font-size: 9px;
    padding: 3px 0;
    margin: 2px 0 8px 0;
    overflow-y: hidden;
  }
  .status-row--compact .status-item { gap: 4px; flex-shrink: 0; }
  .status-row--compact .dot { width: 5px; height: 5px; }
  .status-row--compact .state { font-size: 9px; letter-spacing: 0.12em; }

  .status-row--chips {
    gap: 6px;
    padding: 3px 0;
    margin: 2px 0 8px 0;
    overflow-y: hidden;
  }
  .status-row--chips .badge {
    padding: 3px 8px;
    font-size: 9px;
    letter-spacing: 0.08em;
  }

  /* Data-scroll tables wrap in a shrunk scroll container */
  .data-wrap { max-height: calc(100vh - 240px); }

  /* Reports list: direct-open tap targets */
  .report-list > li > a { padding: 12px; gap: 10px; }
  .report-list .report-name {
    font-size: 13px;
    white-space: normal;
    overflow: visible;
  }
  .report-list .report-meta { font-size: 9px; flex-shrink: 0; }

  /* Markdown panels (memory, workspace) — tighter padding, smaller head */
  .panel { padding: 10px 12px; }
  .markdown-panel { font-size: 12px; line-height: 1.5; }
  .markdown-panel-head { font-size: 9px; margin-bottom: 8px; }

  /* Login panel — responsive rather than fixed 360px (used to overflow
     at 375px once you accounted for 16px margins each side). */
  .login-panel {
    width: min(360px, calc(100vw - 24px)) !important;
    padding: 24px 20px !important;
  }

  /* Narrow the actions column on phones so tables don't horizontal-scroll
     just to show a row of icon buttons */
  table.data th.col-actions,
  table.data td.col-actions { min-width: 140px; }

  /* Usage page — tenant cards stack full-width on phone; the 4-up
     metric grid stays 4-col (it's already compact enough at 56px
     columns) but fonts shrink one notch. */
  .tenant-cards { grid-template-columns: 1fr; gap: 8px; }
  .tenant-card { padding: 8px 10px; }
  .tenant-card__name { font-size: 12px; }
  .tenant-card__metrics { gap: 4px; }
  .tenant-card__metrics .mono { font-size: 12px !important; }

  /* Tenant editor — stack into a single column, label then field. */
  .tenant-editor {
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 8px 10px;
  }
  .tenant-editor .btn { grid-column: 1; }

  /* Multi-mode leading checkbox column — tighter on phones. */
  .multi-host.multi-active .queue-row {
    grid-template-columns: 20px minmax(0, 1fr);
  }
  .multi-footer { gap: 6px; }
  .tasks-title { font-size: 14px; }
}



/* ─────────────── Atlas — topbar trigger + right-side drawer ───────────────
   StartProto-style: 'ASK ATLAS' button lives in the topbar (right
   side, next to the clock). Click → slide-in 380px right-side drawer
   that does NOT block any page content. */
.topbar-atlas {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  background: var(--accent);
  color: #000;
  border: 1px solid var(--accent);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.18em;
  cursor: pointer;
  text-transform: uppercase;
  transition: filter 0.12s;
}
.topbar-atlas:hover { filter: brightness(1.1); }
.topbar-atlas:active { transform: translateY(0.5px); }
.topbar-atlas .brand-mark { font-size: 11px; line-height: 1; }
@media (max-width: 560px) {
  .topbar-atlas { padding: 0 8px; }
  .topbar-atlas span:last-child { display: none; }
}

.atlas-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100dvh;
  width: 380px;
  max-width: 92vw;
  background: var(--bg-elev);
  border-left: 1px solid var(--accent);
  box-shadow:
    -8px 0 32px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(254, 125, 1, 0.15) inset;
  z-index: 61;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.18s ease-out;
}
.atlas-drawer.is-open { transform: translateX(0); }

.atlas-drawer__head {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule);
}
.atlas-drawer__sub {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.atlas-drawer__form { display: flex; flex-direction: column; gap: 6px; }
.atlas-drawer__form textarea {
  font-family: var(--mono);
  font-size: 12px;
  padding: 8px;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--rule);
  resize: vertical;
  min-height: 96px;
  line-height: 1.4;
}
.atlas-drawer__form textarea:focus { outline: none; border-color: var(--accent); }
.atlas-drawer__quick { display: flex; flex-direction: column; gap: 4px; }
.atlas-drawer__qbtn { width: 100%; justify-content: flex-start; text-transform: lowercase; }

.atlas-drawer__backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s;
  z-index: 60;
}
.atlas-drawer.is-open ~ .atlas-drawer__backdrop {
  opacity: 1;
  pointer-events: auto;
}
@media (max-width: 480px) {
  .atlas-drawer { width: 100vw; max-width: 100vw; }
}


/* ─────────────── Customer detail — PLG sparkline panel ─────────────── */
.cust-plg__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}
.cust-plg__current { font-family: var(--mono); font-size: 16px; font-weight: 700; }
.cust-plg__delta--up   { color: var(--ok); }
.cust-plg__delta--down { color: var(--alert); }
.cust-plg__delta--flat { color: var(--muted); }


/* ─────────────── Form primitives ───────────────
   Pulled out of inline styles in customer.html / reports.html /
   atlas drawer so we have one source of truth. */
.form-textarea, .form-input {
  font-family: var(--mono);
  font-size: 12px;
  padding: 6px 8px;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--rule);
  resize: vertical;
}
.form-textarea:focus, .form-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Inline form layouts — used by the customer-page action drawers
   and any other 'small form crammed into a row' surface. The grid
   has a flexible 1fr column for the main control + auto cols for
   selectors and the submit button; the textarea/long input below
   spans the whole grid via grid-column: 1 / -1. */
.inline-form {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 6px;
  align-items: center;
  margin-top: 6px;
}
.inline-form > textarea,
.inline-form > input[type="text"] {
  grid-column: 1 / -1;
}
.inline-form input[type="date"] { font-family: var(--mono); }

@media (max-width: 560px) {
  .inline-form {
    grid-template-columns: 1fr 1fr;
  }
  .inline-form > button { grid-column: 2; }
}
