/* ============================================================================
   PLUMB — components. Every interactive thing has all seven states.
   ========================================================================= */
@layer components {

/* ═══ BUTTON ═══════════════════════════════════════════════════════════════ */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--ink);
  --btn-bd: var(--border-strong);
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-3);
  padding: 0 var(--s-6);
  height: 32px;
  background: var(--btn-bg); color: var(--btn-fg);
  border: 1px solid var(--btn-bd);
  border-radius: var(--r-sm);
  font-size: var(--t-sm); font-weight: var(--w-med);
  letter-spacing: -0.004em;
  white-space: nowrap; cursor: pointer; user-select: none;
  text-decoration: none;
  transition: background-color var(--d-fast) var(--ease-out),
              border-color var(--d-fast) var(--ease-out),
              color var(--d-fast) var(--ease-out),
              transform var(--d-press) var(--ease-out);
}
.btn:hover { background: color-mix(in oklch, var(--btn-bg) 94%, var(--ink)); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.45; cursor: not-allowed; transform: none;
}
.btn svg { width: 15px; height: 15px; }

.btn--primary { --btn-bg: var(--brand); --btn-fg: var(--on-brand); --btn-bd: var(--brand); }
.btn--primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn--primary:active:not(:disabled) { background: var(--brand-active); }

.btn--danger { --btn-bg: var(--neg); --btn-fg: oklch(99% 0.01 26); --btn-bd: var(--neg); }
.btn--danger:hover { background: color-mix(in oklch, var(--neg) 88%, black); }

.btn--ghost { --btn-bd: transparent; --btn-bg: transparent; --btn-fg: var(--ink-2); }
.btn--ghost:hover { background: var(--sunken); color: var(--ink); }

.btn--soft { --btn-bg: var(--brand-soft); --btn-fg: var(--brand-ink); --btn-bd: var(--brand-soft); }
.btn--soft:hover { background: var(--brand-soft-2); }

.btn--sm { height: 26px; padding: 0 var(--s-4); font-size: var(--t-xs); }
.btn--sm svg { width: 13px; height: 13px; }
.btn--lg { height: 38px; padding: 0 var(--s-9); font-size: var(--t-base); }
.btn--icon { width: 32px; padding: 0; }
.btn--icon.btn--sm { width: 26px; }
.btn--block { width: 100%; }

.btn[data-loading="true"] { color: transparent !important; pointer-events: none; }
.btn[data-loading="true"]::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 13px; height: 13px; border-radius: var(--r-full);
  border: 2px solid color-mix(in oklch, currentColor 25%, transparent);
  border-top-color: var(--btn-fg);
  animation: spin 560ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--r-sm) 0 0 var(--r-sm); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.btn-group .btn:hover, .btn-group .btn[aria-pressed="true"] { z-index: 1; }

/* ═══ PILL / STATUS ════════════════════════════════════════════════════════
   Color is never the only cue — every pill carries a dot whose shape varies. */
