/* ==========================================================================
   Design System
   Default palette: Signature Green #1B5E20 / Spark Gold #FFC107
   ========================================================================== */

/* ---------- 0. Self-hosted fonts ----------
   Two VARIABLE woff2 files, subset to Latin. A variable file carries the whole
   weight axis in one download, so 400/500/800 cost a single request each — and
   nothing is fetched from a third-party origin, which is what keeps the app
   fully offline-capable.

   `font-display: swap` paints text immediately in the fallback stack and
   re-renders when the face arrives, so a cold first load never shows invisible
   text (the failure mode of `block`).

   Paths are relative to this stylesheet, hence `../assets/fonts/`. */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../assets/fonts/inter-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Plus Jakarta Sans';
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url('../assets/fonts/plus-jakarta-sans-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- 1. Design Tokens ----------
   The brand + gold + sidebar tokens below are the fallback for the default
   palette. At runtime js/brand.js recomputes and overwrites every one of them
   as an inline custom property on <html>, which outranks both :root and
   [data-theme="dark"] — so a client's own brand always wins.
   Values here are generated by buildPalette(DEFAULT_BRAND, 'light') and must
   stay in sync with it (asserted by scripts/test-core.js). */
:root {
  /* ---------- Brand identity ramp ----------
     "The Check-Invoice mark" green as a fixed 6-step ramp. This is the APP's
     own identity (Smart Invoice Pro) and is deliberately kept separate from the
     white-label --brand tokens below: a client's palette re-themes the whole
     UI, but the app logo/icon always keeps these greens. */
  --brand-900: #0F3D14;
  --brand-700: #1B5E20;
  --brand-500: #43A047;
  --brand-200: #A5D6A7;
  --brand-100: #C8E6C9;
  --brand-50:  #E8F5E9;

  /* ---------- Accent ramp (gold) ---------- */
  --spark: #FFC107;
  --spark-100: #FFECB3;
  --spark-900: #5D4300;

  /* ---------- Live brand tokens ----------
     Generated by buildPalette(DEFAULT_BRAND, 'light') and kept in sync with it
     (asserted by scripts/test-brand.js). js/brand.js overwrites every one of
     these inline on <html> at runtime, so a client's palette always wins. */
  --brand: #1B5E20;
  --brand-dark: #103613;
  --brand-darker: #071708;
  --brand-light: #26862D;
  --brand-soft: #EDF2ED;
  --brand-ink: #1B5E20;
  --brand-contrast: #FFFFFF;
  --gold: #FFC107;
  --gold-light: #FFD044;
  --gold-soft: #FFF8E1;
  --gold-ink: #AD8200;
  --gold-contrast: #1A1A1A;

  /* Sidebar surface — swapped by the sidebar style option. */
  --sidebar-bg: linear-gradient(180deg, #071708 0%, #103613 60%, #1B5E20 100%);
  --sidebar-fg: #FFFFFF;
  --sidebar-fg-soft: rgba(255, 255, 255, 0.55);
  --sidebar-hover: rgba(255, 255, 255, 0.10);
  --sidebar-border: rgba(255, 255, 255, 0.12);
  --sidebar-active-bg: #FFC107;
  --sidebar-active-fg: #1A1A1A;
  --sidebar-logo-bg: #FFFFFF;
  --sidebar-logo-border: transparent;
  --sidebar-card-bg: rgba(255, 255, 255, 0.10);

  /* ---------- Neutrals ----------
     Green-tinted greys so the chrome sits in the same family as the brand.
     --ink-2 / --line are the canonical names from the design system; the older
     --ink-soft / --border names are kept and carry the same values, so a
     component may use either. */
  --ink: #0F1F14;
  --ink-2: #4C5F52;
  --ink-soft: #4C5F52;
  --ink-faint: #7C8F82;
  --bg: #F4F8F4;
  --surface: #FFFFFF;
  --surface-2: #EDF3EE;
  --line: #D5E2D6;
  --border: #D5E2D6;
  --border-strong: #B9CDBB;

  /* ---------- Semantic ---------- */
  --danger: #B3261E;
  --danger-100: #FFCDD2;
  --danger-900: #7A1414;
  --danger-soft: #FDECEA;
  --success: #2E7D32;
  --success-soft: #E8F5E9;
  --warning: #F57C00;
  --warning-soft: #FFF3E0;
  --info: #1B5E20;
  --info-soft: #E8F5E9;

  /* ---------- Enterprise surface, border & text scale ----------
     The canonical names for chrome, surfaces, hairlines and the text ramp.
     In dark mode the legacy tokens (--bg, --surface, --ink, --border, …) are
     ALIASED to these, so a component may use either name and get the same
     result.

     The light values deliberately reproduce the legacy tokens exactly, so
     adding this scale changes nothing in light mode. */
  --bg-canvas: #F4F8F4;
  --bg-surface: #FFFFFF;
  --bg-elevated: #FFFFFF;
  --bg-hover: #EDF3EE;

  --border-subtle: #D5E2D6;
  --border-medium: #B9CDBB;
  /* Focus ring border. Derived from the brand so a client's palette drives it. */
  --border-focus: var(--brand);

  --text-primary: #0F1F14;
  --text-secondary: #4C5F52;
  --text-tertiary: #7C8F82;

  --accent-primary: var(--brand);
  --accent-glow: var(--brand-soft);

  /* ---------- Translucent status pills ----------
     Light mode keeps the solid legacy fills (see .badge-* in section 9);
     dark mode re-points them at the translucent values in section 25. */
  --badge-paid-bg: var(--success-soft);
  --badge-paid-text: var(--success);
  --badge-paid-border: transparent;
  --badge-unpaid-bg: var(--warning-soft);
  --badge-unpaid-text: var(--warning);
  --badge-unpaid-border: transparent;
  --badge-partial-bg: var(--gold-soft);
  --badge-partial-text: var(--gold-ink);
  --badge-partial-border: transparent;
  --badge-overdue-bg: var(--danger-soft);
  --badge-overdue-text: var(--danger);
  --badge-overdue-border: transparent;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 999px;

  /* Elevation, in the design system's two-step form. The longer shadow ramp
     below predates it and is kept for existing components. */
  --shadow-1: 0 1px 2px rgba(15, 31, 20, 0.06);
  --shadow-2: 0 4px 16px rgba(15, 31, 20, 0.08);

  --shadow-xs: 0 1px 2px rgba(15, 31, 20, 0.05);
  --shadow-sm: 0 2px 6px rgba(15, 31, 20, 0.06);
  --shadow: 0 6px 18px rgba(15, 31, 20, 0.08);
  --shadow-md: 0 10px 30px rgba(15, 31, 20, 0.10);
  --shadow-lg: 0 18px 50px rgba(15, 31, 20, 0.14);
  --shadow-brand: 0 8px 22px rgba(27, 94, 32, 0.28);

  /* Display face for headings, brand and big numbers; Inter for everything
     else. Both are self-hosted (see section 0) and both fall back to the
     platform UI stack if the woff2 fails to load. */
  --font-sans: 'Inter', "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-display: 'Plus Jakarta Sans', 'Inter', "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;

  --sidebar-w: 264px;
  --topbar-h: 68px;
  --bottomnav-h: 66px;

  /* Dim behind the onboarding spotlight and the help drawer. A token rather
     than a literal so dark mode can deepen it — on a near-black canvas the
     light scrim reads as no dimming at all. */
  --tour-scrim: rgba(18, 24, 18, 0.62);

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --speed: 0.22s;
}

/* ==========================================================================
   Dark theme — deep forest
   ==========================================================================
   A green-tinted near-black scale: a deep canvas, two raised surfaces, quiet
   hairline borders, and a three-step text ramp. It is the dark counterpart of
   the light theme's green-tinted neutrals, so both themes sit in the brand's
   own colour family rather than fighting it.

   Two properties make this safe to layer on top of a white-label app:

     1. The brand tokens (--brand*, --gold*, --sidebar-*) are still written
        INLINE on <html> by js/brand.js. An inline custom property outranks this
        block, so a client's own palette always wins. Everything below that is
        expressed in terms of --brand therefore re-themes automatically.

     2. The legacy tokens (--bg, --surface, --ink, --border, …) are ALIASED to
        the new scale rather than deleted. That means all ~1200 lines of
        component CSS adopt the dark palette without a single component rule
        needing to change, and any component written later keeps working.

   Component-level dark rules live in section 25.
   ========================================================================== */
[data-theme="dark"] {
  /* ---------- Surface scale ---------- */
  --bg-canvas: #0B1610;
  --bg-surface: #12231A;
  --bg-elevated: #182C20;
  --bg-hover: #22382A;

  /* ---------- Micro-borders ---------- */
  --border-subtle: #233A2B;
  --border-medium: #2F4A38;
  /* The reference spec is rgba(99, 102, 241, 0.6) — an indigo ring. It is
     derived from --brand instead so the ring follows a client's palette rather
     than fighting it. Choose the Indigo preset for the reference look, or see
     the README for the one line that pins it to indigo. */
  --border-focus: color-mix(in srgb, var(--brand) 60%, transparent);

  /* ---------- Typography contrast ---------- */
  --text-primary: #EAF3EC;
  --text-secondary: #9DB2A3;
  --text-tertiary: #6E8474;

  /* ---------- Accent & glow (brand-derived — see --border-focus note) ---------- */
  --accent-primary: var(--brand);
  --accent-glow: color-mix(in srgb, var(--brand) 25%, transparent);

  /* ---------- Translucent status pills ---------- */
  --badge-paid-bg: rgba(16, 185, 129, 0.12);
  --badge-paid-text: #34D399;
  --badge-paid-border: rgba(16, 185, 129, 0.25);
  --badge-unpaid-bg: rgba(245, 158, 11, 0.12);
  --badge-unpaid-text: #FBBF24;
  --badge-unpaid-border: rgba(245, 158, 11, 0.25);
  --badge-partial-bg: rgba(56, 189, 248, 0.12);
  --badge-partial-text: #38BDF8;
  --badge-partial-border: rgba(56, 189, 248, 0.25);
  --badge-overdue-bg: rgba(244, 63, 94, 0.12);
  --badge-overdue-text: #FB7185;
  --badge-overdue-border: rgba(244, 63, 94, 0.25);

  /* ---------- Legacy aliases → enterprise scale ----------
     The one block that makes the whole stylesheet adopt the new palette. */
  --bg: var(--bg-canvas);
  --surface: var(--bg-surface);
  --surface-2: var(--bg-elevated);
  --border: var(--border-subtle);
  --border-strong: var(--border-medium);
  --ink: var(--text-primary);
  --ink-soft: var(--text-secondary);
  --ink-faint: var(--text-tertiary);

  /* ---------- Canonical neutral names, re-pointed for dark ---------- */
  --ink-2: #9DB2A3;
  --line: #233A2B;

  /* ---------- Brand identity ramp, re-pointed for dark ----------
     The ramp is fixed in light mode; on a dark canvas the 700 step has to lift
     so it still reads as the brand's link/text colour. The mark and the icon
     backgrounds keep the true #1B5E20. */
  --brand-700: #43A047;

  /* ---------- Brand fallbacks ----------
     Only used if js/brand.js never runs (missing script / blocked). Kept in
     sync with buildPalette(DEFAULT_BRAND, 'dark') — asserted by test-brand.js. */
  --brand: #2D9D36;
  --brand-dark: #1B5E20;
  --brand-darker: #103613;
  --brand-light: #48CA51;
  --brand-soft: rgba(45, 157, 54, 0.16);
  --brand-ink: #2D9D36;
  --brand-contrast: #1A1A1A;
  --gold: #FFCE3A;
  --gold-light: #FFE28C;
  --gold-soft: rgba(255, 206, 58, 0.14);
  --gold-ink: #FFCE3A;
  --gold-contrast: #1A1A1A;

  /* ---------- Status ---------- */
  --danger: #EF5350;
  --danger-soft: rgba(239, 83, 80, 0.14);
  --success: #66BB6A;
  --success-soft: rgba(102, 187, 106, 0.14);
  --warning: #FFA726;
  --warning-soft: rgba(255, 167, 38, 0.14);
  --info: #81C784;
  --info-soft: rgba(129, 199, 132, 0.14);

  /* ---------- Shadows ----------
     Deeper and softer than light mode: a near-black canvas swallows a small
     shadow entirely, so the offset has to grow to read as depth. */
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 4px 16px rgba(0, 0, 0, 0.45);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.35);
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.6);
  --shadow-brand: 0 8px 22px rgba(45, 157, 54, 0.25);

  /* The spotlight scrim: deeper than the light value, because dimming a
     near-black canvas with a light wash reads as *lightening* it. */
  --tour-scrim: rgba(0, 0, 0, 0.74);
}

