/* ==========================================================================
   Obolus — design tokens
   --------------------------------------------------------------------------
   This is the ONLY file where raw values (hex colors, rem/px sizes, ms
   durations, font files) are allowed. Everything else references tokens.
   `bash scripts/check-styles.sh` enforces this.

   Three tiers, in three separate :root blocks (the style guide at
   #/styleguide reads them in this order, so keep them separate):

     1. PRIMITIVES  raw palette and scales            --color-blue-45
     2. SEMANTIC    roles the UI thinks in            --color-primary
     3. COMPONENT   per-component knobs               --button-filled-bg

   Rule of thumb: components use tier 3 (or tier 2); nothing outside this
   file uses tier 1 directly.

   Naming: numbers in primitive names are pixel equivalents at the default
   16px browser font size (--space-16 = 1rem = 16px). Sizes are stored in
   rem so the whole UI scales when someone increases their browser font size.

   Theme: Frost Paper (design direction C). A white page, flat light-grey cards with
   no border or shadow, hairline dividers, near-black text and one lime accent.
   Light by default; .dark supplies neutral graphite (no green or blue tint on
   surfaces). Instrument Sans for the app and Inter on the paper.
   ========================================================================== */


/* --------------------------------------------------------------------------
   Fonts — two families, both self-hosted and under the SIL Open Font License:
   Instrument Sans for the app (text and headings) and Inter for the paper (documents and PDFs).
   Files live in /assets/fonts. To switch fonts: add @font-face rules for the
   new family here and point --font-family-brand at it.
   -------------------------------------------------------------------------- */
