/* Casely design tokens — the single place colours live.
 *
 * Every template used to carry its own inline :root block: 15 copies, which
 * had already drifted (12 on #6c63ff, deadstock on #5d7ab8, reconcile on
 * #5b7fff). Changing the palette meant editing 15 files and missing some.
 *
 * Templates link this file and DON'T declare :root. A template that genuinely
 * needs a different value overrides just that variable in its own <style>,
 * which wins because it comes after this link.
 *
 * Cache: linked with ?v=N — bump that when you edit this file, or browsers
 * will serve the old palette.
 *
 * ── Themes ──────────────────────────────────────────────────────────────
 *   :root             the Casely light UI — now the default everywhere
 *   html.theme-light  kept as an explicit alias; the partner portal sets it
 *   html.theme-dark   the previous dark UI, for anything not yet converted
 *
 * Brand reference (getcasely.com): primary #5773be, ink #262735, body grey
 * #6a6c77, neutrals #e1e5ee / #f2f2f8 / #eff1f7. Brand face is Graphik, not
 * licensed for this app; Inter is the approved substitute.
 */

:root,
html.theme-light {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --border: #e1e5ee;
  --accent: #5773be;
  --accent-soft: rgba(87, 115, 190, .12);
  --accent-ink: #3f5794;
  /* darkened for contrast on white — the dark-UI brights glow here */
  --danger: #c0392b;
  --warn: #b9741f;
  --ok: #2f8659;
  --text: #262735;
  --muted: #6a6c77;
  --shadow: 0 1px 2px rgba(38, 39, 53, .06), 0 8px 24px rgba(38, 39, 53, .06);
  --font: 'Inter', -apple-system, 'Segoe UI', system-ui, sans-serif;
}

/* Escape hatch: add class="theme-dark" to <html> to put a page back on the
 * old palette if something in it hasn't been converted yet. */
html.theme-dark {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2d3a;
  --accent: #6c63ff;
  --accent-soft: rgba(108, 99, 255, .14);
  --accent-ink: #a8a2ff;
  --danger: #e05252;
  --warn: #e0943a;
  --ok: #4caf7d;
  --text: #e8eaf0;
  --muted: #7b7f96;
  --shadow: 0 14px 40px rgba(0, 0, 0, .5);
  --font: 'Inter', system-ui, sans-serif;
}

/* ── Dark-UI idioms that break on white ──────────────────────────────────
 * These were written into individual templates when the whole app was dark.
 * Correcting them centrally means each template doesn't need touching. */

/* Popovers/modals used heavy black drop shadows for separation. */
html:not(.theme-dark) .modal,
html:not(.theme-dark) [class*="-pop"],
html:not(.theme-dark) [class*="dropdown"] { box-shadow: var(--shadow); }

/* Modal scrims were near-opaque black, which on a light page reads as a
 * blackout rather than a dim. */
html:not(.theme-dark) .modal-bg { background: rgba(38, 39, 53, .38) !important; }

/* Inputs were sunken wells (background:var(--bg)); on white they need to be
 * the surface with a visible edge instead. */
html:not(.theme-dark) input[type=text],
html:not(.theme-dark) input[type=password],
html:not(.theme-dark) input[type=date],
html:not(.theme-dark) input[type=number],
html:not(.theme-dark) input[type=search],
html:not(.theme-dark) textarea,
html:not(.theme-dark) select { background: var(--surface); color: var(--text); }

/* Scrollbars inherit the OS light styling; nothing to do, but table headers
 * that relied on a dark surface for stickiness need an opaque background. */
html:not(.theme-dark) thead th { background: var(--surface); }

/* A handful of buttons were never given a class and fell back to the browser
 * default (the Sync buttons on Defects, for instance). That was always the
 * case; it just reads as unfinished now that the page is light. Scoped to
 * :not([class]) so nothing already styled is touched. */
