/* A3 components. Ported from design/ui-overhaul/mockups/a2.css (the locked reference;
   change it there first, then re-port). Colours come only from tokens.css. */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--ground); color: var(--text); font: 400 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.nil, .muted { color: var(--muted); }
.ico { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico-sm { width: 14px; height: 14px; }

/* Title tile: the page's icon in the ink colour, beside every page title. */
.tile { width: 36px; height: 36px; border-radius: 10px; background: var(--tile); color: var(--tile-ink); display: grid; place-items: center; flex: none; }
.tile .ico { width: 18px; height: 18px; stroke-width: 1.6; }
.tile-sm { width: 28px; height: 28px; border-radius: 8px; }
.tile-sm .ico { width: 15px; height: 15px; }

/* ── app shell ───────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
#side { position: sticky; top: 0; height: 100vh; overflow: visible; z-index: 30; display: flex; flex-direction: column; padding: 18px 12px 14px; }  /* above the sheet, so the user menu can hang out of the collapsed rail */
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 22px; }
.brand-txt { display: grid; line-height: 1.2; }
.brand-txt b { font-weight: 600; font-size: 14px; }
.brand-txt span { font-size: 12px; color: var(--muted); }
.menu-btn { display: none; margin-left: auto; background: none; border: 0; padding: 8px; }
/* The nav is the only thing in the rail that scrolls; the brand and the foot stay put. */
.nav { display: flex; flex-direction: column; gap: 22px; flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; }
.nav-group { display: grid; gap: 1px; }
.nav-label { font-size: 12px; color: var(--muted); padding: 0 10px 6px; }
.nav-item { display: flex; align-items: center; gap: 10px; height: 32px; padding: 0 10px; border-radius: var(--radius-control); color: var(--text); opacity: .86; font-size: 14px; }
.nav-item .ico { color: var(--muted); }
.nav-item:hover { background: var(--hover); opacity: 1; }
.nav-item.is-active { background: var(--surface); opacity: 1; outline: 1px solid var(--border); outline-offset: -1px; }
.nav-item.is-active .ico { color: var(--text); }
.nav-foot { display: grid; gap: 1px; padding-top: 16px; flex: none; }
.user { display: flex; align-items: center; gap: 10px; padding: 12px 10px 2px; margin-top: 8px; border-top: 1px solid var(--rule); }
.user div { display: grid; line-height: 1.25; }
.user b { font-weight: 500; font-size: 13px; }
.user span { font-size: 12px; color: var(--muted); }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 600; background: var(--active); color: var(--text); }
#main { min-width: 0; padding: 32px 40px 48px; display: flex; flex-direction: column; }

