/* ============================================================
   Nanocrew AIO — Shared Design System
   Brief 01: Shell + Engagements
   ============================================================ */

/* ---------- Tokens (Light) ---------- */
:root {
  --green-900: #14211B;
  --green-800: #1E3028;
  --green-700: #2A4237;
  --green-600: #3A5648;
  --gold-500: #C9A84C;
  --gold-600: #B08F36;
  --gold-400: #D6BB6F;
  --cream-100: #F5F3EE;
  --cream-200: #EDEAE1;
  --cream-50:  #FAF8F4;
  /* 2026-05-21 (P2-1): scale-step tokens referenced across ~35 files but
     previously undefined → financial red/gold colour-coding silently vanished.
     Defined here (light) + in the dark block below so they flip with theme. */
  --gold-700: #8A6E22;
  --gold-200: #EAD9A0;
  --red-500:  #B03A2E;
  --red-700:  #8E2C22;
  --green-200: #BFD8C4;
  --green-100: #DCEAE0;
  --ink:      #1E3028;
  --ink-2:    #5A5F5B;
  --surface-2: var(--cream-50);
  --surface: #FFFFFF;
  --text-primary: #1E3028;
  --text-secondary: #5A5F5B;
  --text-muted: #8A8F8C;
  --success: #4C8C4A;
  --warning: #D79924;
  --danger: #B03A2E;
  --info: #3F6E94;
  /* Semantic alias triplets — used heavily across pages as
     --{state}-fg (text/icon on neutral bg), --{state}-bg (tinted panel),
     --{state}-bg-strong (heavier tint for status pills/banners),
     --warning-border (pill outline). Defining them here means pages
     that say `color: var(--success-fg)` get the right hue in BOTH themes
     instead of falling through to nothing (= inherited dark text).
     Light theme: foreground = base hue (good contrast on white surface).
     Background tints are sourced via color-mix off the surface so they
     read as pale-tinted cards on light, dark-tinted cards in dark mode. */
  --success-fg:  #4C8C4A;
  --success-bg:  color-mix(in oklab, #4C8C4A 12%, var(--surface));
  --success-bg-strong: color-mix(in oklab, #4C8C4A 22%, var(--surface));
  --warning-fg:  #B07515;
  --warning-bg:  color-mix(in oklab, #D79924 14%, var(--surface));
  --warning-bg-strong: color-mix(in oklab, #D79924 28%, var(--surface));
  --warning-border: color-mix(in oklab, #D79924 45%, var(--surface));
  --danger-fg:   #B03A2E;
  --danger-bg:   color-mix(in oklab, #B03A2E 10%, var(--surface));
  --danger-bg-strong: color-mix(in oklab, #B03A2E 22%, var(--surface));
  --info-fg:     #3F6E94;
  --info-bg:     color-mix(in oklab, #3F6E94 12%, var(--surface));
  --info-bg-strong: color-mix(in oklab, #3F6E94 22%, var(--surface));
  --border: rgba(30, 48, 40, 0.10);
  --border-strong: rgba(30, 48, 40, 0.18);
  --border-gold: rgba(201, 168, 76, 0.35);
  --shadow-sm: 0 1px 2px rgba(30, 48, 40, 0.04), 0 2px 4px rgba(30, 48, 40, 0.04);
  --shadow-md: 0 2px 6px rgba(30, 48, 40, 0.05), 0 8px 24px rgba(30, 48, 40, 0.06);
  --shadow-lg: 0 8px 16px rgba(30, 48, 40, 0.08), 0 24px 48px rgba(30, 48, 40, 0.10);

  --radius-card: 14px;
  --radius-input: 10px;
  --radius-btn: 8px;
  --radius-pill: 999px;

  --glass-bg: rgba(255, 255, 255, 0.68);
  --glass-bg-strong: rgba(255, 255, 255, 0.80);
  --glass-blur: blur(20px) saturate(140%);

  --sidebar-w: 260px;
  --sidebar-w-collapsed: 64px;
  --topbar-h: 56px;

  --density-row: 44px;
  --density-pad: 16px;

  /* ---- Defensive aliases ----
     Some pages reference Tailwind-style token names (--panel, --muted,
     --border-soft, --input-bg, --gold) that historically had no definition,
     so they fell through to bright Tailwind hex fallbacks (#fff, #fafafa,
     #f8fafc, #6b7280) which rendered as cream slabs in dark mode. Alias
     them here so they always pick up the active theme. */
  --panel: var(--surface);
  --panel-soft: var(--cream-50);
  --muted: var(--text-secondary);
  --border-soft: var(--border);
  --input-bg: var(--surface);
  --gold: var(--gold-500);
  /* Hero/dark-green surfaces (e.g. dashboard hero) need light text in BOTH
     themes. Don't bind to --surface or --cream-* (those flip). */
  --ink-on-dark: #F5F3EE;

  /* ---- Audit 2026-05-05: missing tokens used across 40+ pages ----
     These were referenced via var(...) in dozens of PAGE_CSS blocks and
     inline styles without a definition, falling through to `initial` —
     producing transparent backgrounds, invisible text in dark mode,
     unbordered chips, and silent layout failures. Defining them here
     fixes ~50 findings without touching the consumer files. */
  --green: var(--green-800);
  --cream: var(--cream-100);
  --text: var(--text-primary);

  /* Gold semantic triplet (parallel to --success-/--warning-/--danger-/--info-). */
  --gold-fg: var(--gold-600);
  --gold-bg: color-mix(in oklab, var(--gold-500) 12%, var(--surface));
  --gold-bg-strong: color-mix(in oklab, var(--gold-500) 22%, var(--surface));
  --gold-border: var(--border-gold);

  /* Active-state primaries (used by tabs, chips, period selectors). */
  --primary: var(--green-800);
  --primary-contrast: var(--gold-400);

  /* Table-head background — used by 17+ list pages via .ltab th. */
  --table-head-bg: var(--cream-50);

  /* Bordered status-chip outlines (paired with --*-bg + --*-fg). */
  --success-border: color-mix(in oklab, var(--success) 35%, transparent);
  --danger-border:  color-mix(in oklab, var(--danger)  35%, transparent);
  --info-border:    color-mix(in oklab, var(--info)    35%, transparent);

  /* Z-index scale — replaces ad-hoc 50/100/.../99999 values. */
  --z-topbar:    50;
  --z-sticky:    60;
  --z-dropdown:  100;
  --z-modal:     200;
  --z-drawer:    300;
  --z-toast:     400;
  --z-popover:   500;
  --z-dialog:    9000;

  /* Alias tokens added 2026-05-07 — resolves undefined-token warnings */
  --accent: var(--gold-500);
  --accent-tint: color-mix(in srgb, var(--gold-500) 12%, transparent);
  --accent-ink: var(--gold-fg);
  --accent-soft: var(--gold-bg);
  --bg: var(--surface);
  --error-fg: var(--danger-fg);
}

/* ---------- Tokens (Dark) ---------- */
[data-theme="dark"] {
  --green-900: #0B1511;
  --green-800: #0F1C17;
  --green-700: #152620;
  --green-600: #1E3028;
  --cream-100: #1A2822;
  --cream-200: #223129;
  --cream-50:  #14211B;
  /* 2026-05-21 (P2-1): dark-theme values for the scale-step tokens — lighter
     gold/red so financial colour-coding stays visible on dark backgrounds. */
  --gold-700: #D6BB6F;
  --gold-200: #3A3320;
  --red-500:  #E07A6E;
  --red-700:  #C85A4C;
  --green-200: #1E3028;
  --green-100: #152620;
  --ink:      #E8E6DE;
  --ink-2:    #A8ADA6;
  --surface-2: #14211B;
  --surface: #1A2822;
  --text-primary: #E8E6DE;
  --text-secondary: #A8ADA6;
  --text-muted: #7A7F7B;
  --border: rgba(232, 230, 222, 0.08);
  --border-strong: rgba(232, 230, 222, 0.14);
  --border-gold: rgba(201, 168, 76, 0.45);
  --glass-bg: rgba(20, 33, 27, 0.70);
  --glass-bg-strong: rgba(20, 33, 27, 0.85);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.25);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.30);
  --shadow-lg: 0 20px 48px rgba(0,0,0,0.45);
  /* Dark-mode semantic triplets. The base hue tokens (--success/danger/
     warning/info) stay at their light-mode hex (used for accent fills
     where saturation matters), but the *-fg variants brighten so text
     on the dark surface clears WCAG AA contrast (#1A2822 surface ≈ L 32),
     and the *-bg variants get a darker, saturated tint that reads as
     "this card is in the warning/danger family" without going pastel. */
  --success-fg:  #7FBF7C;
  --success-bg:  color-mix(in oklab, #4C8C4A 18%, var(--surface));
  --success-bg-strong: color-mix(in oklab, #4C8C4A 32%, var(--surface));
  --warning-fg:  #E6B95A;
  --warning-bg:  color-mix(in oklab, #D79924 18%, var(--surface));
  --warning-bg-strong: color-mix(in oklab, #D79924 32%, var(--surface));
  --warning-border: color-mix(in oklab, #D79924 55%, var(--surface));
  --danger-fg:   #E07060;
  --danger-bg:   color-mix(in oklab, #B03A2E 16%, var(--surface));
  --danger-bg-strong: color-mix(in oklab, #B03A2E 30%, var(--surface));
  --info-fg:     #7AAFD1;
  --info-bg:     color-mix(in oklab, #3F6E94 18%, var(--surface));
  --info-bg-strong: color-mix(in oklab, #3F6E94 32%, var(--surface));

  /* Dark-mode overrides for the audit tokens. Aliases that point at
     other tokens (e.g. --green: var(--green-800)) automatically flip
     because their target token flips — only redefine here when the
     dark-mode value diverges from the alias chain. */
  --green: var(--green-700);
  /* --cream and --text aliases auto-follow their targets. */

  /* Gold semantic triplet — fg brightens to clear WCAG on the dark
     surface (#1A2822 ≈ L 32). */
  --gold-fg: var(--gold-400);
  --gold-bg: color-mix(in oklab, var(--gold-500) 18%, var(--surface));
  --gold-bg-strong: color-mix(in oklab, var(--gold-500) 32%, var(--surface));

  --primary: var(--green-700);
  --primary-contrast: var(--gold-400);

  --table-head-bg: var(--cream-100);
}

/* Density */
[data-density="compact"] {
  --density-row: 36px;
  --density-pad: 10px;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Barlow', system-ui, -apple-system, sans-serif;
  font-weight: 400;
  color: var(--text-primary);
  background: var(--cream-100);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
  min-height: 100vh;
  background-image:
    radial-gradient(1200px 600px at 90% -10%, rgba(201, 168, 76, 0.10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(30, 48, 40, 0.08), transparent 60%);
  background-attachment: fixed;
}
[data-theme="dark"] body {
  background-image:
    radial-gradient(1200px 600px at 90% -10%, rgba(201, 168, 76, 0.08), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(201, 168, 76, 0.04), transparent 60%);
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input, select, textarea { font-family: inherit; color: inherit; }
img { display: block; max-width: 100%; }

/* ---------- Theme-aware native form-control defaults ----------
   Many pages use inline-styled `background:#fff` cards and bare <input> /
   <select> / <textarea> elements which then render light-on-light in dark
   mode. These rules ensure native form controls always pick up the active
   theme tokens, even when wrapped in a hardcoded white card. Use
   :where() selectors so component classes (e.g. `.input`, `.fld-input`,
   `.lookup-input`) can still override without specificity wars in light
   mode, and use `[data-theme="dark"] :where(...)` overrides with explicit
   token values for dark mode. Specificity ([data-theme="dark"] adds 1
   class-level) beats inline `background:#fff` only with !important; we
   keep !important scoped to dark mode so light mode looks unchanged. */
:where(input[type="text"], input[type="email"], input[type="password"],
       input[type="search"], input[type="tel"], input[type="url"],
       input[type="number"], input[type="date"], input[type="time"],
       input[type="datetime-local"], input[type="month"], input[type="week"],
       input:not([type]), select, textarea) {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-input, 8px);
  font-family: inherit;
  font-size: 14px;
  padding: 8px 10px;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
:where(input[type="text"], input[type="email"], input[type="password"],
       input[type="search"], input[type="tel"], input[type="url"],
       input[type="number"], input[type="date"], input[type="time"],
       input[type="datetime-local"], input[type="month"], input[type="week"],
       input:not([type]), select, textarea):focus {
  border-color: var(--gold-500);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--gold-500) 22%, transparent);
}
:where(input, select, textarea)::placeholder {
  color: var(--text-muted);
  opacity: 1;
}
:where(input[type="checkbox"], input[type="radio"]) {
  accent-color: var(--gold-500);
}
:where(input[type="file"]) {
  color: var(--text-secondary);
  background: transparent;
}
/* Dark-mode override that beats inline `background:#fff` from cards.
   Limited !important to dark mode so light mode (the design baseline)
   keeps full inline-style flexibility. */
[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="email"],
[data-theme="dark"] input[type="password"],
[data-theme="dark"] input[type="search"],
[data-theme="dark"] input[type="tel"],
[data-theme="dark"] input[type="url"],
[data-theme="dark"] input[type="number"],
[data-theme="dark"] input[type="date"],
[data-theme="dark"] input[type="time"],
[data-theme="dark"] input[type="datetime-local"],
[data-theme="dark"] input[type="month"],
[data-theme="dark"] input[type="week"],
[data-theme="dark"] input:not([type]),
[data-theme="dark"] select,
[data-theme="dark"] textarea {
  background: var(--surface) !important;
  color: var(--text-primary) !important;
  border-color: var(--border) !important;
}
[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder {
  color: var(--text-muted) !important;
}
/* Recolour native <select> dropdown arrow (via background-image SVG)
   so the chevron is visible in dark mode. Light mode keeps the OS chevron. */
[data-theme="dark"] select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' stroke='%23E8E6DE' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>") !important;
  background-repeat: no-repeat !important;
  background-position: right 10px center !important;
  padding-right: 30px !important;
}
/* Cards/panels with hardcoded `background:#fff` look jarring in dark mode.
   Re-tint any element whose inline background is white (#fff / #FFFFFF) to
   the surface token. Cannot select on inline style, so we instead rely on
   common card class names used across the codebase. */
[data-theme="dark"] [style*="background: #fff"],
[data-theme="dark"] [style*="background:#fff"],
[data-theme="dark"] [style*="background-color: #fff"],
[data-theme="dark"] [style*="background-color:#fff"],
[data-theme="dark"] [style*="background: #FFF"],
[data-theme="dark"] [style*="background:#FFF"],
[data-theme="dark"] [style*="background: white"],
[data-theme="dark"] [style*="background:white"],
/* Common Tailwind grey/slate fallbacks that historically leaked through
   `var(--undefined-token, #xxxxxx)` patterns. */
[data-theme="dark"] [style*="#fafafa"],
[data-theme="dark"] [style*="#FAFAFA"],
[data-theme="dark"] [style*="#f8fafc"],
[data-theme="dark"] [style*="#F8FAFC"],
[data-theme="dark"] [style*="#f1f5f9"],
[data-theme="dark"] [style*="#F1F5F9"] {
  background: var(--surface) !important;
}
[data-theme="dark"] [style*="border: 1px solid #e2ddd2"],
[data-theme="dark"] [style*="border:1px solid #e2ddd2"],
[data-theme="dark"] [style*="border: 1px solid #c9bfa9"],
[data-theme="dark"] [style*="border:1px solid #c9bfa9"],
[data-theme="dark"] [style*="border: 1px solid #d7d2c4"],
[data-theme="dark"] [style*="border:1px solid #d7d2c4"] {
  border-color: var(--border-strong) !important;
}

/* ---------- Typography ---------- */
.heading, h1, h2, h3, h4 {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-primary);
  margin: 0;
  line-height: 1.15;
}
h1 { font-size: 32px; }
h2 { font-size: 22px; }
h3 { font-size: 16px; }
h4 { font-size: 13px; letter-spacing: 0.12em; color: var(--text-secondary); }

.eyebrow {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

p { margin: 0 0 12px; }
small, .small { font-size: 12px; color: var(--text-secondary); }
.mono { font-family: 'JetBrains Mono', 'SF Mono', Menlo, monospace; font-size: 12px; }

/* ---------- App Shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  min-height: 100vh;
  transition: grid-template-columns 220ms ease;
}
.app[data-collapsed="true"] { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }

/* ---------- Top Bar ---------- */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  height: var(--topbar-h);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .logo {
  display: flex; align-items: center; gap: 10px;
  width: calc(var(--sidebar-w) - 20px);
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 16px;
  color: var(--text-primary);
  transition: width 220ms ease;
}
.app[data-collapsed="true"] .topbar .logo { width: calc(var(--sidebar-w-collapsed) - 20px); }
.topbar .logo .mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--green-800), var(--green-700));
  display: grid; place-items: center;
  color: var(--gold-500);
  font-weight: 700; font-size: 14px;
  box-shadow: inset 0 0 0 1px var(--border-gold);
  flex: 0 0 auto;
}
.app[data-collapsed="true"] .topbar .logo .wordmark { display: none; }

.client-pill {
  display: flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 12px;
  max-width: 240px;
  flex: 0 1 auto;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  font-weight: 500; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.client-pill > span:nth-of-type(2) { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.client-pill:hover { border-color: var(--border-gold); }
.client-pill .crest {
  width: 22px; height: 22px; border-radius: 50%;
  background: linear-gradient(135deg, var(--green-800), var(--gold-500));
  display: grid; place-items: center;
  font-family: 'Barlow Condensed', sans-serif;
  color: #fff; font-size: 10px; font-weight: 700;
  letter-spacing: 0.06em;
}
.client-pill .chev { opacity: 0.55; }
.client-pill.empty { color: var(--gold-600); font-weight: 600; }

.topbar .spacer { flex: 1; }

.search {
  display: flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 12px;
  min-width: 220px;
  flex: 0 1 320px;
  border-radius: var(--radius-input);
  background: var(--cream-50);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 13px;
  overflow: hidden;
}
.search .ico { flex: 0 0 auto; width: 18px; height: 18px; color: var(--text-muted); }
.search input {
  border: 0; background: transparent; outline: none;
  flex: 1 1 auto; min-width: 0;
  font-size: 13px;
}
.search kbd { flex: 0 0 auto; }
.search kbd {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  padding: 2px 6px; border-radius: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.icon-btn {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: grid; place-items: center;
  color: var(--text-secondary);
  position: relative;
}
.icon-btn:hover { background: var(--cream-50); color: var(--text-primary); }
.icon-btn.on { background: var(--cream-100); color: var(--text-primary); }

/* ---------- Action popover (⋯ menus) ---------- */
.nc-popover {
  position: fixed;
  z-index: 220;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  font-size: 13px;
  opacity: 0;
  transform: translateY(-4px) scale(0.98);
  pointer-events: none;
  transition: opacity .14s ease, transform .14s ease;
}
.nc-popover.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.nc-popover .pop-head {
  padding: 8px 10px 6px;
  font-family: 'Barlow Condensed', sans-serif;
  text-transform: uppercase;
  letter-spacing: .1em;
  font-size: 10.5px;
  color: var(--text-muted);
  font-weight: 600;
}
.nc-popover .pop-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 2px;
}
.nc-popover button.pop-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  border-radius: 8px;
  color: var(--text-primary);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.nc-popover button.pop-item:hover { background: var(--cream-50); }
.nc-popover button.pop-item.danger { color: var(--danger); }
.nc-popover button.pop-item.danger:hover { background: rgba(176, 58, 46, 0.08); }
.nc-popover button.pop-item svg {
  width: 15px; height: 15px;
  stroke: currentColor;
  flex: 0 0 auto;
  opacity: .85;
}
.nc-popover button.pop-item .hint {
  margin-left: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
}

/* ---------- Client context bar (below topbar, above page) ---------- */
.ctx-bar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 32px;
  background: color-mix(in oklab, var(--green-900) 2%, var(--glass-bg-strong));
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: var(--topbar-h);
  z-index: 40;
  margin: -28px -32px 22px;
  font-size: 12.5px;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.ctx-bar::-webkit-scrollbar { display: none; }
.ctx-bar .ctx-client {
  display: flex; align-items: center; gap: 10px;
  font-weight: 600;
}
.ctx-bar .ctx-client .crest {
  width: 22px; height: 22px; border-radius: 50%;
  background: linear-gradient(135deg, var(--green-800), var(--gold-500));
  color: #fff; display: grid; place-items: center;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
  flex: 0 0 auto;
}
.ctx-bar .ctx-sep {
  width: 1px; height: 16px; background: var(--border-strong);
}
.ctx-bar .ctx-field {
  display: flex; align-items: center; gap: 10px;
  color: var(--text-secondary);
}
.ctx-bar .ctx-field > strong {
  color: var(--text-primary);
  font-weight: 600;
}
.ctx-bar .ctx-field .ctx-label {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--text-muted);
  padding-right: 2px;
}
.ctx-bar .ctx-spacer { flex: 1; }
.ctx-bar .ctx-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px;
  border-radius: 6px;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.10em; text-transform: uppercase;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
}
.ctx-bar .ctx-btn:hover { color: var(--text-primary); border-color: var(--border-strong); }
.ctx-bar .ctx-btn svg { width: 12px; height: 12px; }
.ctx-bar.no-client {
  background: color-mix(in oklab, var(--gold-500) 8%, var(--surface));
  border-bottom: 1px solid var(--border-gold);
}
.ctx-bar.no-client .ctx-client { color: var(--gold-600); }
.ctx-bar.no-client .ctx-btn {
  background: var(--green-800);
  color: var(--gold-400);
  border-color: var(--green-800);
  box-shadow: inset 0 0 0 1px var(--border-gold);
}

/* Period dropdown */
.ctx-period-menu {
  position: absolute;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  padding: 4px;
  min-width: 180px;
  z-index: 50;
  display: none;
}
.ctx-period-menu.open { display: block; }
.ctx-period-menu button {
  display: block; width: 100%; text-align: left;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--text-primary);
}
.ctx-period-menu button:hover { background: var(--cream-50); }
.ctx-period-menu button.on {
  background: color-mix(in oklab, var(--gold-500) 12%, transparent);
  color: var(--gold-600); font-weight: 600;
}

/* ---------- State simulation overlays ---------- */
/* When Tweaks → Simulate state ≠ normal, every .card gets skinned. */
.app[data-sim-state="loading"] .card:not(.no-sim) {
  position: relative;
  overflow: hidden;
}
.app[data-sim-state="loading"] .card:not(.no-sim) > * {
  visibility: hidden;
}
.app[data-sim-state="loading"] .card:not(.no-sim)::after {
  content: '';
  position: absolute; inset: 0;
  background:
    linear-gradient(var(--cream-50), var(--cream-50)) padding-box,
    linear-gradient(90deg, transparent, color-mix(in oklab, var(--gold-500) 18%, transparent), transparent) content-box;
  background-size: 100% 100%, 40% 100%;
  background-repeat: no-repeat;
  background-position: 0 0, -40% 0;
  animation: nc-shimmer 1.4s linear infinite;
  border-radius: inherit;
}
@keyframes nc-shimmer {
  from { background-position: 0 0, -40% 0; }
  to   { background-position: 0 0, 140% 0; }
}

.app[data-sim-state="empty"] .content .card:not(.no-sim) > *,
.app[data-sim-state="error"] .content .card:not(.no-sim) > *,
.app[data-sim-state="noperm"] .content .card:not(.no-sim) > * {
  display: none !important;
}
.app[data-sim-state="empty"] .content .card:not(.no-sim),
.app[data-sim-state="error"] .content .card:not(.no-sim),
.app[data-sim-state="noperm"] .content .card:not(.no-sim) {
  min-height: 180px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 40px 24px;
}
.app[data-sim-state="empty"] .content .card:not(.no-sim)::before {
  content: 'No data for this period — try a different filter, or import source records.';
  display: block;
  color: var(--text-secondary);
  font-size: 13px;
  max-width: 360px;
}
.app[data-sim-state="error"] .content .card:not(.no-sim)::before {
  content: 'Something went wrong loading this module. Retry, or contact your admin.';
  display: block;
  color: var(--danger);
  font-size: 13px;
  max-width: 360px;
}
.app[data-sim-state="noperm"] .content .card:not(.no-sim)::before {
  content: 'You don\2019t have access to this module. Ask an administrator for permission.';
  display: block;
  color: var(--text-secondary);
  font-size: 13px;
  max-width: 360px;
}

/* Page-head banner in non-normal states */
.ctx-sim-banner {
  display: none;
  align-items: center; gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 12.5px;
  margin-bottom: 18px;
  border: 1px solid;
}
.app[data-sim-state="empty"] .ctx-sim-banner.sim-empty,
.app[data-sim-state="loading"] .ctx-sim-banner.sim-loading,
.app[data-sim-state="error"] .ctx-sim-banner.sim-error,
.app[data-sim-state="noperm"] .ctx-sim-banner.sim-noperm {
  display: flex;
}
.ctx-sim-banner.sim-empty {
  background: var(--cream-50);
  border-color: var(--border);
  color: var(--text-secondary);
}
.ctx-sim-banner.sim-loading {
  background: color-mix(in oklab, var(--info) 8%, var(--surface));
  border-color: color-mix(in oklab, var(--info) 35%, transparent);
  color: var(--info);
}
.ctx-sim-banner.sim-error {
  background: color-mix(in oklab, var(--danger) 8%, var(--surface));
  border-color: color-mix(in oklab, var(--danger) 35%, transparent);
  color: var(--danger);
}
.ctx-sim-banner.sim-noperm {
  background: color-mix(in oklab, var(--warning) 10%, var(--surface));
  border-color: color-mix(in oklab, var(--warning) 35%, transparent);
  color: var(--warning);
}

/* Pick-a-client CTA card (shown when no active client) */
.pick-client-cta {
  background: linear-gradient(135deg, var(--green-900), var(--green-700));
  color: #F5F3EE;
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-card);
  padding: 40px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.pick-client-cta::before {
  content: '';
  position: absolute; right: -80px; top: -80px;
  width: 240px; height: 240px; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in oklab, var(--gold-500) 28%, transparent), transparent 70%);
  pointer-events: none;
}
.pick-client-cta h2 {
  color: #F5F3EE;
  font-size: 22px;
  text-transform: none;
  letter-spacing: 0.02em;
  margin-bottom: 8px;
}
.pick-client-cta p {
  color: var(--gold-400);
  font-size: 13.5px;
  max-width: 480px;
  margin: 0 auto 20px;
}

/* ---------- Accessibility ---------- */
:focus-visible {
  outline: 2px solid var(--gold-500);
  outline-offset: 2px;
  border-radius: 4px;
}
.btn:focus-visible,
.icon-btn:focus-visible,
.filter-chip:focus-visible,
.client-pill:focus-visible {
  outline-offset: 2px;
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--gold-500) 30%, transparent);
}
.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible {
  outline: none;
}
/* When no active client, softly de-emphasise non-essential content but keep
   it navigable — the CTA is a prompt, not a blocker. Direct-URL visits must
   stay functional (audit finding: "Dashboard tile navigation blocked by
   client-picker"). */
[data-dim-noclient="true"] {
  opacity: 0.72;
}

/* Compact client banner (shown when host opts into compact mode AND a client
   is selected) — collapses the hero "pick-client-cta" space into a 36px bar.
   The ctx-bar already occupies this role by default; this rule tightens its
   footprint further when pages explicitly request a minimal chrome. */
.app[data-compact-client-banner="true"] .pick-client-cta {
  padding: 12px 16px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 36px;
}
.app[data-compact-client-banner="true"] .pick-client-cta h2 {
  font-size: 13px;
  margin: 0;
}
.app[data-compact-client-banner="true"] .pick-client-cta p { display: none; }
.app[data-compact-client-banner="true"] .pick-client-cta::before { display: none; }

/* Client pill — empty state */
.client-pill.empty .crest {
  background: linear-gradient(135deg, var(--text-muted), var(--gold-500));
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.icon-btn .badge-dot {
  position: absolute; top: 8px; right: 8px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 2px var(--glass-bg-strong);
}

.me {
  display: flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 10px 0 4px;
  border-radius: var(--radius-pill);
}
.me:hover { background: var(--cream-50); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--green-700), var(--gold-500));
  color: #fff;
  display: grid; place-items: center;
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700; font-size: 11px; letter-spacing: 0.06em;
  flex: 0 0 auto;
}
.avatar.sm { width: 22px; height: 22px; font-size: 9px; }
.avatar.lg { width: 40px; height: 40px; font-size: 14px; }
.avatar.xl { width: 56px; height: 56px; font-size: 18px; }

/* ---------- Sidebar ---------- */
.sidebar {
  grid-row: 2;
  grid-column: 1;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--border);
  padding: 12px 10px 80px;
  overflow-y: auto;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
}
.sidebar .group { margin-bottom: 6px; }
.sidebar .group-label {
  /* FE-NAV-01 heading treatment — SINGLE SOURCE (was also injected by
     StudioShell.tsx, which caused a post-hydration font shift). Group
     headers read as headings, distinct from Section-parents + leaves. */
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 12px 6px;
  /* SIDEBAR-CONSISTENCY-01 — caret always LEFT: flex-start + gap so the
     toggle-only group button renders [caret][label] (not label…caret-right). */
  display: flex; align-items: center; justify-content: flex-start; gap: 2px;
}
.app[data-collapsed="true"] .sidebar .group-label { display: none; }

.sidebar .nav-item {
  display: flex; align-items: center; justify-content: flex-start; gap: 10px;
  padding: 8px 10px 8px 13px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  position: relative;
  border-left: 3px solid transparent;
  margin-bottom: 1px;
}
.sidebar .nav-item:hover { background: var(--cream-50); }
.sidebar .nav-item.active {
  border-left-color: var(--gold-500);
  background: color-mix(in oklab, var(--gold-500) 8%, transparent);
  font-weight: 600;
}
.sidebar .nav-item .ico { width: 18px; height: 18px; flex: 0 0 auto; color: var(--text-secondary); }
.sidebar .nav-item .label { flex: 1 1 auto; min-width: 0; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .nav-item.active .ico { color: var(--gold-600); }
.sidebar .nav-item.sub { font-size: 12.5px; color: var(--text-secondary); font-weight: 400; }
.sidebar .nav-item.sub.active {
  color: var(--text-primary);
  border-left-color: var(--gold-500);
  background: color-mix(in oklab, var(--gold-500) 8%, transparent);
  font-weight: 600;
}
.sidebar .nav-item.sub.active .ico { color: var(--gold-600); }

/* ---- Two-level nav: nav-parent (collapsible item) + nav-children ---- */
/* The full runtime styles are injected by StudioShell.tsx; these rules
   supply safe fallbacks for pages that render before JS wires the DOM. */
.sidebar .nav-parent { display: flex; align-items: center; justify-content: flex-start; gap: 10px; }
/* Chevron is a fixed-width LEFT gutter (before icon); the flex gap adds the same
   spacing to the icon for every item — so parent + leaf icons line up. */
.sidebar .nav-parent .nav-parent-chev { width: 10px; margin-right: 0; text-align: center; flex-shrink: 0; }
/* ASSETS-SIDEBAR-PPE-REGROUP-01 — reserve the SAME chevron gutter for leaf items
   (no children): an empty spacer the width of the chevron, so every icon/label at a
   level lines up whether or not the item expands. Hidden when the rail is collapsed
   (icons centre — [data-collapsed] behaviour unchanged). */
.sidebar .nav-item:not(.nav-parent):not(.nav-parent-link)::before { content: ''; flex: 0 0 10px; }
.app[data-collapsed="true"] .sidebar .nav-item::before { display: none; }
/* Child connector rail: single source of truth for sub-item indent */
.sidebar .nav-children { margin-left: 22px; border-left: 1px solid var(--border); }
.sidebar .nav-children .nav-item.sub { padding-left: 16px; }
/* ASSETS-SIDEBAR-PPE-POLISH-01 — the 3rd tier (group > parent > PPE > child) was
   double-indented (the 22px rail compounded per level) and truncated long labels at
   --sidebar-w 260px. Halve the SECOND-level rail so a 3rd-tier item is still clearly
   nested (one step deeper than its 2nd-tier siblings) but keeps the width to render
   its label in full — verified headless: longest deep label fits with ~30px to spare. */
.sidebar .nav-children .nav-children { margin-left: 14px; }
/* nav-parent-wrap children hidden pre-hydration (no attr yet) AND when
   collapsed post-hydration ([data-expanded="false"]). SINGLE SOURCE — the
   duplicate [data-expanded="false"] rule was removed from StudioShell.tsx. */
.sidebar .nav-parent-wrap:not([data-expanded]) .nav-children,
.sidebar .nav-parent-wrap[data-expanded="false"] .nav-children { display: none; }
/* --- end two-level nav --- */

.app[data-collapsed="true"] .sidebar .nav-item .label,
.app[data-collapsed="true"] .sidebar .nav-item.sub,
.app[data-collapsed="true"] .sidebar .nav-parent-wrap,
.app[data-collapsed="true"] .sidebar .chip-coming { display: none; }
.app[data-collapsed="true"] .sidebar .nav-item { justify-content: center; padding: 10px; }

.sidebar .divider {
  height: 1px; background: var(--border);
  margin: 10px 8px;
}

.chip-coming {
  margin-left: auto;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 10px; letter-spacing: 0.08em;
  padding: 2px 7px; border-radius: var(--radius-pill);
  background: var(--cream-200); color: var(--text-muted);
  text-transform: uppercase; font-weight: 600;
}

/* Collapse toggle floating at bottom of sidebar.
   Lives in a dedicated "safe zone" at sidebar foot — we extend the sidebar's
   bottom padding and lay down a fade-mask so group labels scroll out before
   they can visually collide with the circular pill. */
.sidebar { padding-bottom: 64px; }
.sidebar::after {
  content: '';
  position: sticky;
  display: block;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  margin: 0 -10px -12px;
  background: linear-gradient(to bottom, transparent, var(--glass-bg) 55%);
  pointer-events: none;
  z-index: 1;
}
.collapse-toggle {
  position: fixed;
  bottom: 16px;
  left: calc(var(--sidebar-w) - 40px);
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: grid; place-items: center;
  color: var(--text-secondary);
  box-shadow: var(--shadow-sm);
  transition: left 220ms ease, transform 220ms ease;
  z-index: 45;
}
.app[data-collapsed="true"] .collapse-toggle {
  left: calc(var(--sidebar-w-collapsed) - 40px);
  transform: rotate(180deg);
}
/* Guard: group labels should never render in the same horizontal band as the
   floating toggle. The sidebar scrolls, so we extend its scroll-bottom gutter. */
.sidebar .group:last-of-type { margin-bottom: 40px; }

/* ---------- Content ---------- */
.content {
  grid-row: 2; grid-column: 2;
  padding: 28px 32px 80px;
  min-width: 0;
}
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 24px; margin-bottom: 22px; flex-wrap: wrap;
}
.page-head > :first-child { min-width: 0; flex: 1 1 320px; }
.page-head h1 { font-size: 28px; }

/* ---------- Cards ---------- */
.card {
  background: var(--glass-bg-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card.hover:hover {
  border-color: var(--border-gold);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  transition: all 160ms ease;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.card-head h3 { font-size: 13px; letter-spacing: 0.12em; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 14px;
  border-radius: var(--radius-btn);
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  transition: all 140ms ease;
  border: 1px solid transparent;
  white-space: nowrap;
}
.btn-primary {
  background: var(--green-800);
  color: var(--gold-400);
  border-color: var(--green-800);
  box-shadow: inset 0 0 0 1px var(--border-gold);
}
.btn-primary:hover { background: var(--green-700); color: var(--gold-400); }
.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.btn-secondary:hover { border-color: var(--border-gold); }
.btn-ghost { color: var(--text-secondary); padding: 0 10px; }
.btn-ghost:hover { color: var(--text-primary); background: var(--cream-50); }
.btn-danger {
  background: var(--danger); color: #fff; border-color: var(--danger);
}
.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; }
.btn-lg { height: 44px; padding: 0 20px; font-size: 14px; }

/* ---------- Pills / Chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 22px; padding: 1px 10px;
  border-radius: var(--radius-pill);
  background: var(--cream-200);
  color: var(--text-secondary);
  font-size: 11px; font-weight: 600;
  font-family: 'Barlow Condensed', sans-serif;
  letter-spacing: 0.08em;
  line-height: 18px;            /* contain tall 'Barlow Condensed' caps within the pill */
  white-space: nowrap;          /* a chip label never wraps inside the pill */
  text-transform: uppercase;
  border: 1px solid transparent;
}
.chip.gold { background: color-mix(in oklab, var(--gold-500) 16%, var(--surface)); color: var(--gold-600); border-color: var(--border-gold); }
.chip.green { background: color-mix(in oklab, var(--success) 18%, var(--surface)); color: var(--success); }
.chip.amber { background: color-mix(in oklab, var(--warning) 20%, var(--surface)); color: var(--warning); }
.chip.red { background: color-mix(in oklab, var(--danger) 15%, var(--surface)); color: var(--danger); }
.chip.outline { background: transparent; border-color: var(--border-strong); color: var(--text-secondary); }
.chip.solid-dark { background: var(--green-800); color: var(--gold-400); }
/* Opt-in: truncate long chip text (e.g. asset category/sub-category) to a single
   ellipsised line instead of overflowing the pill — pair with a title="" tooltip. */
.chip.truncate { display: inline-block; max-width: 240px; min-width: 0; line-height: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }

.status-dot {
  display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted);
  flex: 0 0 auto;
}
.status-dot.green { background: var(--success); box-shadow: 0 0 0 3px color-mix(in oklab, var(--success) 20%, transparent); }
.status-dot.amber { background: var(--warning); box-shadow: 0 0 0 3px color-mix(in oklab, var(--warning) 20%, transparent); }
.status-dot.red { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in oklab, var(--danger) 20%, transparent); }
.status-dot.grey { background: var(--text-muted); }

/* Priority dots */
.prio {
  display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
}
.prio.high { background: var(--danger); }
.prio.med  { background: var(--warning); }
.prio.low  { background: var(--text-muted); }

/* ---------- Filter chips (tabs-as-pills) ---------- */
.filter-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.filter-chip {
  height: 30px; padding: 0 14px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 600; font-size: 12px; letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.filter-chip:hover { color: var(--text-primary); border-color: var(--border-strong); }
.filter-chip.active {
  background: var(--green-800); color: var(--gold-400);
  border-color: var(--green-800);
  box-shadow: inset 0 0 0 1px var(--border-gold);
}

/* ---------- Inputs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--text-secondary);
}
.input, .select, .textarea {
  height: 40px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  font-size: 14px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.textarea { height: auto; padding: 10px 12px; resize: vertical; min-height: 80px; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--gold-500);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--gold-500) 20%, transparent);
}
.input.lg { height: 44px; font-size: 15px; }
.input-group { position: relative; }
.input-group .ico {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted);
}
.input-group .input { padding-left: 38px; }

/* ---------- Table ---------- */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  overflow: hidden;
}
.table th, .table td {
  padding: 12px 16px;
  text-align: left;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.table th {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: var(--cream-50);
}
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: color-mix(in oklab, var(--gold-500) 5%, var(--surface)); }
.table tr.clickable:hover td:first-child { box-shadow: inset 3px 0 0 0 var(--gold-500); }

/* ---------- Progress bars ---------- */
.progress {
  height: 6px; width: 100%;
  background: var(--cream-200);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress > span {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--gold-500), var(--gold-400));
  border-radius: inherit;
}
.progress.thick { height: 10px; }

.circ-progress { --val: 70; --size: 40px;
  width: var(--size); height: var(--size);
  border-radius: 50%;
  background: conic-gradient(var(--gold-500) calc(var(--val)*1%), var(--cream-200) 0);
  display: grid; place-items: center;
  position: relative;
}
.circ-progress::after {
  content: ''; position: absolute; inset: 4px;
  background: var(--surface); border-radius: 50%;
}
.circ-progress span {
  position: relative; z-index: 1;
  font-size: 11px; font-weight: 700;
  font-family: 'Barlow Condensed', sans-serif;
}

/* ---------- Avatar stack ---------- */
.stack { display: inline-flex; }
.stack .avatar {
  border: 2px solid var(--surface);
  margin-left: -8px;
}
.stack .avatar:first-child { margin-left: 0; }
.stack .more {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--surface);
  margin-left: -8px;
  background: var(--cream-200);
  color: var(--text-secondary);
  display: grid; place-items: center;
  font-size: 10px; font-weight: 700;
  font-family: 'Barlow Condensed', sans-serif;
}

/* ---------- Modal ---------- */
.modal-scrim {
  position: fixed; inset: 0;
  background: rgba(30, 48, 40, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: grid; place-items: center;
  z-index: 100;
  opacity: 0; pointer-events: none;
  transition: opacity 180ms ease;
}
.modal-scrim.open { opacity: 1; pointer-events: auto; }
.modal {
  width: min(640px, 94vw);
  max-height: 86vh;
  background: var(--glass-bg-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex; flex-direction: column;
  transform: translateY(10px) scale(0.98);
  transition: transform 180ms ease;
}
.modal-scrim.open .modal { transform: none; }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px 22px; overflow-y: auto; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--cream-50); }

/* ---------- Drawer ---------- */
.drawer-scrim {
  position: fixed; inset: 0;
  background: rgba(30, 48, 40, 0.25);
  backdrop-filter: blur(4px);
  z-index: 110;
  opacity: 0; pointer-events: none;
  transition: opacity 180ms ease;
}
.drawer-scrim.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed;
  top: 0; right: 0; height: 100vh;
  width: min(520px, 94vw);
  background: var(--glass-bg-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-left: 1px solid var(--border-gold);
  box-shadow: var(--shadow-lg);
  z-index: 120;
  transform: translateX(100%);
  transition: transform 220ms cubic-bezier(0.4, 0, 0.2, 1);
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.drawer-body { padding: 18px 22px; overflow-y: auto; flex: 1; }
.drawer-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; background: var(--cream-50); }

/* ---------- Toast ---------- */
.toasts {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 200;
}
.toast {
  min-width: 280px; max-width: 380px;
  padding: 12px 14px;
  background: var(--glass-bg-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-md);
  display: flex; align-items: flex-start; gap: 10px;
  font-size: 13px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.info { border-left: 3px solid var(--info); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.error { border-left: 3px solid var(--danger); }

/* ---------- Breadcrumb ---------- */
.breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px;
  font-family: 'Barlow Condensed', sans-serif;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.breadcrumb a:hover { color: var(--text-primary); }
.breadcrumb .sep { opacity: 0.5; }
.breadcrumb .here { color: var(--text-primary); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 2px;
  border-bottom: 1px solid var(--border);
}
.tab {
  padding: 10px 16px;
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text-primary); }
.tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--gold-500);
}

/* ---------- Empty / Loading / Error ---------- */
.empty-state {
  text-align: center;
  padding: 64px 24px;
  max-width: 460px;
  margin: 40px auto;
}
.empty-state .empty-ico {
  width: 64px; height: 64px;
  margin: 0 auto 16px;
  opacity: 0.4;
  color: var(--text-secondary);
}
.empty-state h3 { font-size: 18px; margin-bottom: 8px; }
.empty-state p { color: var(--text-secondary); margin-bottom: 20px; }

.skeleton {
  background: linear-gradient(90deg, var(--cream-200), var(--cream-50), var(--cream-200));
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: 6px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.error-card {
  background: color-mix(in oklab, var(--danger) 6%, var(--surface));
  border: 1px solid color-mix(in oklab, var(--danger) 30%, transparent);
  border-radius: var(--radius-card);
  padding: 16px 18px;
  display: flex; gap: 14px; align-items: flex-start;
}
.error-card .ico { color: var(--danger); flex: 0 0 auto; }

/* ---------- Login shell ---------- */
.auth-body {
  display: grid; place-items: center;
  min-height: 100vh;
  padding: 24px;
  background-image:
    radial-gradient(800px 500px at 50% 0%, rgba(201, 168, 76, 0.16), transparent 60%),
    radial-gradient(700px 600px at 100% 100%, rgba(30, 48, 40, 0.10), transparent 60%);
}
.auth-card {
  width: 420px; max-width: 100%;
  background: var(--glass-bg-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 34px 30px;
}
.auth-foot {
  text-align: center; margin-top: 28px;
  font-size: 12px; color: var(--text-muted);
  font-family: 'Barlow Condensed', sans-serif;
  letter-spacing: 0.10em;
  text-transform: uppercase;
}

/* FE-TWEAKS-01: the floating Tweaks panel was removed from the production shell
   (theme is changed via the topbar ThemeToggle; density folds into Settings →
   Appearance). Its .tweaks-* styles and the --accent-hue-shift token are gone. */

/* ---------- Utility ---------- */
.row { display: flex; align-items: center; gap: 10px; }
.col { display: flex; flex-direction: column; gap: 10px; }
.gap-4 { gap: 4px; } .gap-6 { gap: 6px; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; } .gap-20 { gap: 20px; } .gap-24 { gap: 24px; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; } .mt-32 { margin-top: 32px; }
.mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-right { text-align: right; }
.flex-1 { flex: 1; }
.grow { flex-grow: 1; }
.nowrap { white-space: nowrap; }
.hide-sm { }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: color-mix(in oklab, var(--text-secondary) 25%, transparent);
  border-radius: 5px; border: 2px solid transparent; background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: color-mix(in oklab, var(--text-secondary) 40%, transparent); background-clip: padding-box; }

/* ---------- Recharts (chart library) — theme-aware overrides ----------
   Recharts ships defaults that hardcode white tooltips, light-grey grid
   strokes, and black axis text. In dark mode those render as a glaring
   white tooltip slab and unreadable axis labels. Override at the CSS
   layer so every <Tooltip>, <XAxis>, <YAxis>, <CartesianGrid> picks up
   the active theme without needing per-page wiring. */
.recharts-default-tooltip,
.recharts-tooltip-wrapper .recharts-default-tooltip {
  background: var(--surface) !important;
  border: 1px solid var(--border-strong) !important;
  border-radius: 10px !important;
  box-shadow: var(--shadow-md) !important;
  color: var(--text-primary) !important;
}
.recharts-tooltip-label {
  color: var(--text-primary) !important;
  font-family: 'Barlow Condensed', sans-serif !important;
  font-weight: 600 !important;
  letter-spacing: 0.04em !important;
}
.recharts-tooltip-item,
.recharts-tooltip-item-name,
.recharts-tooltip-item-value,
.recharts-tooltip-item-separator {
  color: var(--text-secondary) !important;
}
/* Axis tick text + axis lines */
.recharts-cartesian-axis-tick-value,
.recharts-cartesian-axis-tick text,
.recharts-text {
  fill: var(--text-secondary) !important;
}
.recharts-cartesian-axis-line,
.recharts-cartesian-axis-tick-line {
  stroke: var(--border-strong) !important;
}
.recharts-cartesian-grid-horizontal line,
.recharts-cartesian-grid-vertical line {
  stroke: var(--border) !important;
}
.recharts-legend-item-text {
  color: var(--text-secondary) !important;
}

/* ---------- Defensive overrides for known hardcoded rgba() tints ----------
   Pages that pre-date the semantic-token system used inline
   `background: rgba(180,40,40,0.08)` for danger banners and similar.
   They still work because alpha blending keeps them subtle, but they
   ignore the active theme. This selector list re-tints those exact
   patterns to use the semantic tokens. The match list is intentionally
   conservative — only the hardcoded triplets actually present in the
   tree, not a general regex (CSS can't regex inline styles). */
[data-theme="dark"] [style*="rgba(220,50,50,0.08)"],
[data-theme="dark"] [style*="rgba(180,40,40,0.08)"],
[data-theme="dark"] [style*="rgba(220, 50, 50, 0.08)"],
[data-theme="dark"] [style*="rgba(180, 40, 40, 0.08)"],
[data-theme="dark"] [style*="rgba(220,38,38,0.04)"],
[data-theme="dark"] [style*="rgba(220, 38, 38, 0.04)"] {
  background: var(--danger-bg) !important;
}

/* ---------- Status pill / badge defaults ----------
   Provide first-class classes for status pills so feature pages can
   stop reaching for hand-rolled inline rgba() tints. Components can
   migrate at their own pace; both old and new co-exist safely. */
.pill-status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  font-family: 'Barlow Condensed', sans-serif;
  background: var(--cream-100); color: var(--text-secondary);
  border: 1px solid var(--border);
}
.pill-status.success { background: var(--success-bg); color: var(--success-fg); border-color: color-mix(in oklab, var(--success-fg) 30%, transparent); }
.pill-status.warning { background: var(--warning-bg); color: var(--warning-fg); border-color: var(--warning-border); }
.pill-status.danger  { background: var(--danger-bg);  color: var(--danger-fg);  border-color: color-mix(in oklab, var(--danger-fg) 30%, transparent); }
.pill-status.info    { background: var(--info-bg);    color: var(--info-fg);    border-color: color-mix(in oklab, var(--info-fg) 30%, transparent); }

/* ============================================================
   RESPONSIVE SAFETY NET (2026-05-22)
   Feature pages inject fixed `grid-template-columns: repeat(N,1fr)`
   grids from a per-page <style> block in <body>, which wins the
   cascade over this stylesheet (loaded in <head>) at equal
   specificity. So these overrides MUST use !important to take hold.
   Desktop (>1280px) is left untouched; below that, fixed N-column
   strips collapse to auto-fit so they never overflow narrow viewports.
   ============================================================ */

/* --- KPI strips: collapse first (they pack 4-5 tiles) --- */
@media (max-width: 1280px) {
  .kpi-row, .kpi-strip, .kpi-4, .kpi2, .kpi5, .vc-kpi, .far-kpi, .gi-kpis, .eg-sec-strip {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)) !important;
  }
}

