/* Self-hosted Roboto (SIL Open Font License 1.1; see static/fonts/OFL-Roboto.txt).
 * One family for everything: a variable upright file (wght 100–900, used at 400 / 500 / 600) and a
 * static italic, each split into a Latin and a Latin-Extended subset so a page only downloads the
 * glyph ranges it uses. Files come from Google Fonts' CSS2 endpoint (Roboto v51); scripts/build_fonts.py
 * rebuilds the same subsets from the upstream TTFs. */
@font-face {
  font-family: "Roboto";
  src: url("../fonts/Roboto.var.b7627e3c9663.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  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: "Roboto";
  src: url("../fonts/Roboto-ext.var.536359ff0fc9.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  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-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Roboto";
  src: url("../fonts/Roboto-Italic.var.4afb1f656ffe.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
  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: "Roboto";
  src: url("../fonts/Roboto-Italic-ext.var.6eb65794f2ac.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
  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-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* Design tokens (docs/DESIGN-DIRECTION.md §2, documented in docs/DESIGN_SYSTEM.md)
 * ------------------------------------------------------------------
 * Every colour, size and motion value used by the product lives here.
 * Light theme is on :root; dark theme overrides under
 * html[data-resolved-theme="dark"] (set by the inline script in base.html
 * from data-theme=system|light|dark + prefers-color-scheme).
 *
 * Bold, friendly fintech: one saturated brand blue carries the identity (hero cards, active
 * tabs, primary buttons, the "+"); everything else is white cards on a light blue-grey ground.
 * Income is green, spending is red, totals are ink-dark; pastel tiles carry category icons.
 *
 * Breakpoints (min-width, mobile first — CSS cannot read these as vars):
 *   sm  640px   two-column grids, inline form rows
 *   md  900px   desktop sidebar replaces the bottom nav, sheets become dialogs
 *   lg  1200px  three-column grids, wider content
 */

:root {
  color-scheme: light;

  /* Brand palette. --brand-blue mirrors config/brand.py BRAND_COLORS (the mark); the UI's
   * identity blue (docs/DESIGN-DIRECTION.md §2) is --color-primary below. */
  --brand-navy: #0f1f3d;
  --brand-blue: #1e40af;
  --brand-teal: #0f766e;
  --brand-green: #22a35f;
  --brand-amber: #f59e0b;
  --brand-red: #dc2626;
  --brand-cream: #f6f5f1;
  --brand-sky: #3b6bf0;
  --brand-leaf: #4ade80;
  --brand-purple: var(--brand-teal); /* legacy name: the accent is teal now */
  --brand-gradient: linear-gradient(135deg, var(--brand-blue) 0%, var(--brand-green) 100%); /* the mark only, never UI */

  /* Surfaces: white cards on a very light blue-grey ground. */
  --color-bg: #f3f6fb;
  --color-surface: #ffffff;
  --color-surface-raised: #ffffff;
  --color-surface-sunken: #eef2f8;
  --color-surface-overlay: rgba(15, 23, 42, 0.5);
  --color-surface-inverse: #0f172a;

  /* Text (AA on --color-bg, --color-surface and --color-surface-sunken; verified by
   * apps/core/tests/test_design_system.py::TestContrast) */
  --color-text: #0f172a;
  --color-text-muted: #58687f; /* 5.7:1 white · 5.2:1 ground · 5.0:1 sunken */
  --color-text-subtle: #5f6f86; /* 5.1:1 white · 4.7:1 ground · 4.6:1 sunken */
  --color-text-inverse: #ffffff;
  --color-text-on-primary: #ffffff;
  --color-on-primary: #ffffff;
  --color-text-on-danger: #ffffff;
  --color-text-on-success: #ffffff;
  --color-text-on-teal: #ffffff;

  /* The hero card (.hero-card / .summary-card / .card--hero) is a deep teal (not the identity
   * blue, which stays on buttons, tabs and links) with white text in BOTH themes, so its tokens
   * are fixed here and never redefined by the dark block. Status figures on it are light tints
   * (AA on the teal). */
  --color-hero-bg: #0f766e;
  --color-hero-bg-end: #134e4a;
  --color-hero-text: #ffffff;
  --color-hero-text-muted: rgba(255, 255, 255, 0.94);
  --color-hero-text-subtle: rgba(255, 255, 255, 0.92);
  --color-hero-border: rgba(255, 255, 255, 0.24);
  --color-hero-surface: rgba(255, 255, 255, 0.14);
  --color-hero-primary: #ffffff;
  --color-hero-success: #dcfce7;
  --color-hero-warning: #fef3c7;
  --color-hero-danger: #fef2f2;
  --color-hero-teal: #ccfbf1;

  /* Borders: very light hairlines; inputs use the stronger one. */
  --color-border: #e6ebf3;
  --color-border-strong: #cbd5e1;
  --color-border-focus: var(--color-primary);
  --color-field-bg: #ffffff;
  --color-field-border: #cbd5e1;

  /* Primary: the identity blue, a deep royal blue (hero cards, active tabs, primary buttons,
   * the "+"): white labels 8.7:1. --color-primary-bright is the lighter tint for icons and
   * bars where the fill would be too heavy; --color-primary-text is the blue used AS TEXT
   * (links, active labels): 8.7:1 on white, 7.6:1 on the sunken surface. */
  --color-primary: #1e40af;
  --color-primary-hover: #1e3a8a;
  --color-primary-active: #172554;
  --color-primary-bright: #2563eb;
  --color-primary-text: #1e40af;
  --color-primary-soft: #e8edff;
  --color-primary-soft-text: #1e40af;

  /* Teal: people, sharing, contributors (also the legacy "accent") */
  --color-teal: #0f766e;
  --color-teal-bright: #14b8a6;
  --color-teal-soft: #d8f3f0;
  --color-teal-soft-text: #0f766e;
  --color-accent: var(--color-teal);
  --color-accent-soft: var(--color-teal-soft);
  --color-accent-soft-text: var(--color-teal-soft-text);

  /* States. "text" variants pass AA on white, ground and sunken; "bright" variants are fills
   * (bars, badges, button backgrounds); "soft" pairs are chips, notes and tinted cards.
   * Income is green, spending is red: --color-income / --color-expense are the amount colours
   * (text); --color-income-bright / --color-expense-bright the fills (#16a34a / #dc2626). */
  --color-success: #14783a;
  --color-success-bright: #16a34a;
  --color-success-soft: #e7f7ec;
  --color-success-soft-text: #14783a;
  --color-income: #14783a;
  --color-income-bright: #16a34a;
  --color-warning: #a34a07;
  --color-warning-bright: #f59e0b;
  --color-warning-soft: #fff4d6;
  --color-warning-soft-text: #a34a07;
  --color-danger: #b91c1c;
  --color-danger-bright: #dc2626;
  --color-danger-soft: #fdecec;
  --color-danger-soft-text: #b91c1c;
  --color-expense: #b91c1c;
  --color-expense-bright: #dc2626;
  --color-danger-border: rgba(220, 38, 38, 0.35);
  --color-info: #1e40af;
  --color-info-bright: #2563eb;
  --color-info-soft: #e8edff;
  --color-info-soft-text: #1e40af;
  --color-neutral-soft: #eef2f8;
  --color-neutral-soft-text: #58687f;

  /* Pastel icon tiles (category / transaction rows): background / ink (AA for the ink). */
  --tile-yellow: #fff3c4;
  --tile-yellow-ink: #a34a07;
  --tile-pink: #ffe4ec;
  --tile-pink-ink: #be185d;
  --tile-sky: #e0f0ff;
  --tile-sky-ink: #1d4ed8;
  --tile-mint: #dcf7e8;
  --tile-mint-ink: #14783a;
  --tile-lilac: #ece6ff;
  --tile-lilac-ink: #6d28d9;
  --tile-peach: #ffe8d6;
  --tile-peach-ink: #b63d0b;

  /* Tinted insight cards. */
  --tint-amber: #fff4d6;
  --tint-lilac: #ece6ff;
  --tint-rose: #ffe4ec;
  --tint-sky: #e0f0ff;

  /* Money tones */
  --color-money-positive: var(--color-income);
  --color-money-negative: var(--color-text);
  --color-money-pending: var(--color-warning);

  /* Resolved copies of the page text tokens. A surface nested inside the hero card (a stat,
   * a banner, a list) restores these, because --color-text is re-scoped to white there. */
  --color-on-surface: var(--color-text);
  --color-on-surface-muted: var(--color-text-muted);
  --color-on-surface-subtle: var(--color-text-subtle);
  --color-on-surface-border: var(--color-border);
  --color-on-surface-success: var(--color-success);
  --color-on-surface-warning: var(--color-warning);
  --color-on-surface-danger: var(--color-danger);
  --color-on-surface-primary: var(--color-primary-text);

  /* Legacy token names kept as aliases so older page CSS keeps resolving. */
  --color-surface-muted: var(--color-surface-sunken);
  --color-surface-alt: var(--color-surface-sunken);
  --color-focus: var(--color-border-focus);
  --color-navy: var(--brand-navy);

  /* Charts: 8 categorical (blue, green, amber, violet, pink, sky, slate, brown), sequential blues */
  --chart-1: #1e40af;
  --chart-2: #16a34a;
  --chart-3: #f59e0b;
  --chart-4: #8b5cf6;
  --chart-5: #ec4899;
  --chart-6: #0ea5e9;
  --chart-7: #64748b;
  --chart-8: #92400e;
  --chart-seq-1: #e8edff;
  --chart-seq-2: #bfd3ff;
  --chart-seq-3: #7ea4ff;
  --chart-seq-4: #2563eb;
  --chart-seq-5: #172554;
  --chart-grid: #e6ebf3;
  --chart-axis: #58687f;
  --chart-baseline: #cbd5e1;
  --chart-tooltip-bg: #0f172a;
  --chart-tooltip-text: #ffffff;
  /* Semantic series: income green, spending red, savings teal, plan blue. */
  --chart-income: var(--color-income-bright);
  --chart-spent: var(--color-expense-bright);
  --chart-savings: var(--color-teal-bright);
  --chart-plan: var(--color-primary);

  /* Typography: Roboto everywhere. 400 for reading, 500 for labels and buttons, 700 for
   * headlines and money (tabular numerals via "tnum"). --font-display / --font-numeric stay
   * as names so page CSS keeps resolving; they are the same family now. */
  --font-sans: "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-display: "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-numeric: var(--font-display);
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --font-features-body: "liga" 1, "kern" 1;
  --font-features-numeric: "tnum" 1;
  /* Type scale (size / line): display 32/40, title 22/28, heading 17/24, body 16/24,
   * label 14/20, caption 12/16, eyebrow 11/16 uppercase. Nothing below 11px. */
  --text-display: 2rem;
  --text-title: 1.375rem;
  --text-heading: 1.0625rem;
  --text-body: 1rem;
  --text-label: 0.875rem;
  --text-caption: 0.75rem;
  --text-eyebrow: 0.6875rem;
  --text-min: 11px;
  --leading-display: 1.25;
  --leading-title: 1.275;
  --leading-heading: 1.42;
  --leading-body: 1.5;
  --leading-label: 1.43;
  --leading-caption: 1.34;
  /* Legacy size steps mapped onto the scale. */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.0625rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.375rem;
  --text-3xl: 2rem;
  --text-4xl: 2.25rem;
  --text-hero: var(--text-display); /* 1.75rem below 360px: see the end of this file */
  --text-md: var(--text-base);
  --font-size-xs: var(--text-xs);
  --font-size-sm: var(--text-sm);
  --font-size-md: var(--text-base);
  --font-size-xl: var(--text-xl);
  --leading-tight: 1.25;
  --leading-snug: 1.35;
  --leading-normal: 1.5;
  --leading-relaxed: 1.65;
  --weight-regular: 400;
  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-display: 700;
  /* One headline/money weight (Roboto 700); bold/extrabold resolve to it so no rule ever asks
   * for a weight the fonts do not ship. */
  --weight-bold: 700;
  --weight-extrabold: 700;
  --tracking-tight: -0.01em;
  --tracking-tighter: -0.015em;
  --tracking-wide: 0.04em;
  --tracking-eyebrow: 0.06em;

  /* Spacing (4px base): the design scale is 4 · 8 · 12 · 16 · 24 · 32 (space-1/2/3/4/6/8);
   * the larger steps are for page layout only. Cards are 12px inside on phones, 16px from
   * 640px (--card-padding); stacks of cards sit 8–12px apart. */
  --space-0: 0;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --card-padding: var(--space-3);
  --card-gap: var(--space-3);
  --stack-gap-default: var(--space-3);

  /* Radii: 12 controls, 16 cards, 20 hero cards and sheets, 999 chips and pills */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-2xl: 24px;
  --radius-full: 999px;
  --radius-pill: 999px;
  --radius-control: var(--radius-md);
  --radius-card: var(--radius-lg);

  /* Shadows: cards carry one soft shadow (--shadow-card); sheets, popovers and the "+" more. */
  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px -16px rgba(15, 23, 42, 0.18);
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 1px rgba(15, 23, 42, 0.03);
  --shadow-md: 0 8px 24px -12px rgba(15, 23, 42, 0.18), 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 16px 40px -16px rgba(15, 23, 42, 0.28), 0 2px 6px rgba(15, 23, 42, 0.06);
  --shadow-popover: var(--shadow-lg);
  --shadow-sheet: 0 -8px 40px rgba(15, 23, 42, 0.18);
  --shadow-fab: 0 8px 20px rgba(30, 64, 175, 0.35);
  --shadow-nav: 0 -4px 20px rgba(15, 23, 42, 0.05);
  --shadow-focus: 0 0 0 3px rgba(30, 64, 175, 0.28);
  --overlay-light: rgba(255, 255, 255, 0.16);
  --overlay-stripe: rgba(255, 255, 255, 0.45);
  --overlay-dark: rgba(15, 23, 42, 0.08);
  --shadow-drop: 0 1px 1px rgba(0, 0, 0, 0.15);

  /* Z-index scale */
  --z-dropdown: 20;
  --z-sticky: 30;
  --z-fab: 40;
  --z-sheet: 50;
  --z-dialog: 55;
  --z-toast: 60;

  /* Motion */
  --duration-fast: 120ms;
  --duration: 200ms;
  --duration-slow: 320ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.3, 0.64, 1);

  /* Layout */
  --sidebar-width: 256px;
  --topbar-height: 56px;
  --bottom-nav-height: 64px;
  --content-max: 1280px;
  --content-narrow: 680px;
  --gutter: var(--space-4);
  --touch-target: 44px;
  --control-sm: 36px; /* chips, segmented items, small buttons; the touch target on coarse pointers */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

html[data-resolved-theme="dark"] {
  color-scheme: dark;

  --color-bg: #0b1220;
  --color-surface: #111a2e;
  --color-surface-raised: #16213a;
  --color-surface-sunken: #0f172a;
  --color-surface-overlay: rgba(2, 6, 23, 0.7);
  --color-surface-inverse: #e8eefc;

  --color-text: #e8eefc;
  --color-text-muted: #94a3b8;
  --color-text-subtle: #8794ab;
  --color-text-inverse: #0f172a;
  --color-text-on-primary: #ffffff; /* 5.2:1 on #2563eb */
  --color-on-primary: #ffffff;
  --color-text-on-danger: #2a0f13; /* the dark fills are light: dark text keeps ≥ 5.6:1 */
  --color-text-on-success: #06260f;
  --color-text-on-teal: #042f2b;

  --color-border: #22304a;
  --color-border-strong: #334766;
  --color-border-focus: #60a5fa;
  --color-field-bg: #0f172a;
  --color-field-border: #334766;

  /* Filled primary lifts to #2563eb in the dark theme (white labels 5.2:1; the deep #1e40af
   * would sink into the ground), and #3b82f6 is the bright accent for icons, bars and active
   * states (3.7:1 with white, so never a button fill). */
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-active: #1e40af;
  --color-primary-bright: #3b82f6;
  --color-primary-text: #8ab4ff;
  --color-primary-soft: #1b2e5e;
  --color-primary-soft-text: #a9c4ff;

  --color-teal: #2dd4bf;
  --color-teal-bright: #14b8a6;
  --color-teal-soft: #0f2e2b;
  --color-teal-soft-text: #2dd4bf;

  --color-success: #4ade80;
  --color-success-bright: #22c55e;
  --color-success-soft: #14301f;
  --color-success-soft-text: #4ade80;
  --color-income: #4ade80;
  --color-income-bright: #22c55e;
  --color-warning: #fbbf24;
  --color-warning-bright: #fbbf24;
  --color-warning-soft: #3a2a0c;
  --color-warning-soft-text: #fbbf24;
  --color-danger: #f87171;
  --color-danger-bright: #ef4444;
  --color-danger-soft: #3b1a1a;
  --color-danger-soft-text: #f87171;
  --color-expense: #f87171;
  --color-expense-bright: #ef4444;
  --color-danger-border: rgba(248, 113, 113, 0.4);
  --color-info: #8ab4ff;
  --color-info-bright: #3b82f6;
  --color-info-soft: #1b2e5e;
  --color-info-soft-text: #a9c4ff;
  --color-neutral-soft: #1c2740;
  --color-neutral-soft-text: #c5cddb;

  --tile-yellow: #3a2d0c;
  --tile-yellow-ink: #fcd34d;
  --tile-pink: #3b1526;
  --tile-pink-ink: #f9a8d4;
  --tile-sky: #0f2447;
  --tile-sky-ink: #93c5fd;
  --tile-mint: #0f2e1c;
  --tile-mint-ink: #86efac;
  --tile-lilac: #231a45;
  --tile-lilac-ink: #c4b5fd;
  --tile-peach: #3a1f0f;
  --tile-peach-ink: #fdba74;

  --tint-amber: #2f250c;
  --tint-lilac: #231a45;
  --tint-rose: #3b1526;
  --tint-sky: #0f2447;

  --color-money-positive: var(--color-income);
  --color-money-negative: var(--color-text);
  --color-money-pending: var(--color-warning);

  --chart-1: #60a5fa;
  --chart-2: #4ade80;
  --chart-3: #fbbf24;
  --chart-4: #a78bfa;
  --chart-5: #f472b6;
  --chart-6: #38bdf8;
  --chart-7: #94a3b8;
  --chart-8: #d6a26a;
  --chart-seq-1: #1b2e5e;
  --chart-seq-2: #27448f;
  --chart-seq-3: #3b82f6;
  --chart-seq-4: #8ab4ff;
  --chart-seq-5: #bfd3ff;
  --chart-grid: #22304a;
  --chart-axis: #94a3b8;
  --chart-baseline: #334766;
  --chart-tooltip-bg: #e8eefc;
  --chart-tooltip-text: #0f172a;
  --chart-income: #4ade80;
  --chart-spent: #f87171;
  --chart-savings: #2dd4bf;
  --chart-plan: #8ab4ff;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px -16px rgba(0, 0, 0, 0.6);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px -12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 16px 40px -16px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.3);
  --shadow-sheet: 0 -8px 40px rgba(0, 0, 0, 0.5);
  --shadow-fab: 0 8px 20px rgba(37, 99, 235, 0.45);
  --shadow-nav: 0 -4px 20px rgba(0, 0, 0, 0.35);
  --shadow-focus: 0 0 0 3px rgba(96, 165, 250, 0.4);
  --overlay-dark: rgba(255, 255, 255, 0.06);
}

/* Cards get their 16px inside padding from 640px up (12px on phones). */
@media (min-width: 640px) {
  :root { --card-padding: var(--space-4); }
}

/* Narrow phones (320–359px): display money steps down one size so eight-digit amounts fit. */
@media (max-width: 359.98px) {
  :root { --text-hero: 1.75rem; }
}

/* Coarse pointers (touch): chips, segmented items and small buttons grow to the 44px touch
 * target; desktop keeps the 36px rhythm. */
@media (pointer: coarse) {
  :root { --control-sm: var(--touch-target); }
}