.pill {
  --pill-fg: var(--idle); --pill-bg: var(--idle-soft); --pill-bd: var(--idle-line);
  display: inline-flex; align-items: center; gap: var(--s-3);
  padding: 1px var(--s-4) 1px var(--s-3);
  background: var(--pill-bg); color: var(--pill-fg);
  border: 1px solid var(--pill-bd);
  border-radius: var(--r-full);
  font-size: var(--t-micro); font-weight: var(--w-semi);
  line-height: 16px; white-space: nowrap;
  letter-spacing: 0.002em;
}
.pill::before {
  content: ""; width: 6px; height: 6px; flex: 0 0 6px;
  background: currentColor; border-radius: var(--r-full);
}
.pill--ok      { --pill-fg: var(--pos);    --pill-bg: var(--pos-soft);    --pill-bd: var(--pos-line); }
.pill--warn    { --pill-fg: var(--signal-ink); --pill-bg: var(--signal-soft); --pill-bd: var(--signal-line); }
.pill--bad     { --pill-fg: var(--neg);    --pill-bg: var(--neg-soft);    --pill-bd: var(--neg-line); }
.pill--info    { --pill-fg: var(--info);   --pill-bg: var(--info-soft);   --pill-bd: var(--info-line); }
.pill--brand   { --pill-fg: var(--brand-ink); --pill-bg: var(--brand-soft); --pill-bd: var(--brand-line); }
.pill--pending { --pill-fg: var(--warn);   --pill-bg: var(--warn-soft);   --pill-bd: var(--warn-line); }
/* second cue: dot shape differs per state so CVD readers still parse it */
.pill--warn::before    { border-radius: 1px; transform: rotate(45deg); }   /* diamond */
.pill--bad::before     { border-radius: 1px; }                             /* square  */
.pill--pending::before { border-radius: var(--r-full); box-shadow: inset 0 0 0 1px var(--pill-bg); background: transparent; border: 1.5px solid currentColor; width: 7px; height: 7px; flex-basis: 7px; }
.pill--plain::before   { display: none; }
.pill--plain { padding-inline: var(--s-4); }
.pill--lg { font-size: var(--t-xs); padding: 2px var(--s-5) 2px var(--s-4); line-height: 18px; }

/* ═══ TAG / CHIP ═══════════════════════════════════════════════════════════ */
.tag {
  display: inline-flex; align-items: center; gap: var(--s-2);
  padding: 1px var(--s-3);
  background: var(--sunken); color: var(--ink-2);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  font-size: var(--t-micro); font-weight: var(--w-med);
  line-height: 16px; white-space: nowrap;
  /* tags stay on one line, but a long one truncates rather than widening
     the page — nowrap without a ceiling is how a label breaks a layout */
  max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.tag--code { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: -0.01em; }
.tag--entity { background: var(--brand-soft); border-color: var(--brand-line); color: var(--brand-ink); }

.chip {
  display: inline-flex; align-items: center; gap: var(--s-3);
  padding: 3px var(--s-5); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--r-full);
  font-size: var(--t-xs); font-weight: var(--w-med); color: var(--ink-2);
  cursor: pointer; white-space: nowrap;
  transition: all var(--d-fast) var(--ease-out);
}
.chip:hover { border-color: var(--border-loud); color: var(--ink); }
.chip[aria-pressed="true"] {
  background: var(--brand); border-color: var(--brand); color: var(--on-brand);
}
.chip:active { transform: scale(0.97); }
.chip:focus-visible { outline: none; box-shadow: var(--focus); }

.kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--sunken); border: 1px solid var(--border-strong);
  border-radius: var(--r-xs);
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 500;
  color: var(--muted); line-height: 1;
}

/* ═══ CARD / PANEL ═════════════════════════════════════════════════════════
   Elevation is a lightness step, not a shadow. No nested cards, ever. */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  min-width: 0;
}
.panel__head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-6);
  padding: var(--s-6) var(--s-8);
  border-bottom: 1px solid var(--border);
  min-height: 46px;
}
.panel__title {
  font-family: var(--font-ui); font-size: var(--t-sm); font-weight: var(--w-semi);
  letter-spacing: var(--track-tight); color: var(--ink);
  display: flex; align-items: center; gap: var(--s-4);
}
.panel__body { padding: var(--s-8); }
.panel__body--flush { padding: 0; }
.panel__foot {
  padding: var(--s-6) var(--s-8); border-top: 1px solid var(--border);
  background: var(--sunken); border-radius: 0 0 var(--r-lg) var(--r-lg);
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-6);
  flex-wrap: wrap;
}
.panel__head { flex-wrap: wrap; }
.toolbar > * { min-width: 0; }

/* ═══ SECTION LABEL ════════════════════════════════════════════════════════ */
.eyebrow {
  font-size: var(--t-micro); font-weight: var(--w-semi);
  letter-spacing: var(--track-label); text-transform: uppercase;
  color: var(--muted);
}