/* ---------- 2. Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
  min-height: 100vh;
}

img, svg, canvas { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
ul, ol { list-style: none; }
h1, h2, h3, h4, h5, h6 { font-family: var(--font-display); font-weight: 700; line-height: 1.25; letter-spacing: -0.01em; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--gold-soft); color: var(--ink); }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }

/* ---------- 3. Typography ---------- */
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.85rem; }
.text-base { font-size: 0.95rem; }
.text-lg { font-size: 1.1rem; }
.text-xl { font-size: 1.35rem; }
.text-2xl { font-size: 1.6rem; }
.text-3xl { font-size: 2rem; }
.text-4xl { font-size: 2.5rem; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.font-black { font-weight: 800; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }
.text-muted { color: var(--ink-soft); }
.text-faint { color: var(--ink-faint); }
.text-brand { color: var(--brand-ink); }
.text-gold { color: var(--gold-ink); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-white { color: #fff; }
.uppercase { text-transform: uppercase; }
.capitalize { text-transform: capitalize; }
.tracking-wide { letter-spacing: 0.04em; }
.tracking-widest { letter-spacing: 0.12em; }
.leading-tight { line-height: 1.25; }
.leading-none { line-height: 1; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.break-all { word-break: break-all; }
.break-words { overflow-wrap: break-word; }

/* ---------- 4. Layout ---------- */
.app-shell { display: flex; min-height: 100vh; }

/* Mobile-first: the sidebar lives off-canvas until there is room to dock it
   (see the min-width: 1024px block at the end of this file). */
.sidebar {
  position: fixed; inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex; flex-direction: column;
  z-index: 60;
  transform: translateX(-100%);
  transition: transform var(--speed) var(--ease), background var(--speed) var(--ease);
  box-shadow: var(--shadow-md);
}
.sidebar.open { transform: translateX(0); }

.sidebar-backdrop {
  position: fixed; inset: 0; z-index: 55; background: rgba(0, 0, 0, 0.45);
  opacity: 0; pointer-events: none; transition: opacity var(--speed) var(--ease);
}
.sidebar-backdrop.open { opacity: 1; pointer-events: auto; }

.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-brand .logo-box {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--sidebar-logo-bg); display: grid; place-items: center;
  box-shadow: var(--shadow-sm); overflow: hidden; flex-shrink: 0;
  border: 1px solid var(--sidebar-logo-border);
}
.sidebar-brand .logo-box img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-brand .logo-box .logo-fallback {
  width: 100%; height: 100%; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--gold-light), var(--gold));
  color: var(--gold-contrast); font-weight: 800; font-size: 1.1rem;
}
.sidebar-brand .brand-name { font-weight: 800; font-size: 1.05rem; line-height: 1.15; }
.sidebar-brand .brand-sub { font-size: 0.7rem; opacity: 0.75; letter-spacing: 0.08em; text-transform: uppercase; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 14px 12px; }
.sidebar-nav .nav-label {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--sidebar-fg-soft); padding: 14px 12px 6px; font-weight: 700;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; margin: 2px 0;
  border-radius: var(--radius);
  color: var(--sidebar-fg);
  opacity: 0.85;
  font-weight: 600; font-size: 0.9rem;
  transition: background var(--speed) var(--ease), transform var(--speed) var(--ease);
  position: relative;
}
.nav-item:hover { background: var(--sidebar-hover); text-decoration: none; transform: translateX(2px); opacity: 1; }
.nav-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-fg); opacity: 1; box-shadow: var(--shadow-sm); }
.nav-item.active::before {
  content: ""; position: absolute; left: -12px; top: 20%; bottom: 20%;
  width: 4px; border-radius: 0 4px 4px 0; background: var(--sidebar-active-bg);
}
.nav-item .nav-icon { width: 20px; height: 20px; flex-shrink: 0; }
.nav-item .nav-badge {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: 0.68rem; font-weight: 700; padding: 2px 7px; border-radius: var(--radius-full);
}
.nav-item.active .nav-badge { background: rgba(0, 0, 0, 0.22); color: inherit; }

.sidebar-footer { padding: 14px; border-top: 1px solid var(--sidebar-border); }
.sidebar-footer .install-card {
  background: var(--sidebar-card-bg); border-radius: var(--radius);
  padding: 12px; display: flex; align-items: center; gap: 10px;
}
.sidebar-footer .install-card .ic-text { font-size: 0.75rem; line-height: 1.3; flex: 1; }
.sidebar-footer .install-card .ic-text strong { display: block; font-size: 0.82rem; }

/* min-width:0 lets grid/flex children shrink below their content width —
   without it a wide table or select forces the whole page to scroll sideways. */
.main {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
  padding-bottom: var(--bottomnav-h);
}

/* Mobile-first topbar. The currency <select> used to be ~220px wide and, with
   the title and two icon buttons, forced a 378px minimum page width — which
   scrolled sideways on a 320px phone. Everything here must be allowed to
   shrink or truncate. */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px;
  min-width: 0;
}
.topbar .page-title { font-size: 1.05rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .page-sub { font-size: 0.78rem; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar > div:not(.topbar-spacer) { min-width: 0; }
.topbar-spacer { flex: 1; }
.topbar .select { max-width: 108px; min-width: 0; text-overflow: ellipsis; }

/* The hamburger only exists while the sidebar is off-canvas. */
#menuBtn { display: inline-grid; }

/* `overflow-x: clip` rather than `hidden`: clip does NOT create a scroll
   container, so it cannot break `position: sticky` or scroll-into-view for any
   descendant — it only stops a stray wide child from producing a page-level
   horizontal scrollbar. Belt and braces: .grid > * already removes the cause. */
.content { padding: 14px; flex: 1; width: 100%; max-width: 1440px; margin: 0 auto; min-width: 0; overflow-x: clip; }

/* Bottom navigation — the primary nav on touch devices, hidden at ≥1024px */
.bottom-nav {
  display: block;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 55;
  height: var(--bottomnav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav .bn-inner { display: flex; height: 100%; }
.bottom-nav .bn-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--ink-faint); font-size: 0.66rem; font-weight: 600;
  transition: color var(--speed) var(--ease);
  position: relative;
}
.bottom-nav .bn-item svg { width: 22px; height: 22px; }
.bottom-nav .bn-item.active { color: var(--brand); }
.bottom-nav .bn-item.active::before {
  content: ""; position: absolute; top: 0; left: 30%; right: 30%;
  height: 3px; border-radius: 0 0 4px 4px; background: var(--gold);
}

/* FAB */
.fab {
  position: fixed; right: 22px; bottom: calc(var(--bottomnav-h) + 20px);
  z-index: 50; width: 58px; height: 58px; border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--brand-light), var(--brand));
  color: #fff; display: grid; place-items: center;
  box-shadow: var(--shadow-brand);
  transition: transform var(--speed) var(--ease-spring), box-shadow var(--speed) var(--ease);
}
.fab:hover { transform: scale(1.08) translateY(-2px); box-shadow: 0 14px 30px rgba(46, 125, 50, 0.4); }
.fab:active { transform: scale(0.96); }
.fab svg { width: 26px; height: 26px; }

/* ---------- 5. Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--speed) var(--ease), transform var(--speed) var(--ease), border-color var(--speed) var(--ease);
}
.card-hover:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: var(--border-strong); }
.card-pad { padding: 20px; }
.card-header { display: flex; align-items: center; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.card-header h3 { font-size: 1rem; }
.card-body { padding: 20px; }
.card-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }

.stat-card { position: relative; overflow: hidden; }
.stat-card .stat-icon {
  width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center;
  margin-bottom: 14px;
}
.stat-card .stat-icon svg { width: 22px; height: 22px; }
.stat-card .stat-value { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.stat-card .stat-label { font-size: 0.78rem; color: var(--ink-faint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; margin-top: 4px; }
.stat-card .stat-trend { font-size: 0.75rem; font-weight: 700; margin-top: 8px; display: inline-flex; align-items: center; gap: 4px; }
.stat-card .stat-deco {
  position: absolute; right: -18px; top: -18px; width: 110px; height: 110px;
  border-radius: 50%; opacity: 0.08; pointer-events: none;
}

/* ---------- 6. Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--radius);
  font-weight: 700; font-size: 0.88rem; line-height: 1.2;
  border: 1px solid transparent;
  transition: all var(--speed) var(--ease);
  white-space: nowrap; user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn svg { width: 17px; height: 17px; flex-shrink: 0; }
.btn-primary { background: linear-gradient(135deg, var(--brand-light), var(--brand)); color: var(--brand-contrast); box-shadow: var(--shadow-brand); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-gold { background: linear-gradient(135deg, var(--gold-light), var(--gold)); color: var(--gold-contrast); box-shadow: 0 6px 18px rgba(249, 168, 37, 0.3); }
.btn-gold:hover { filter: brightness(1.05); }
.btn-outline { border-color: var(--border-strong); color: var(--ink); background: var(--surface); }
.btn-outline:hover { border-color: var(--brand); color: var(--brand-ink); background: var(--brand-soft); }
.btn-ghost { color: var(--ink-soft); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-danger-outline { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn-danger-outline:hover { background: var(--danger-soft); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.08); }
.btn-sm { padding: 7px 12px; font-size: 0.8rem; border-radius: 9px; }
.btn-sm svg { width: 15px; height: 15px; }
.btn-lg { padding: 13px 24px; font-size: 0.95rem; border-radius: 14px; }
.btn-block { width: 100%; }
.btn-icon { padding: 9px; border-radius: 10px; }
.btn-icon svg { width: 18px; height: 18px; }
.btn[disabled] { opacity: 0.55; pointer-events: none; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; display: inline-grid; place-items: center;
  color: var(--ink-soft); transition: all var(--speed) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn.success:hover { background: var(--success-soft); color: var(--success); }

/* ---------- 7. Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > label,
.field > .field-label { font-size: 0.8rem; font-weight: 700; color: var(--ink-soft); }
.field .hint { font-size: 0.72rem; color: var(--ink-faint); }
.field .req { color: var(--danger); }
.input, .select, .textarea {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-faint); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-soft);
}
.input.invalid, .select.invalid, .textarea.invalid { border-color: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }
.textarea { min-height: 90px; resize: vertical; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238A8A8A' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 38px; }
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: var(--radius) 0 0 var(--radius); }
.input-group .input-group-addon {
  display: inline-flex; align-items: center; padding: 0 14px;
  background: var(--surface-2); border: 1.5px solid var(--border-strong); border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.85rem; font-weight: 700; color: var(--ink-soft);
}
.input-group .input-group-addon.prefix { border-radius: var(--radius) 0 0 var(--radius); border-right: none; border-left: 1.5px solid var(--border-strong); }
.input-group .input-group-addon.prefix + .input { border-radius: 0 var(--radius) var(--radius) 0; }

/* Uploaded artwork (logo / signature / stamp) in Settings. `contain` rather
   than `cover` so a wide signature is not cropped to a square. */
.asset-preview {
  width: 64px; height: 64px; flex: none;
  border-radius: 12px; background: var(--surface-2);
  display: grid; place-items: center; overflow: hidden;
  border: 1px solid var(--border);
}
.asset-preview img { width: 100%; height: 100%; object-fit: contain; }

.checkbox, .radio { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 0.88rem; user-select: none; }
.checkbox input, .radio input { width: 18px; height: 18px; accent-color: var(--brand); cursor: pointer; }

.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; border-radius: var(--radius-full);
  background: var(--border-strong); transition: background var(--speed) var(--ease);
}
.switch .slider::before {
  content: ""; position: absolute; width: 20px; height: 20px; border-radius: 50%;
  left: 3px; top: 3px; background: #fff; box-shadow: var(--shadow-xs);
  transition: transform var(--speed) var(--ease-spring);
}
.switch input:checked + .slider { background: var(--brand); }
.switch input:checked + .slider::before { transform: translateX(20px); }
.switch input:focus-visible + .slider { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- 8. Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); }
.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; min-width: 640px; }
.table thead th {
  text-align: left; padding: 12px 16px;
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--ink-faint); font-weight: 700;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background var(--speed) var(--ease); }
.table tbody tr:hover { background: var(--brand-soft); }
.table tbody tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { display: flex; gap: 4px; justify-content: flex-end; }
.table .cell-main { font-weight: 600; }

/* Line-item editor ---------------------------------------------------------
   The shared cell padding (16px) plus the control padding (14px) consumed
   almost all of an 80px numeric column, so the Qty box rendered ~20px wide and
   clipped its own digits behind the spinner arrows. `table-layout: fixed`
   makes the declared column widths authoritative instead of letting the wide
   Product/Description column (a <select> whose intrinsic width follows its
   longest option) steal the space, and the tighter padding buys the numbers
   room to actually be read. */