/* --- All content grids: collapse on tablet/narrow --- */
@media (max-width: 1000px) {
  .kpi-row, .kpi-strip, .kpi-4, .kpi2, .kpi5, .vc-kpi, .far-kpi, .gi-kpis, .eg-sec-strip,
  .age-grid, .assumption-grid, .audit-grid, .auth-chain, .bgrid, .bp-grid, .cal-grid,
  .cards, .cashup, .cohort-grid, .comp-grid, .cond-grid, .disclosure-grid, .drv,
  .ehs-grid, .enf-grid, .entity-grid, .eq-grid, .ext-grid, .fp-grid, .grant-grid,
  .grants-grid, .hc-grid, .ia-grid, .ippf-grid, .journey, .ladder, .linked, .meta-grid,
  .meta-kv, .mini-heat, .mix-leg, .mlp-bands, .mt, .party-grid, .phase, .phases,
  .plan-grid, .plot-grid, .pp-grid, .ppr-grid, .pprr, .rep-grid, .rev-grid, .sans-grid,
  .sched, .segrid, .series-grid, .sev-grid, .sg-grid, .split, .stat-grid, .status-grid,
  .sub-grid, .svc-grid, .tariff-grid, .th-grid, .tl, .tranche-grid, .trend, .triple,
  .up-grid, .up-tot, .xref {
    grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)) !important;
  }
}