/* ═══ TABLE ════════════════════════════════════════════════════════════════ */
.tablewrap {
  overflow-x: auto; overflow-y: visible;
  border-radius: var(--r-lg);
  /* grid and flex children default to min-width:auto, which lets a wide table
     push its container instead of scrolling inside it */
  min-width: 0; max-width: 100%;
}
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--t-sm); }
.table th {
  position: sticky; top: 0; z-index: var(--z-sticky);
  background: var(--sunken);
  padding: 0 var(--s-6); height: 34px;
  text-align: left; white-space: nowrap;
  font-size: var(--t-micro); font-weight: var(--w-semi);
  letter-spacing: 0.045em; text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.table th[data-sortable] { cursor: pointer; user-select: none; }
.table th[data-sortable]:hover { color: var(--ink-2); background: var(--sunken-2); }
.table th[data-sort="asc"], .table th[data-sort="desc"] { color: var(--brand-ink); }
.table th[data-sort="asc"]::after  { content: " ↑"; }
.table th[data-sort="desc"]::after { content: " ↓"; }
.table td {
  padding: 0 var(--s-6); height: var(--row-h);
  border-bottom: 1px solid var(--border);
  vertical-align: middle; color: var(--ink-2);
  line-height: 1.4;
}
.table tbody tr { transition: background-color var(--d-press) var(--ease-out); }
.table tbody tr:hover { background: var(--sunken); }
.table tbody tr[aria-selected="true"] { background: var(--brand-soft); }
.table tbody tr[data-flag="exception"] { background: color-mix(in oklch, var(--signal-soft) 55%, transparent); }
.table tbody tr[data-flag="exception"]:hover { background: var(--signal-soft); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.strong { color: var(--ink); font-weight: var(--w-med); }
.table .cell-sub { display: block; font-size: var(--t-micro); color: var(--muted); line-height: 1.3; }
.table__actions { opacity: 0; transition: opacity var(--d-fast) var(--ease-out); }
.table tbody tr:hover .table__actions,
.table tbody tr:focus-within .table__actions { opacity: 1; }
[data-density="compact"] .table td { height: var(--row-h-compact); }
[data-density="compact"] .table .cell-sub { display: none; }
.table--linked tbody tr { cursor: pointer; }
.table td.sticky-l, .table th.sticky-l {
  position: sticky; left: 0; z-index: 1; background: var(--surface);
}
.table th.sticky-l { z-index: calc(var(--z-sticky) + 1); background: var(--sunken); }
.table tbody tr:hover td.sticky-l { background: var(--sunken); }

/* ═══ TOOLBAR ══════════════════════════════════════════════════════════════ */
.toolbar {
  display: flex; align-items: center; gap: var(--s-4);
  padding: var(--s-5) var(--s-8);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.toolbar__spacer { flex: 1 1 auto; }

.searchbox { position: relative; min-width: 180px; }
.searchbox svg {
  position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; color: var(--muted); pointer-events: none;
}
.searchbox input { padding-left: 29px; height: 30px; }

/* ═══ SEGMENTED ════════════════════════════════════════════════════════════ */
.segmented {
  display: inline-flex; padding: 2px; gap: 2px;
  background: var(--sunken); border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.segmented button {
  padding: 0 var(--s-5); height: 24px;
  background: transparent; border: 0; border-radius: var(--r-xs);
  font-size: var(--t-xs); font-weight: var(--w-med); color: var(--muted);
  cursor: pointer; white-space: nowrap;
  transition: background-color var(--d-fast) var(--ease-out), color var(--d-fast) var(--ease-out);
}
.segmented button:hover { color: var(--ink-2); }
.segmented button[aria-pressed="true"] {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border);
  box-shadow: 0 1px 1px oklch(21% 0.01 162 / 0.05);
  padding: 0 calc(var(--s-5) - 1px); height: 24px;
}
.segmented button:focus-visible { outline: none; box-shadow: var(--focus); }

/* ═══ TABS ═════════════════════════════════════════════════════════════════ */
.tabs {
  display: flex; gap: var(--s-8); align-items: stretch;
  border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  position: relative; padding: var(--s-5) 0 calc(var(--s-5) - 1px);
  background: none; border: 0; cursor: pointer; white-space: nowrap;
  font-size: var(--t-sm); font-weight: var(--w-med); color: var(--muted);
  display: flex; align-items: center; gap: var(--s-4);
  transition: color var(--d-fast) var(--ease-out);
}
.tabs button::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: var(--brand); border-radius: 2px 2px 0 0;
  transform: scaleX(0); transform-origin: center;
  transition: transform var(--d-base) var(--ease-out);
}
.tabs button:hover { color: var(--ink-2); }
.tabs button[aria-selected="true"] { color: var(--ink); }
.tabs button[aria-selected="true"]::after { transform: scaleX(1); }
.tabs button:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-xs); }
.tabs .count {
  font-size: var(--t-micro); color: var(--muted); background: var(--sunken-2);
  padding: 0 5px; border-radius: var(--r-full); font-variant-numeric: tabular-nums;
  min-width: 17px; text-align: center;
}

