/* ==========================================================================
   DESIGN TOKENS — the single source of every colour, space, type size, radius,
   shadow and motion value used in UI code. (docs/design-system.md)

   Rules
   - Components reference ONLY these custom properties. No hex, px or ms
     literals in component CSS. If a value is missing, add it HERE first.
   - Colours are named by ROLE, not appearance.
   - Dark mode is a token swap, declared twice below (OS preference block and
     the explicit [data-theme="dark"] block). The two dark blocks MUST stay
     identical — scripts/check_tokens.js fails the build if they drift.
   - Every chart/status colour here was validated with the dataviz
     validate_palette.js on 2026-10-28 (light on #ffffff, dark on #1a1a19).
   - Text colours (…-text, --color-text*, --color-muted) all clear WCAG 4.5:1
     on their surface; the plain status/chart colours are MARK colours
     (dots, bars, fills) and are never used for text.

   Served at /styles/tokens.css (server.js mounts src/styles statically).
   ========================================================================== */

:root {
  color-scheme: light;

  /* ---- Neutral scale (warm grey) -------------------------------------- */
  --gray-50:  #fcfcfb;
  --gray-100: #f0efec;
  --gray-200: #e1e0d9;
  --gray-300: #c3c2b7;
  --gray-400: #898781;
  --gray-500: #6f6d67;
  --gray-600: #52514e;
  --gray-700: #383835;
  --gray-800: #1a1a19;
  --gray-900: #0b0b0b;

  /* ---- Surfaces & chrome ---------------------------------------------- */
  --color-bg:            #f9f9f7;           /* page plane */
  --color-surface:       #ffffff;           /* cards, tables, inputs */
  --color-surface-2:     var(--gray-50);    /* chart surface, table header */
  --color-surface-hover: var(--gray-100);   /* row / option hover wash */
  --color-border:        var(--gray-200);   /* hairlines, gridlines */
  --color-border-strong: var(--gray-300);   /* axis baseline, input border */
  --color-ring:          rgba(11, 11, 11, 0.10);  /* 1px ring on overlapping marks */

  /* ---- Text (all ≥ 4.5:1 on --color-surface) --------------------------- */
  --color-text:    var(--gray-900);         /* primary ink */
  --color-text-2:  var(--gray-600);         /* secondary ink 7.9:1 */
  --color-muted:   var(--gray-500);         /* muted text 5.2:1 */
  --color-on-fill: #ffffff;                 /* text on a strong fill */
  --color-on-primary: #ffffff;              /* text on --color-primary-strong 4.6:1 */
  --color-on-fill-dark: var(--gray-900);    /* text on yellow / warning fills */

  /* ---- Brand & roles (MARK colour / TEXT colour pairs) ------------------ */
  --color-primary:        #ff6b35;          /* brand coral: accents, active pill */
  --color-primary-strong: #c84d1a;          /* filled buttons, links  4.6:1 */
  --color-primary-wash:   rgba(255, 107, 53, 0.10);
  --color-success:        #0ca30c;
  --color-success-text:   #007a00;          /* 5.6:1 */
  --color-warning:        #fab219;
  --color-warning-text:   #9a6400;          /* 5.0:1 */
  --color-serious:        #ec835a;
  --color-serious-text:   #b24a1f;          /* 5.4:1 */
  --color-danger:         #d03b3b;          /* 4.8:1 — usable as text too */
  --color-danger-text:    #b42626;          /* 6.5:1 */
  --color-info:           #2a78d6;
  --color-info-text:      #1c5cab;          /* 6.6:1 */

  /* ---- Chart series: 8 fixed slots, assigned by ENTITY, never cycled ---- */
  --chart-1: #2a78d6;   /* blue    — income & refunds      */
  --chart-2: #eb6834;   /* orange  — food & dining         */
  --chart-3: #1baf7a;   /* aqua    — travel & leisure      */
  --chart-4: #eda100;   /* yellow  — shopping & gadgets    */
  --chart-5: #e87ba4;   /* magenta — health & insurance    */
  --chart-6: #008300;   /* green   — savings & investments */
  --chart-7: #6250d6;   /* violet  — business (FnF)        */
  --chart-8: #e34948;   /* red     — bills, fuel, loans    */
  --chart-neutral: #898781;   /* transfers & other */
  --chart-grid:     var(--gray-200);
  --chart-axis:     var(--gray-300);
  --chart-surface:  var(--color-surface-2);
  /* Tinted washes of each slot for pills / row tints. Derived from the slot, so
     they follow dark mode automatically; text on a wash stays in ink tokens. */
  --chart-1-wash: color-mix(in srgb, var(--chart-1) 14%, transparent);
  --chart-2-wash: color-mix(in srgb, var(--chart-2) 14%, transparent);
  --chart-3-wash: color-mix(in srgb, var(--chart-3) 14%, transparent);
  --chart-4-wash: color-mix(in srgb, var(--chart-4) 16%, transparent);
  --chart-5-wash: color-mix(in srgb, var(--chart-5) 14%, transparent);
  --chart-6-wash: color-mix(in srgb, var(--chart-6) 12%, transparent);
  --chart-7-wash: color-mix(in srgb, var(--chart-7) 14%, transparent);
  --chart-8-wash: color-mix(in srgb, var(--chart-8) 14%, transparent);
  --chart-neutral-wash: color-mix(in srgb, var(--chart-neutral) 14%, transparent);

  /* ---- Diverging amount scale: money IN (blue arm) / OUT (red arm) ------ */
  /* 4 ordinal steps, fixed ₹ bands: <500 | 500–5k | 5k–25k | ≥25k           */
  --amount-in-1:  #86b6ef;  --amount-in-2:  #3987e5;  --amount-in-3:  #1c5cab;  --amount-in-4:  #104281;
  --amount-out-1: #ea9a93;  --amount-out-2: #d75853;  --amount-out-3: #9e3432;  --amount-out-4: #762221;
  --amount-mid:   var(--gray-100);          /* neutral midpoint */
  --amount-in-wash:  color-mix(in srgb, var(--amount-in-2) 12%, transparent);
  --amount-out-wash: color-mix(in srgb, var(--amount-out-2) 12%, transparent);

  /* ---- Rows & tables (admin-style contrast) ---------------------------- */
  --color-row-hover:    var(--color-primary-wash);     /* obvious brand-tinted hover */
  --color-row-stripe:   var(--gray-50);                /* zebra */
  --color-row-selected: color-mix(in srgb, var(--color-info) 14%, transparent);
  --color-table-head:   var(--gray-100);               /* header band */

  /* ---- Spacing (8px base) --------------------------------------------- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
  --space-6: 48px;

  /* ---- Typography (one family) ---------------------------------------- */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --text-xs:  12px;
  --text-sm:  14px;
  --text-md:  16px;
  --text-lg:  18px;
  --text-xl:  24px;
  --text-2xl: 32px;
  --leading-tight:  1.2;
  --leading-normal: 1.5;
  --weight-regular:  400;
  --weight-medium:   500;
  --weight-semibold: 600;
  --weight-bold:     700;
  --weight-black:    800;
  --tracking-caps: 0.04em;                  /* uppercase labels */

  /* ---- Shape & elevation ---------------------------------------------- */
  --radius-sm: 4px;                         /* pills, inputs, bar ends */
  --radius-md: 8px;                         /* cards */
  --shadow-card: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 12px rgba(11, 11, 11, 0.06);

  /* ---- Controls & focus ----------------------------------------------- */
  --control-h:     40px;                    /* min click target height */
  --control-h-sm:  32px;                    /* dense tables only, never primary actions */
  --focus-ring:    0 0 0 3px rgba(42, 120, 214, 0.45);

  /* ---- Layout --------------------------------------------------------- */
  --grid-gutter:   var(--space-4);          /* 12-col grid, 24px gutter */
  --content-max:   1400px;
  --z-sticky: 10;
  --z-dropdown: 50;
  --z-modal: 100;

  /* ---- Motion --------------------------------------------------------- */
  --motion-fast: 120ms;
  --motion-base: 200ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);
}