.items-table { table-layout: fixed; }
.items-table thead th { padding: 12px 10px; }
.items-table tbody td { padding: 10px; }
.items-table .input,
.items-table .select { padding: 9px 8px; min-width: 0; }
.items-table .select { padding-right: 26px; background-position: right 6px center; }
.items-table .num { padding-right: 12px; }
.table .cell-sub { font-size: 0.76rem; color: var(--ink-faint); }

/* ---------- 9. Badges & Chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: var(--radius-full);
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.02em;
  white-space: nowrap;
}
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-green { background: var(--success-soft); color: var(--success); }
.badge-gold { background: var(--gold-soft); color: var(--gold-ink); }
.badge-red { background: var(--danger-soft); color: var(--danger); }
.badge-gray { background: var(--surface-2); color: var(--ink-soft); }
.badge-blue { background: var(--info-soft); color: var(--info); }
.badge-orange { background: var(--warning-soft); color: var(--warning); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: var(--radius-full);
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 0.8rem; font-weight: 600; color: var(--ink-soft);
  transition: all var(--speed) var(--ease); cursor: pointer;
}
.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip.active { background: var(--brand); color: var(--brand-contrast); border-color: var(--brand); }

/* ---------- 10. Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(18, 24, 18, 0.55);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  padding: 20px;
  opacity: 0; pointer-events: none;
  transition: opacity var(--speed) var(--ease);
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  transform: translateY(16px) scale(0.97);
  transition: transform var(--speed) var(--ease-spring);
}
.modal-overlay.open .modal { transform: translateY(0) scale(1); }
.modal-lg { max-width: 760px; }
.modal-xl { max-width: 980px; }
.modal-header { display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 1.05rem; flex: 1; }
.modal-body { padding: 22px; overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); }

/* ---------- 11. Toast ---------- */
.toast-container {
  position: fixed; top: 18px; right: 18px; z-index: 200;
  display: flex; flex-direction: column; gap: 10px;
  max-width: min(380px, calc(100vw - 36px));
}
.toast {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  border-radius: var(--radius);
  padding: 13px 16px;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.3s var(--ease-spring);
  font-size: 0.88rem;
  min-width: 0; max-width: 100%;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast .toast-icon { width: 20px; height: 20px; flex-shrink: 0; margin-top: 1px; }
.toast .toast-msg { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast .toast-close { color: var(--ink-faint); }
.toast.leaving { animation: toast-out 0.25s var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px) scale(0.95); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px) scale(0.95); } }

/* ---------- 12. Skeleton ---------- */
.skeleton {
  position: relative; overflow: hidden;
  background: var(--surface-2); border-radius: var(--radius);
  min-height: 14px;
}
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  animation: shimmer 1.4s infinite;
}
[data-theme="dark"] .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent); }
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ---------- 13. Utilities ---------- */
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }
.hidden { display: none !important; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; } .gap-5 { gap: 20px; } .gap-6 { gap: 24px; }
.flex-1 { flex: 1; }
.flex-none { flex: none; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-5 { margin-top: 20px; } .mt-6 { margin-top: 24px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; } .mb-5 { margin-bottom: 20px; } .mb-6 { margin-bottom: 24px; }
.ml-auto { margin-left: auto; }
.mr-auto { margin-right: auto; }
.mx-auto { margin-left: auto; margin-right: auto; }
.p-0 { padding: 0; } .p-2 { padding: 8px; } .p-3 { padding: 12px; } .p-4 { padding: 16px; } .p-5 { padding: 20px; } .p-6 { padding: 24px; }
.px-2 { padding-left: 8px; padding-right: 8px; } .px-3 { padding-left: 12px; padding-right: 12px; } .px-4 { padding-left: 16px; padding-right: 16px; } .px-5 { padding-left: 20px; padding-right: 20px; } .px-6 { padding-left: 24px; padding-right: 24px; }
.py-1 { padding-top: 4px; padding-bottom: 4px; } .py-2 { padding-top: 8px; padding-bottom: 8px; } .py-3 { padding-top: 12px; padding-bottom: 12px; } .py-4 { padding-top: 16px; padding-bottom: 16px; }
.w-full { width: 100%; }
.h-full { height: 100%; }
.relative { position: relative; }
.absolute { position: absolute; }
.sticky { position: sticky; }
.overflow-hidden { overflow: hidden; }
.overflow-auto { overflow: auto; }
.rounded { border-radius: var(--radius); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-full { border-radius: var(--radius-full); }
.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow { box-shadow: var(--shadow); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }
.border { border: 1px solid var(--border); }
.border-top { border-top: 1px solid var(--border); }
.border-bottom { border-bottom: 1px solid var(--border); }
.bg-surface { background: var(--surface); }
.bg-surface-2 { background: var(--surface-2); }
.bg-brand { background: var(--brand); }
.bg-brand-soft { background: var(--brand-soft); }
.bg-gold-soft { background: var(--gold-soft); }
.bg-danger-soft { background: var(--danger-soft); }
.bg-success-soft { background: var(--success-soft); }
.bg-warning-soft { background: var(--warning-soft); }
.cursor-pointer { cursor: pointer; }
.cursor-not-allowed { cursor: not-allowed; }
.select-none { user-select: none; }
.animate-fade { animation: fade-in 0.3s var(--ease); }
.animate-slide-up { animation: slide-up 0.35s var(--ease-spring); }
.animate-scale { animation: scale-in 0.3s var(--ease-spring); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes scale-in { from { opacity: 0; transform: scale(0.94); } to { opacity: 1; transform: scale(1); } }

/* ---------- 14. Grid helpers (mobile-first) ----------
   Base = a single column. The min-width blocks at the end of this file add
   columns as the viewport grows.

   Leaving a 12-column grid un-collapsed was the worst responsive bug in this
   app: every child carries `col-span-N`, which resolved to `span 1` in a
   12-track grid, crushing each card to ~1/12 of the width. `minmax(0, 1fr)`
   (rather than bare `1fr`) also stops wide children such as tables from
   forcing the track — and the page — wider than the viewport. */
.grid-cols-2, .grid-cols-3, .grid-cols-4,
.grid-cols-5, .grid-cols-6, .grid-cols-12 { grid-template-columns: minmax(0, 1fr); }

/* Every span is defined; a missing one silently collapses the element instead
   of failing loudly. All of them are inert until the 12-track grid is enabled. */
.col-span-1, .col-span-2, .col-span-3, .col-span-4, .col-span-5, .col-span-6,
.col-span-7, .col-span-8, .col-span-9, .col-span-10, .col-span-11, .col-span-12 { grid-column: auto; }

/* A grid item defaults to `min-width: auto`, whose automatic minimum is the
   item's MIN-CONTENT size. So a wide child — a 640px table, a 90-column chart,
   a nowrap button row — forces its track wider than its share and the grid
   overflows the page, even though every track is already `minmax(0, 1fr)`.
   Collapsing the tracks is only half the contract; this is the other half. */
.grid > * { min-width: 0; }

/* ---------- 15. Empty state ---------- */
.empty-state { text-align: center; padding: 48px 24px; }
.empty-state .empty-icon {
  width: 84px; height: 84px; margin: 0 auto 18px; border-radius: 50%;
  background: var(--brand-soft); display: grid; place-items: center; color: var(--brand);
}
.empty-state .empty-icon svg { width: 38px; height: 38px; }
.empty-state h3 { font-size: 1.1rem; margin-bottom: 6px; }
.empty-state p { color: var(--ink-faint); font-size: 0.88rem; max-width: 380px; margin: 0 auto 18px; }

/* ---------- 16. Search bar ---------- */
.search-bar { position: relative; }
.search-bar svg {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  width: 17px; height: 17px; color: var(--ink-faint); pointer-events: none;
}
.search-bar .input { padding-left: 40px; }

/* ---------- 17. Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  padding: 11px 16px; font-weight: 700; font-size: 0.86rem;
  color: var(--ink-faint); border-bottom: 3px solid transparent;
  margin-bottom: -1px; white-space: nowrap;
  transition: color var(--speed) var(--ease), border-color var(--speed) var(--ease);
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--brand); border-bottom-color: var(--gold); }

/* ---------- 18. Progress ---------- */
.progress { height: 8px; border-radius: var(--radius-full); background: var(--surface-2); overflow: hidden; }
.progress .bar { height: 100%; border-radius: var(--radius-full); background: linear-gradient(90deg, var(--brand-light), var(--brand)); transition: width 0.5s var(--ease); }
.progress .bar.gold { background: linear-gradient(90deg, var(--gold-light), var(--gold)); }
.progress .bar.danger { background: linear-gradient(90deg, #EF5350, var(--danger)); }

/* ---------- 19. Avatar ---------- */
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 800; font-size: 0.9rem;
  background: linear-gradient(135deg, var(--brand-light), var(--brand)); color: var(--brand-contrast);
}
.avatar.gold { background: linear-gradient(135deg, var(--gold-light), var(--gold)); color: var(--brand-darker); }
.avatar-sm { width: 32px; height: 32px; font-size: 0.75rem; }

/* ---------- 20. Dropdown ---------- */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 70;
  min-width: 200px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-md); padding: 6px;
  opacity: 0; pointer-events: none; transform: translateY(-6px) scale(0.98);
  transition: all var(--speed) var(--ease);
}
.dropdown.open .dropdown-menu { opacity: 1; pointer-events: auto; transform: none; }
.dropdown-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px; border-radius: 9px; font-size: 0.86rem; font-weight: 600;
  color: var(--ink); transition: background var(--speed) var(--ease);
}
.dropdown-item:hover { background: var(--surface-2); text-decoration: none; }
.dropdown-item svg { width: 16px; height: 16px; color: var(--ink-faint); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger svg { color: var(--danger); }
.dropdown-item.danger:hover { background: var(--danger-soft); }
.dropdown-divider { height: 1px; background: var(--border); margin: 6px 4px; }

/* ---------- 21. Invoice document ---------- */
.invoice-doc {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: 40px; max-width: 820px; margin: 0 auto;
}
.invoice-doc .doc-header { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.invoice-doc .doc-logo { width: 96px; height: 96px; border-radius: 16px; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; }
.invoice-doc .doc-logo img { width: 100%; height: 100%; object-fit: contain; }
.invoice-doc .doc-title { font-size: 2rem; font-weight: 800; color: var(--brand-ink); letter-spacing: 0.02em; }
.invoice-doc .doc-meta { display: grid; grid-template-columns: auto auto; gap: 6px 18px; font-size: 0.85rem; }
.invoice-doc .doc-meta .k { color: var(--ink-faint); font-weight: 600; }
.invoice-doc .doc-meta .v { font-weight: 700; text-align: right; }
.invoice-doc .doc-company { font-size: 0.85rem; color: var(--ink-soft); line-height: 1.6; }
.invoice-doc .doc-company strong { color: var(--ink); font-size: 1.05rem; display: block; }
.invoice-doc .doc-section-title { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-faint); font-weight: 800; margin-bottom: 8px; }
.invoice-doc .doc-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.invoice-doc .doc-table th {
  text-align: left; padding: 10px 12px; background: var(--brand); color: var(--brand-contrast);
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em;
}
.invoice-doc .doc-table th:first-child { border-radius: 10px 0 0 10px; }
.invoice-doc .doc-table th:last-child { border-radius: 0 10px 10px 0; }
.invoice-doc .doc-table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.invoice-doc .doc-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.invoice-doc .totals { margin-left: auto; width: 280px; font-size: 0.88rem; }
.invoice-doc .totals .row { display: flex; justify-content: space-between; padding: 6px 0; }
.invoice-doc .totals .row.grand { border-top: 2px solid var(--brand); margin-top: 6px; padding-top: 10px; font-weight: 800; font-size: 1.05rem; color: var(--brand-ink); }
.invoice-doc .amount-words { font-size: 0.82rem; color: var(--ink-soft); font-style: italic; }
.invoice-doc .doc-footer { border-top: 1px solid var(--border); margin-top: 28px; padding-top: 16px; font-size: 0.78rem; color: var(--ink-faint); text-align: center; }

/* Brand block: the business name, then the logo beneath it, then the contact
   details — the letterhead order the client asked for. */
.invoice-doc .doc-brand { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; min-width: 0; }
.invoice-doc .doc-brand .doc-logo { flex: none; }

/* Authorisation block: signature + company stamp, sitting under the totals. */
.invoice-doc .doc-sign { display: flex; gap: 44px; flex-wrap: wrap; align-items: flex-end; margin-top: 34px; }
.invoice-doc .doc-sign-cell { min-width: 0; }
.invoice-doc .doc-sign-img { display: block; height: 54px; max-width: 210px; object-fit: contain; margin: 0 0 2px 4px; }
.invoice-doc .doc-sign-rule { border-top: 1px solid var(--border-strong); width: 210px; }
.invoice-doc .doc-sign-label { font-size: 0.72rem; color: var(--ink-faint); margin-top: 6px; }
.invoice-doc .doc-stamp-img { display: block; height: 84px; max-width: 130px; object-fit: contain; }
.invoice-doc .doc-stamp-ring {
  width: 84px; height: 84px; border: 2px solid var(--gold); border-radius: 50%;
  display: grid; place-items: center; text-align: center; padding: 8px;
  font-size: 0.58rem; font-weight: 800; letter-spacing: 0.06em; color: var(--gold-ink);
}

/* ---------- 22. Charts ---------- */
/* The bar chart is a flex row with one column per day. A flex item's default
   `min-width: auto` floors it at its own min-content width, so 30 or 90 date
   columns refuse to shrink below their labels. They then overflow the card —
   and because the card is a GRID item (also min-width: auto) the overflow drags
   the grid, and the page, wider than the viewport. So the chart owns its own
   overflow and scrolls; it never pushes the layout wide.

   Column width comes from --bar-w, switched by data-density (set in
   renderSalesChart, js/app.js):
     0px      a 7-day range shares the width equally and fills the card
     40px     a 30-day range gets a readable column and the chart scrolls
     32px     a 90-day range, same idea, tighter
   flex-grow stays 1 so a short range still fills a wide card. */
.chart-bar {
  --bar-w: 0px;
  width: 100%; max-width: 100%; min-width: 0;
}
.chart-bar[data-density="dense"] { --bar-w: 40px; }
.chart-bar[data-density="ultra"] { --bar-w: 32px; }

/* Three stacked bands, all measured from the same box. --scale-h is the
   0..axis-max plotting band; the two gutters give the on-bar value label and
   the x-axis label somewhere to live WITHOUT stealing height from the bars.
   `.chart-ybox`, `.chart-grid` and `.bar-scale` must all end up exactly
   --scale-h tall, or the ticks stop lining up with the gridlines. */
.chart-figure {
  --scale-h: 168px;
  /* 24px, not 20: the on-bar value label of a 100% bar is ~17px tall plus a 5px
     gap, so a 20px gutter left it clipped by a hair inside .chart-cols. */
  --gutter-top: 24px;
  --gutter-bottom: 22px;
  display: flex; align-items: flex-start; gap: 8px;
  margin: 0; width: 100%; min-width: 0;
  height: calc(var(--gutter-top) + var(--scale-h) + var(--gutter-bottom));
}
.chart-figure-empty { display: block; height: auto; min-height: 240px; }

/* Y axis — its own column so it stays put while a 30/90-day plot scrolls. */
.chart-yaxis { position: relative; flex: 0 0 46px; width: 46px; height: calc(var(--gutter-top) + var(--scale-h)); }
.chart-ybox { position: absolute; left: 0; right: 0; top: var(--gutter-top); height: var(--scale-h); }
.chart-ytick {
  position: absolute; left: 0; right: 6px; text-align: right;
  transform: translateY(50%);           /* centre the text on its own tick */
  font-size: 0.64rem; font-weight: 600; line-height: 1;
  color: var(--ink-faint); font-variant-numeric: tabular-nums; white-space: nowrap;
}

.chart-plot {
  position: relative; flex: 1 1 auto; min-width: 0;
  height: calc(var(--gutter-top) + var(--scale-h) + var(--gutter-bottom));
}

/* Gridlines sit in the --scale-h band only, so 0% is the baseline and 100% is
   the top tick. Faint on purpose: they are a reading aid, not a feature. */
.chart-grid { position: absolute; left: 0; right: 0; top: var(--gutter-top); height: var(--scale-h); pointer-events: none; }
.chart-grid span { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--ink); opacity: 0.08; }

/* The scroll container spans the WHOLE plot, gutters included, so the on-bar
   value label of the tallest bar is not clipped: `overflow-x: auto` forces
   overflow-y to auto too, so anything poking above this box is cut off — and
   the tallest bar's label always pokes into the top gutter. The matching
   `::before` spacer on .bar-col keeps .bar-scale itself exactly --scale-h tall,
   so the bars still measure against the same band as the gridlines. */
.chart-cols {
  position: absolute; left: 0; right: 0; top: 0;
  height: calc(var(--gutter-top) + var(--scale-h) + var(--gutter-bottom));
  display: flex; align-items: flex-end; gap: 8px;
  overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain;
}
.chart-cols::-webkit-scrollbar { height: 6px; }
.chart-cols::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 0; }