/* ═══ CALLOUT — full borders + tint. Never a side stripe. ═════════════════ */
.callout {
  --co-bg: var(--info-soft); --co-bd: var(--info-line); --co-fg: var(--info);
  display: flex; gap: var(--s-5); align-items: flex-start;
  padding: var(--s-6) var(--s-7);
  background: var(--co-bg); border: 1px solid var(--co-bd);
  border-radius: var(--r-md);
  font-size: var(--t-sm); color: var(--ink-2);
  line-height: var(--lh-snug);
}
.callout__icon { color: var(--co-fg); width: 16px; height: 16px; margin-top: 1px; flex: 0 0 16px; }
.callout__title { font-weight: var(--w-semi); color: var(--ink); display: block; margin-bottom: 2px; }
.callout--warn { --co-bg: var(--signal-soft); --co-bd: var(--signal-line); --co-fg: var(--signal-ink); }
.callout--bad  { --co-bg: var(--neg-soft);  --co-bd: var(--neg-line);  --co-fg: var(--neg); }
.callout--ok   { --co-bg: var(--pos-soft);  --co-bd: var(--pos-line);  --co-fg: var(--pos); }
.callout--quiet{ --co-bg: var(--sunken);    --co-bd: var(--border);    --co-fg: var(--muted); }

/* ═══ AI — the governor pattern ════════════════════════════════════════════
   Proposed values render provisional (dashed, dimmed) until a human accepts. */
.ai {
  background: var(--ai-soft);
  border: 1px solid var(--ai-line);
  border-radius: var(--r-md);
  padding: var(--s-6);
  font-size: var(--t-sm);
}
.ai[data-state="proposed"] { border-style: dashed; }
.ai[data-state="proposed"] .ai__value { opacity: 0.72; }
.ai[data-state="accepted"] { border-style: solid; background: var(--surface); border-color: var(--border); }
.ai[data-state="dismissed"] { opacity: 0.42; }
.ai__head {
  display: flex; align-items: center; gap: var(--s-3);
  font-size: var(--t-micro); font-weight: var(--w-semi);
  letter-spacing: 0.05em; text-transform: uppercase; color: var(--ai-ink);
  margin-bottom: var(--s-4);
}
.ai__mark { width: 12px; height: 12px; }
.ai__value { font-size: var(--t-sm); color: var(--ink); font-weight: var(--w-med); }
.ai__why { color: var(--muted); font-size: var(--t-xs); line-height: 1.45; margin-top: var(--s-3); }
.ai__acts { display: flex; gap: var(--s-3); margin-top: var(--s-5); }

/* confidence: three tiers in words, plus a bar. Never a bare percentage. */
.conf { display: inline-flex; align-items: center; gap: var(--s-3); font-size: var(--t-micro); }
.conf__bar { display: flex; gap: 2px; }
.conf__bar i { width: 4px; height: 9px; border-radius: 1px; background: var(--border-strong); }
.conf--high  { color: var(--pos); }
.conf--high  .conf__bar i { background: var(--pos); }
.conf--med   { color: var(--signal-ink); }
.conf--med   .conf__bar i:nth-child(-n+2) { background: var(--signal); }
.conf--low   { color: var(--neg); }
.conf--low   .conf__bar i:nth-child(1) { background: var(--neg); }