@media (prefers-reduced-motion: reduce) {
  :root { --motion-fast: 0ms; --motion-base: 0ms; }
}

/* ==========================================================================
   DARK — same tokens, different values. Block A (OS preference) and Block B
   (explicit toggle) are IDENTICAL; edit both. scripts/check_tokens.js enforces.
   ========================================================================== */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --color-bg:            #0d0d0d;
    --color-surface:       #1a1a19;
    --color-surface-2:     #202020;
    --color-surface-hover: #2c2c2a;
    --color-border:        #2c2c2a;
    --color-border-strong: #383835;
    --color-ring:          rgba(255, 255, 255, 0.10);
    --color-text:    #f0efec;
    --color-text-2:  #c3c2b7;
    --color-muted:   #898781;
    --color-on-fill: #ffffff;
    --color-on-primary: #0b0b0b;            /* coral is bright in dark: dark text 6.7:1 */
    --color-on-fill-dark: #0b0b0b;
    --color-primary:        #ff6b35;
    --color-primary-strong: #ff6b35;
    --color-primary-wash:   rgba(255, 107, 53, 0.16);
    --color-success:        #0ca30c;
    --color-success-text:   #0ca30c;
    --color-warning:        #fab219;
    --color-warning-text:   #fab219;
    --color-serious:        #ec835a;
    --color-serious-text:   #f09a78;
    --color-danger:         #d03b3b;
    --color-danger-text:    #ee7c7c;
    --color-info:           #3987e5;
    --color-info-text:      #6da7ec;
    --chart-1: #3987e5;
    --chart-2: #d95926;
    --chart-3: #199e70;
    --chart-4: #c98500;
    --chart-5: #d55181;
    --chart-6: #008300;
    --chart-7: #9085e9;
    --chart-8: #e66767;
    --chart-neutral: #898781;
    --chart-grid:    #2c2c2a;
    --chart-axis:    #383835;
    --amount-in-1:  #184f95;  --amount-in-2:  #2a78d6;  --amount-in-3:  #5598e7;  --amount-in-4:  #9ec5f4;
    --amount-out-1: #892b2a;  --amount-out-2: #c74845;  --amount-out-3: #dd716a;  --amount-out-4: #f1aea8;
    --amount-mid:   #383835;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.40), 0 4px 12px rgba(0, 0, 0, 0.50);
    --focus-ring:  0 0 0 3px rgba(109, 167, 236, 0.55);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --color-bg:            #0d0d0d;
  --color-surface:       #1a1a19;
  --color-surface-2:     #202020;
  --color-surface-hover: #2c2c2a;
  --color-border:        #2c2c2a;
  --color-border-strong: #383835;
  --color-ring:          rgba(255, 255, 255, 0.10);
  --color-text:    #f0efec;
  --color-text-2:  #c3c2b7;
  --color-muted:   #898781;
  --color-on-fill: #ffffff;
  --color-on-primary: #0b0b0b;            /* coral is bright in dark: dark text 6.7:1 */
  --color-on-fill-dark: #0b0b0b;
  --color-primary:        #ff6b35;
  --color-primary-strong: #ff6b35;
  --color-primary-wash:   rgba(255, 107, 53, 0.16);
  --color-success:        #0ca30c;
  --color-success-text:   #0ca30c;
  --color-warning:        #fab219;
  --color-warning-text:   #fab219;
  --color-serious:        #ec835a;
  --color-serious-text:   #f09a78;
  --color-danger:         #d03b3b;
  --color-danger-text:    #ee7c7c;
  --color-info:           #3987e5;
  --color-info-text:      #6da7ec;
  --chart-1: #3987e5;
  --chart-2: #d95926;
  --chart-3: #199e70;
  --chart-4: #c98500;
  --chart-5: #d55181;
  --chart-6: #008300;
  --chart-7: #9085e9;
  --chart-8: #e66767;
  --chart-neutral: #898781;
  --chart-grid:    #2c2c2a;
  --chart-axis:    #383835;
  --amount-in-1:  #184f95;  --amount-in-2:  #2a78d6;  --amount-in-3:  #5598e7;  --amount-in-4:  #9ec5f4;
  --amount-out-1: #892b2a;  --amount-out-2: #c74845;  --amount-out-3: #dd716a;  --amount-out-4: #f1aea8;
  --amount-mid:   #383835;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.40), 0 4px 12px rgba(0, 0, 0, 0.50);
  --focus-ring:  0 0 0 3px rgba(109, 167, 236, 0.55);
}

/* Base: the page wears the tokens. Components build on top. */
html { background: var(--color-bg); color: var(--color-text); }
body { font-family: var(--font-sans); font-size: var(--text-sm); line-height: var(--leading-normal); }
:focus-visible { outline: none; box-shadow: var(--focus-ring); }