.chart-bar .bar-col {
  /* min-width: 0 is what lets the basis actually hold — without it the
     automatic minimum re-inflates the column to its label width. */
  position: relative;
  flex: 1 0 var(--bar-w); min-width: 0;
  height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
}
/* Cancels the top gutter so .bar-scale resolves to exactly --scale-h. */
.chart-bar .bar-col::before { content: ''; flex: 0 0 var(--gutter-top); }

/* The bar's own reference box. It is the only flex child that grows, so it
   resolves to exactly --scale-h — the same band the gridlines use. The value
   label is a SIBLING of the bar, not a child: inside the bar it would be
   squashed by the scaleY() entrance. */
.chart-bar .bar-scale {
  position: relative; flex: 1 1 auto; width: 100%; min-height: 0;
  display: flex; align-items: flex-end; justify-content: center;
}
.chart-bar .bar-fill {
  width: 100%; max-width: 42px; height: var(--h, 0%);
  border-radius: 8px 8px 0 0;                 /* rounded top, flat baseline */
  background: var(--brand-700);
  opacity: 0.85;
  transform-origin: bottom;
  transition: opacity 160ms var(--ease);
}
/* The single highest period is the one thing worth calling out. */
.chart-bar .bar-fill.is-peak { background: var(--spark); }
.chart-bar .bar-col:hover .bar-fill { opacity: 1; }

.chart-bar .bar-value {
  position: absolute; left: 0; right: 0;
  bottom: calc(var(--h, 0%) + 5px);           /* rides just above the bar top */
  text-align: center; white-space: nowrap;
  font-size: 0.68rem; font-weight: 800; color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
/* At 30/90 columns a money value is wider than its own column and would collide
   with its neighbour. The bar's title attribute already carries the figure. */
.chart-bar[data-density="dense"] .bar-value,
.chart-bar[data-density="ultra"] .bar-value { display: none; }

.chart-bar .bar-label {
  flex: 0 0 auto; height: var(--gutter-bottom);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.68rem; font-weight: 600; color: var(--ink-faint); white-space: nowrap;
}

/* Bar entrance: scaleY only, from the baseline, staggered left to right. The
   class is added by js/charts.js once the chart is actually on screen, so a
   script failure leaves the bars at full height instead of invisible. */
@keyframes barGrow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
.chart-bar.is-grown .bar-fill {
  animation-name: barGrow;
  animation-duration: 500ms;
  animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
  animation-fill-mode: both;
  animation-delay: var(--d, 0ms);
}

/* Donut --------------------------------------------------------------------
   A thick inline-SVG ring. Geometry lives in js/charts.js (viewBox 0 0 42 42,
   r 13, stroke 6.2 -> a 62% cutout); this block owns only the material and the
   motion. Every colour is a token, so both themes work with no extra rules.

   The segments are rotated individually via a rotate(-90 cx cy) ATTRIBUTE on
   each circle, not a `transform` on the <svg>. That matters: the hover pop-out
   translates the wrapping <g> in the unrotated frame, so a rotation on the
   ancestor would send every segment outward in the wrong direction. */
.donut-host { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.donut-figure { position: relative; width: 170px; height: 170px; margin: 0; flex-shrink: 0; }
.donut-svg { width: 100%; height: 100%; display: block; overflow: visible; }

.donut-seg { transform: translate(0, 0); transition: transform 180ms var(--ease); cursor: pointer; }
.donut-seg.is-pop { transform: var(--pop); }
/* The arc grows from nothing on first paint; --dash is written by js/charts.js. */
.donut-arc { transition: stroke-dasharray 700ms cubic-bezier(0.2, 0.8, 0.2, 1); }

.donut-center {
  position: absolute; inset: 0; display: grid; place-content: center;
  text-align: center; pointer-events: none;
}
.donut-total {
  font-family: var(--font-display); font-weight: 800; font-size: 1.15rem;
  line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums;
}
.donut-caption {
  font-size: 0.6rem; color: var(--ink-faint); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em; margin-top: 2px;
}

/* Legend — below the ring, and the accessible copy of the data: the label and
   the amount are always text, so colour is never the only signal. */
.legend {
  display: flex; flex-direction: column; gap: 2px;
  font-size: 0.84rem; width: 100%; padding: 0 16px;
}
.legend-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: var(--radius-sm);
  transition: background var(--speed) var(--ease); cursor: pointer;
}
.legend-row:hover, .legend-row.is-active { background: var(--brand-soft); }
.legend-swatch { width: 12px; height: 12px; border-radius: 4px; flex-shrink: 0; }
.legend-label { font-weight: 600; }
.legend-value { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Tooltip — inverts against the surface so it reads in both themes. */
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none;
  transform: translate(-50%, -50%);
  background: var(--ink); color: var(--surface);
  font-size: 0.72rem; font-weight: 600; white-space: nowrap;
  padding: 5px 9px; border-radius: var(--radius-sm); box-shadow: var(--shadow-2);
}
.chart-tip[hidden] { display: none; }

/* Empty state — centred in the panel, one clear action. */
.chart-empty {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  text-align: center; padding: 26px 16px;
}
.chart-empty-icon {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand-ink); margin-bottom: 2px;
}
.chart-empty-icon svg { width: 22px; height: 22px; }
.chart-empty-title { font-family: var(--font-display); font-weight: 800; font-size: 0.98rem; }
.chart-empty-body { font-size: 0.8rem; color: var(--ink-faint); max-width: 280px; }

/* Entrance motion. Transform + opacity only, and the global
   prefers-reduced-motion block collapses it to nothing. */
@keyframes riseIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}
.rise-in { animation: riseIn 280ms ease-out both; }

/* The data table a screen reader gets. Not `display:none` — that would remove
   it from the accessibility tree too, which is the opposite of the point. */
.sr-only {
  position: absolute !important; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap; border: 0;
}

/* ---------- 23. Brand customizer ---------- */
.swatch-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px;
}
.swatch {
  border: 2px solid var(--border); border-radius: var(--radius);
  background: var(--surface); padding: 0; overflow: hidden;
  cursor: pointer; text-align: left;
  transition: border-color var(--speed) var(--ease), transform var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}
.swatch:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.swatch.active { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.swatch .sw-bar { height: 34px; display: flex; }
.swatch .sw-bar i { flex: 1; display: block; }
.swatch .sw-name {
  display: flex; align-items: center; gap: 4px;
  font-size: 0.68rem; font-weight: 700; padding: 6px 8px; color: var(--ink-soft);
  line-height: 1.2;
}
.swatch .sw-check { margin-left: auto; color: var(--brand-ink); display: none; }
.swatch.active .sw-check { display: block; }

.color-field { display: flex; align-items: center; gap: 8px; }
.color-field input[type="color"] {
  width: 46px; height: 40px; padding: 0; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; flex-shrink: 0;
}
.color-field input[type="color"]::-webkit-color-swatch-wrapper { padding: 3px; }
.color-field input[type="color"]::-webkit-color-swatch { border: none; border-radius: 5px; }
.color-field .input { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; text-transform: uppercase; }

.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  flex: 1; min-width: 68px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  font-size: 0.78rem; font-weight: 600; color: var(--ink-soft);
  transition: all var(--speed) var(--ease);
}
.seg button:hover { border-color: var(--border-strong); color: var(--ink); }
.seg button.active {
  background: var(--brand-soft); border-color: var(--brand);
  color: var(--brand-ink); font-weight: 700;
}

.range-row { display: flex; align-items: center; gap: 12px; }
.range-row input[type="range"] { flex: 1; accent-color: var(--brand); }
.range-row .range-val {
  min-width: 46px; text-align: center; font-weight: 700; font-size: 0.8rem;
  font-variant-numeric: tabular-nums; color: var(--ink-soft);
}