/* a field the model is unsure about — flagged; confident fields stay quiet */
.field-flag {
  background: var(--signal-soft) !important;
  border-color: var(--signal-line) !important;
}
.field-flag:focus-visible { box-shadow: 0 0 0 3px color-mix(in oklch, var(--signal) 22%, transparent) !important; }

/* ═══ FIELD ════════════════════════════════════════════════════════════════ */
.field { display: flex; flex-direction: column; gap: var(--s-3); }
.field__label {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-4);
  font-size: var(--t-xs); font-weight: var(--w-med); color: var(--ink-2);
}
.field__hint { font-size: var(--t-micro); color: var(--muted); line-height: 1.4; }
.field__err { font-size: var(--t-micro); color: var(--neg); font-weight: var(--w-med); }
.field-grid { display: grid; gap: var(--s-6); }
.field-grid--2 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* ═══ SWITCH ═══════════════════════════════════════════════════════════════ */
.switch { position: relative; display: inline-flex; align-items: center; gap: var(--s-4); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track {
  width: 32px; height: 18px; border-radius: var(--r-full);
  background: var(--border-loud); position: relative;
  transition: background-color var(--d-base) var(--ease-out);
  flex: 0 0 32px;
}
.switch__track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: var(--r-full); background: var(--surface);
  transition: transform var(--d-base) var(--ease-out);
}
.switch input:checked + .switch__track { background: var(--brand); }
.switch input:checked + .switch__track::after { transform: translateX(14px); }
.switch input:focus-visible + .switch__track { box-shadow: var(--focus); }

/* ═══ PROGRESS / METER ═════════════════════════════════════════════════════ */
.meter {
  height: 6px; background: var(--sunken-2); border-radius: var(--r-full); overflow: hidden;
}
.meter > i {
  display: block; height: 100%; background: var(--brand); border-radius: var(--r-full);
  transition: width var(--d-slow) var(--ease-out);
}
.meter--warn > i { background: var(--signal); }
.meter--bad > i  { background: var(--neg); }
.meter--ok > i   { background: var(--pos); }
.meter--stack { display: flex; }
.meter--stack > i { transition: width var(--d-slow) var(--ease-out); border-radius: 0; }

/* ═══ AVATAR ═══════════════════════════════════════════════════════════════ */
.avatar {
  display: inline-grid; place-content: center;
  width: 24px; height: 24px; flex: 0 0 24px;
  border-radius: var(--r-full);
  background: var(--brand-soft-2); color: var(--brand-ink);
  font-size: 10px; font-weight: var(--w-semi); letter-spacing: 0.01em;
  text-transform: uppercase; user-select: none;
}
.avatar--sm { width: 19px; height: 19px; flex-basis: 19px; font-size: 8.5px; }
.avatar--lg { width: 34px; height: 34px; flex-basis: 34px; font-size: 13px; }
.avatar--bot { background: var(--sunken-2); color: var(--muted); }

/* ═══ EMPTY ════════════════════════════════════════════════════════════════ */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--s-5); padding: var(--s-16) var(--s-8); text-align: center;
}
.empty__icon { width: 26px; height: 26px; color: var(--faint); }
.empty__title { font-size: var(--t-md); font-weight: var(--w-semi); color: var(--ink); font-family: var(--font-ui); }
.empty__body { font-size: var(--t-sm); color: var(--muted); max-width: 44ch; line-height: 1.5; }

/* ═══ SKELETON ═════════════════════════════════════════════════════════════ */
.skeleton {
  background: linear-gradient(90deg, var(--sunken) 25%, var(--sunken-2) 50%, var(--sunken) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
  border-radius: var(--r-xs);
}
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; background: var(--sunken-2); } }