/* ── page head ───────────────────────────────────────────────────────── */
.head { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.head-title { display: flex; align-items: center; gap: 14px; min-width: 0; }
.head-title > div { display: grid; gap: 2px; min-width: 0; }
h1 { font-size: 24px; font-weight: 400; letter-spacing: -0.02em; line-height: 1.2; margin: 0; white-space: nowrap; }
.subtitle { margin: 0; color: var(--muted); font-size: 13px; }
.head-actions { display: flex; align-items: center; gap: 8px; flex: none; flex-wrap: wrap; justify-content: flex-end; }
h2 { font-size: 15px; font-weight: 500; margin: 0; }

/* ── buttons ─────────────────────────────────────────────────────────── */
.btn { height: var(--control-h); padding: 0 14px; border-radius: var(--radius-control); display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 13px; font-weight: 500; border: 1px solid transparent; white-space: nowrap; background: none; }
.btn .ico { width: 15px; height: 15px; }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); border-color: var(--control); color: var(--text); }
.btn-secondary:hover { background: var(--hover); }
.btn-ghost { color: var(--text); }
.btn-ghost:hover { background: var(--hover); }
.btn-danger { background: var(--surface); border-color: var(--control); color: var(--negative); }
.btn-danger:hover { background: var(--negative-soft); border-color: var(--negative-soft); }
.btn-danger-solid { background: var(--negative); color: #ffffff; }
.btn-icon { width: var(--control-h); padding: 0; }
.btn-icon .ico { stroke-width: 2.4; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-sm.btn-icon { width: 28px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ── controls ────────────────────────────────────────────────────────── */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ctl { height: var(--control-h); padding: 0 12px; display: inline-flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--control); border-radius: var(--radius-control); font-size: 13px; white-space: nowrap; }
.ctl:hover { background: var(--hover); }
.ctl .ico-sm { color: var(--muted); }
.ctl.is-on { border-color: var(--text); }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--positive); box-shadow: 0 0 0 3px var(--positive-soft); }
.search { flex: 1 1 280px; max-width: 420px; min-width: 0; height: var(--control-h); display: flex; align-items: center; gap: 8px; padding: 0 12px; background: var(--surface); border: 1px solid var(--control); border-radius: var(--radius-control); color: var(--muted); }
.search input { border: 0; outline: 0; background: none; width: 100%; min-width: 0; font-size: 13px; color: var(--text); }
.search input::placeholder { color: var(--faint); }
.search:focus-within { border-color: var(--text); }
/* Segmented control: a well with the selected option lifted onto the surface. */
.seg { display: inline-flex; height: var(--control-h); padding: 3px; gap: 2px; background: var(--active); border-radius: var(--radius-control); }
.seg button { border: 0; background: none; padding: 0 12px; border-radius: 6px; font-size: 13px; color: var(--muted); }
.seg button:hover { color: var(--text); }
.seg button.is-on { background: var(--surface); color: var(--text); font-weight: 500; }
.tabs { display: flex; align-items: center; gap: 24px; border-bottom: 1px solid var(--border); }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 0 0 10px; margin-bottom: -1px; font-size: 14px; color: var(--muted); }
.tabs button:hover { color: var(--text); }
.tabs button.is-on { color: var(--text); font-weight: 500; border-bottom-color: var(--text); }
.tabs .count { margin-left: 4px; }
.field { display: grid; gap: 7px; font-size: 13px; font-weight: 500; }
.field input, .field select, .field textarea { height: 38px; padding: 0 12px; border-radius: var(--radius-control); border: 1px solid var(--control); background: var(--surface); font-size: 14px; font-weight: 400; color: var(--text); }
.field textarea { height: 76px; padding: 10px 12px; resize: none; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--text); box-shadow: 0 0 0 3px var(--active); }
.field .hint { font-weight: 400; font-size: 12px; color: var(--muted); }
.field.has-error input { border-color: var(--negative); }
.field.has-error .hint { color: var(--negative); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; }
.check input { appearance: none; width: 16px; height: 16px; border: 1px solid var(--control); border-radius: 4px; background: var(--surface); display: grid; place-items: center; margin: 0; }
.check input:checked { background: var(--primary); border-color: var(--primary); }
.check input:checked::after { content: ""; width: 8px; height: 4px; border: 1.6px solid var(--primary-ink); border-top: 0; border-right: 0; transform: translateY(-1px) rotate(-45deg); }
.switch { display: inline-flex; align-items: center; gap: 10px; font-size: 13px; }
.switch input { appearance: none; width: 30px; height: 18px; border-radius: 9px; background: var(--control); position: relative; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #ffffff; }
.switch input:checked { background: var(--positive); }
.switch input:checked::after { transform: translateX(12px); }

/* ── surfaces ────────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 24px; padding: 20px 0 12px; border-bottom: 1px solid var(--rule); }
.count { font-size: 12px; color: var(--muted); font-weight: 400; }
.well { background: var(--well); border-radius: 12px; }
.float { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: 0 12px 32px rgba(20, 18, 15, .07), 0 1px 3px rgba(20, 18, 15, .05); }

/* ── status said in words ────────────────────────────────────────────── */
.st { font-size: 13px; white-space: nowrap; display: inline-flex; align-items: center; gap: 7px; }
.st::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.st-tracking { color: var(--st-tracking); }
.st-evaluating { color: var(--st-evaluating); }
.st-best-final { color: var(--st-bf); }
.st-loi { color: var(--st-loi); }
.st-coming-soon { color: var(--st-soon); }
.st-likely-pass { color: var(--st-pass); }
.ms { font-size: 13px; color: var(--muted); }
.ms-complete { color: var(--positive); }
.ms-in-progress { color: var(--st-evaluating); }
.tag { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: var(--radius-chip); font-size: 12px; font-weight: 500; background: var(--active); color: var(--text); white-space: nowrap; }
.tag-accent { background: var(--accent-soft); color: var(--accent); }
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; font-size: 13px; line-height: 1.45; }
.notice .ico { margin-top: 1px; }
.notice b { font-weight: 500; }
.notice-info { background: var(--accent-soft); color: var(--text); }
.notice-info .ico { color: var(--accent); }
.notice-warn { background: var(--notice-soft); color: var(--text); }
.notice-warn .ico { color: var(--notice); }
.notice-error { background: var(--negative-soft); color: var(--text); }
.notice-error .ico { color: var(--negative); }
.toast { display: inline-flex; align-items: center; gap: 10px; height: 40px; padding: 0 14px 0 16px; border-radius: 10px; background: var(--primary); color: var(--primary-ink); font-size: 13px; }
.toast button { background: none; border: 0; color: inherit; opacity: .7; font-weight: 500; }