/* Live preview panel */
.brand-preview {
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; background: var(--bg);
}
.brand-preview .bp-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; background: var(--sidebar-bg); color: var(--sidebar-fg);
}
.brand-preview .bp-head .bp-dot {
  width: 26px; height: 26px; border-radius: 8px; flex-shrink: 0;
  background: var(--sidebar-logo-bg); border: 1px solid var(--sidebar-logo-border);
  display: grid; place-items: center; font-size: 0.66rem; font-weight: 800; color: var(--gold-contrast);
  background-image: linear-gradient(135deg, var(--gold-light), var(--gold));
}
.brand-preview .bp-head .bp-title { font-size: 0.8rem; font-weight: 800; }
.brand-preview .bp-head .bp-sub { font-size: 0.6rem; opacity: 0.7; letter-spacing: 0.08em; text-transform: uppercase; }
.brand-preview .bp-body { padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--surface); }
.brand-preview .bp-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.brand-preview .bp-swatchline { display: flex; gap: 6px; }
.brand-preview .bp-swatchline i {
  width: 30px; height: 30px; border-radius: 8px; display: block;
  border: 1px solid var(--border);
}
.brand-preview .bp-link { font-size: 0.8rem; font-weight: 600; color: var(--brand-ink); text-decoration: underline; }

.contrast-list { display: flex; flex-direction: column; gap: 6px; }
.contrast-item { display: flex; align-items: center; gap: 8px; font-size: 0.76rem; }
.contrast-item .ci-sample {
  width: 62px; height: 26px; border-radius: 6px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 0.68rem; font-weight: 800;
  border: 1px solid var(--border);
}
.contrast-item .ci-label { flex: 1; color: var(--ink-soft); }
.contrast-pill {
  font-size: 0.66rem; font-weight: 800; padding: 2px 8px; border-radius: var(--radius-full);
  letter-spacing: 0.03em; white-space: nowrap;
}
.contrast-pill.pass { background: var(--success-soft); color: var(--success); }
.contrast-pill.warn { background: var(--warning-soft); color: var(--warning); }
.contrast-pill.fail { background: var(--danger-soft); color: var(--danger); }

.autosave-note {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.74rem; color: var(--ink-faint);
}

/* ---------- 24. Interaction polish ----------
   Micro-interactions in the spirit of uiverse.io: shine sweeps, press depth,
   spring-backed toggles, drawn checkmarks, ripples. Every colour is a brand
   token, so a client's own palette drives all of it — and the
   prefers-reduced-motion block at the end of this file neutralises the motion
   for anyone who asks for less. */

/* 24.1 Filled buttons — shine sweep, hover lift, press depth ---------------
   The highlight is a background *layer* rather than a pseudo-element, because
   a pseudo-element would paint on top of the label instead of under it. */
.btn-primary { --btn-base: linear-gradient(135deg, var(--brand-light), var(--brand)); }
.btn-gold { --btn-base: linear-gradient(135deg, var(--gold-light), var(--gold)); }
.btn-success { --btn-base: linear-gradient(135deg, color-mix(in srgb, var(--success) 82%, #fff), var(--success)); }
.btn-danger { --btn-base: linear-gradient(135deg, color-mix(in srgb, var(--danger) 82%, #fff), var(--danger)); }

.btn-primary, .btn-gold, .btn-success, .btn-danger {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background-image:
    linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.30) 50%, transparent 60%),
    var(--btn-base);
  background-size: 200% 100%, 100% 100%;
  background-position: -50% 0, 0 0;
  background-repeat: no-repeat, no-repeat;
  transition:
    background-position 0.55s var(--ease),
    transform var(--speed) var(--ease),
    box-shadow var(--speed) var(--ease),
    filter var(--speed) var(--ease);
}
.btn-primary:hover, .btn-gold:hover, .btn-success:hover, .btn-danger:hover {
  background-position: 150% 0, 0 0;
  transform: translateY(-1px);
  filter: brightness(1.05);
}
.btn-primary:active, .btn-gold:active, .btn-success:active, .btn-danger:active {
  transform: translateY(1px) scale(0.985);
  filter: brightness(0.97);
  transition-duration: 0.08s;
}
.btn-primary:disabled, .btn-gold:disabled, .btn-success:disabled, .btn-danger:disabled { filter: grayscale(0.35); }

/* 24.2 Loading state ------------------------------------------------------ */
.btn.loading { pointer-events: none; }
.btn.loading > :not(.btn-spinner) { opacity: 0.6; }
/* An icon-only button has no room for a spinner — dim it and block re-entry. */
.icon-btn.loading, .btn-icon.loading { opacity: 0.45; pointer-events: none; }
.btn-spinner {
  width: 15px; height: 15px; flex-shrink: 0;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  opacity: 0.85;
  animation: spin 0.65s linear infinite;
}

/* 24.3 Standalone spinners ------------------------------------------------ */
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  animation: spin 0.8s linear infinite;
}
.spinner-sm { width: 16px; height: 16px; border-width: 2px; }
.spinner-lg { width: 46px; height: 46px; border-width: 4px; }
.spinner-center { margin: 32px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 24.4 Ripple -------------------------------------------------------------
   Sits at z-index -1 inside an isolated stacking context, so it paints above
   the button's own background but beneath its label. */
.ripple {
  position: absolute; z-index: -1;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.42);
  transform: scale(0);
  pointer-events: none;
  animation: ripple-out 0.6s var(--ease) forwards;
}
/* .fab is already position:fixed, which is enough of a containing block —
   setting position:relative here would unstick it from the viewport. */
.fab { overflow: hidden; isolation: isolate; }
@keyframes ripple-out { to { transform: scale(2.8); opacity: 0; } }

/* 24.5 Inputs — hover affordance and an inset well ------------------------ */
.input, .select, .textarea { box-shadow: inset 0 1px 2px rgba(43, 43, 43, 0.03); }
[data-theme="dark"] .input, [data-theme="dark"] .select, [data-theme="dark"] .textarea {
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
}
.input:hover:not(:focus):not(:disabled),
.select:hover:not(:focus):not(:disabled),
.textarea:hover:not(:focus):not(:disabled) { border-color: var(--ink-faint); }
.input:focus, .select:focus, .textarea:focus {
  box-shadow: 0 0 0 4px var(--brand-soft), inset 0 1px 2px rgba(43, 43, 43, 0.02);
}
.input.invalid, .select.invalid, .textarea.invalid {
  box-shadow: 0 0 0 4px var(--danger-soft), inset 0 1px 2px rgba(43, 43, 43, 0.02);
}
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-2); cursor: not-allowed; opacity: 0.75; }

/* 24.6 Checkbox — a tick that draws itself in ----------------------------- */
.checkbox input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 20px; height: 20px; flex-shrink: 0;
  border: 2px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  display: grid; place-items: center;
  cursor: pointer;
  transition: background var(--speed) var(--ease), border-color var(--speed) var(--ease);
}
.checkbox input[type="checkbox"]:hover { border-color: var(--brand); }
.checkbox input[type="checkbox"]:checked { background: var(--brand); border-color: var(--brand); }
.checkbox input[type="checkbox"]::after {
  content: ""; width: 9px; height: 5px; margin-top: -2px;
  border-left: 2.5px solid var(--brand-contrast);
  border-bottom: 2.5px solid var(--brand-contrast);
  transform: rotate(-45deg) scale(0);
  transition: transform 0.2s var(--ease-spring);
}
.checkbox input[type="checkbox"]:checked::after { transform: rotate(-45deg) scale(1); }
.checkbox input[type="checkbox"]:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* 24.7 Switch — inset track and a thumb that squishes on press ------------ */
.switch .slider {
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(43, 43, 43, 0.18);
}
.switch .slider::before { box-shadow: 0 1px 3px rgba(43, 43, 43, 0.3); }
.switch input:checked + .slider {
  background: linear-gradient(135deg, var(--brand-light), var(--brand));
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.12);
}
.switch:active .slider::before { width: 23px; }
.switch:has(input:checked):active .slider::before { transform: translateX(17px); }

/* 24.8 Cards — layered shadows read as depth rather than a grey blur ------ */
.card { box-shadow: 0 1px 2px rgba(43, 43, 43, 0.04), 0 4px 12px rgba(43, 43, 43, 0.04); }
.card-hover:hover { box-shadow: 0 2px 4px rgba(43, 43, 43, 0.05), 0 14px 30px rgba(43, 43, 43, 0.10); }
[data-theme="dark"] .card { box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.3); }
[data-theme="dark"] .card-hover:hover { box-shadow: 0 2px 4px rgba(0, 0, 0, 0.45), 0 14px 32px rgba(0, 0, 0, 0.5); }

/* 24.9 Stat cards — a soft glow in the icon's own colour ------------------ */
.stat-card .stat-icon { box-shadow: 0 6px 16px -6px currentColor; }
.stat-card .stat-deco { transition: transform 0.5s var(--ease); }
.stat-card:hover .stat-deco { transform: scale(1.15); }

/* 24.10 Empty state — a lit halo instead of a flat disc ------------------ */
.empty-state .empty-icon {
  background: radial-gradient(circle at 50% 40%, var(--brand-soft), transparent 72%);
  box-shadow: inset 0 0 0 1px var(--brand-soft);
}

/* 24.11 Navigation — the active rail grows in ---------------------------- */
.nav-item.active::before { animation: rail-in 0.3s var(--ease-spring); }
@keyframes rail-in { from { transform: scaleY(0); } to { transform: scaleY(1); } }
.bottom-nav .bn-item svg { transition: transform 0.25s var(--ease-spring); }
.bottom-nav .bn-item.active svg { transform: translateY(-2px) scale(1.08); }

/* 24.12 Tooltip — replaces the unstyled, slow native title --------------
   Opt in with class="tip" data-tip="…"; keep an aria-label for screen readers. */
.tip { position: relative; }
.tip::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 7px); left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--ink); color: var(--bg);
  font-size: 0.72rem; font-weight: 600; line-height: 1.35;
  padding: 5px 9px; border-radius: 7px;
  width: max-content; max-width: 240px;
  white-space: normal; text-align: center;
  box-shadow: var(--shadow-sm);
  opacity: 0; pointer-events: none; z-index: 90;
  transition: opacity 0.16s var(--ease), transform 0.16s var(--ease);
}
.tip:hover::after, .tip:focus-visible::after { opacity: 1; transform: translateX(-50%) translateY(0); }
/* Anchored variant for controls sitting near the right edge — a centred tooltip
   would overflow the viewport there. */
.tip-end::after { left: auto; right: 0; transform: translateY(4px); }
.tip-end:hover::after, .tip-end:focus-visible::after { transform: translateY(0); }

/* 24.13 Progress — recessed track --------------------------------------- */
.progress { box-shadow: inset 0 1px 2px rgba(43, 43, 43, 0.08); }

/* 24.14 Touch devices — hover styles stick after a tap, so drop the lifts -- */
@media (hover: none) {
  .btn-primary:hover, .btn-gold:hover, .btn-success:hover, .btn-danger:hover { transform: none; }
  .card-hover:hover { transform: none; }
  .nav-item:hover { transform: none; }
  .swatch:hover { transform: none; }
  .fab:hover { transform: none; }
  .stat-card:hover .stat-deco { transform: none; }
}

/* ---------- 25. Dark theme — component treatments ----------
   The token layer (the [data-theme="dark"] block in section 1) already
   re-paints every surface, hairline and text node in the app, because the
   legacy tokens are aliased to the enterprise slate scale rather than deleted.
   So most of the ~1200 lines above need nothing here.

   What is left is the short list of components that either
     (a) hardcode a light-only value in their base rule that has no dark
         counterpart (a shadow tinted for a white canvas, a solid pale badge
         fill, a white tooltip bubble), or
     (b) need a *different material* in dark — glass chrome, a raised overlay
         that has to clear a near-black canvas, an inner sheen so a filled
         button reads as a solid object rather than a flat sticker.

   Every selector below is scoped to [data-theme="dark"], so light mode cannot
   be affected by construction. scripts/.diag-baseline.js captures light-mode
   computed styles and is diffed to prove that, and scripts/test-markup.js
   asserts the two token blocks stay in sync. */

/* 25.1 Chrome — a blurred translucent bar rather than an opaque slab --------
   The base .topbar already blurs, but derives its fill from --surface at 88%,
   which on a near-black canvas is effectively opaque — the blur has nothing to
   show. Pin the alpha lower so the glass actually reads as glass. */
[data-theme="dark"] .topbar {
  background: rgba(18, 35, 26, 0.75);
  border-bottom: 1px solid var(--border-subtle);
}

/* The sidebar fill is owned by the brand engine, which writes --sidebar-bg
   INLINE on <html> (js/brand.js → sidebarVars) for all four sidebar styles.
   An inline custom property outranks any selector, so a dark rule here cannot
   repaint it — and overriding the `background` *property* instead would
   silently discard the client's Gradient / Solid / Deep / Light choice. So we
   keep the brand fill and add only the glass material: a blur, a hairline seam
   and a top highlight. See the README for the one-line opt-in to a slate
   sidebar if a deployment genuinely wants one. */