/* ═══ MENU / DROPDOWN — popover so it escapes overflow containers ═════════ */
.menu {
  position: fixed; z-index: var(--z-dropdown);
  min-width: 180px; padding: var(--s-3);
  background: var(--overlay); border: 1px solid var(--border-strong);
  border-radius: var(--r-md); box-shadow: var(--lift-pop);
  transform-origin: var(--menu-origin, top left);
}
.menu[popover]:popover-open { animation: pop-in var(--d-fast) var(--ease-out); }
@keyframes pop-in { from { opacity: 0; transform: scale(0.96); } }
.menu__item {
  display: flex; align-items: center; gap: var(--s-4); width: 100%;
  padding: var(--s-3) var(--s-4); border: 0; background: none;
  border-radius: var(--r-xs); cursor: pointer; text-align: left;
  font-size: var(--t-sm); color: var(--ink-2); text-decoration: none;
}
.menu__item:hover, .menu__item:focus-visible { background: var(--sunken); color: var(--ink); outline: none; }
.menu__item svg { width: 14px; height: 14px; color: var(--muted); }
.menu__item--danger { color: var(--neg); }
.menu__item--danger:hover { background: var(--neg-soft); color: var(--neg); }
.menu__sep { height: 1px; background: var(--border); margin: var(--s-3) 0; }
.menu__label { padding: var(--s-3) var(--s-4) var(--s-2); font-size: var(--t-micro);
  text-transform: uppercase; letter-spacing: var(--track-label); color: var(--muted); }

/* ═══ DRAWER ═══════════════════════════════════════════════════════════════ */
.drawer {
  position: fixed; inset: 0 0 0 auto; z-index: var(--z-drawer);
  width: min(560px, 100vw); background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--d-drawer) var(--ease-drawer);
}
.drawer[data-open="true"] { transform: translateX(0); }
.drawer__scrim {
  position: fixed; inset: 0; z-index: var(--z-drawer-scrim);
  background: var(--scrim); opacity: 0; pointer-events: none;
  transition: opacity var(--d-base) var(--ease-out);
}
.drawer__scrim[data-open="true"] { opacity: 1; pointer-events: auto; }
.drawer__head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-6);
  padding: var(--s-7) var(--s-9); border-bottom: 1px solid var(--border);
}
.drawer__body { flex: 1; overflow-y: auto; padding: var(--s-9); }
.drawer__foot {
  padding: var(--s-7) var(--s-9); border-top: 1px solid var(--border);
  background: var(--sunken); display: flex; gap: var(--s-4); justify-content: flex-end;
}

/* ═══ MODAL — centered, so transform-origin stays center ═════════════════ */
.modal {
  position: fixed; z-index: var(--z-modal);
  top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0.97);
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 64px);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-xl); box-shadow: var(--lift-modal);
  display: flex; flex-direction: column;
  opacity: 0; pointer-events: none;
  transition: opacity var(--d-base) var(--ease-out), transform var(--d-base) var(--ease-out);
}
.modal[data-open="true"] { opacity: 1; transform: translate(-50%, -50%) scale(1); pointer-events: auto; }
.modal__scrim { position: fixed; inset: 0; z-index: var(--z-modal-scrim);
  background: var(--scrim); opacity: 0; pointer-events: none;
  transition: opacity var(--d-base) var(--ease-out); }
.modal__scrim[data-open="true"] { opacity: 1; pointer-events: auto; }
.modal__head { padding: var(--s-9) var(--s-9) var(--s-6); }
.modal__title { font-size: var(--t-lg); font-family: var(--font-ui); font-weight: var(--w-semi);
  letter-spacing: var(--track-tight); }
.modal__body { padding: 0 var(--s-9) var(--s-9); overflow-y: auto; font-size: var(--t-sm); color: var(--ink-2); }
.modal__foot { padding: var(--s-7) var(--s-9); border-top: 1px solid var(--border);
  background: var(--sunken); border-radius: 0 0 var(--r-xl) var(--r-xl);
  display: flex; gap: var(--s-4); justify-content: flex-end; }