html:not(.theme-dark) button:not([class]) {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
html:not(.theme-dark) button:not([class]):hover { border-color: var(--accent); }
html:not(.theme-dark) button:not([class]):disabled { opacity: .5; cursor: default; }

/* Tinted chrome — pills, chips, badges, cards, rows, hovers — was drawn as a
 * white film over a dark surface (rgba(255,255,255,.015–.14), ~20 rules). On
 * white that film is invisible, so these render as bare text with no chrome
 * at all and every hover state is a no-op. The code looks correct, which is
 * why it survived the light conversion: on Defects, gCatPill() has been
 * emitting pills that draw as plain grey words since the switch.
 *
 * On a light surface the equivalent lift is a darkening, so they map onto the
 * neutral scale. --n-100 is the resting tint: it holds --muted text at 4.7:1,
 * which --n-150 does not (4.4:1, under AA). --n-150 is therefore reserved for
 * states that carry the darker --text, or that have to out-read a resting
 * twin sitting next to them. */

/* Resting chrome: the tint IS the object. */
html:not(.theme-dark) .reason-pill,
html:not(.theme-dark) .badge-neutral,
html:not(.theme-dark) .sev-chip,
html:not(.theme-dark) .ai-row .row-count,
html:not(.theme-dark) .alert-card,
html:not(.theme-dark) .alert-card .ac-action,
html:not(.theme-dark) tr.rs-detail > td { background: var(--n-100); }

/* Seats the sub-tab row under the primary tabs. Without it the two rows are
 * the same white with the same active underline, and the levels read as one. */
html:not(.theme-dark) .tab-bar-sub { background: var(--n-100); }

/* .ai-row and .ai-sum-chip are the exception: they had a resting tint AND a
 * hover tint. Giving both --n-100 would flatten the hover, and stepping hover
 * to --n-150 would put their --muted sub-text (.row-cat, .row-age, .lbl) at
 * 4.4:1. So the resting tint goes instead — on white their existing border
 * already separates them from the card — and --n-100 becomes the hover. */
html:not(.theme-dark) .ai-row,
html:not(.theme-dark) .ai-sum-chip { background: transparent; }

/* Hover. */
html:not(.theme-dark) .date-preset:hover,
html:not(.theme-dark) .cb-action-btn:hover,
html:not(.theme-dark) .status-seg button:hover,
html:not(.theme-dark) tr.rs-row:hover td,
html:not(.theme-dark) .ai-row:hover,
html:not(.theme-dark) .ai-sum-chip:hover { background: var(--n-100); }

/* Active states last, so they win over :hover at equal specificity. The two
 * on --n-150 both set color:var(--text) themselves, so they stay at 12:1.
 * .ai-sum-chip.active keeps --muted in its label, so it leans on the accent
 * border it already sets rather than a darker fill. */
html:not(.theme-dark) .sev-chip.active,
html:not(.theme-dark) .status-seg button.on { background: var(--n-150); }
html:not(.theme-dark) .ai-sum-chip.active { background: var(--n-100); }

/* ══ App shell: sidebar + top bar + command palette ═══════════════════════
 * Added 2026-08-04, replacing the horizontal tab bar that was hand-copied
 * into 11 templates (and had drifted — deadstock was missing four links).
 * All nav markup now comes from _shell.html, which renders from NAV in
 * app.py. Token values below are copied from the ops dashboard rather than
 * shared as a package, per the brief.
 */
:root {
  --n-100: #f2f4f8;          /* item hover */
  --n-150: #e8ecf3;          /* item active */
  --ui-font-size: 13px;      /* base UI text */
  --ui-radius: 8px;
  --ui-control-h: 28px;
  --sb-w: 240px;             /* flipped to 56px by body.sb-collapsed */
  --tb-h: 48px;
}
body.sb-collapsed { --sb-w: 56px; }

/* ── sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sb-w); z-index: 60;
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
  font-size: var(--ui-font-size);
  transition: width .12s ease;
}
.sb-head { padding: 12px 8px 4px; }
.sb-brand {
  display: flex; align-items: center; gap: 8px; width: 100%;
  height: 32px; padding: 0 8px; border: 0; border-radius: var(--ui-radius);
  background: transparent; color: var(--text); cursor: pointer;
  font: 600 var(--ui-font-size)/1 var(--font); text-align: left;
}
.sb-brand { cursor: default; }
/* Square sun mark (cropped from the full lockup — the wordmark was
 * illegible once scaled into an 18px slot). */
.sb-mark { width: 20px; height: 20px; object-fit: contain; flex: 0 0 auto; }
.sb-brand-label { flex: 1; white-space: nowrap; overflow: hidden; }
.sb-user-menu a {
  display: flex; align-items: center; gap: 8px; height: var(--ui-control-h);
  padding: 0 8px; border-radius: 6px; color: var(--text); text-decoration: none;
}
.sb-user-menu a:hover { background: var(--n-100); }

.sb-nav { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.sb-group-label {
  margin: 20px 0 4px; padding: 0 8px;
  font-size: 11px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted); white-space: nowrap;
}
.sb-item {
  position: relative; display: flex; align-items: center; gap: 10px;
  height: 32px; padding: 0 8px; margin: 1px 0;
  border: 0; width: 100%; background: transparent; cursor: pointer;
  border-radius: var(--ui-radius); color: var(--muted);
  font: 400 var(--ui-font-size)/1 var(--font); text-decoration: none;
  white-space: nowrap;
}
.sb-item:hover { background: var(--n-100); color: var(--text); text-decoration: none; }
.sb-item.active { background: var(--n-150); color: var(--text); font-weight: 500; }
.sb-item svg, .sb-avatar { flex: 0 0 auto; }
.sb-label { overflow: hidden; text-overflow: ellipsis; }

.sb-foot { padding: 8px; border-top: 1px solid var(--border); }
.sb-user-wrap { position: relative; }
.sb-avatar {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-ink);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 600;
}
.sb-user-menu {
  position: absolute; bottom: calc(100% + 4px); left: 0; right: 0; z-index: 5;
  padding: 4px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--ui-radius);
  box-shadow: var(--shadow);
}
body.sb-collapsed .sb-user-menu { left: 0; right: auto; width: 150px; }