[data-theme="dark"] .sidebar {
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-right: 1px solid var(--border-subtle);
}
[data-theme="dark"] .sidebar-brand {
  box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .bottom-nav {
  background: rgba(18, 35, 26, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-subtle);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.45);
}

/* 25.2 Cards — tighter corners and a hairline seam -------------------------
   18px reads as soft/consumer; 12px reads as a dense enterprise panel. */
[data-theme="dark"] .card { border-radius: var(--radius); }
[data-theme="dark"] .card-header,
[data-theme="dark"] .card-footer { border-color: var(--border-subtle); }
[data-theme="dark"] .card-hover:hover { border-color: var(--border-medium); }

/* 25.3 Tables — hairline rows, a raised head, a neutral row hover ----------
   .table-wrap is nested INSIDE .card, so the card already draws the outer
   border; adding one here would double it. Only the radius needs to match. */
[data-theme="dark"] .table-wrap { border-radius: var(--radius); }
[data-theme="dark"] .table thead th {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-medium);
}
[data-theme="dark"] .table tbody td { border-bottom: 1px solid var(--border-subtle); }
[data-theme="dark"] .table tbody tr:hover { background: var(--bg-hover); }
[data-theme="dark"] .table tbody tr:last-child td { border-bottom: none; }

/* 25.4 Buttons — an inner sheen so a filled button reads as a solid object,
   and a glow instead of a tint when focused. */
[data-theme="dark"] .btn-primary { box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.2), var(--shadow-brand); }
[data-theme="dark"] .btn-gold,
[data-theme="dark"] .btn-success,
[data-theme="dark"] .btn-danger { box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.2), var(--shadow-sm); }
[data-theme="dark"] .btn-primary:hover,
[data-theme="dark"] .btn-primary:focus-visible {
  box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.24), var(--shadow-brand), 0 0 0 4px var(--accent-glow);
}
[data-theme="dark"] .btn-outline { background: var(--bg-elevated); border-color: var(--border-medium); color: var(--text-primary); }
[data-theme="dark"] .btn-outline:hover { border-color: var(--brand); color: var(--brand-ink); background: var(--accent-glow); }
[data-theme="dark"] .btn-ghost { color: var(--text-secondary); }
[data-theme="dark"] .btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
[data-theme="dark"] .icon-btn { color: var(--text-secondary); }
[data-theme="dark"] .icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* 25.5 Forms — a recessed well on a slate ground, and a ring that glows ---- */
[data-theme="dark"] .input,
[data-theme="dark"] .select,
[data-theme="dark"] .textarea {
  background: var(--bg-elevated);
  border-color: var(--border-medium);
  color: var(--text-primary);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.3);
}
[data-theme="dark"] .input::placeholder,
[data-theme="dark"] .textarea::placeholder { color: var(--text-tertiary); }
[data-theme="dark"] .input:hover:not(:focus):not(:disabled),
[data-theme="dark"] .select:hover:not(:focus):not(:disabled),
[data-theme="dark"] .textarea:hover:not(:focus):not(:disabled) { border-color: var(--text-tertiary); }
[data-theme="dark"] .input:focus,
[data-theme="dark"] .select:focus,
[data-theme="dark"] .textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 4px var(--accent-glow), inset 0 1px 2px rgba(0, 0, 0, 0.3);
}
[data-theme="dark"] .input:disabled,
[data-theme="dark"] .select:disabled,
[data-theme="dark"] .textarea:disabled { background: var(--bg-surface); opacity: 0.6; }
[data-theme="dark"] .input-group .input-group-addon {
  background: var(--bg-hover);
  border-color: var(--border-medium);
  color: var(--text-secondary);
}
[data-theme="dark"] .field > label,
[data-theme="dark"] .field > .field-label { color: var(--text-secondary); }

/* 25.6 Status pills — a translucent tint with a matching text colour and a
   hairline ring, instead of the solid near-white fills the light palette uses
   (a #E8F5E9 pill on a #111726 card is a glaring white blob). */
[data-theme="dark"] .badge-green  { background: var(--badge-paid-bg);    color: var(--badge-paid-text);    border: 1px solid var(--badge-paid-border); }
[data-theme="dark"] .badge-orange { background: var(--badge-unpaid-bg);  color: var(--badge-unpaid-text);  border: 1px solid var(--badge-unpaid-border); }
[data-theme="dark"] .badge-gold   { background: var(--badge-partial-bg); color: var(--badge-partial-text); border: 1px solid var(--badge-partial-border); }
[data-theme="dark"] .badge-red    { background: var(--badge-overdue-bg); color: var(--badge-overdue-text); border: 1px solid var(--badge-overdue-border); }
[data-theme="dark"] .badge-blue   { background: var(--badge-partial-bg); color: var(--badge-partial-text); border: 1px solid var(--badge-partial-border); }
[data-theme="dark"] .badge-gray   { background: var(--bg-hover);         color: var(--text-secondary);     border: 1px solid var(--border-subtle); }

/* 25.7 Chips — a raised pill that lights up on hover ---------------------- */
[data-theme="dark"] .chip { background: var(--bg-elevated); border-color: var(--border-subtle); color: var(--text-secondary); }
[data-theme="dark"] .chip:hover { border-color: var(--border-focus); color: var(--text-primary); }
[data-theme="dark"] .chip.active { background: var(--brand); color: var(--brand-contrast); border-color: var(--brand); }

/* 25.8 Overlays — a modal, toast or menu has to sit ABOVE the canvas, so it
   gets the elevated surface rather than the base one, plus a hairline so its
   edge does not dissolve into the shadow. */
[data-theme="dark"] .modal-overlay { background: rgba(2, 4, 9, 0.72); }
[data-theme="dark"] .modal { background: var(--bg-elevated); border: 1px solid var(--border-subtle); }
[data-theme="dark"] .modal-header,
[data-theme="dark"] .modal-footer { border-color: var(--border-subtle); }
/* The three sides only: the left edge is the toast's status stripe, and a
   blanket `border-color` here would be the same specificity as
   `.toast.success` but later in the file — flattening it to grey. */
[data-theme="dark"] .toast {
  background: var(--bg-elevated);
  border-top-color: var(--border-subtle);
  border-right-color: var(--border-subtle);
  border-bottom-color: var(--border-subtle);
  color: var(--text-primary);
}
[data-theme="dark"] .toast .toast-close { color: var(--text-tertiary); }
[data-theme="dark"] .dropdown-menu { background: var(--bg-elevated); border-color: var(--border-subtle); }
[data-theme="dark"] .dropdown-item { color: var(--text-primary); }
[data-theme="dark"] .dropdown-item:hover { background: var(--bg-hover); }
[data-theme="dark"] .dropdown-item svg { color: var(--text-tertiary); }
[data-theme="dark"] .dropdown-divider { background: var(--border-subtle); }

/* 25.9 Document, meters, skeletons & plans -------------------------------
   The tooltip is the one place worth calling out: its base rule is
   `background: var(--ink); color: var(--bg)`, which inverts to a near-white
   bubble in dark mode. A slate bubble with light text matches the rest of the
   theme and is far less glaring on a near-black canvas. */
[data-theme="dark"] .invoice-doc { background: var(--bg-elevated); border-color: var(--border-subtle); }
[data-theme="dark"] .invoice-doc .doc-logo { background: var(--bg-hover); }
[data-theme="dark"] .invoice-doc .doc-table td { border-bottom: 1px solid var(--border-subtle); }
[data-theme="dark"] .invoice-doc .doc-footer { border-color: var(--border-subtle); }
[data-theme="dark"] .progress { background: var(--bg-hover); box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4); }
[data-theme="dark"] .meter { background: var(--bg-hover); }
[data-theme="dark"] .skeleton { background: var(--bg-hover); }
[data-theme="dark"] .switch .slider { background: var(--bg-hover); }
[data-theme="dark"] .plan-card { background: var(--bg-surface); }
[data-theme="dark"] .gateway { background: var(--bg-surface); }
[data-theme="dark"] .tab.active { color: var(--brand-ink); }
[data-theme="dark"] .tip::after {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}

/* 25.10 Variants that a generic dark rule would otherwise flatten -----------
   Every rule above is a generic `[data-theme="dark"] <component>` override, so
   it lands at exactly the same specificity as that component's own variant
   rules — and because this section is last in the file, "same specificity"
   means the generic dark rule wins. Left alone, that silently strips the
   danger/success accents the variants exist to provide. Restore them one step
   higher. */
[data-theme="dark"] .dropdown-item.danger { color: var(--danger); }
[data-theme="dark"] .dropdown-item.danger svg { color: var(--danger); }
[data-theme="dark"] .dropdown-item.danger:hover { background: var(--danger-soft); }
[data-theme="dark"] .icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
[data-theme="dark"] .icon-btn.success:hover { background: var(--success-soft); color: var(--success); }

/* ---------- 26. Onboarding guide & help panel ----------

   Two surfaces, one content model (js/onboarding.js):

     .tour-root    the spotlight tour — four dimming panels arranged around a
                   cut-out rectangle, plus the coach-mark card.
     .help-overlay the scrollable manual.

   WHY FOUR PANELS AND NOT ONE OVERLAY WITH A PUNCHED HOLE
     A single overlay dimmed by a big `box-shadow` hole looks identical, but it
     still covers the element — so tapping the very button the card is pointing
     at does nothing. Four panels leave a genuinely un-covered rectangle, which
     is what makes a step like "tap New Invoice" work on a phone.
--------------------------------------------------------------------------- */

.tour-root {
  position: fixed; inset: 0; z-index: 300;
  opacity: 0; pointer-events: none;
  transition: opacity var(--speed) var(--ease);
}
.tour-root.open { opacity: 1; pointer-events: auto; }

/* While the page smooth-scrolls to the next anchor, the dimming is hidden.
   The panels are positioned in viewport coordinates and would otherwise hold
   still while the content moves beneath them, so the cut-out appears to slip
   off the element it is supposed to frame. */
.tour-root.repositioning .tour-block,
.tour-root.repositioning .tour-glow { opacity: 0; }

/* Each panel is inert by construction: it only ever paints the area OUTSIDE
   the cut-out, so clicks that reach a panel are clicks on the dimmed page. */
.tour-block {
  position: fixed;
  background: var(--tour-scrim);
  transition: all var(--speed) var(--ease);
}

/* The cut-out itself. Purely decorative — no background, no pointer capture —
   so the highlighted control stays fully interactive. The ring is drawn with a
   border rather than a shadow so it cannot bleed into neighbours. */
.tour-glow {
  position: fixed; pointer-events: none;
  border: 2px solid var(--brand);
  border-radius: var(--radius-lg);
  box-shadow: 0 0 0 4px var(--brand-soft);
  transition: all var(--speed) var(--ease);
}
.tour-glow.hidden { display: none; }