/* ═══ TOAST ════════════════════════════════════════════════════════════════ */
.toaster {
  position: fixed; bottom: var(--s-9); right: var(--s-9); z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--s-4); pointer-events: none;
  max-width: min(380px, calc(100vw - 32px));
}
.toast {
  display: flex; align-items: flex-start; gap: var(--s-5);
  padding: var(--s-6) var(--s-7);
  background: var(--overlay); border: 1px solid var(--border-strong);
  border-radius: var(--r-md); box-shadow: var(--lift-pop);
  font-size: var(--t-sm); color: var(--ink-2); pointer-events: auto;
  transition: opacity var(--d-slow) var(--ease-out), transform var(--d-slow) var(--ease-out);
}
@starting-style { .toast { opacity: 0; transform: translateY(12px); } }
.toast[data-leaving="true"] { opacity: 0; transform: translateX(16px); }
.toast__icon { width: 15px; height: 15px; margin-top: 1px; flex: 0 0 15px; color: var(--brand); }
.toast--ok  .toast__icon { color: var(--pos); }
.toast--bad .toast__icon { color: var(--neg); }
.toast--warn .toast__icon { color: var(--signal-ink); }
.toast strong { display: block; color: var(--ink); font-weight: var(--w-semi); }

/* ═══ TIMELINE / ACTIVITY ══════════════════════════════════════════════════ */
.tl { display: flex; flex-direction: column; }
.tl__day {
  position: sticky; top: 0; z-index: 1;
  padding: var(--s-4) 0 var(--s-3);
  background: var(--surface);
  font-size: var(--t-micro); font-weight: var(--w-semi);
  letter-spacing: var(--track-label); text-transform: uppercase; color: var(--muted);
}
.tl__row {
  display: grid; grid-template-columns: 22px 1fr auto; gap: var(--s-5);
  padding: var(--s-4) 0; align-items: start;
  font-size: var(--t-sm); line-height: 1.45;
}
.tl__row + .tl__row { border-top: 1px solid var(--border); }
.tl__row[data-actor="system"] { color: var(--muted); }
.tl__row[data-actor="system"] .tl__what { color: var(--muted); }
.tl__what { color: var(--ink-2); }
.tl__what b { font-weight: var(--w-semi); color: var(--ink); }
.tl__when { font-size: var(--t-micro); color: var(--muted); white-space: nowrap;
  font-variant-numeric: tabular-nums; padding-top: 2px; }
.tl__diff {
  display: inline-flex; align-items: center; gap: var(--s-3); margin-top: var(--s-2);
  font-family: var(--font-mono); font-size: 10.5px;
}
.tl__diff s { color: var(--muted); text-decoration-color: var(--neg); }
.tl__diff em { font-style: normal; color: var(--pos); }

/* ═══ STAT ═════════════════════════════════════════════════════════════════ */
.stat { display: flex; flex-direction: column; gap: var(--s-2); }
.stat__label { font-size: var(--t-micro); color: var(--muted); font-weight: var(--w-med);
  letter-spacing: 0.03em; text-transform: uppercase; }
.stat__value { font-family: var(--font-display); font-variation-settings: "wdth" 112;
  font-size: var(--t-2xl); font-weight: var(--w-med); line-height: var(--lh-num);
  font-variant-numeric: tabular-nums; letter-spacing: var(--track-num); color: var(--ink); }
.stat__delta { font-size: var(--t-micro); color: var(--muted); font-variant-numeric: tabular-nums; }
.stat__delta--up { color: var(--pos); }
.stat__delta--down { color: var(--neg); }

/* ═══ CHECKLIST ════════════════════════════════════════════════════════════ */
.check { display: flex; flex-direction: column; }
.check__row {
  display: grid; grid-template-columns: 16px 1fr auto; gap: var(--s-5);
  padding: var(--s-5) 0; align-items: center; font-size: var(--t-sm);
}
.check__row + .check__row { border-top: 1px solid var(--border); }
.check__mark { width: 16px; height: 16px; }
.check__row[data-ok="true"]  .check__mark { color: var(--pos); }
.check__row[data-ok="false"] .check__mark { color: var(--neg); }
.check__row[data-ok="warn"]  .check__mark { color: var(--signal-ink); }
.check__row[data-ok="false"] { color: var(--ink); }