/* Collapsed rail: icons only, labels become hover tooltips. */
body.sb-collapsed .sb-label,
body.sb-collapsed .sb-brand-label,
body.sb-collapsed .sb-group-label { display: none; }
body.sb-collapsed .sb-group-label { display: block; height: 1px; margin: 12px 8px;
  padding: 0; background: var(--border); overflow: hidden; text-indent: -999px; }
body.sb-collapsed .sb-item { justify-content: center; padding: 0; }
body.sb-collapsed .sb-brand { justify-content: center; padding: 0; }
body.sb-collapsed .sb-item[data-tip]:hover::after {
  content: attr(data-tip); position: absolute; left: calc(100% + 8px); top: 50%;
  transform: translateY(-50%); z-index: 70;
  background: var(--text); color: var(--surface);
  padding: 5px 8px; border-radius: 6px; font-size: 12px; white-space: nowrap;
  box-shadow: var(--shadow); pointer-events: none;
}

/* ── top bar ─────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--tb-h);
  display: flex; align-items: center; gap: 12px; padding: 0 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.tb-fresh { font-size: 12px; color: var(--muted); }
.tb-title { font-size: 14px; font-weight: 600; color: var(--text); }
.tb-sep, .tb-crumb { color: var(--muted); font-weight: 400; margin-left: 6px; }
.tb-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.tb-sync { display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted); }
/* An author `display` beats the UA rule for [hidden], so the attribute alone
 * would not hide this — idle must render nothing at all. */
.tb-sync[hidden] { display: none; }
.tb-spinner {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: tb-spin .7s linear infinite;
}
@keyframes tb-spin { to { transform: rotate(360deg); } }
/* Checkbox/radio sizing. Browser defaults render ~13-16px with uneven
 * built-in margins, which read as oversized next to this app's 11-13px
 * labels. Sized once here so every filter chip and list agrees. */