.tour-card {
  position: fixed;
  width: min(340px, calc(100vw - 20px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 18px;
  display: flex; flex-direction: column; gap: 10px;
  transition: left var(--speed) var(--ease), top var(--speed) var(--ease);
}

.tour-art {
  width: 100%; height: 76px;
  display: grid; place-items: center;
  background: var(--brand-soft);
  color: var(--brand);
  border-radius: var(--radius);
  margin-bottom: 2px;
}
.tour-art svg { width: 76px; height: 68px; }

.tour-meta { display: flex; align-items: center; gap: 8px; }
.tour-step-badge {
  font-size: 0.68rem; font-weight: 800; letter-spacing: 0.08em;
  color: var(--brand); text-transform: uppercase;
}
.tour-page-badge {
  font-size: 0.66rem; font-weight: 700;
  padding: 2px 8px; border-radius: var(--radius-full);
  background: var(--gold-soft); color: var(--gold-ink);
}
.tour-title { font-size: 1.02rem; font-family: var(--font-display); line-height: 1.25; }
.tour-body { font-size: 0.86rem; color: var(--ink-soft); line-height: 1.55; margin: 0; }

.tour-dots { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tour-dot {
  width: 8px; height: 8px; padding: 0; border: none; cursor: pointer;
  border-radius: var(--radius-full);
  background: var(--border-strong);
  transition: all var(--speed) var(--ease);
}
.tour-dot:hover { background: var(--brand-light); }
.tour-dot.active { width: 22px; background: var(--brand); }

.tour-actions { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.tour-spacer { flex: 1; }

/* Tighten the coach mark on a phone: it is the only thing on screen, so a
   stacked layout reads better than a squeezed row. */
@media (max-width: 480px) {
  .tour-card { padding: 15px; width: calc(100vw - 16px); }
  .tour-art { height: 62px; }
  .tour-art svg { width: 62px; height: 56px; }
  .tour-actions .btn { flex: 1; }
}

/* ---------- Help panel (the manual) ---------- */

.help-overlay {
  position: fixed; inset: 0; z-index: 290;
  background: var(--tour-scrim);
  backdrop-filter: blur(4px);
  display: flex; justify-content: flex-end;
  opacity: 0; pointer-events: none;
  transition: opacity var(--speed) var(--ease);
}
.help-overlay.open { opacity: 1; pointer-events: auto; }

.help-drawer {
  width: min(520px, 100vw);
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  transform: translateX(24px);
  transition: transform var(--speed) var(--ease-spring);
}
.help-overlay.open .help-drawer { transform: translateX(0); }

.help-head {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.help-head-icon {
  width: 40px; height: 40px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: var(--radius); color: var(--brand);
  background: var(--brand-soft);
}
.help-head-icon svg { width: 22px; height: 22px; }
.help-head-text { flex: 1; min-width: 0; }
.help-head-text h3 { font-size: 1.05rem; }
.help-head-text p { font-size: 0.8rem; color: var(--ink-faint); margin: 3px 0 0; }

.help-body { flex: 1; overflow-y: auto; padding: 18px 20px; }
.help-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }

.help-step {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.help-step-art {
  width: 56px; height: 56px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  background: var(--brand-soft); color: var(--brand);
}
.help-step-art svg { width: 40px; height: 38px; }
.help-step-text { min-width: 0; }
.help-step-text h4 {
  font-size: 0.9rem; display: flex; align-items: center; gap: 8px;
  margin: 0 0 5px;
}
.help-step-num {
  width: 20px; height: 20px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: var(--radius-full);
  background: var(--brand); color: var(--brand-contrast);
  font-size: 0.68rem; font-weight: 800;
}
.help-step-text p { font-size: 0.83rem; color: var(--ink-soft); line-height: 1.55; margin: 0; }
.help-step-where {
  display: inline-block; margin-top: 7px;
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.help-note {
  margin-top: 18px; padding: 14px;
  border-radius: var(--radius);
  background: var(--brand-soft);
  border: 1px solid var(--border);
}
.help-note strong { display: block; font-size: 0.86rem; margin-bottom: 5px; }
.help-note p { font-size: 0.82rem; color: var(--ink-soft); line-height: 1.55; margin: 0; }

.help-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.help-foot .btn-primary { display: inline-flex; align-items: center; gap: 7px; }

/* ---------- The Guide launcher (sidebar + bottom nav) ---------- */

.guide-card {
  display: flex; align-items: center; gap: 10px;
  width: 100%; margin-bottom: 8px;
  padding: 10px 12px;
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius);
  background: var(--sidebar-card-bg);
  color: var(--sidebar-fg);
  font: inherit; font-size: 0.78rem; font-weight: 700;
  text-align: left; cursor: pointer;
  transition: background var(--speed) var(--ease);
}
.guide-card:hover { background: var(--sidebar-hover); }
.guide-card svg { width: 18px; height: 18px; flex-shrink: 0; }
.guide-card .gc-text { display: block; font-weight: 500; opacity: 0.7; font-size: 0.7rem; }

/* A quiet pulse on the sidebar launcher until the tour has been seen once.
   js/onboarding.js removes `.is-new` from the storage check, so it stops the
   moment the user has actually looked — not on a fixed timer. */
.guide-card.is-new { animation: guide-pulse 2.4s var(--ease) infinite; }
@keyframes guide-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
  50%      { box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.10); }
}

/* ---------- Page-level "watch the guide" affordance ---------- */

.guide-hint {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all var(--speed) var(--ease);
}
.guide-hint:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.guide-hint svg { width: 17px; height: 17px; flex-shrink: 0; }
.guide-hint strong { color: var(--ink); font-weight: 700; }

/* While either surface is open the page must not scroll behind it — otherwise
   the spotlight drifts away from the element it is highlighting on touch. */
.tour-active, .help-active { overflow: hidden; }

/* ---------- Dark theme ---------- */

[data-theme="dark"] .tour-glow { box-shadow: 0 0 0 4px var(--accent-glow), 0 0 30px var(--accent-glow); }
[data-theme="dark"] .tour-art,
[data-theme="dark"] .help-step-art,
[data-theme="dark"] .help-head-icon { background: var(--bg-hover); color: var(--brand-light); }
[data-theme="dark"] .help-note { background: var(--bg-hover); }
[data-theme="dark"] .tour-page-badge { background: var(--badge-partial-bg); color: var(--badge-partial-text); }

/* ---------- Reduced motion ----------
   The tour moves a lot of geometry. Collapsing the transitions is enough here:
   the panels still land in the right place, they just arrive instantly. The
   launcher pulse is dropped entirely because it is a decorative loop. */
@media (prefers-reduced-motion: reduce) {
  .tour-block, .tour-glow, .tour-card, .help-drawer { transition: none !important; }
  .guide-card.is-new { animation: none !important; }
}

/* ---------- 27. Print ---------- */
@media print {
  @page { size: A4 portrait; margin: 12mm; }

  /* Printing is paper, so force the LIGHT structural scale. Without this a
     dark-mode session prints near-white text (--ink resolves to #EAF3EC) on a
     dark block (.invoice-doc / .card keep --bg-elevated) — an unreadable page.
     This block sits after [data-theme="dark"] at equal specificity, so it wins
     for the print media. The BRAND tokens are not here: they are written inline
     on <html> by js/brand.js and cannot be reached from a stylesheet, so
     js/shell.js swaps in the light palette on `beforeprint` instead. */
  :root {
    --bg-canvas: #F4F8F4;  --bg-surface: #FFFFFF;  --bg-elevated: #FFFFFF;  --bg-hover: #EDF3EE;
    --border-subtle: #D5E2D6;  --border-medium: #B9CDBB;
    --text-primary: #0F1F14;  --text-secondary: #4C5F52;  --text-tertiary: #7C8F82;
    --bg: #F4F8F4;  --surface: #FFFFFF;  --surface-2: #EDF3EE;
    --border: #D5E2D6;  --border-strong: #B9CDBB;
    --ink: #0F1F14;  --ink-soft: #4C5F52;  --ink-faint: #7C8F82;
    --accent-glow: var(--brand-soft);  --border-focus: var(--brand);
  }

  body { background: #fff !important; }
  .sidebar, .topbar, .bottom-nav, .fab, .toast-container, .no-print, .modal-overlay,
  .tour-root, .help-overlay, .guide-card { display: none !important; }
  .main { margin: 0 !important; }
  .content { padding: 0 !important; max-width: none !important; }
  .card, .invoice-doc { box-shadow: none !important; border: none !important; border-radius: 0 !important; }
  .invoice-doc { padding: 0 !important; max-width: none !important; }
  a { text-decoration: none !important; color: inherit !important; }
  .print-break { page-break-before: always; }
}

/* ---------- 28. Subscription, plans & payment gateways ----------
   Mobile-first like everything else: one column at base, three across once
   there is room for them. */
.plan-grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }

.plan-card {
  display: flex; flex-direction: column; gap: 10px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}
.plan-card.current {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.plan-card .plan-name { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.plan-card .plan-price { font-size: 1.3rem; font-weight: 800; color: var(--brand-ink); line-height: 1.2; }
.plan-card .plan-price small { font-size: 0.72rem; font-weight: 600; color: var(--ink-faint); }
.plan-card ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; font-size: 0.84rem; color: var(--ink-soft); }
.plan-card ul li { display: flex; gap: 7px; align-items: flex-start; }
.plan-card ul li::before { content: "\2713"; color: var(--success); font-weight: 700; flex: none; }
.plan-card .plan-cta { margin-top: auto; }

/* Usage meter */
.meter { height: 8px; border-radius: var(--radius-full); background: var(--surface-2); overflow: hidden; }
.meter > span { display: block; height: 100%; width: 0; background: var(--brand); transition: width 0.35s var(--ease); }
.meter.is-full > span { background: var(--warning); }
.meter.is-over > span { background: var(--danger); }

/* Payment gateway rows */
.gateway {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.gateway + .gateway { margin-top: 10px; }
.gateway-mark {
  flex: none; width: 40px; height: 40px; border-radius: var(--radius-sm);
  display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand-ink);
  font-weight: 800; font-size: 0.9rem;
}
.gateway-body { min-width: 0; flex: 1; }
.gateway-body strong { display: block; }
.gateway-body .gateway-methods { font-size: 0.8rem; color: var(--ink-faint); margin-top: 3px; }
.gateway-status {
  flex: none;
  display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
}
.gateway-note {
  margin-top: 10px; padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--warning-soft);
  color: var(--ink);
  font-size: 0.8rem;
}

/* ---------- Plan locks ----------
   A control the current plan does not include. Locked, never hidden: the
   control keeps its place in the form, so nothing jumps when a plan is
   activated, and the user learns the feature exists — which is the whole
   reason a free tier is offered.

   Deliberately an AMBER treatment, not a disabled grey. Grey reads as
   "broken"; amber with a label reads as "not yours yet", which is the actual
   situation and the one worth paying to change. Nothing here is `disabled`,
   because a disabled control cannot receive the press that opens the upgrade
   prompt. */
.pro-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: var(--radius-full);
  background: var(--gold-soft);
  color: var(--gold-ink);
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  vertical-align: middle;
}

/* The field: an amber wash, a pointer cursor, and the hint line explains why. */
.field.is-locked > label,
.field.is-locked > .field-label { color: var(--ink-soft); }
.field.is-locked .input,
.field.is-locked .select {
  background: var(--gold-soft);
  border-color: var(--gold);
  cursor: pointer;
}

/* Inputs are made read-only rather than disabled so they stay in the tab
   order — a keyboard user must be able to reach the control to hear why it is
   locked. That means the focus ring has to survive the amber background. */
.input.is-locked:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* Toolbar controls: the Monthly tab and the two export buttons. */
.tab.is-locked { color: var(--ink-soft); }
.tab.is-locked::after {
  content: "PRO";
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: var(--radius-full);
  background: var(--gold-soft);
  color: var(--gold-ink);
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  vertical-align: 1px;
}

.btn.is-locked { border-color: var(--gold); background: var(--gold-soft); color: var(--ink); }
.btn.is-locked::after {
  content: "PRO";
  margin-left: 7px;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  background: var(--gold-soft);
  color: var(--gold-ink);
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.05em;
}

/* What Pro actually adds, listed inside the upgrade prompt. */
.upgrade-features {
  list-style: none; margin: 10px 0 0; padding: 0;
  display: flex; flex-direction: column; gap: 4px;
  font-size: 0.82rem; color: var(--ink-soft);
}
.upgrade-features li { display: flex; gap: 7px; align-items: flex-start; }
.upgrade-features li::before { content: "\2713"; color: var(--success); font-weight: 700; flex: none; }

@media (min-width: 769px) {
  .plan-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- 29. Brand identity polish ----------
   The design system applied to the chrome. Kept as one layer that sits ON TOP
   of the component rules above rather than being folded into each of them, so a
   component never has to be rewritten to pick up the brand — and so the
   responsive overrides that follow still win at phone widths.

   Placement matters: this block must stay ABOVE section 31 (Responsive).
   Media queries add no specificity, so a rule here would otherwise override the
   phone compaction at 320–480px and start clipping the page title. */

/* Money and big numbers are set in the display face with tabular figures: a
   column of totals then aligns on the decimal, and a value does not jitter as
   it updates (proportional digits are different widths per glyph). */
.stat-card .stat-value,
.money,
.table .num,
.table .num-cell,
.invoice-doc .totals td:last-child {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}
.stat-card .stat-value { font-family: var(--font-display); font-weight: 800; }

/* Headings, the brand lockup and the page title all use the display face. */
h1, h2, h3, h4, h5, h6,
.page-title,
.brand-name,
.plan-card .plan-price,
.empty-state h3 { font-family: var(--font-display); }
.topbar .page-title { font-weight: 800; letter-spacing: -0.02em; }

/* The active nav row keeps a rail on its leading edge, in the accent so it
   reads against both the brand-gradient sidebar and the light sidebar. */
.nav-item.active::before { width: 3px; background: var(--spark); }

/* Touch targets. The sidebar rows and the bottom-nav items are full-width, so
   they can simply be made tall enough to meet the 44px minimum. The compact
   topbar icon buttons keep their 38px visual box — growing the box itself is
   what pushes a 320px topbar into horizontal scroll — and grow an invisible
   44px hit area instead. */
.nav-item { min-height: 44px; }
.bottom-nav .bn-item { min-height: 44px; }
.icon-btn { position: relative; }
.icon-btn::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 44px; height: 44px; transform: translate(-50%, -50%);
}

/* A 2px brand ring. The previous 3px gold ring all but vanished against the
   light canvas (#FFC107 on #FFFFFF is ~1.6:1); the mid brand green clears the
   3:1 WCAG threshold for non-text UI on both themes. */
:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }

/* ---------- 30. Feedback, rating & admin console ----------
   The review form, the one-time dashboard nudge, the star widget, and the
   vendor's licence desk. */

.star-rating { display: flex; align-items: center; gap: 6px; }

.star-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  padding: 0;
  border: none; background: none;
  color: var(--ink-faint);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color var(--speed) var(--ease), transform var(--speed) var(--ease);
}
.star-btn svg { width: 28px; height: 28px; }
.star-btn:hover { transform: scale(1.08); }
.star-btn.is-on { color: var(--gold); }
.star-btn.is-on svg { fill: currentColor; }