/* --- Phone: single column for everything --- */
@media (max-width: 560px) {
  .kpi-row, .kpi-strip, .kpi-4, .kpi2, .kpi5, .vc-kpi, .far-kpi, .gi-kpis, .eg-sec-strip,
  .age-grid, .assumption-grid, .audit-grid, .auth-chain, .bgrid, .bp-grid, .cal-grid,
  .cards, .cashup, .cohort-grid, .comp-grid, .cond-grid, .disclosure-grid, .drv,
  .ehs-grid, .enf-grid, .entity-grid, .eq-grid, .ext-grid, .fp-grid, .grant-grid,
  .grants-grid, .hc-grid, .ia-grid, .ippf-grid, .journey, .ladder, .linked, .meta-grid,
  .meta-kv, .mini-heat, .mix-leg, .mlp-bands, .mt, .party-grid, .phase, .phases,
  .plan-grid, .plot-grid, .pp-grid, .ppr-grid, .pprr, .rep-grid, .rev-grid, .sans-grid,
  .sched, .segrid, .series-grid, .sev-grid, .sg-grid, .split, .stat-grid, .status-grid,
  .sub-grid, .svc-grid, .tariff-grid, .th-grid, .tl, .tranche-grid, .trend, .triple,
  .up-grid, .up-tot, .xref {
    grid-template-columns: 1fr !important;
  }
}