html body input[type="checkbox"],
html body input[type="radio"] {
  width: 14px; height: 14px; flex: 0 0 auto;
  accent-color: var(--accent); cursor: pointer;
}

/* Inline spinner for in-page "Loading…" placeholders. The shell adds one to
 * any placeholder it finds, so a slow table reads as busy rather than frozen.
 * Shares the tb-spin keyframes above. */
.spin {
  display: inline-block; width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: tb-spin .7s linear infinite;
  vertical-align: -2px; margin-right: 7px;
}
/* Clicking a nav item dims it while the next page is fetched. */
.sb-item.pending { opacity: .55; }

.tb-burger { display: none; background: transparent; border: 0; cursor: pointer;
  color: var(--muted); padding: 4px; border-radius: 6px; }
.tb-burger:hover { background: var(--n-100); color: var(--text); }

/* Page content sits beside the rail. The offset is padding on <body> rather
 * than a margin on a content wrapper: dashboard.html has no wrapper at all
 * (its sections are direct body children), and the admin token banner sits
 * outside any container too. `html body` outranks the plain `body` rule each
 * template declares in its own <style>, which loads after this file. */
html body { padding-left: var(--sb-w); transition: padding-left .12s ease; }
html body > .container, html body > .wrap, html body > main, html body > .page {
  padding: 24px; max-width: none; margin-left: 0;
}

/* ── command palette ─────────────────────────────────────────────────── */
.cmdk-bg {
  position: fixed; inset: 0; z-index: 9500;
  background: rgba(38, 39, 53, .38);
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 14vh;
}
.cmdk-bg[hidden] { display: none; }
.cmdk {
  width: min(520px, 92vw); background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); overflow: hidden;
}
.cmdk-input-row {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--border); color: var(--muted);
}
.cmdk-input-row input {
  flex: 1; border: 0 !important; background: transparent !important;
  font-size: 14px; color: var(--text); outline: none; padding: 0 !important;
}
.cmdk-input-row kbd {
  font-size: 10px; color: var(--muted); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 5px; font-family: var(--font);
}
.cmdk-list { max-height: 300px; overflow-y: auto; padding: 6px; }
.cmdk-item {
  display: flex; align-items: center; height: 32px; padding: 0 10px;
  border-radius: 6px; color: var(--text); text-decoration: none;
  font-size: var(--ui-font-size);
}
.cmdk-item.sel, .cmdk-item:hover { background: var(--n-100); text-decoration: none; }
.cmdk-empty { padding: 14px 10px; color: var(--muted); font-size: var(--ui-font-size); }

/* ── responsive: sidebar becomes an overlay drawer ───────────────────── */
.sb-scrim { position: fixed; inset: 0; z-index: 55; background: rgba(38,39,53,.38); }
.sb-scrim[hidden] { display: none; }
@media (max-width: 1023px) {
  .sidebar { transform: translateX(-100%); transition: transform .16s ease; width: 240px; }
  .sidebar.open { transform: none; }
  html body { padding-left: 0; }
  .tb-burger { display: inline-flex; }
  /* The rail toggle is meaningless in drawer mode. */
  .sb-collapse { display: none; }
}
@media (min-width: 1024px) { .sb-scrim { display: none; } }

/* ── shell interop with pre-existing fixed/overlay elements ──────────────
 * Introducing a fixed 240px rail (z-index 60) changed the stacking context
 * these were written against. Selectors are `html body …` so they outrank
 * each template's own inline <style>, which loads after this file.
 */

/* Admin's user modal was z-index 50 — the rail painted over its scrim and
 * stayed clickable behind the dialog. */
html body .modal-bg { z-index: 200; }

/* The MT3 audit's selection bar is fixed to the bottom at left:0, so it ran
 * under the rail and covered the sidebar footer (user menu + collapse). Pin
 * it to the content column instead; full width again once the rail becomes
 * an overlay drawer. */
html body #action-bar { left: var(--sb-w); transition: left .12s ease; }
@media (max-width: 1023px) { html body #action-bar { left: 0; } }