@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: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("../assets/fonts/inter-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}


@font-face {
  font-family: "Instrument Sans";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../assets/fonts/instrument-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;
}
@font-face {
  font-family: "Instrument Sans";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../assets/fonts/instrument-sans-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* ==========================================================================
   1. PRIMITIVES
   ========================================================================== */
/* Frost Paper palette (light). Raw values only here. */
:root, ::backdrop {
  --background: #ffffff;
  --foreground: #15171a;
  --card: #f5f5f7;                     /* the one flat card tone */
  --card-foreground: #15171a;
  --popover: #ffffff;
  --popover-foreground: #15171a;
  --primary: oklch(0.85 0.21 128);     /* lime: primary actions, current tab, focus ring, progress, switches */
  --primary-foreground: #142200;
  --secondary: #efeff2;                /* segmented track, tonal buttons */
  --secondary-foreground: #15171a;
  --muted: #f5f5f7;
  --muted-foreground: #6a6f76;
  --accent: #efeff2;
  --accent-foreground: #15171a;
  --destructive: oklch(0.577 0.245 27.325);
  --border: rgba(0, 0, 0, 0.07);       /* hairline dividers */
  --input: rgba(0, 0, 0, 0.1);         /* field and outlined-control borders */
  --ring: rgba(120, 200, 20, 0.25);    /* focus ring colour (4px halo) */
  --chart-1: oklch(0.62 0.2 135);      /* billed */
  --chart-2: oklch(0.6 0.02 255);      /* paid */
  --chart-3: oklch(0.444 0.011 73.639);
  --chart-4: oklch(0.374 0.01 67.558);
  --chart-5: oklch(0.268 0.007 34.298);
  --radius: 0.75rem;                   /* 12px: inputs, selects, line fields */
  --sidebar: #ffffff;
  --sidebar-foreground: #15171a;
  --sidebar-primary: oklch(0.85 0.21 128);
  --sidebar-primary-foreground: #142200;
  --sidebar-accent: rgba(0, 0, 0, 0.055);
  --sidebar-accent-foreground: #15171a;
  --sidebar-border: rgba(0, 0, 0, 0.07);
  --sidebar-ring: rgba(120, 200, 20, 0.25);

  /* Frost Paper extras */
  --frost-hover: rgba(0, 0, 0, 0.045);
  --frost-selected: rgba(0, 0, 0, 0.055);
  --frost-icon-chip: #e8e8ec;
  --frost-neutral-bg: rgba(0, 0, 0, 0.06);
  --frost-header-glass: rgba(255, 255, 255, 0.8);
  --frost-pop-glass: rgba(255, 255, 255, 0.9);
  --frost-shadow-menu: 0 18px 48px -12px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(0, 0, 0, 0.05);
  --frost-check-stroke: rgba(0, 0, 0, 0.28);
  --frost-primary-ink: #3b7600;        /* links and accent ink on light */
  --frost-tip-bg: #17191c;
  --frost-tip-fg: #f2f3f4;
  --frost-field-bg: #ffffff;
  --frost-money-mark: oklch(0.85 0.21 128);
  --frost-progress-end: oklch(0.92 0.2 110);
  /* Status chips: tinted pill + dot */
  --frost-blue-bg: oklch(0.93 0.04 250);   --frost-blue-fg: oklch(0.42 0.14 258);
  --frost-lime-bg: oklch(0.93 0.12 125);   --frost-lime-fg: oklch(0.36 0.1 130);
  --frost-amber-bg: oklch(0.94 0.07 80);   --frost-amber-fg: oklch(0.45 0.11 65);
  --frost-red-bg: oklch(0.94 0.045 20);    --frost-red-fg: oklch(0.48 0.18 25);
  --frost-green-bg: oklch(0.93 0.06 160);  --frost-green-fg: oklch(0.4 0.1 160);
  --frost-bad: #e5484d;                    /* the bell's count badge */

  /* App-specific status colors complement the palette in both themes. */
  --theme-primary-text: var(--frost-primary-ink);
  /* Small status text needs a little more contrast on tinted containers. */
  --theme-error-text: color-mix(in srgb, var(--destructive) 85%, var(--foreground));
  --theme-muted-text: var(--muted-foreground);
  --theme-on-destructive: oklch(1 0 0);
  --theme-success: oklch(0.448 0.119 151.328);
  --theme-warning: oklch(0.473 0.137 46.201);
  --theme-info: oklch(0.488 0.243 264.376);
  --theme-approved: oklch(0.437 0.078 188.216);
  --theme-converted: oklch(0.491 0.27 292.581);
  --theme-inverse-primary: var(--primary);
  --theme-field-bg: var(--frost-field-bg);
  --shadow-card: none;                 /* flat cards: no shadow */
  --shadow-popover: var(--frost-shadow-menu);
  --shadow-focus: 0 0 0 4px var(--ring);

  /* ---- Color: blue — the "sent" status and the blue document accent.
     Tone number ≈ lightness (0 black … 100 white) */
  --color-blue-10: #0B1D48;
  --color-blue-20: #102C6E;
  --color-blue-30: #173C94;
  --color-blue-40: #1E4EC0;
  --color-blue-45: #2563EB; /* white text on it: 5.17:1 (WCAG AA ✓) */
  --color-blue-50: #3F78F0;
  --color-blue-60: #6090F3;
  --color-blue-70: #86ABF6;
  --color-blue-80: #ADC6FA; /* blue text on dark surfaces ✓ */
  --color-blue-90: #D6E2FD;
  --color-blue-95: #EBF1FE;

  /* ---- Reference neutrals — retained for printed documents and accent presets */
  --color-neutral-0: #000000;
  --color-neutral-4: #0A0A0B;
  --color-neutral-6: #111111;
  --color-neutral-10: #1C1C1E;
  --color-neutral-12: #222224;
  --color-neutral-17: #2A2A2D;
  --color-neutral-20: #303033;
  --color-neutral-22: #353538;
  --color-neutral-24: #3A3A3E;
  --color-neutral-30: #48484C;
  --color-neutral-40: #5F5F64;
  --color-neutral-46: #737378; /* quiet placeholder text: 4.7:1 on white */
  --color-neutral-50: #77777C;
  --color-neutral-60: #919196;
  --color-neutral-70: #ACACB1;
  --color-neutral-80: #C7C7CB;
  --color-neutral-90: #F0F0F0;
  --color-neutral-95: #F5F5F5;
  --color-neutral-98: #FAFAFA;
  --color-neutral-100: #FFFFFF;

  /* ---- Color: neutral variant (cool gray) — secondary text, outlines */
  --color-neutral-variant-30: #2E2E32; /* dividers, card borders (decorative) */
  --color-neutral-variant-50: #6B7280;
  --color-neutral-variant-60: #6F7582; /* not used by fields any more: fields and outlined controls use --color-outline */
  --color-neutral-variant-80: #9CA3AF;
  --color-neutral-variant-90: #D1D5DB;

  /* ---- Color: sage (gray with a little green) — selected states, tonal highlights */
  --color-slate-20: #15231A;
  --color-slate-30: #1F3A27;
  --color-slate-80: #A9D3B1;
  --color-slate-90: #D3F0D8;

  /* ---- Color: red — errors, destructive actions, overdue */
  --color-red-10: #410002;
  --color-red-20: #690005;
  --color-red-30: #93000A;
  --color-red-45: #D32F2F; /* white text on it: 4.98:1 ✓ */
  --color-red-80: #FFB4AB;
  --color-red-90: #FFDAD6;

  /* ---- Reference greens — retained for document accent presets */
  --color-green-10: #0E2114;
  --color-green-20: #14301C;
  --color-green-30: #1B5E2E;
  --color-green-45: #2A8539; /* document brand accent */
  --color-green-50: #2D8C3C;
  --color-green-60: #4FAE5F;
  --color-green-70: #7DC88B;
  --color-green-80: #A5DBAE;
  --color-green-90: #D3F0D8;
  --color-green-95: #E8F5E9;

  /* ---- Color: amber — warning, unpaid */
  --color-amber-10: #271900;
  --color-amber-20: #412D00;
  --color-amber-30: #5D4200;
  --color-amber-40: #7A5200;
  --color-amber-80: #F7C35C;
  --color-amber-90: #FFDF9E;

  /* ---- Color: teal — approved */
  --color-teal-30: #00504B;
  --color-teal-40: #00695F;
  --color-teal-80: #7ED8CE;
  --color-teal-90: #B2F1E9;

  /* ---- Color: violet — converted */
  --color-violet-30: #4A3A8A;
  --color-violet-80: #CBBEFF;
  --color-violet-90: #E7DEFF;

  /* ---- Font families */
  --font-family-inter: "Inter";
  --font-family-instrument: "Instrument Sans";
  --font-family-system: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-family-monospace: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* ---- Font sizes (rem; name = px equivalent) */
  --font-size-11: 0.6875rem;
  --font-size-12: 0.75rem;
  --font-size-14: 0.875rem;
  --font-size-15: 0.9375rem;
  --font-size-16: 1rem;
  --font-size-18: 1.125rem;
  --font-size-20: 1.25rem;
  --font-size-22: 1.375rem;
  --font-size-24: 1.5rem;
  --font-size-26: 1.625rem;
  --font-size-28: 1.75rem;
  --font-size-32: 2rem;
  --font-size-36: 2.25rem;
  --font-size-45: 2.8125rem;
  --font-size-13: 0.8125rem;
  --font-size-17: 1.0625rem;
  --font-size-30: 1.875rem;
  --font-size-34: 2.125rem;
  --font-size-38: 2.375rem;
  --font-size-40: 2.5rem;
  --font-size-52: 3.25rem;
  --font-size-57: 3.5625rem;

  /* ---- Font weights (Inter is variable, so any value 100–900 works) */
  --font-weight-400: 400;
  --font-weight-500: 500;
  --font-weight-600: 600;
  --font-weight-550: 550;
  --font-weight-650: 650;
  --font-weight-700: 700;

  /* ---- Line heights (rem; name = px equivalent) */
  --line-height-16: 1rem;
  --line-height-20: 1.25rem;
  --line-height-24: 1.5rem;
  --line-height-28: 1.75rem;
  --line-height-32: 2rem;
  --line-height-36: 2.25rem;
  --line-height-40: 2.5rem;
  --line-height-44: 2.75rem;
  --line-height-52: 3.25rem;
  --line-height-64: 4rem;

  /* ---- Letter spacing */
  --letter-spacing-tighter: -0.025em;
  --letter-spacing-tight: -0.02em;
  --letter-spacing-snug: -0.01em;
  --letter-spacing-none: 0em;
  --letter-spacing-wide: 0.01em;
  --letter-spacing-wider: 0.02em;
  --letter-spacing-display: -0.045em;
  --letter-spacing-title: -0.04em;
  --letter-spacing-money: -0.05em;
  --letter-spacing-stat: -0.04em;

  /* ---- Spacing (4px base; name = px equivalent) */
  --space-0: 0rem;
  --space-2: 0.125rem;
  --space-4: 0.25rem;
  --space-6: 0.375rem;
  --space-8: 0.5rem;
  --space-12: 0.75rem;
  --space-16: 1rem;
  --space-20: 1.25rem;
  --space-24: 1.5rem;
  --space-32: 2rem;
  --space-40: 2.5rem;
  --space-48: 3rem;
  --space-64: 4rem;
  --space-96: 6rem;
  --space-10: 0.625rem;
  --space-14: 0.875rem;
  --space-22: 1.375rem;
  --space-18: 1.125rem;
  --space-28: 1.75rem;

  /* ---- Sizes (fixed dimensions of controls and layout) */
  --size-2: 0.125rem;
  --size-4: 0.25rem;
  --size-6: 0.375rem;
  --size-8: 0.5rem;
  --size-12: 0.75rem;
  --size-16: 1rem;
  --size-18: 1.125rem;
  --size-20: 1.25rem;
  --size-24: 1.5rem;
  --size-28: 1.75rem;
  --size-32: 2rem;
  --size-40: 2.5rem;
  --size-48: 3rem;
  --size-52: 3.25rem;
  --size-56: 3.5rem;
  --size-64: 4rem;
  --size-72: 4.5rem;
  --size-80: 5rem;
  --size-88: 5.5rem;
  --size-96: 6rem;
  --size-112: 7rem;
  --size-160: 10rem;
  --size-240: 15rem;
  --size-280: 17.5rem;
  --size-360: 22.5rem;
  --size-560: 35rem;
  --size-640: 40rem;
  --size-720: 45rem;
  --size-960: 60rem;
  --size-1120: 70rem;
  --size-26: 1.625rem;
  --size-260: 16.25rem;
  --size-36: 2.25rem;
  --size-44: 2.75rem;
  --size-46: 2.875rem;
  --size-68: 4.25rem;
  --size-108: 6.75rem;
  --size-116: 7.25rem;
  --size-76: 4.75rem;
  --size-460: 28.75rem;
  --size-1240: 77.5rem;
  --size-3: 0.1875rem;
  --size-1: 0.0625rem;
  --size-10: 0.625rem;

  /* ---- Radii */
  --radius-0: 0rem;
  --radius-4: 0.25rem;
  --radius-6: 0.375rem;
  --radius-8: 0.5rem;
  --radius-10: 0.625rem;
  --radius-12: 0.75rem;
  --radius-14: 0.875rem;
  --radius-16: 1rem;
  --radius-18: 1.125rem;
  --radius-20: 1.25rem;
  --radius-22: 1.375rem;
  --radius-28: 1.75rem;
  --radius-3: 0.1875rem;
  --radius-full: 624.9375rem; /* "pill" — any huge value works */

  /* ---- Border widths (px on purpose: hairlines should stay crisp) */
  --border-width-1: 1px;
  --border-width-2: 2px;
  --border-width-3: 3px;

  /* ---- Opacity (percent, so they work in both `opacity` and `color-mix()`) */
  --opacity-0: 0%;
  --opacity-8: 8%;
  --opacity-10: 10%;
  --opacity-12: 12%;
  --opacity-16: 16%;
  --opacity-30: 30%;
  --opacity-38: 38%;
  --opacity-60: 60%;
  --opacity-100: 100%;

  /* ---- Z-index scale */
  --z-minus-1: -1;
  --z-0: 0;
  --z-1: 1;
  --z-10: 10;
  --z-100: 100;
  --z-200: 200;
  --z-300: 300;

  /* ---- Motion (Material 3 durations and easing curves) */
  --duration-0: 0ms;
  --duration-50: 50ms;
  --duration-100: 100ms;
  --duration-150: 150ms;
  --duration-200: 200ms;
  --duration-250: 250ms;
  --duration-300: 300ms;
  --duration-400: 400ms;
  --duration-500: 500ms;
  --duration-1400: 1400ms;
  --duration-2000: 2000ms;
  --easing-standard: cubic-bezier(0.2, 0, 0, 1);
  --easing-standard-decelerate: cubic-bezier(0, 0, 0, 1);
  --easing-standard-accelerate: cubic-bezier(0.3, 0, 1, 1);
  --easing-emphasized-decelerate: cubic-bezier(0.05, 0.7, 0.1, 1);
  --easing-emphasized-accelerate: cubic-bezier(0.3, 0, 0.8, 0.15);
  --easing-linear: linear;

  /* ---- Icon sizes */
  --icon-size-14: 0.875rem;
  --icon-size-16: 1rem;
  --icon-size-18: 1.125rem;
  --icon-size-20: 1.25rem;
  --icon-size-24: 1.5rem;
  --icon-size-32: 2rem;
  --icon-size-40: 2.5rem;

  /* ---- Breakpoints (Material 3 window size classes) — REFERENCE ONLY.
     CSS can't use variables inside @media, so media queries repeat these
     numbers. If you change one, search the project for the old value.
       compact   0–599px     phones: bottom nav bar, dialogs become sheets
       medium    600–839px   tablets: navigation rail
       expanded  840–1199px  two-pane editor (form + live preview)
       large     1200px+     wide desktop */
  --breakpoint-medium: 600px;
  --breakpoint-expanded: 840px;
  --breakpoint-large: 1200px;

  /* ---- Paper and print sizes (documents use print units: in, mm, pt) */
  --paper-letter-width: 8.5in;
  --paper-letter-height: 11in;
  --paper-a4-width: 210mm;
  --paper-a4-height: 297mm;
  --paper-margin: 0.6in;
  --print-size-0-75: 0.75pt;
  --print-size-1-5: 1.5pt;
  --print-size-3: 3pt;
  --print-size-4: 4pt;
  --print-size-6: 6pt;
  --print-size-8: 8pt;
  --print-size-9: 9pt;
  --print-size-10: 10pt;
  --print-size-12: 12pt;
  --print-size-14: 14pt;
  --print-size-18: 18pt;
  --print-size-24: 24pt;
  --print-size-28: 28pt;
  --print-size-40: 40pt;
  --print-size-56: 56pt;
  --print-size-180: 180pt;
  --print-size-220: 220pt;
  --line-height-tight: 1.2;
  --line-height-display: 1.1;
  --line-height-relaxed: 1.45;
}


/* ==========================================================================
   2. SEMANTIC TOKENS — roles. Pages and components think in these.

   Color pattern for primary / error / success / warning:
     --color-X                strong fill (filled buttons, FAB)
     --color-on-X             text/icons placed ON that fill
     --color-X-text           that hue as text/icons on dark surfaces
     --color-X-container      soft tonal fill (chips, highlights)
     --color-on-X-container   text/icons on the soft fill
   The preset palette is declared with the primitives. The existing roles map
   to it here so every component responds to the same light/dark theme.
   ========================================================================== */
:root, ::backdrop {
  color-scheme: light;

  /* ---- Preset aliases consumed by the existing app components */
  --color-primary: var(--primary);
  --color-on-primary: var(--primary-foreground);
  --color-primary-text: var(--theme-primary-text);
  --color-primary-container: color-mix(in srgb, var(--primary) 16%, var(--card));
  --color-on-primary-container: var(--theme-primary-text);
  --color-primary-tint: color-mix(in srgb, var(--primary) 7%, var(--card));
  --color-primary-tint-border: color-mix(in srgb, var(--primary) 30%, var(--border));
  --color-inverse-primary: var(--theme-inverse-primary);
  --color-chart-1: var(--chart-1);
  --color-chart-2: var(--chart-2);
  --color-chart-3: var(--chart-3);
  --color-chart-4: var(--chart-4);
  --color-chart-5: var(--chart-5);
  --color-secondary: var(--secondary);
  --color-on-secondary: var(--secondary-foreground);
  --color-secondary-container: var(--accent);
  --color-on-secondary-container: var(--accent-foreground);
  --color-background: var(--background);
  --color-surface: var(--background);
  --color-surface-dim: var(--muted);
  --color-surface-bright: var(--card);
  --color-surface-container-lowest: var(--muted);
  --color-surface-container-low: var(--card);
  --color-surface-container: var(--muted);
  --color-surface-container-high: var(--accent);
  --color-surface-container-highest: var(--secondary);
  --color-on-surface: var(--foreground);
  --color-on-surface-variant: var(--theme-muted-text);
  --color-inverse-surface: var(--foreground);
  --color-inverse-on-surface: var(--background);
  --color-outline: var(--input);
  --color-outline-variant: var(--border);
  --color-outline-quiet: var(--border);
  --color-scrim: color-mix(in srgb, var(--color-neutral-0) var(--opacity-60), transparent);
  --color-error: var(--destructive);
  --color-on-error: var(--theme-on-destructive);
  --color-error-text: var(--theme-error-text);
  --color-error-container: color-mix(in srgb, var(--destructive) 10%, var(--card));
  --color-on-error-container: var(--theme-error-text);
  --color-success: var(--theme-success);
  --color-on-success: var(--background);
  --color-success-text: var(--theme-success);
  --color-success-container: color-mix(in srgb, var(--theme-success) 10%, var(--card));
  --color-on-success-container: var(--theme-success);
  --color-warning: var(--theme-warning);
  --color-on-warning: var(--background);
  --color-warning-text: var(--theme-warning);
  --color-warning-container: color-mix(in srgb, var(--theme-warning) 10%, var(--card));
  --color-on-warning-container: var(--theme-warning);
  --color-status-draft: var(--muted-foreground);
  --color-status-draft-container: var(--frost-neutral-bg);
  --color-status-sent: var(--frost-blue-fg);
  --color-status-sent-container: var(--frost-blue-bg);
  --color-status-approved: var(--frost-lime-fg);
  --color-status-approved-container: var(--frost-lime-bg);
  --color-status-declined: var(--frost-red-fg);
  --color-status-declined-container: var(--frost-red-bg);
  --color-status-converted: var(--theme-converted);
  --color-status-converted-container: color-mix(in srgb, var(--theme-converted) 10%, var(--card));
  --color-status-paid: var(--frost-green-fg);
  --color-status-paid-container: var(--frost-green-bg);
  --color-status-unpaid: var(--frost-amber-fg);
  --color-status-unpaid-container: var(--frost-amber-bg);
  --color-status-overdue: var(--frost-red-fg);
  --color-status-overdue-container: var(--frost-red-bg);

  /* ---- State layers: a flat overlay of the content color at these opacities */
  --state-hover-opacity: var(--opacity-8);
  --state-focus-opacity: var(--opacity-10);
  --state-pressed-opacity: var(--opacity-10);
  --state-dragged-opacity: var(--opacity-16);
  --state-selected-opacity: var(--opacity-12);
  --state-disabled-content-opacity: var(--opacity-38);
  --state-disabled-container-opacity: var(--opacity-12);

  /* ---- Focus ring (keyboard focus) */
  --focus-ring-color: var(--ring);
  --focus-ring-width: var(--border-width-2);
  --focus-ring-offset: var(--border-width-2);

  /* ---- Typography: families */
  --font-family-brand: var(--font-family-instrument);
  --font-family-base: var(--font-family-brand), var(--font-family-system);
  --font-family-heading: var(--font-family-instrument), var(--font-family-system);
  --font-family-code: var(--font-family-monospace);

  /* ---- Typography: shared role names, Instrument Sans body and heading scale. */
  --font-display-lg-size: var(--font-size-57);
  --font-display-lg-line-height: var(--line-height-64);
  --font-display-lg-weight: var(--font-weight-700);
  --font-display-lg-tracking: var(--letter-spacing-tighter);
  --font-display-md-size: var(--font-size-45);
  --font-display-md-line-height: var(--line-height-52);
  --font-display-md-weight: var(--font-weight-700);
  --font-display-md-tracking: var(--letter-spacing-tighter);
  --font-display-sm-size: var(--font-size-36);
  --font-display-sm-line-height: var(--line-height-44);
  --font-display-sm-weight: var(--font-weight-700);
  --font-display-sm-tracking: var(--letter-spacing-tighter);

  --font-headline-lg-size: var(--font-size-32);
  --font-headline-lg-line-height: var(--line-height-40);
  --font-headline-lg-weight: var(--font-weight-700);
  --font-headline-lg-tracking: var(--letter-spacing-tighter);
  --font-headline-md-size: var(--font-size-28);         /* big numbers on stat cards */
  --font-headline-md-line-height: var(--line-height-36);
  --font-headline-md-weight: var(--font-weight-700);
  --font-headline-md-tracking: var(--letter-spacing-tighter);
  --font-headline-sm-size: var(--font-size-28);
  --font-headline-sm-line-height: var(--line-height-32);
  --font-headline-sm-weight: var(--font-weight-600);
  --font-headline-sm-tracking: var(--letter-spacing-tight);

  --font-title-lg-size: var(--font-size-18);
  --font-title-lg-line-height: var(--line-height-28);
  --font-title-lg-weight: var(--font-weight-600);
  --font-title-lg-tracking: var(--letter-spacing-snug);
  --font-title-md-size: var(--font-size-16);
  --font-title-md-line-height: var(--line-height-24);
  --font-title-md-weight: var(--font-weight-600);
  --font-title-md-tracking: var(--letter-spacing-snug);
  --font-title-sm-size: var(--font-size-14);
  --font-title-sm-line-height: var(--line-height-20);
  --font-title-sm-weight: var(--font-weight-600);
  --font-title-sm-tracking: var(--letter-spacing-none);

  --font-subheading-size: var(--font-size-15);
  --font-subheading-line-height: var(--line-height-20);
  --font-subheading-weight: var(--font-weight-500);
  --font-subheading-tracking: var(--letter-spacing-none);

  --font-body-lg-size: var(--font-size-16);             /* text in fields (16px stops phones zooming in) */
  --font-body-lg-line-height: var(--line-height-24);
  --font-body-lg-weight: var(--font-weight-400);
  --font-body-lg-tracking: var(--letter-spacing-none);
  --font-body-md-size: var(--font-size-14);
  --font-body-md-line-height: var(--line-height-20);
  --font-body-md-weight: var(--font-weight-400);
  --font-body-md-tracking: var(--letter-spacing-none);
  --font-body-sm-size: var(--font-size-12);
  --font-body-sm-line-height: var(--line-height-16);
  --font-body-sm-weight: var(--font-weight-400);
  --font-body-sm-tracking: var(--letter-spacing-wide);

  --font-label-lg-size: var(--font-size-14);
  --font-label-lg-line-height: var(--line-height-20);
  --font-label-lg-weight: var(--font-weight-500);
  --font-label-lg-tracking: var(--letter-spacing-none);
  --font-label-md-size: var(--font-size-12);
  --font-label-md-line-height: var(--line-height-16);
  --font-label-md-weight: var(--font-weight-500);
  --font-label-md-tracking: var(--letter-spacing-wide);
  --font-label-sm-size: var(--font-size-11);
  --font-label-sm-line-height: var(--line-height-16);
  --font-label-sm-weight: var(--font-weight-500);
  --font-label-sm-tracking: var(--letter-spacing-wider);

  /* ---- Caption: the smallest running text (timestamps, helper and hint lines, footnotes) */
  --font-caption-size: var(--font-size-12);
  --font-caption-line-height: var(--line-height-16);
  --font-caption-weight: var(--font-weight-400);
  --font-caption-tracking: var(--letter-spacing-wide);

  /* ---- Spacing roles */
  --space-none: var(--space-0);
  --space-3xs: var(--space-2);
  --space-2xs: var(--space-4);
  --space-xs: var(--space-8);
  --space-sm: var(--space-12);
  --space-md: var(--space-16);
  --space-card: var(--space-lg);
  --space-lg: var(--space-24);
  --space-xl: var(--space-32);
  --space-2xl: var(--space-48);
  --space-3xl: var(--space-64);

  /* ---- Layout */
  --layout-gutter: var(--space-14);           /* page side padding on phones */
  --layout-gutter-wide: var(--space-28);
  --layout-max-width: var(--size-1240);       /* content column max width */
  --layout-reading-width: var(--size-640);    /* comfortable text width */
  --layout-form-width: var(--size-720);       /* forms such as Settings */

  /* ---- Sizes */
  --size-touch-target: var(--size-44);        /* minimum tap area for anything interactive */
  --size-control-sm: var(--size-36);
  --size-control-md: var(--size-44);
  --size-control-lg: var(--size-52);
  --size-field: var(--size-44);

  /* ---- Shape (corner radius) scale */
  --shape-none: var(--radius-0);
  --shape-xs: calc(var(--radius) - var(--space-2xs));
  --shape-sm: calc(var(--radius) - var(--space-3xs));
  --shape-md: var(--radius);
  --shape-lg: calc(var(--radius) + var(--space-2xs));
  --shape-xl: calc(var(--radius) + var(--space-xs));
  --shape-full: var(--radius-full);
  --shape-btn: var(--radius-14);           /* buttons, search, the segmented control */
  --shape-card: var(--radius-20);          /* grey cards */
  --shape-band: var(--radius-22);          /* the Home number band */

  /* ---- Borders */
  --border-width-hairline: var(--border-width-1);
  --border-width-thick: var(--border-width-2);

  /* ---- Elevation: subtle borders and shadows */
  --elevation-none: none;
  --elevation-1: var(--shadow-card);     /* cards, rows that sit on the page */
  --elevation-2: var(--shadow-popover);  /* menus, popovers, floating sheets */
  --elevation-focus: var(--shadow-focus); /* keyboard focus halo */

  /* ---- Layers (stacking order). Dialogs, menus and snackbars use the
     browser's top layer and don't need z-index. */
  --z-behind: var(--z-minus-1);   /* state-layer overlays sit behind content */
  --z-raised: var(--z-1);
  --z-sticky: var(--z-10);
  --z-nav: var(--z-100);
  --z-fab: var(--z-200);

  /* ---- Motion */
  --motion-duration-short: var(--duration-100);
  --motion-duration-medium: var(--duration-200);
  --motion-duration-long: var(--duration-400);
  --motion-duration-extra-long: var(--duration-500);
  --motion-duration-spin: var(--duration-1400);
  --motion-duration-progress: var(--duration-2000);
  --motion-easing-standard: var(--easing-standard);
  --motion-easing-enter: var(--easing-emphasized-decelerate);
  --motion-easing-exit: var(--easing-emphasized-accelerate);
  --motion-easing-linear: var(--easing-linear);

  /* ---- Icon sizes */
  --icon-size-sm: var(--icon-size-18);
  --icon-size-md: var(--icon-size-24);
  --icon-size-lg: var(--icon-size-32);
  --icon-size-xl: var(--icon-size-40);

  /* ---- Documents (contracts / invoices) always render light, even in the
     dark app. --doc-color-accent is replaced at runtime by the brand accent
     color chosen in Settings. */
  --doc-color-background: var(--color-neutral-100);
  --doc-color-text: var(--color-neutral-10);
  --doc-color-text-muted: var(--color-neutral-40);
  --doc-color-border: var(--color-neutral-90);
  --doc-color-surface: var(--color-neutral-95);
  --doc-color-accent: var(--doc-accent-green);
  --doc-font-family: var(--font-family-inter), var(--font-family-system);

  /* Document type and spacing (print units, so PDFs come out the same size everywhere) */
  --doc-font-size-xs: var(--print-size-8);
  --doc-font-size-sm: var(--print-size-9);
  --doc-font-size-body: var(--print-size-10);
  --doc-font-size-lg: var(--print-size-12);
  --doc-font-size-title: var(--print-size-18);
  --doc-font-size-display: var(--print-size-24);
  --doc-line-height: var(--line-height-relaxed);
  --doc-line-height-tight: var(--line-height-tight);
  --doc-space-xs: var(--print-size-3);
  --doc-space-sm: var(--print-size-6);
  --doc-space-md: var(--print-size-12);
  --doc-space-lg: var(--print-size-18);
  --doc-space-xl: var(--print-size-28);
  --doc-space-2xl: var(--print-size-40);
  --doc-border-width: var(--print-size-0-75);
  --doc-rule-width: var(--print-size-1-5);
  --doc-radius: var(--print-size-3);
  --doc-logo-max-height: var(--print-size-56);
  --doc-logo-max-width: var(--print-size-180);
  --doc-signature-width: var(--print-size-220);
  --doc-signature-height: var(--print-size-56);
  --doc-page-margin: var(--paper-margin);
  --doc-page-width-letter: var(--paper-letter-width);
  --doc-page-height-letter: var(--paper-letter-height);
  --doc-page-width-a4: var(--paper-a4-width);
  --doc-page-height-a4: var(--paper-a4-height);
  --doc-color-paid: var(--doc-accent-brand);
  --doc-color-on-accent: var(--color-neutral-100);   /* text on an accent-colored band (presets all pass 4.5:1) */
  --doc-stamp-rotation: -12deg;

  /* Editing on the sheet (templates/edit.css). These draw on the light paper, never in a PDF. */
  --doc-edit-focus-outline: var(--doc-color-accent);          /* the brand color: 4.6:1 or more on white for every preset */
  --doc-edit-outline-width: var(--border-width-thick);
  --doc-edit-outline-offset: var(--size-2);                   /* outlines sit OUTSIDE the text, so editing never shifts the layout */
  --doc-edit-radius: var(--doc-radius);
  --doc-edit-placeholder: var(--color-neutral-46);              /* lighter than the text, still 4.7:1 on white */
  --doc-slot-hover: var(--doc-color-surface);                 /* the soft fill under a slot you point at */
  --doc-edit-wont-print: var(--color-neutral-60);             /* dashed outline for things that don't print */
  --doc-edit-add-fg: var(--doc-color-accent);                 /* "+ Add tax" and friends */
  --doc-edit-toolbar-bg: var(--doc-color-background);
  --doc-edit-hint-bg: var(--doc-color-surface);
  --doc-edit-invalid: var(--color-error-text);                 /* a price that isn't a number */
  --doc-edit-drop-before: 0 calc(var(--doc-edit-outline-width) * -1) 0 var(--doc-edit-focus-outline);  /* where a dragged line lands */
  --doc-edit-drop-after: 0 var(--doc-edit-outline-width) 0 var(--doc-edit-focus-outline);

  /* Editor chrome on the sheet. These follow the app theme (the paper tokens above never change, so print and the
     paper preview stay white). Light values are the paper's own, so light mode is unchanged. */
  --edit-slot-hover-bg: var(--doc-color-surface);             /* the fill under a slot or line you point at */
  --edit-toolbar-bg: var(--doc-color-background);             /* the line toolbar and the client actions */
  --edit-toolbar-border: var(--color-outline-variant);
  --edit-placeholder: var(--doc-edit-placeholder);            /* placeholders, the drag grip, dashed money underlines */
  --edit-brand-text: var(--doc-color-accent);                 /* brand-coloured text: "Add tax", "Change", status lines */
  --edit-slot-rest-shadow: none;                              /* resting line under text slots (dark only; none in light) */
  /* Phones: the sheet reflows to the screen width instead of shrinking, at these readable sizes.
     (The width where this starts, 600px, is written in templates/edit.css — a container query can't use variables.) */
  --doc-edit-phone-font-size-xs: var(--font-size-12);
  --doc-edit-phone-font-size-sm: var(--font-size-14);
  --doc-edit-phone-font-size-body: var(--font-size-16);
  --doc-edit-phone-font-size-lg: var(--font-size-18);
  --doc-edit-phone-font-size-title: var(--font-size-22);
  --doc-edit-phone-font-size-display: var(--font-size-28);
  --doc-edit-phone-input-font-size: max(var(--font-size-16), 1em); /* fields on a phone: never under 16px (no zoom on focus) */

  /* Brand-color choices offered in Settings. All pass 4.5:1 on white paper. */
  --doc-accent-blue: var(--color-blue-45);        /* 5.17:1 */
  --doc-accent-navy: var(--color-blue-30);        /* 9.95:1 */
  --doc-accent-teal: var(--color-teal-40);        /* 6.59:1 */
  --doc-accent-brand: oklch(from var(--primary) 0.52 0.15 h); /* the app's lime, darkened until it is readable as text on paper: 5.2:1 */
  --doc-accent-green: var(--doc-accent-brand);    /* the default accent on all three designs */
  --doc-accent-red: var(--color-red-45);          /* 4.98:1 */
  --doc-accent-burgundy: var(--color-red-30);     /* 9.35:1 */
  --doc-accent-violet: var(--color-violet-30);    /* 9.28:1 */
  --doc-accent-brown: var(--color-amber-40);      /* 6.92:1 */
  --doc-accent-slate: var(--color-slate-30);      /* 9.36:1 */
  --doc-accent-charcoal: var(--color-neutral-20); /* 13.17:1 */
}

/* Reduced motion: every animation and transition collapses to (almost) instant.
   Spinners keep turning slowly so "loading" is still visible. */
@media (prefers-reduced-motion: reduce) {
  :root, ::backdrop {
    --motion-duration-short: var(--duration-0);
    --motion-duration-medium: var(--duration-0);
    --motion-duration-long: var(--duration-0);
    --motion-duration-extra-long: var(--duration-0);
    --motion-duration-spin: var(--duration-2000);
  }
}


/* ==========================================================================
   3. COMPONENT TOKENS — reference semantic tokens only.
   Grouped by component, in the same order as /components.
   ========================================================================== */
:root, ::backdrop {
  /* ---- app-icon */
  --icon-size: var(--icon-size-md);
  --icon-color: currentColor;

  /* ---- app-button */
  --button-height: var(--size-control-md);
  --button-height-sm: var(--size-control-sm);
  --button-height-lg: var(--size-control-lg);
  --button-padding-x: var(--space-md);
  --button-padding-x-with-icon: var(--space-sm);
  --button-padding-x-text: var(--space-sm);
  --button-gap: var(--space-xs);
  --button-radius: var(--shape-btn);
  --button-icon-size: var(--icon-size-sm);
  --button-filled-bg: var(--color-primary);
  --button-filled-fg: var(--color-on-primary);
  --button-tonal-bg: var(--frost-neutral-bg);
  --button-tonal-fg: var(--secondary-foreground);
  --button-outlined-border: var(--color-outline);
  --button-outlined-bg: var(--frost-field-bg);
  --button-outlined-fg: var(--color-on-surface);
  --button-text-fg: var(--foreground);
  --button-danger-bg: var(--color-error);
  --button-danger-fg: var(--color-on-error);
  --button-disabled-bg: color-mix(in srgb, var(--color-on-surface) var(--state-disabled-container-opacity), transparent);
  --button-disabled-fg: color-mix(in srgb, var(--color-on-surface) var(--state-disabled-content-opacity), transparent);

  /* ---- app-icon-button */
  --icon-button-size: var(--size-control-md);
  --icon-button-radius: var(--radius-12);
  --icon-button-fg: var(--color-on-surface-variant);
  --icon-button-selected-fg: var(--color-primary-text);
  --icon-button-filled-bg: var(--color-primary);
  --icon-button-filled-fg: var(--color-on-primary);
  --icon-button-tonal-bg: var(--color-surface-container-highest);
  --icon-button-tonal-fg: var(--color-on-surface);
  --icon-button-outlined-border: var(--color-outline);

  /* ---- app-fab */
  --fab-size: var(--size-56);
  --fab-radius: var(--shape-lg);
  --fab-bg: var(--color-primary);
  --fab-fg: var(--color-on-primary);
  --fab-padding-x: var(--space-md);
  --fab-offset: var(--space-md);

  /* ---- Fields: app-text-field, app-select, app-date-field */
  --field-height: var(--size-control-md);
  --field-padding-x: var(--space-sm);
  --field-padding-y: var(--space-xs);
  --field-radius: var(--shape-md);
  --field-gap: var(--space-sm);
  --field-border-width: var(--border-width-hairline);
  --field-border-width-focus: var(--border-width-thick);
  --field-border-color: var(--color-outline);
  --field-border-color-hover: var(--color-outline);
  --field-border-color-focus: var(--primary);
  --field-label-color: var(--foreground);
  --field-label-color-focus: var(--foreground);
  --field-text-color: var(--color-on-surface);
  --field-supporting-color: var(--color-on-surface-variant);
  --field-error-color: var(--color-error-text);
  --field-notch-padding: var(--space-2xs);
  --field-bg: var(--theme-field-bg);
  --field-label-float-scale: 0.75; /* floating label = 12/16 of resting size */

  /* ---- app-switch */
  --switch-track-width: var(--size-44);
  --switch-track-height: var(--size-26);
  --switch-track-border: 0rem;
  --switch-track-off-bg: var(--frost-check-stroke);
  --switch-track-off-border: transparent;
  --switch-track-on-bg: var(--color-primary);
  --switch-handle-off-size: var(--size-20);
  --switch-handle-on-size: var(--size-20);
  --switch-handle-pressed-size: var(--size-24);
  --switch-handle-off-bg: var(--color-neutral-100);
  --switch-handle-on-bg: var(--color-neutral-100);
  --switch-handle-icon-color: var(--primary-foreground);

  /* ---- app-chip */
  --chip-height: var(--size-control-sm);
  --chip-radius: var(--shape-full);
  --chip-padding-x: var(--space-md);
  --chip-padding-x-with-icon: var(--space-xs);
  --chip-gap: var(--space-xs);
  --chip-border: var(--color-outline);
  --chip-fg: var(--color-on-surface-variant);
  --chip-selected-bg: var(--color-primary-container);
  --chip-selected-fg: var(--color-on-primary-container);

  /* ---- app-status-chip */
  --status-chip-height: var(--size-26);
  --status-chip-radius: var(--shape-full);
  --status-chip-padding-start: 0.5625rem;
  --status-chip-padding-end: 0.6875rem;
  --status-chip-dot-size: var(--size-6);
  --status-chip-gap: var(--space-6);

  /* ---- app-card */
  --card-shadow: var(--elevation-1);
  --card-radius: var(--shape-card);
  --card-padding: var(--space-card);
  --card-border: transparent;
  --card-elevated-bg: var(--color-surface-container-low);
  --card-filled-bg: var(--color-surface-container-highest);
  --card-outlined-bg: var(--color-surface);
  --card-outlined-border: var(--color-outline-variant);

  /* ---- app-dialog / app-bottom-sheet */
  --dialog-bg: var(--popover);
  --dialog-radius: var(--shape-xl);
  --dialog-padding: var(--space-lg);
  --dialog-min-width: var(--size-280);
  --dialog-max-width: var(--size-560);
  --dialog-wide-max-width: var(--size-960);
  --dialog-scrim: var(--color-scrim);
  --sheet-bg: var(--color-surface-container-low);
  --sheet-max-width: var(--size-640);
  --sheet-handle-width: var(--size-32);
  --sheet-handle-height: var(--size-4);
  --sheet-handle-color: var(--color-on-surface-variant);

  /* ---- app-snackbar */
  --snackbar-bg: var(--color-inverse-surface);
  --snackbar-fg: var(--color-inverse-on-surface);
  --snackbar-action-fg: var(--color-inverse-primary);
  --snackbar-radius: var(--shape-md);
  --snackbar-min-height: var(--size-48);
  --snackbar-max-width: var(--size-560);
  --snackbar-offset: var(--space-md);

  /* ---- app-menu */
  --popover-shadow: var(--elevation-2);
  --menu-bg: var(--popover);
  --menu-radius: var(--shape-xl);
  --menu-glass-bg: var(--frost-pop-glass);
  --menu-min-width: var(--size-112);
  --menu-max-width: var(--size-280);
  --menu-item-height: var(--size-44);
  --menu-padding-y: var(--space-xs);

  /* ---- app-segmented */
  --segmented-height: var(--size-control-md);
  --segmented-radius: var(--shape-btn);
  --segmented-track-bg: var(--secondary);
  --segmented-border: var(--color-outline);
  --segmented-selected-bg: var(--frost-field-bg);
  --segmented-selected-fg: var(--card-foreground);
  --segmented-selected-shadow: 0 0.0625rem 0.1875rem oklch(0 0 0 / 12%);

  /* ---- app-list-item */
  --list-item-min-height: var(--size-56);
  --list-item-min-height-two-line: var(--size-72);
  --list-item-padding-x: var(--space-md);
  --list-item-padding-y: var(--space-xs);
  --list-item-gap: var(--space-md);
  --list-item-avatar-size: var(--size-40);
  --list-item-avatar-bg: var(--color-primary-container);
  --list-item-avatar-fg: var(--color-on-primary-container);
  --avatar-size: var(--size-36);
  --avatar-bg-l: 0.9;
  --avatar-chroma: 0.07;
  --avatar-fg-l: 0.38;
  --avatar-chroma-fg: 0.09;
  --avatar-hue-default: 200;
  --list-item-divider: var(--color-outline-variant);
  --list-item-selected-bg: var(--color-secondary-container);
  --list-item-selected-fg: var(--color-on-secondary-container);

  /* ---- Tabs (Settings areas): a muted track with a raised selected tab */
  --tabs-track-bg: var(--secondary);
  --tabs-track-border: transparent;
  --tabs-radius: var(--shape-btn);
  --tabs-fg: var(--color-on-surface-variant);
  --tabs-active-bg: var(--frost-field-bg);
  --tabs-active-fg: var(--card-foreground);
  --tabs-active-shadow: 0 0.0625rem 0.1875rem oklch(0 0 0 / 12%);

  /* ---- app-empty-state */
  --empty-state-icon-box: var(--size-80);
  --empty-state-icon-bg: var(--color-surface-container-high);
  --empty-state-icon-fg: var(--color-primary-text);
  --empty-state-max-width: var(--size-360);

  /* ---- app-top-bar */
  --top-bar-height: var(--size-108);               /* the sticky header's height (two rows); phones: see the media query at the end */
  --top-bar-bg: var(--color-surface);
  --top-bar-scrolled-bg: var(--background);
  --top-bar-padding-x: var(--space-2xs);
  --page-title-size: var(--font-size-40);        /* the big headline at the top of a main page */
  --page-title-size-phone: var(--font-size-32);
  --page-title-weight: var(--font-weight-650);
  --page-title-tracking: var(--letter-spacing-display);
  --page-head-gap: var(--space-24);

  /* ---- app-nav: the sticky frosted header (wide) and the bottom tab bar (phones) */
  --nav-border: var(--border);
  --nav-bg: var(--frost-header-glass);
  --nav-bar-bg: var(--frost-pop-glass);
  --nav-blur: blur(1.5rem) saturate(1.6);
  --nav-item-fg: var(--muted-foreground);
  --nav-item-hover-fg: var(--foreground);
  --nav-item-active-fg: var(--foreground);
  --nav-tab-height: var(--size-48);
  --nav-underline-height: var(--size-3);
  --nav-bar-height: var(--size-68);
  --nav-tool-size: var(--size-44);
  --nav-search-max: 35rem;
  --nav-search-min: 7.5rem;
  --nav-search-bg: var(--card);
  --nav-radius: var(--shape-btn);
  --nav-badge-bg: var(--frost-bad);
  --nav-badge-fg: var(--color-neutral-100);

  /* ---- app-sync-status (cloud icon in the top bar) */
  --sync-status-error-fg: var(--color-error-text);
  --sync-status-offline-fg: var(--color-on-surface-variant);
  --sync-status-spin-duration: var(--duration-1400);

  /* ---- Search bar on the dashboard (opens #/search) */
  --search-launcher-height: var(--size-field);
  --search-launcher-bg: var(--color-surface-container-low);
  --search-launcher-fg: var(--color-on-surface-variant);
  --search-launcher-radius: var(--shape-md);

  /* ---- app-stat-card */
  --stat-card-bg: var(--color-surface-container-low);
  --stat-card-radius: var(--shape-band);
  --stat-card-padding: var(--space-card);
  --stat-card-icon-box: var(--size-40);
  --stat-card-icon-radius: var(--shape-md);
  --stat-card-border: transparent;
  --stat-card-highlight-bg: var(--card);
  --stat-card-highlight-border: transparent;

  /* ---- app-bar-chart */
  --bar-chart-height: var(--size-240);
  --bar-chart-series-1: var(--color-chart-1);
  --bar-chart-series-2: var(--color-chart-2);
  --bar-chart-series-3: var(--color-chart-3);
  --bar-chart-series-4: var(--color-chart-4);
  --bar-chart-grid: var(--color-outline-variant);
  --bar-chart-axis-text: var(--color-on-surface-variant);
  --bar-chart-bar-radius: var(--radius-6);
  --bar-chart-hatch-width: 6; /* stripe thickness, in SVG units of a 6×6 pattern tile (the rest is the gap) */

  /* ---- app-line-chart */
  --line-chart-height: 14.375rem;
  --line-chart-series-1: var(--chart-1);
  --line-chart-series-2: var(--chart-2);

  /* ---- app-progress */
  --progress-color: var(--primary);
  --progress-track: var(--frost-neutral-bg);
  --progress-linear-height: var(--size-10);
  --progress-circular-size: var(--size-40);
  --progress-circular-size-sm: var(--size-18);
  --progress-stroke-width: 4; /* in SVG units of a 48×48 box */

  /* ---- app-tooltip */
  --tooltip-bg: var(--color-inverse-surface);
  --tooltip-fg: var(--color-inverse-on-surface);
  --tooltip-radius: var(--shape-sm);
  --tooltip-max-width: var(--size-280);

  /* ---- app-banner */
  --banner-bg: var(--card);
  --banner-radius: var(--shape-card);
  --banner-icon-fg: var(--color-primary-text);

  /* ---- app-image-field */
  --image-field-preview-size: var(--size-96);
  --image-field-preview-bg: var(--color-surface-container-highest);
  --image-field-preview-border: var(--color-outline-variant);
  --image-field-preview-radius: var(--shape-md);
  --image-field-drop-border: var(--color-primary-text);

  /* ---- app-color-field */
  --color-field-swatch-size: var(--size-40);
  --color-field-swatch-border: var(--color-outline);   /* visible edge even for dark swatches */
  --color-field-selected-ring: var(--color-on-surface);


  /* ---- app-summary (label / amount rows) */
  --summary-row-gap: var(--space-xs);
  --summary-divider: var(--color-outline-variant);

  /* ---- app-signature-pad */
  --signature-pad-height: var(--size-160);
  --signature-pad-bg: var(--doc-color-background);
  --signature-pad-ink: var(--doc-color-text);
  --signature-pad-guide: var(--doc-color-border);
  --signature-pad-radius: var(--shape-md);

  /* ---- Document editor page (pages/editor.css): the sheet in the middle, the Status panel beside it */
  --editor-inspector-width: 20rem;                     /* 320px */
  --editor-canvas-bg: var(--color-surface);
  --editor-inspector-bg: var(--card);
  --editor-paper-shadow: var(--shadow-popover);
  --editor-price-column-width: calc(var(--size-360) + var(--space-48)); /* 408px: the sticky price column beside the work (computers); wide enough for the totals table (it needs ~355px inside the card's padding) */
  --editor-price-column-width-narrow: calc(var(--size-360) + var(--space-32)); /* 392px: the same column from 760px of page, where the work column is still 350px or more */
  --editor-bar-height: calc(var(--size-control-lg) + var(--space-sm) * 2); /* the phone/tablet bottom bar: one large button */
  /* The status stepper (Draft → Sent → Paid) under the editor's top bar and in the Status panel */
  --steps-dot-size: var(--size-20);
  --steps-line-width: var(--border-width-thick);
  --steps-done: var(--color-success-text);
  --steps-current: var(--color-on-surface);
  --steps-todo: var(--color-outline-variant);
  --steps-error: var(--color-error-text);
  --steps-muted: var(--color-on-surface-variant);

  /* ---- Client picker (pages/_client-picker.js): the popover over the sheet; a bottom sheet on phones */
  --client-picker-width: var(--size-360);
  --client-picker-list-max-height: var(--size-280);
  --client-picker-bg: var(--popover);
  --client-picker-radius: var(--shape-md);
  --client-picker-row-height: var(--size-56);
  --line-suggest-width: 30rem;                          /* 480px */

  /* ---- app-doc-preview (paper preview of a document) */
  --doc-preview-bg: var(--color-surface-container-lowest);
  --doc-preview-radius: var(--shape-md);
  --doc-preview-padding: var(--space-md);
  --doc-preview-padding-compact: var(--space-none);

  /* ---- app-template-picker */
  --template-picker-min: var(--size-160);
  --template-picker-thumb-height: var(--size-240);
  --template-picker-thumb-height-compact: var(--size-112);
  --template-picker-selected: var(--color-primary-text);

}

/* Applying .dark to <html> switches the entire component system. */
.dark, .dark ::backdrop {
  color-scheme: dark;
  /* Neutral graphite: no green or blue tint on any surface. One step between page and card. */
  --background: #0d0d0e;
  --foreground: #eceeef;
  --card: #1b1b1d;
  --card-foreground: #eceeef;
  --popover: #1b1b1d;
  --popover-foreground: #eceeef;
  --primary: oklch(0.88 0.22 128);
  --primary-foreground: #142200;
  --secondary: #1b1b1d;
  --secondary-foreground: #eceeef;
  --muted: #1b1b1d;
  --muted-foreground: #8c9198;
  --accent: #242426;
  --accent-foreground: #eceeef;
  --destructive: oklch(0.704 0.191 22.216);
  --border: rgba(255, 255, 255, 0.07);
  --input: rgba(255, 255, 255, 0.1);
  --ring: rgba(190, 255, 60, 0.2);
  --chart-1: oklch(0.88 0.22 128);
  --chart-2: oklch(0.75 0.02 255);
  --chart-3: oklch(0.72 0.01 73);
  --chart-4: oklch(0.63 0.01 67);
  --chart-5: oklch(0.52 0.01 34);
  --sidebar: #0d0d0e;
  --sidebar-foreground: #eceeef;
  --sidebar-primary: oklch(0.88 0.22 128);
  --sidebar-primary-foreground: #142200;
  --sidebar-accent: rgba(255, 255, 255, 0.07);
  --sidebar-accent-foreground: #eceeef;
  --sidebar-border: rgba(255, 255, 255, 0.07);
  --sidebar-ring: rgba(190, 255, 60, 0.2);

  --frost-hover: rgba(255, 255, 255, 0.06);
  --frost-selected: rgba(255, 255, 255, 0.07);
  --frost-icon-chip: rgba(255, 255, 255, 0.07);
  --frost-neutral-bg: rgba(255, 255, 255, 0.08);
  --frost-header-glass: rgba(13, 13, 14, 0.8);
  --frost-pop-glass: rgba(30, 32, 35, 0.9);
  --frost-shadow-menu: 0 24px 60px -12px rgba(0, 0, 0, 0.7);
  --frost-check-stroke: rgba(255, 255, 255, 0.3);
  --frost-primary-ink: oklch(0.88 0.2 128);
  --frost-tip-bg: #f1f2f3;
  --frost-tip-fg: #15171a;
  --frost-field-bg: #141415;
  --frost-money-mark: oklch(0.55 0.16 128);
  --frost-blue-bg: oklch(0.32 0.07 255);   --frost-blue-fg: oklch(0.85 0.08 250);
  --frost-lime-bg: oklch(0.34 0.08 128);   --frost-lime-fg: oklch(0.92 0.15 128);
  --frost-amber-bg: oklch(0.34 0.06 75);   --frost-amber-fg: oklch(0.86 0.12 80);
  --frost-red-bg: oklch(0.33 0.09 20);     --frost-red-fg: oklch(0.85 0.11 22);
  --frost-green-bg: oklch(0.33 0.07 160);  --frost-green-fg: oklch(0.86 0.1 160);

  --theme-primary-text: var(--primary);
  --theme-error-text: var(--destructive);
  --theme-muted-text: var(--muted-foreground);
  --theme-on-destructive: var(--background);
  --theme-success: oklch(0.792 0.209 151.711);
  --theme-warning: oklch(0.828 0.189 84.429);
  --theme-info: oklch(0.809 0.105 251.813);
  --theme-approved: oklch(0.855 0.138 181.071);
  --theme-converted: oklch(0.811 0.111 293.571);
  --theme-inverse-primary: var(--primary-foreground);
  --theme-field-bg: var(--frost-field-bg);
  --shadow-popover: var(--frost-shadow-menu);

  --avatar-bg-l: 0.38;
  --avatar-chroma: 0.07;
  --avatar-fg-l: 0.92;
  --avatar-chroma-fg: 0.07;

  /* Control borders: hairline as in the reference. Fields stand out by their darker fill. */
  --color-outline: rgba(255, 255, 255, 0.1);
  --field-border-color-hover: rgba(255, 255, 255, 0.22);
  --field-border-color-focus: var(--color-primary-text);
  /* Selected segment sits lighter than its track */
  --segmented-selected-bg: rgba(255, 255, 255, 0.1);
  --tabs-active-bg: rgba(255, 255, 255, 0.1);
  --tabs-active-shadow: none;
  --segmented-selected-shadow: none;

  /* Editor on the sheet (templates/edit.css): the light paper tokens are replaced by theme-aware ones */
  --edit-slot-hover-bg: oklch(1 0 0 / 8%);
  --edit-toolbar-bg: var(--popover);
  --edit-toolbar-border: oklch(1 0 0 / 20%);
  --edit-placeholder: oklch(0.67 0.01 56);
  --edit-brand-text: oklch(0.72 0.15 131);
  --edit-slot-rest-shadow: inset 0 -1px 0 var(--color-outline);
}

/* Phones: the header is brand row + search row (no tabs; they sit in the bottom bar) */
@media (max-width: 759.98px) {
  :root { --top-bar-height: var(--size-116); }
}

/* Avatar tint: the one rule that lives here, because it builds a colour from the hue (--avatar-hue, set per
   person by lib/clients.js avatarHtml) and the lightness/chroma tokens above. Layout is in styles/base.css. */
.avatar, .nav__avatar, .list-item__avatar {
  --avatar-hue: var(--avatar-hue-default);
  background: oklch(var(--avatar-bg-l) var(--avatar-chroma) var(--avatar-hue));
  color: oklch(var(--avatar-fg-l) var(--avatar-chroma-fg) var(--avatar-hue));
}