/* ═══ CODE BLOCK ═══════════════════════════════════════════════════════════ */
.code {
  background: var(--sunken); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: var(--s-6) var(--s-7);
  font-family: var(--font-mono); font-size: var(--t-xs); line-height: 1.65;
  color: var(--ink-2); overflow-x: auto; white-space: pre;
  tab-size: 4;
}
.code .tab { color: var(--border-loud); }
.code .k { color: var(--brand-ink); font-weight: 500; }
.code .n { color: var(--info); }
.code .s { color: var(--pos); }
.code .c { color: var(--muted); }

/* ═══ SPLIT BAR (allocation remainder) ═════════════════════════════════════ */
.remainder {
  display: inline-flex; align-items: center; gap: var(--s-3);
  padding: 2px var(--s-4); border-radius: var(--r-full);
  font-size: var(--t-micro); font-weight: var(--w-semi);
  font-variant-numeric: tabular-nums;
  background: var(--pos-soft); color: var(--pos); border: 1px solid var(--pos-line);
}
.remainder[data-over="true"] { background: var(--signal-soft); color: var(--signal-ink); border-color: var(--signal-line); }

/* ═══ BULK BAR ═════════════════════════════════════════════════════════════ */
.bulkbar {
  position: fixed; bottom: var(--s-9); left: 50%; z-index: var(--z-toast);
  transform: translateX(-50%) translateY(140%);
  display: flex; align-items: center; gap: var(--s-6);
  padding: var(--s-5) var(--s-7);
  background: var(--overlay); border: 1px solid var(--border-strong);
  border-radius: var(--r-full); box-shadow: var(--lift-pop);
  font-size: var(--t-sm); white-space: nowrap;
  transition: transform var(--d-base) var(--ease-out);
}
.bulkbar[data-open="true"] { transform: translateX(-50%) translateY(0); }
.bulkbar__count { font-weight: var(--w-semi); color: var(--ink); font-variant-numeric: tabular-nums; }

/* ═══ TOOLTIP ══════════════════════════════════════════════════════════════ */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 6px); left: 50%;
  transform: translateX(-50%) scale(0.97);
  transform-origin: bottom center;
  padding: 4px var(--s-5);
  background: var(--ink); color: var(--canvas);
  border-radius: var(--r-xs); font-size: var(--t-micro); font-weight: var(--w-med);
  white-space: nowrap; pointer-events: none; opacity: 0;
  z-index: var(--z-tooltip);
  transition: opacity var(--d-fast) var(--ease-out), transform var(--d-fast) var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  [data-tip]:hover::after { opacity: 1; transform: translateX(-50%) scale(1); }
}
[data-tip]:focus-visible::after { opacity: 1; transform: translateX(-50%) scale(1); }

/* Near a viewport edge a centred tooltip overflows the page — and because it is
   laid out even while hidden, it inflates scrollWidth on every screen. Anchor
   those inward instead. */
[data-tip][data-tip-at="right"]::after {
  left: auto; right: 0; transform: translateX(0) scale(0.97); transform-origin: bottom right;
}
@media (hover: hover) and (pointer: fine) {
  [data-tip][data-tip-at="right"]:hover::after { transform: translateX(0) scale(1); }
}
[data-tip][data-tip-at="right"]:focus-visible::after { transform: translateX(0) scale(1); }
[data-tip][data-tip-at="left"]::after {
  left: 0; right: auto; transform: translateX(0) scale(0.97); transform-origin: bottom left;
}
@media (hover: hover) and (pointer: fine) {
  [data-tip][data-tip-at="left"]:hover::after { transform: translateX(0) scale(1); }
}
[data-tip][data-tip-at="left"]:focus-visible::after { transform: translateX(0) scale(1); }

}