/* --- Wide tables/cards never clip: allow horizontal scroll --- */
@media (max-width: 900px) {
  .sec, .card, .panel, .tbl-wrap, .table-wrap { overflow-x: auto; }
}

/* --- Mobile shell: sidebar becomes an off-canvas drawer (<=860px) ---
   The desktop layout is a 2-column grid (sidebar | content). On narrow
   screens that squeezes content into a sliver, so below 860px the content
   spans the full width and the sidebar slides in over it as a drawer,
   toggled by the existing topbar ≡ button (wired in utils.js). The
   desktop icon-only collapse is suppressed here — the drawer always shows
   full labels. */
@media (max-width: 860px) {
  .app,
  .app[data-collapsed="true"] { grid-template-columns: 1fr; max-width: 100vw; }

  /* Grid-blowout guard: without min-width:0 a grid item expands to its
     content's min-content width, blowing the 1fr column (and the spanning
     topbar) past the viewport. Clamp it and clip stray horizontal bleed.
     Also move .content into column 1 — it's pinned to column 2 for the
     desktop sidebar layout, but we've collapsed to a single column here, so
     leaving it at column 2 spawns a content-sized implicit column. */
  .content, .sidebar { min-width: 0; }
  .content { grid-column: 1; overflow-x: hidden; }

  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    width: var(--sidebar-w);
    max-width: 84vw;
    height: calc(100vh - var(--topbar-h));
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 220ms ease;
    box-shadow: 2px 0 18px rgba(0, 0, 0, 0.22);
  }
  .app[data-mobile-nav="open"] .sidebar { transform: translateX(0); }

  /* Dimmed backdrop behind the open drawer (clicks close it via utils.js). */
  .app[data-mobile-nav="open"]::after {
    content: "";
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    background: rgba(0, 0, 0, 0.42);
    z-index: 55;
  }

  /* Never icon-collapse the drawer — always show full labels/sections. */
  .app[data-collapsed="true"] .sidebar .group-label,
  .app[data-collapsed="true"] .sidebar .nav-item .label,
  .app[data-collapsed="true"] .sidebar .nav-item.sub { display: revert; }

  /* The floating desktop collapse FAB is meaningless on mobile. */
  #sidebarCollapseBtn.collapse-toggle { display: none !important; }

  /* Give the content a little breathing room now it's full-bleed. */
  .content { padding-left: 16px; padding-right: 16px; }

  /* The ctx-bar bleeds to the edge via negative margins sized for the
     desktop 32px content padding — re-match them to the mobile 16px. */
  .ctx-bar { margin-left: -16px; margin-right: -16px; padding-left: 16px; padding-right: 16px; }

  /* Topbar: the logo reserves a fixed 240px (= sidebar width) on desktop so
     it lines up with the sidebar column. With no sidebar column on mobile
     that just wastes space and forces overflow — let it size to content. */
  .topbar { gap: 8px; padding: 0 12px; }
  .topbar .logo,
  .app[data-collapsed="true"] .topbar .logo { width: auto; }

  /* Compact topbar: below the drawer breakpoint the topbar can't fit all
     ~8 controls in one row, so shed the secondary chrome. Navigation lives
     in the ≡ drawer; search has no Ctrl+K affordance on touch anyway. */
  .search { display: none; }
  .topbar .me span:nth-of-type(2) { display: none; } /* keep avatar, drop name */
  /* !important: ThemeToggle injects its own .tt-btn{display:inline-flex}
     <style> in <body>, which beats this head rule at equal specificity. */
  .tt-btn { display: none !important; }               /* theme toggle: desktop-only */
  .client-pill { max-width: 160px; }
}

/* Phone: tighten the remaining topbar spacing so the essentials always fit. */
@media (max-width: 600px) {
  .topbar { gap: 6px; padding: 0 8px; }
  .client-pill { max-width: 150px; }
}

@media (max-width: 440px) {
  .topbar .logo .wordmark { display: none; }          /* keep the mark, drop wordmark */
}