/* Live hover preview. `~` is what makes it read "up to here": the group hover
   paints every star, then every star AFTER the hovered one is repainted empty.
   The sibling rule outranks `.is-on` (0,3,0 vs 0,2,0), so the preview wins
   while the pointer is down — which is the whole point of a preview. */
.star-rating:hover .star-btn { color: var(--gold); }
.star-rating:hover .star-btn svg { fill: currentColor; }
.star-btn:hover ~ .star-btn { color: var(--ink-faint); }
.star-btn:hover ~ .star-btn svg { fill: none; }

/* Read-only stars in the "previous reviews" list. */
.fb-stars-static { display: inline-flex; gap: 1px; flex: none; }
.fb-stars-static span { color: var(--ink-faint); display: inline-grid; place-items: center; }
.fb-stars-static span svg { width: 14px; height: 14px; }
.fb-stars-static span.on { color: var(--gold); }
.fb-stars-static span.on svg { fill: currentColor; }

.feedback-list { display: flex; flex-direction: column; gap: 10px; }
.feedback-item {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.fb-item-body { min-width: 0; font-size: 0.82rem; }
.fb-item-body strong { display: block; }
.fb-item-body .text-muted { overflow-wrap: anywhere; }

/* Stage two: the review is saved, so the confirmation should feel like one. */
.fb-thanks { text-align: center; padding: 6px 0 18px; }
.fb-thanks-mark {
  width: 52px; height: 52px; margin: 0 auto 12px;
  display: grid; place-items: center;
  border-radius: var(--radius-full);
  background: var(--success-soft); color: var(--success);
}
.fb-thanks-mark svg { width: 26px; height: 26px; }
.fb-thanks h4 { font-size: 1.05rem; margin-bottom: 4px; }

/* ---------- The one-time nudge ----------
   Appended to the END of the dashboard content column on purpose: anything
   inserted above would push the dashboard's primary action down the page. */
.feedback-nudge {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 16px; padding: 14px 16px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius);
  background: var(--surface);
}
.fn-mark {
  flex: none; width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  background: var(--gold-soft); color: var(--gold-ink);
}
.fn-mark svg { width: 20px; height: 20px; fill: currentColor; }
.fn-body { min-width: 0; flex: 1 1 220px; display: flex; flex-direction: column; gap: 2px; }
.fn-body strong { font-size: 0.9rem; }
.fn-body span { font-size: 0.8rem; color: var(--ink-soft); }
.fn-actions { display: flex; align-items: center; gap: 8px; flex: none; margin-left: auto; }

/* ---------- The admin console ----------
   A licence desk, so it should read as one: dense, plain, no decoration that
   competes with the numbers. */

/* Monospaced for anything a human has to read aloud or type back — licence
   keys above all. A proportional font makes 0/O and 1/l ambiguous, and these
   strings get read down a phone line. */
.mono, .key-code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.key-code { font-size: 0.8rem; letter-spacing: 0.02em; white-space: nowrap; }

.admin-gate { display: grid; place-items: center; min-height: 60vh; padding: 20px 0; }
.admin-gate-card { width: 100%; max-width: 380px; padding: 26px; text-align: left; }
.admin-gate-card h2 { font-size: 1.15rem; margin-bottom: 6px; }
.admin-gate-card > .text-muted { font-size: 0.86rem; margin-bottom: 16px; }
.admin-gate-mark {
  width: 48px; height: 48px; margin-bottom: 14px;
  display: grid; place-items: center;
  border-radius: var(--radius);
  background: var(--brand-soft); color: var(--brand-ink);
}
.admin-gate-mark svg { width: 24px; height: 24px; }

/* `auto-fit` rather than fixed columns: the console has to work at 320px as
   well as 1600px, and a media query per breakpoint would only ever be right
   for the widths someone remembered to check. */
.admin-stats {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.admin-stat { padding: 14px 16px; }
.admin-stat .as-value {
  font-family: var(--font-display);
  font-size: 1.35rem; font-weight: 800; line-height: 1.15;
  color: var(--brand-ink);
  font-variant-numeric: tabular-nums;
}
.admin-stat .as-label {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--ink-faint); margin-top: 3px;
}
.admin-stat .as-sub { font-size: 0.76rem; color: var(--ink-soft); margin-top: 2px; }

/* Verdict panels: a licence check result, and the licence state on the device.
   `good`/`bad` are the only two outcomes, so they are classes rather than a
   colour argument — a caller cannot invent a third state by typo. */
.admin-verdict {
  display: flex; flex-direction: column; gap: 3px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 0.85rem;
}
.admin-verdict strong { font-size: 0.92rem; }
.admin-verdict span { color: var(--ink-soft); overflow-wrap: anywhere; }
.admin-verdict.good { border-left-color: var(--success); }
.admin-verdict.good strong { color: var(--success); }
.admin-verdict.bad { border-left-color: var(--danger); }
.admin-verdict.bad strong { color: var(--danger); }

.matrix-yes { color: var(--success); font-weight: 800; }

/* ---------- 31. Responsive (mobile-first) ----------
   Base styles above already target the phone. These blocks add capability as
   the viewport grows, so nothing has to be un-done with a max-width override.

   Breakpoints
     < 481px   phone            single column, off-canvas nav, bottom nav
     ≥ 481px   large phone      2-up stat grids, roomier padding
     ≥ 769px   tablet           bottom nav retires, hamburger nav, 2–3 up grids
     ≥ 1024px  desktop          sidebar docks, 12-column grid, full nav
     ≥ 1280px  wide desktop     4- and 6-up grids (need the extra width)
     ≥ 1441px  large desktop    wider gutters
     ≥ 1600px  very wide        2-up quick actions inside a col-span-4 card */

@media (min-width: 481px) {
  .content { padding: 18px; }
  .topbar { gap: 12px; padding: 0 16px; }
  .topbar .select { max-width: 190px; }
  .grid-cols-2, .grid-cols-3, .grid-cols-4,
  .grid-cols-5, .grid-cols-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-pad, .card-body { padding: 18px; }
}

@media (min-width: 769px) {
  .content { padding: 20px; }
  /* The bottom nav is a phone-sized touch affordance. From tablet up the
     hamburger drawer handles navigation, so the bar retires and the FAB
     returns to the corner. (The sidebar itself docks at 1024px.) */
  .bottom-nav { display: none; }
  .main { padding-bottom: 0; }
  .fab { bottom: 22px; right: 22px; }
  .toast-container { left: auto; right: 18px; max-width: min(380px, calc(100vw - 36px)); }
  .grid-cols-3, .grid-cols-4, .grid-cols-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .modal { max-height: 88vh; }
}

@media (min-width: 1024px) {
  /* Dock the sidebar and drop the off-canvas affordances. */
  .sidebar { transform: none; }
  .main { margin-left: var(--sidebar-w); }
  #menuBtn, .sidebar-backdrop { display: none !important; }
  .content { padding: 24px; }

  /* Only here is the topbar wide enough for the full display-size title. On a
     phone the title stays compact so it never has to truncate. */
  .topbar .page-title { font-size: 1.25rem; }

  /* The 12-column grid only exists where there is width to honour the spans. */
  .grid-cols-12 { grid-template-columns: repeat(12, minmax(0, 1fr)); }
  .col-span-1 { grid-column: span 1; }
  .col-span-2 { grid-column: span 2; }
  .col-span-3 { grid-column: span 3; }
  .col-span-4 { grid-column: span 4; }
  .col-span-5 { grid-column: span 5; }
  .col-span-6 { grid-column: span 6; }
  .col-span-7 { grid-column: span 7; }
  .col-span-8 { grid-column: span 8; }
  .col-span-9 { grid-column: span 9; }
  .col-span-10 { grid-column: span 10; }
  .col-span-11 { grid-column: span 11; }
  .col-span-12 { grid-column: span 12; }

  /* NB: the 4- and 6-up grids are NOT enabled here. Docking the sidebar costs
     264px of content width, so at 1024px a 4-up stat grid squeezes a value like
     "TZS 1,662,930.00" below its own text width and clips it. They wait until
     1280px, where the columns are genuinely wide enough. */

  /* A col-span-4 card is only ~223px wide here, so a 2-up grid inside it is
     narrower than its own labels: the buttons are `white-space: nowrap`, need up
     to 157px, and get 85–154px — so they spill out of the card into its
     neighbour. (The page-level overflow check never saw it, because the card is
     `overflow: visible`.) Stack them instead; the 2-up arrangement comes back at
     1600px, where the columns really are wide enough. */
  .col-span-4 .grid-cols-2 { grid-template-columns: minmax(0, 1fr); }
}

/* Only here is there room for 4- and 6-up grids with the sidebar docked:
   (1280 − 264 sidebar − 48 content padding − 48 gaps) / 4 ≈ 230px per column. */
@media (min-width: 1280px) {
  .grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid-cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

@media (min-width: 1600px) {
  /* Measured: a col-span-4 card is ~413px here, giving each button ~182px for a
     178px label. */
  .col-span-4 .grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 1441px) {
  .content { padding: 28px 32px; }
}

/* Phone-only compaction. Kept last so it wins over the min-width blocks above
   at the sizes where they overlap. */
@media (max-width: 768px) {
  .stat-card .stat-value { font-size: 1.45rem; }
  .invoice-doc { padding: 22px 16px; }
  .invoice-doc .doc-header { flex-direction: column; }
  .invoice-doc .totals { width: 100%; }
  .modal { max-height: 92vh; }
  .toast-container { left: 14px; right: 14px; max-width: none; }
  .hide-mobile { display: none !important; }

  /* Toolbars put their actions on the right with .ml-auto. That cluster is a
     flex row whose min-content width is the sum of its buttons, so it refuses
     to shrink and pushes the page wider than the viewport. Letting it wrap —
     and giving the tabs their own line — restores the ability to shrink. */
  .ml-auto.flex.gap-2,
  .ml-auto.flex.gap-3 { flex-wrap: wrap; justify-content: flex-end; }
  .tabs { width: 100%; }

  /* The chart already scrolls at every width (section 22) — this used to be a
     mobile-only patch, which is exactly why the 30/90-day overflow survived on
     desktop. On a phone even 7 columns are too narrow for a money label, so
     every density gets a fixed readable column here. */
  .chart-bar { --bar-w: 58px; }
  .chart-bar[data-density="dense"] { --bar-w: 58px; }
  .chart-bar[data-density="ultra"] { --bar-w: 44px; }
  .chart-bar .bar-value { font-size: 0.6rem; }
  .chart-bar .bar-label { font-size: 0.64rem; }
  /* Shorter plot on a phone so the card does not dominate the viewport. */
  .chart-figure { --scale-h: 140px; }
  .chart-yaxis { flex-basis: 40px; width: 40px; }

  .donut-figure { width: 150px; height: 150px; }
  .legend { padding: 0 4px; }
}

@media (max-width: 480px) {
  .content { padding: 12px; }
  .card-pad, .card-body { padding: 15px; }
  .btn { padding: 9px 14px; }
  /* The subtitle is the first thing to go when the topbar runs out of room. */
  .topbar .page-sub { display: none; }
  .topbar .page-title { font-size: 1rem; }
  /* Tighten the chrome so the page title never has to truncate on a 320px
     screen. The currency code is what matters; the full name is in the list. */
  .topbar { gap: 6px; padding: 0 10px; }
  .topbar .select { max-width: 84px; font-size: 0.78rem; padding: 7px 26px 7px 9px; }
  .icon-btn { width: 34px; height: 34px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  html { scroll-behavior: auto; }
  /* The blanket rule above collapses DURATION but not DELAY. The bar chart
     staggers with animation-delay (up to 60ms x 90 bars), so without this the
     bars would sit at scaleY(0) for seconds. Drop the animation entirely —
     the un-animated state is already the final state. */
  .chart-bar.is-grown .bar-fill { animation: none !important; transform: none !important; }
}