/* ── table ───────────────────────────────────────────────────────────── */
.table-card { overflow: hidden; }
.table-scroll { overflow-x: auto; }
table.grid { border-collapse: collapse; width: 100%; font-size: 13px; }
.grid th { text-align: left; font-weight: 400; font-size: 12px; color: var(--muted); padding: 0 14px; height: 42px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface); }
.grid td { padding: 0 14px; height: var(--row-h); border-bottom: 1px solid var(--rule); white-space: nowrap; }
.grid tr:last-child td { border-bottom: 0; }
.grid th.num, .grid td.num { text-align: right; }
.grid th:first-child, .grid td:first-child { padding-left: 24px; }
.grid th:last-child, .grid td:last-child { padding-right: 24px; }
.grid tbody tr:not(.group):hover td { background: var(--well); }
.grid .name { font-size: 14px; }
.grid .sub { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.group td { height: auto; padding-top: 22px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.group-in { display: inline-flex; align-items: baseline; gap: 10px; }
.group-in b { font-weight: 500; font-size: 13px; }
.group-in span { font-size: 12px; color: var(--muted); }

/* ── title-row and toolbar refinements ───────────────────────────────── */
.stamp { font-size: 12px; color: var(--muted); margin-right: 4px; white-space: nowrap; }
.menu-wrap { position: relative; display: inline-flex; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 240px; padding: 6px; display: grid; gap: 1px; border-radius: 12px; }
.menu button { display: grid; gap: 1px; text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 6px; font-size: 13px; font-weight: 500; }
.menu button span { font-size: 12px; font-weight: 400; color: var(--muted); }
.menu button:hover { background: var(--hover); }
/* A control and its action share one border, inner corners square. */
.joined { display: inline-flex; }
.joined .ctl:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.joined .ctl + .ctl { margin-left: -1px; border-top-left-radius: 0; border-bottom-left-radius: 0; }
.tb-gap { width: 8px; }
.tb-end { margin-left: auto; padding-left: 8px; }
/* The previous layout, kept for comparison. */
body.v1 { --control-h: 34px; }
body.v1 .btn { font-size: 14px; gap: 7px; }

/* ── motion: feedback under the hand, nothing performs an entrance ───── */
.btn, .ctl { transition: transform var(--t-press) var(--ease-out), background-color var(--t-hover) ease, border-color var(--t-hover) ease, color var(--t-hover) ease; }
.btn:active:not([disabled]), .ctl:active { transform: scale(.97); }
.nav-item { transition: background-color var(--t-hover) ease, opacity var(--t-hover) ease; }
.grid td { transition: background-color 120ms ease; }
.search, .field input, .field select, .field textarea { transition: border-color var(--t-hover) ease, box-shadow var(--t-hover) ease; }

/* Segmented control: the lifted thumb slides between options. */
.seg { position: relative; display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
.seg::before { content: ""; position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc((100% - 8px) / 2); border-radius: 6px; background: var(--surface); box-shadow: 0 1px 2px rgba(15, 17, 21, .06); transition: transform var(--t-ui) var(--ease-in-out); }
.seg[data-on="calendar"]::before { transform: translateX(calc(100% + 2px)); }
.seg button { position: relative; z-index: 1; padding: 0 14px; transition: color var(--t-hover) ease; }
.seg button.is-on { background: none; }

.switch input { transition: background-color var(--t-hover) ease; }
.switch input::after { transition: transform 200ms var(--ease-out); }

/* Menus open from their trigger and leave faster than they arrive. */
.menu { opacity: 0; visibility: hidden; pointer-events: none; transform: scale(.97) translateY(-4px); transform-origin: top right;
  transition: opacity var(--t-leave) var(--ease-exit), transform var(--t-leave) var(--ease-exit), visibility 0s var(--t-leave); }
.menu.is-open { opacity: 1; visibility: visible; pointer-events: auto; transform: none;
  transition: opacity var(--t-ui) var(--ease-out), transform var(--t-ui) var(--ease-out), visibility 0s; }
.menu.is-static { position: static; opacity: 1; visibility: visible; pointer-events: auto; transform: none; }
.menu button { transition: background-color 120ms ease; }

/* Dialog: the scrim fades, the panel settles from 97%. */
.overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px; background: rgba(15, 17, 21, .28); opacity: 0; transition: opacity var(--t-ui) ease; }
.overlay[hidden] { display: none; }
.overlay.is-open { opacity: 1; }
.overlay.is-closing { transition: opacity var(--t-leave) ease; }
.dialog { width: 100%; max-width: 440px; padding: 22px 24px 20px; display: grid; gap: 16px; }
.dialog h3 { margin: 0; font-size: 17px; font-weight: 500; }
.dialog p { margin: 0; color: var(--muted); font-size: 13px; }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }
.overlay .dialog { transform: scale(.97) translateY(6px); transition: transform var(--t-dialog) var(--ease-out); }
.overlay.is-open .dialog { transform: none; }
.overlay.is-closing .dialog { transform: scale(.98); transition: transform var(--t-leave) var(--ease-exit); }
.kv { display: flex; justify-content: space-between; font-size: 13px; padding: 10px 12px; }
.kv span { color: var(--muted); }

/* Toast: rises a few pixels to confirm an action, then leaves. */
.toast-float { position: fixed; left: 50%; bottom: 24px; z-index: 60; opacity: 0; pointer-events: none; transform: translate(-50%, 10px);
  transition: opacity var(--t-leave) var(--ease-exit), transform var(--t-leave) var(--ease-exit); }
.toast-float.is-in { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); transition: opacity var(--t-ui) var(--ease-out), transform var(--t-ui) var(--ease-out); }

/* A view swap cross-fades; no travel. */
.view-in { animation: view-in var(--t-hover) ease; }
@keyframes view-in { from { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .btn:active:not([disabled]), .ctl:active { transform: none; }
  .menu, .menu.is-open, .overlay .dialog, .overlay.is-open .dialog, .toast-float, .toast-float.is-in { transform: none; }
  .toast-float, .toast-float.is-in { transform: translateX(-50%); }
  .seg::before, .switch input::after { transition: none; }
}

/* Played states for the Motion screen: the same responses, triggered by script. */
.btn.is-pressed, .ctl.is-pressed { transform: scale(.97); }
.btn-secondary.is-hover, .btn-ghost.is-hover { background: var(--hover); }
.btn-primary.is-hover { background: var(--primary-hover); }
/* Slow motion: every token at five times its length. */
.slow { --t-press: 700ms; --t-hover: 900ms; --t-ui: 1100ms; --t-dialog: 1500ms; --t-leave: 750ms; }

/* ── scrolling: nothing animates in; things stick and edges show more ── */
/* A data grid scrolls inside its card, both ways, so its header row, the
   current stage label and the pinned columns stay in view. */
.grid-frame { position: relative; display: flex; flex-direction: column; min-height: 0; }
.grid-scroll { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; }
@media (prefers-reduced-motion: no-preference) { .grid-scroll { scroll-behavior: smooth; } }
.grid-scroll .grid thead th { position: sticky; top: 0; z-index: 3; transition: box-shadow var(--t-hover) ease; }
.grid-scroll.is-scrolled-y .grid thead th { box-shadow: 0 1px 0 var(--border), 0 8px 10px -10px rgba(15, 17, 21, .28); }
.grid-scroll .grid .group td { position: sticky; top: 42px; z-index: 2; background: var(--surface); }
.grid-scroll .group-in { position: sticky; left: 24px; }
.grid-scroll .grid .pin { position: sticky; z-index: 1; background: var(--surface); transition: box-shadow var(--t-hover) ease; }
.grid-scroll .grid thead th.pin { z-index: 4; }
.grid-scroll .grid .pin-0 { left: 0; width: 48px; min-width: 48px; max-width: 48px; }
.grid-scroll .grid .pin-1 { left: 48px; }
.grid-scroll .grid tbody tr:not(.group):hover td.pin { background: var(--well); }
.grid-scroll.is-scrolled-x .grid .pin-last { box-shadow: 10px 0 10px -10px rgba(15, 17, 21, .22); }
/* More columns to the right: a soft inner shade on the card's right edge. */
.grid-frame::after { content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: 24px; pointer-events: none; z-index: 5;
  border-radius: 0 var(--radius-card) var(--radius-card) 0; box-shadow: inset -14px 0 12px -12px rgba(15, 17, 21, .18);
  opacity: 0; transition: opacity var(--t-hover) ease; }
.grid-frame.has-more-x::after { opacity: 1; }

/* ── more shared parts, added for the Expense comps page ─────────────── */
/* Segmented control with any number of options: set --n, and --i for the selected one. */
.seg { --n: 2; --i: 0; }
.seg::before { width: calc((100% - 6px - (var(--n) - 1) * 2px) / var(--n)); transform: translateX(calc(var(--i) * (100% + 2px))); }
/* Filter fields: a quiet 12px label over a toolbar-height control. */
.filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 16px; }
.ff { display: grid; gap: 6px; min-width: 0; font-size: 12px; color: var(--muted); }
.ff > input, .ff > select, .ff .pair > input, .ff .joined-field > input { height: var(--control-h); padding: 0 10px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); color: var(--text); font-size: 13px; min-width: 0; width: 100%; }
.ff > input::placeholder, .ff .pair > input::placeholder, .ff .joined-field > input::placeholder { color: var(--faint); }
.ff > input:focus, .ff .pair > input:focus, .ff .joined-field > input:focus { outline: none; border-color: var(--text); }
.ff select, select.sel { appearance: none; padding-right: 30px; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23646a73' stroke-width='1.5' stroke-linecap='round'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 10px center; }
.ff .ctl { width: 100%; justify-content: space-between; font-size: 13px; }
.pair { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 6px; }
.pair span { color: var(--muted); }
.joined-field { display: grid; grid-template-columns: minmax(0, 1fr) 84px; }
.joined-field input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.joined-field select { margin-left: -1px; border-top-left-radius: 0; border-bottom-left-radius: 0; }
/* A count inside a control. */
.badge { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
/* Chips: single choices laid out as a row; the chosen one takes the active fill. */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { height: 28px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--control); background: var(--surface); font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; transition: background-color var(--t-hover) ease, color var(--t-hover) ease, border-color var(--t-hover) ease, transform var(--t-press) var(--ease-out); }
.chip:hover { color: var(--text); }
.chip:active { transform: scale(.97); }
.chip.is-on { background: var(--active); border-color: var(--active); color: var(--text); font-weight: 500; }
/* Accordion: opens to its content's height. */
.acc { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 320ms var(--ease-out); }
.acc > div { overflow: hidden; }
.acc.is-open { grid-template-rows: 1fr; }
@media (prefers-reduced-motion: reduce) { .acc { transition: none; } }
/* Pinned columns of any width: set --pin0 on the scroller. */
.grid-scroll .grid .pin-0 { width: var(--pin0, 48px); min-width: var(--pin0, 48px); max-width: var(--pin0, 48px); }
.grid-scroll .grid .pin-1 { left: var(--pin0, 48px); }

/* ── density: compact (default) sits near the live site's scale; data-heavy
   screens use Taste's dense setting. data-density="comfortable" is the airier
   first version, kept for comparison. ─────────────────────────────────── */
.grid th { height: var(--th-h, 42px); }
.grid-scroll .grid .group td { top: var(--th-h, 42px); }
[data-density="compact"] { --control-h: 30px; --row-h: 38px; --th-h: 34px; }
[data-density="compact"] body { font-size: 13px; }
[data-density="compact"] .app { grid-template-columns: 228px minmax(0, 1fr); }
[data-density="compact"] #side { padding: 14px 10px 12px; }
[data-density="compact"] .brand { padding-bottom: 16px; }
[data-density="compact"] .nav { gap: 16px; }
[data-density="compact"] .nav-item { height: 30px; font-size: 13px; gap: 9px; }
[data-density="compact"] .nav-label { padding-bottom: 4px; }
[data-density="compact"] #main { padding: 22px 28px 18px; }
[data-density="compact"] h1 { font-size: 21px; }
[data-density="compact"] .subtitle { font-size: 12px; }
[data-density="compact"] .tile { width: 32px; height: 32px; border-radius: 9px; }
[data-density="compact"] .tile .ico { width: 16px; height: 16px; }
[data-density="compact"] .head-title { gap: 12px; }
[data-density="compact"] #main > .head, [data-density="compact"] .head { margin-bottom: 18px; }
[data-density="compact"] .bar { margin-bottom: 12px; }
[data-density="compact"] .btn, [data-density="compact"] .ctl { font-size: 12.5px; padding-left: 11px; padding-right: 11px; }
[data-density="compact"] .btn-icon { padding: 0; }
[data-density="compact"] .seg button { font-size: 12.5px; padding: 0 12px; }
[data-density="compact"] .search input { font-size: 12.5px; }
[data-density="compact"] .card { border-radius: 14px; }
[data-density="compact"] .card-head { margin: 0 20px; padding: 14px 0 10px; }
[data-density="compact"] h2 { font-size: 14px; }
[data-density="compact"] .grid { font-size: 12.5px; }
[data-density="compact"] .grid .name { font-size: 13px; }
[data-density="compact"] .grid th { font-size: 11.5px; padding: 0 12px; }
[data-density="compact"] .grid td { padding: 0 12px; }
[data-density="compact"] .grid th:first-child, [data-density="compact"] .grid td:first-child { padding-left: 18px; }
[data-density="compact"] .group td { padding-top: 14px; padding-bottom: 6px; }
[data-density="compact"] .st, [data-density="compact"] .ms { font-size: 12.5px; }
[data-density="compact"] .ff { font-size: 11.5px; }
[data-density="compact"] .ff .pair > input, [data-density="compact"] .ff .joined-field > input { font-size: 12.5px; }
[data-density="compact"] .chip { height: 26px; font-size: 12px; }

/* ── reading aids for wide comparison tables (opt in with .grid.striped) ──
   Faint alternating rows, a darker band on subtotals, the benchmark column
   washed in the accent, and the hovered row and column picked out. Each row
   sets --row-bg, so pinned cells and tinted columns follow it. */
.grid.striped tbody tr { --row-bg: var(--surface); }
.grid.striped tbody tr.alt { --row-bg: var(--stripe); }
.grid.striped tbody tr.subtotal, .grid.striped tbody tr.total { --row-bg: var(--band); }
.grid.striped tbody tr:not(.group):hover { --row-bg: var(--hover); }
.grid.striped tbody tr:not(.group) td,
.grid.striped tbody tr:not(.group):hover td,
.grid-scroll .grid.striped tbody tr:not(.group) td.pin,
.grid-scroll .grid.striped tbody tr:not(.group):hover td.pin { background: var(--row-bg); transition: background-color 120ms ease; }
.grid.striped tbody tr:not(.group) td.col-avg,
.grid-scroll .grid.striped tbody tr:not(.group) td.col-avg,
.grid-scroll .grid.striped tbody tr:not(.group):hover td.col-avg { background: color-mix(in srgb, var(--accent) 6%, var(--row-bg)); }
.grid-scroll .grid.striped thead th.col-avg, .grid.striped thead th.col-avg { background: color-mix(in srgb, var(--accent) 6%, var(--surface)); color: var(--text); }
.grid.striped tbody tr:not(.group) td.col-hl,
.grid-scroll .grid.striped tbody tr:not(.group) td.col-hl,
.grid-scroll .grid.striped tbody tr:not(.group):hover td.col-hl { background: color-mix(in srgb, var(--text) 5%, var(--row-bg)); }
.grid.striped thead th.col-hl { color: var(--text); }

/* ── dropdowns (a2-select.js): every select in the app uses this menu, so
   no native menu ever appears. Styled to match Manage properties. ───── */
.dd { position: relative; display: inline-flex; }
.ff .dd, .dd.full { display: flex; width: 100%; }
.dd > .dd-trigger { width: 100%; justify-content: space-between; min-width: 0; }
.dd-val { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.dd-val.is-placeholder { color: var(--faint); }
.dd-trigger[aria-expanded="true"] { border-color: var(--text); }
.dd-trigger .ico-sm { transition: transform var(--t-ui) var(--ease-out); }
.dd-trigger[aria-expanded="true"] .ico-sm { transform: rotate(180deg); }
.menu.dd-menu { left: 0; right: auto; min-width: max(100%, 180px); transform-origin: top left; padding: 6px; max-height: 340px; overflow: auto; display: grid; gap: 1px; align-content: start; }
.dd-menu .dd-opt { display: flex; align-items: center; justify-content: space-between; gap: 14px; width: 100%; padding: 8px 10px; border: 0; background: none; border-radius: 6px; font-size: 13px; font-weight: 400; color: var(--text); text-align: left; white-space: nowrap; }
.dd-menu .dd-opt:hover, .dd-menu .dd-opt:focus-visible { background: var(--hover); outline: none; }
.dd-menu .dd-opt .ico { opacity: 0; color: var(--text); }
.dd-menu .dd-opt[aria-selected="true"] { font-weight: 500; }
.dd-menu .dd-opt[aria-selected="true"] .ico { opacity: 1; }
.dd-menu .dd-opt small { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 6px; }
.menu.dd-multi { min-width: max(100%, 300px); padding: 8px; }
.dd-search { max-width: none; margin-bottom: 4px; }
.dd-tools { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 6px; font-size: 12px; color: var(--muted); }
.dd-tools span:last-child { display: inline-flex; gap: 12px; }
.dd-menu .dd-tools button { display: inline; padding: 0; border: 0; background: none; font-size: 12px; font-weight: 500; color: var(--accent); border-radius: 0; }
.dd-menu .dd-tools button:hover { text-decoration: underline; background: none; }
.dd-list { display: grid; max-height: 260px; overflow: auto; }
.dd-row { padding: 7px 6px; border-radius: 6px; font-size: 13px; }
.dd-row:hover, .dd-row:focus-within { background: var(--hover); }
.dd-row span { flex: 1; }
.dd-row em { font-style: normal; font-size: 12px; color: var(--muted); }
.dd-row[hidden] { display: none; }
/* a dropdown joined to a field (Near address + radius) */
.joined-field .dd > .dd-trigger { margin-left: -1px; border-top-left-radius: 0; border-bottom-left-radius: 0; }
/* Once an accordion has finished opening, menus inside it may hang out of it. */
.acc.is-open.is-settled > div { overflow: visible; }
.setup-head { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.setup-head[aria-expanded="false"] { border-radius: inherit; }
/* A dropdown joined to its action (snapshot picker + Freeze). */
.joined > .dd > .ctl { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.joined > .dd + .ctl { margin-left: -1px; border-top-left-radius: 0; border-bottom-left-radius: 0; }

/* ── collapsible sidebar (a2-nav.js): folds to a 64px icon rail ───────── */
.nav-toggle { width: 100%; border: 0; background: none; text-align: left; cursor: pointer; font: inherit; }
@media (min-width: 901px) {
  .app { transition: grid-template-columns var(--t-ui) var(--ease-in-out); }
  [data-nav="collapsed"] .app { grid-template-columns: 64px minmax(0, 1fr); }
  [data-nav="collapsed"] #side { padding-left: 10px; padding-right: 10px; }
  [data-nav="collapsed"] .brand { padding-left: 8px; padding-right: 0; }
  [data-nav="collapsed"] .brand-txt,
  [data-nav="collapsed"] #side .nav-item span,
  [data-nav="collapsed"] .user div { display: none; }
  [data-nav="collapsed"] .nav-label { font-size: 0; height: 1px; padding: 0; margin: 2px 10px 6px; background: var(--rule); }
  [data-nav="collapsed"] #side .nav-item { justify-content: center; padding: 0; width: 44px; }
  [data-nav="collapsed"] .user { justify-content: center; padding-left: 0; padding-right: 0; }
  [data-nav="collapsed"] .nav-toggle .ico { transform: scaleX(-1); }
}
@media (prefers-reduced-motion: reduce) { .app { transition: none; } }

/* ── Paper (direction A3): the reduction pass in neutral, with a serif voice ── */
:root { --border: #ededed; --rule: #f2f2f2; --control: #e0e0e0; --radius-card: 20px; --radius-control: 999px; }
[data-density="compact"] .card { border-radius: 18px; }
.card { border-color: transparent; box-shadow: 0 1px 2px rgba(0, 0, 0, .035), 0 6px 20px -8px rgba(0, 0, 0, .07); }
.card-head { border-bottom: 0; }
.well { border-radius: 16px; }
/* Type: Bricolage carries the title and the big figures; Geist does the work. */
h1 { font-family: var(--font-display); font-weight: 500; font-size: 30px; letter-spacing: -0.02em; line-height: 1.1; }
[data-density="compact"] h1 { font-size: 26px; }
.subtitle { font-size: 13.5px; }
.head-title { gap: 16px; align-items: center; }
.tile { background: var(--well); color: var(--text); border-radius: 12px; }
#main > .head, .head { margin-bottom: 22px; }
h2 { font-family: var(--font-display); font-weight: 500; font-size: 17px; letter-spacing: -0.01em; }
[data-density="compact"] h2 { font-size: 16px; }
/* Brand: the ring mark, and nothing else orange in the chrome. */
.brand .tile { background: transparent; border: 2.5px solid var(--brand); border-radius: 50%; width: 22px; height: 22px; margin: 3px; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand) 22%, transparent); }
.brand .tile .ico { display: none; }
/* An admin replied to one of this person's reports: a small dot in the quiet accent on the ring (a3/nav.js). */
.brand .tile { position: relative; }
.brand .tile.has-unread::after { content: ""; position: absolute; top: -3px; right: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px #0d0b0a; }
.nav-item { border-radius: 999px; padding: 0 12px; }
.nav-item.is-active { outline: 0; background: var(--active); }
.nav-item.is-active .ico { color: var(--text); }
.user { border-top: 0; }
/* Table: header is a change of type; rows share hairlines. */
.grid th { border-bottom: 0; height: 44px; }
[data-density="compact"] .grid th { height: 38px; }
.group td { border-bottom: 0; }
.group-in b { font-family: var(--font-display); font-weight: 500; font-size: 14px; }
.grid tbody tr:not(.group):hover td { background: var(--well); }
/* Controls: filled pills, quiet until touched. */
.ctl, .search, .btn-secondary, .btn-danger { background: var(--well); border-color: transparent; }
.ctl:hover, .search:hover, .btn-secondary:hover { background: var(--hover); }
.ctl.is-on { background: var(--active); border-color: transparent; }
.search:focus-within { background: var(--surface); border-color: var(--control); box-shadow: 0 0 0 3px var(--active); }
.joined .ctl + .ctl { margin-left: 0; box-shadow: inset 1px 0 0 var(--border); }
.seg { background: var(--well); padding: 3px; }
.seg::before, .seg button { border-radius: 999px; }
.seg::before { box-shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 0 0 1px rgba(0, 0, 0, .04); }
.btn-sm, .menu button { border-radius: 999px; }
.menu button { padding-left: 14px; padding-right: 14px; }
.field input, .field select, .field textarea { background: var(--well); border-color: transparent; border-radius: 12px; }
.field input:focus, .field select:focus, .field textarea:focus { background: var(--surface); border-color: var(--control); box-shadow: 0 0 0 3px var(--active); }
.float, .menu { border-radius: 16px; border-color: transparent; }
/* KPI row: the number is the hero. Serif figure, Geist label, a sparkline in ink. */
.kpis { display: none; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
[data-density="compact"] .kpis { margin-bottom: 14px; }
.kpi { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 16px 20px 14px; min-width: 0; }
[data-density="compact"] .kpi { padding: 14px 18px 12px; }
.kpi .k-label { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; white-space: nowrap; }
.kpi .k-num { font-family: var(--font-display); font-weight: 500; font-size: 30px; line-height: 1; letter-spacing: -0.03em; font-variant-numeric: tabular-nums lining-nums; }
.kpi .k-num small { font-family: var(--font); font-size: 13px; color: var(--muted); margin-left: 6px; letter-spacing: 0; }
.kpi .k-delta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.kpi .k-delta.up { color: var(--positive); }
.kpi .k-delta.down { color: var(--negative); }
.kpi svg { width: 72px; height: 28px; flex: none; overflow: visible; }
.kpi svg path { fill: none; stroke: var(--text); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.kpi svg circle { fill: var(--text); }
/* The AI provenance mark: the only other orange on the page. */
.ai-mark { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-left: 6px; vertical-align: 0; border: 1.5px solid var(--brand); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand) 22%, transparent); }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ── Paper (A3), framed: the signature ───────────────────────────────── */
/* The sidebar is the sign-in's warm black with the ring alive on it; the main
   area is one white sheet floating on the paper. The KPI row is one ledger
   strip, not four boxes. Contrast comes from the two materials meeting. */
body { background: var(--ground); }
:is(#side, .rail) {
  --text: #f4ede7; --muted: #a39890; --faint: #8a7f77;
  --surface: rgba(255, 255, 255, .09); --hover: rgba(255, 255, 255, .06); --active: rgba(255, 255, 255, .11);
  --rule: rgba(255, 255, 255, .08); --border: rgba(255, 255, 255, .10);
  background: #0d0b0a; color: var(--text);
}
:is(#side, .rail) .nav-item { opacity: 1; color: var(--muted); }
:is(#side, .rail) .nav-item:hover { color: var(--text); background: var(--hover); }
:is(#side, .rail) .nav-item.is-active { color: var(--text); background: var(--active); }
:is(#side, .rail) .nav-item.is-active .ico { color: var(--text); }
:is(#side, .rail) .nav-item .ico { color: var(--faint); }
:is(#side, .rail) .nav-item:hover .ico { color: var(--muted); }
:is(#side, .rail) .nav-label { color: var(--faint); }
:is(#side, .rail) .avatar { background: var(--surface); color: var(--text); }
:is(#side, .rail) .brand .tile { border-color: var(--brand); box-shadow: 0 0 12px 1px color-mix(in srgb, var(--brand) 38%, transparent), inset 0 0 4px color-mix(in srgb, var(--brand) 55%, transparent); }
:is(#side, .rail) .brand-txt b { color: var(--text); }
:is(#side, .rail) .brand-txt span { color: var(--muted); }
[data-nav="collapsed"] .nav-label { background: var(--rule); }
/* The sheet. */
#main { margin: 10px 10px 10px 0; background: var(--surface); border-radius: 24px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 10px 30px -14px rgba(0, 0, 0, .10), inset 0 1px 0 #ffffff; padding: 30px 34px 24px; }
[data-density="compact"] #main { padding: 26px 30px 20px; }
.app { background: var(--ground); }
/* On the sheet, a card is a tone or a hairline, never a shadow. */
#main .card { box-shadow: none; border: 1px solid var(--border); }
#main .card.well-card { background: var(--well); border-color: transparent; }
/* KPI ledger strip: one container, hairlines between the figures. */
.kpis { gap: 0; border: 1px solid var(--border); border-radius: 18px; overflow: hidden; background: var(--surface); }
.kpi.card { border: 0; border-left: 1px solid var(--border); border-radius: 0; box-shadow: none; padding: 18px 22px 16px; }
.kpi.card:first-child { border-left: 0; }
.kpi .k-num { font-size: 32px; }
/* Title scale: a touch larger on the sheet. */
h1 { font-size: 32px; }
[data-density="compact"] h1 { font-size: 28px; }
.head-title .tile { display: none; }  /* the sheet's title stands alone; the icon lives in the nav */
.head-title { gap: 0; }
@media (max-width: 900px) { #main { margin: 0; border-radius: 0; } }
/* The frame never scrolls. The rail and the sheet fill the window exactly, and
   a long page scrolls inside the sheet. (When the window scrolled, a tall page
   ran past the sheet's bottom edge onto the paper and slid the rail away.)
   Scripts that scroll the page use #main, not window. */
.app { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }
#side { height: 100%; }
#main { min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; }

/* ── tablet and phone: the rail becomes a top bar ────────────────────── */
/* The brand row stays as a 52px bar over the sheet; the menu button opens the
   nav and its foot (Admin, Feedback, the user menu) over the whole window, and
   a3/nav.js toggles html.nav-open. Collapse is a wide-screen idea only. */
@media (max-width: 900px) {
  .app, [data-density] .app, [data-nav] .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  #side, [data-density] #side { height: auto; padding: 0 max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px)); }
  .brand, [data-density] .brand { height: 52px; padding: 0; flex: none; }
  .menu-btn { display: inline-flex; color: var(--text); border-radius: 999px; cursor: pointer; }
  .menu-btn:hover { background: var(--hover); }
  #side .nav, #side .nav-foot { display: none; }
  .nav-toggle { display: none; }
  [data-nav="collapsed"] .nav-label { background: none; }
  html.nav-open #side { height: 100vh; height: 100dvh; padding-bottom: max(14px, env(safe-area-inset-bottom, 0px)); }
  html.nav-open #side .nav { display: flex; padding-top: 8px; }
  html.nav-open #side .nav-foot { display: grid; }
  html.nav-open #main { display: none; }
  #main, [data-density] #main { padding: 22px max(20px, env(safe-area-inset-right, 0px)) 28px max(20px, env(safe-area-inset-left, 0px)); }
}
@media (max-width: 640px) {
  #main, [data-density] #main { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
}

/* ── user menu (a2-nav.js turns the user row into a button) ─────────── */
.user-wrap { display: block; position: relative; margin-top: 8px; }
button.user { width: 100%; margin-top: 0; background: none; border: 0; border-top: 1px solid var(--rule); border-radius: 0; text-align: left; cursor: pointer; color: inherit; font: inherit; transition: background-color var(--t-hover) ease; }
button.user:hover { background: var(--hover); }
button.user .ico-chev { margin-left: auto; color: var(--muted); }
button.user[aria-expanded="true"] .ico-chev { transform: rotate(180deg); }
.user-menu { top: auto; bottom: calc(100% + 6px); left: 0; right: 0; min-width: 0; transform-origin: bottom left; }
.um-head b, .um-head span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.um-head { display: grid; gap: 1px; padding: 8px 10px 10px; margin-bottom: 4px; border-bottom: 1px solid var(--rule); font-size: 13px; }
.um-head b { font-weight: 500; }
.um-head span { font-size: 12px; color: var(--muted); }
[data-nav="collapsed"] button.user .ico-chev { display: none; }
[data-nav="collapsed"] .user-menu { left: 0; right: auto; width: 228px; }
:is(#side, .rail) button.user { border-top: 0; border-radius: 999px; padding-top: 8px; padding-bottom: 8px; }
:is(#side, .rail) .menu { background: #1a1715; --surface: #1a1715; border: 1px solid rgba(255, 255, 255, .10); box-shadow: 0 12px 32px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .4); }
:is(#side, .rail) .menu button:hover { background: rgba(255, 255, 255, .07); }
:is(#side, .rail) .menu button span { color: var(--muted); }
/* A rail sample on the Components sheet. */
.rail { display: flex; flex-direction: column; width: 228px; padding: 14px 10px 12px; border-radius: 16px; background: var(--ground); }
.rail .nav { gap: 14px; }
.rail .nav-foot { padding-top: 12px; }

/* ── background-job toasts (jobs.js, ported from sidebar.js) ─────────── */
#bw-toast-host { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; max-width: min(560px, calc(100vw - 32px)); }
.bw-toast { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 16px; border-radius: 10px; background: var(--primary); color: var(--primary-ink); font-size: 13px; box-shadow: 0 12px 32px rgba(0, 0, 0, .18); }
.bw-toast.error { background: var(--negative); }
.bw-toast-action { color: inherit; font-weight: 500; text-decoration: underline; text-underline-offset: 3px; white-space: nowrap; }
.bw-toast-close { background: none; border: 0; color: inherit; opacity: .7; font-size: 18px; line-height: 1; padding: 0 2px; }
.bw-toast-close:hover { opacity: 1; }

/* ── arriving from the sign-in: the one entrance the system allows ────── */
/* The sign-in fades to paper before it navigates (a3/auth.js); the next page
   fades in from the same paper, so the hand-off reads as one motion. Set by
   base.html from a sessionStorage flag, once; never on an ordinary load. */
html.arriving .app { animation: a3-arrive 360ms var(--ease-out) both; }
@keyframes a3-arrive { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { html.arriving .app { animation: none; } }
