/* Daybook design tokens — light (default) + tuned dark theme.
 *
 * Dark is not an inversion: surfaces step up in lightness as they get closer to the viewer
 * (bg < surface < surface-2 < raised), shadows are mostly replaced by hairlines, and accents are a
 * touch brighter and less saturated so they glow without vibrating on dark backgrounds.
 * Text colours meet WCAG AA (4.5:1) on --bg, --surface and --surface-2 in both themes.
 *
 * Extra tokens beyond SPEC §6 (safe to use anywhere): --surface-raised, --input-bg, --hover, --press,
 * --ease*, --dur*, --z-*, --fs-4xl, --toast-*, --select-chevron, --*-soft tints.
 */

:root {
  color-scheme: light;

  /* ── Surfaces & text ─────────────────────────────────────────────────────────────── */
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f1f3f6;           /* subtle fill: segmented track, hover, chips */
  --surface-3: #e7eaf0;           /* stronger fill: progress tracks, skeleton */
  --surface-raised: #ffffff;      /* sheets, menus, popovers */
  --input-bg: #ffffff;
  --border: #e5e7ed;              /* hairlines */
  --border-strong: #d2d6df;       /* input borders, dividers that must read */
  --text: #101828;
  --text-2: #475069;              /* secondary  (8.0:1 on white) */
  --text-3: #5d6679;              /* muted      (5.1:1 on surface-2) */
  --overlay: rgba(15, 18, 30, 0.42);
  --hover: rgba(16, 24, 40, 0.045);
  --press: rgba(16, 24, 40, 0.085);

  /* ── Brand ───────────────────────────────────────────────────────────────────────── */
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-contrast: #ffffff;
  --primary-soft: color-mix(in srgb, var(--primary) 11%, transparent);
  --focus: #5b54f0;

  /* ── Status ──────────────────────────────────────────────────────────────────────── */
  --success: #15803d;
  --warning: #b45309;
  --danger: #cf2c2c;
  --profit: #067d4c;
  --loss: #d0291f;
  --neutral: #5d6679;
  --success-soft: color-mix(in srgb, var(--success) 12%, transparent);
  --warning-soft: color-mix(in srgb, var(--warning) 13%, transparent);
  --danger-soft: color-mix(in srgb, var(--danger) 11%, transparent);
  --profit-soft: color-mix(in srgb, var(--profit) 12%, transparent);
  --loss-soft: color-mix(in srgb, var(--loss) 11%, transparent);

  /* ── Module accents (icon chips, rings, chart series — never big fills) ─────────── */
  --food: #f2701d;
  --water: #0ea1e6;
  --learning: #8b5cf6;
  --training: #12a660;
  --expenses: #0d9e94;
  --trades: #4c6bf5;
  --mood: #e64595;
  --goals: #e9a10c;

  /* ── Charts (categorical order is validated for CVD separation — keep the order) ─── */
  --chart-grid: #eceef3;
  --chart-axis: #6b7385;
  --chart-1: #2a78d6;
  --chart-2: #eb6834;
  --chart-3: #1baf7a;
  --chart-4: #eda100;
  --chart-5: #e87ba4;
  --chart-6: #008300;
  --chart-7: #6250d6;
  --chart-8: #e34948;

  /* ── Radii ───────────────────────────────────────────────────────────────────────── */
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --r-xl: 24px;
  --r-full: 999px;

  /* ── Elevation: hairline + layered, very soft shadows ───────────────────────────── */
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.045), 0 1px 1px rgba(16, 24, 40, 0.02);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 14px -3px rgba(16, 24, 40, 0.09);
  --shadow-lg: 0 2px 6px rgba(16, 24, 40, 0.05), 0 14px 28px -8px rgba(16, 24, 40, 0.14),
    0 36px 72px -16px rgba(16, 24, 40, 0.2);

  /* ── Type ────────────────────────────────────────────────────────────────────────── */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 15px;
  --fs-lg: 17px;
  --fs-xl: 20px;
  --fs-2xl: 24px;
  --fs-3xl: 32px;
  --fs-4xl: 40px;
  --lh-tight: 1.2;
  --lh: 1.5;

  /* ── Spacing ─────────────────────────────────────────────────────────────────────── */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-7: 32px;
  --s-8: 48px;

  /* ── Layout ──────────────────────────────────────────────────────────────────────── */
  --sidebar-w: 248px;
  --topbar-h: 56px;
  --bottomnav-h: 64px;
  --content-max: 1120px;

  /* ── Motion ──────────────────────────────────────────────────────────────────────── */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);           /* standard ease-out */
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-sheet: cubic-bezier(0.32, 0.72, 0, 1);    /* iOS-like sheet curve */
  --ease-spring: cubic-bezier(0.34, 1.5, 0.64, 1); /* gentle overshoot for toggles/chips */
  --dur-fast: 150ms;
  --dur: 200ms;
  --dur-slow: 280ms;

  /* ── Layers ──────────────────────────────────────────────────────────────────────── */
  --z-sticky: 20;
  --z-nav: 100;
  --z-sheet: 1000;
  --z-menu: 2000;
  --z-lightbox: 2500;
  --z-toast: 3000;

  /* ── Component tokens ────────────────────────────────────────────────────────────── */
  --toast-bg: #1b1f2c;
  --toast-text: #f5f6fa;
  --toast-action: #a5b4fc;
  --select-chevron: 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='%235d6679' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

/* ── Dark theme ─────────────────────────────────────────────────────────────────────────
 * Declared twice: once for the OS preference (unless the user forced light), once for an
 * explicit data-theme="dark". Keep both blocks identical. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0d12;
    --surface: #13161d;
    --surface-2: #1a1d25;
    --surface-3: #252a35;
    --surface-raised: #1a1d26;
    --input-bg: #0f1218;
    --border: #232733;
    --border-strong: #343a48;
    --text: #eceef4;
    --text-2: #b6bccb;
    --text-3: #8f97a8;
    --overlay: rgba(2, 3, 6, 0.62);
    --hover: rgba(255, 255, 255, 0.05);
    --press: rgba(255, 255, 255, 0.09);

    --primary: #8b93ff;
    --primary-hover: #a2a8ff;
    --primary-contrast: #0d0f2a;
    --primary-soft: color-mix(in srgb, var(--primary) 16%, transparent);
    --focus: #a5acff;

    --success: #4ade80;
    --warning: #f5b84a;
    --danger: #f87171;
    --profit: #43d095;
    --loss: #ec5357;          /* deeper than #ff7b7b so it never collapses into --profit for deuteranopes (OKLab ΔE 11); ≥ 4.7:1 on every dark surface */
    --neutral: #8f97a8;
    --success-soft: color-mix(in srgb, var(--success) 15%, transparent);
    --warning-soft: color-mix(in srgb, var(--warning) 15%, transparent);
    --danger-soft: color-mix(in srgb, var(--danger) 15%, transparent);
    --profit-soft: color-mix(in srgb, var(--profit) 15%, transparent);
    --loss-soft: color-mix(in srgb, var(--loss) 15%, transparent);

    --food: #fb8c4e;
    --water: #46bdf4;
    --learning: #a78bfa;
    --training: #46cc85;
    --expenses: #35c2b5;
    --trades: #7d95ff;
    --mood: #f272b2;
    --goals: #f5bf47;

    --chart-grid: #222632;
    --chart-axis: #8f97a8;
    --chart-1: #3987e5;
    --chart-2: #d95926;
    --chart-3: #199e70;
    --chart-4: #c98500;
    --chart-5: #d55181;
    --chart-6: #0ca30c;
    --chart-7: #9085e9;
    --chart-8: #e66767;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.28);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.32), 0 6px 16px -6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 0 0 1px rgba(255, 255, 255, 0.04), 0 18px 48px -10px rgba(0, 0, 0, 0.7);

    --toast-bg: #2a2f3c;
    --toast-text: #f3f4f8;
    --toast-action: #b4bbff;
    --select-chevron: 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='%238f97a8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0d12;
  --surface: #13161d;
  --surface-2: #1a1d25;
  --surface-3: #252a35;
  --surface-raised: #1a1d26;
  --input-bg: #0f1218;
  --border: #232733;
  --border-strong: #343a48;
  --text: #eceef4;
  --text-2: #b6bccb;
  --text-3: #8f97a8;
  --overlay: rgba(2, 3, 6, 0.62);
  --hover: rgba(255, 255, 255, 0.05);
  --press: rgba(255, 255, 255, 0.09);

  --primary: #8b93ff;
  --primary-hover: #a2a8ff;
  --primary-contrast: #0d0f2a;
  --primary-soft: color-mix(in srgb, var(--primary) 16%, transparent);
  --focus: #a5acff;

  --success: #4ade80;
  --warning: #f5b84a;
  --danger: #f87171;
  --profit: #43d095;
  --loss: #ec5357;
  --neutral: #8f97a8;
  --success-soft: color-mix(in srgb, var(--success) 15%, transparent);
  --warning-soft: color-mix(in srgb, var(--warning) 15%, transparent);
  --danger-soft: color-mix(in srgb, var(--danger) 15%, transparent);
  --profit-soft: color-mix(in srgb, var(--profit) 15%, transparent);
  --loss-soft: color-mix(in srgb, var(--loss) 15%, transparent);

  --food: #fb8c4e;
  --water: #46bdf4;
  --learning: #a78bfa;
  --training: #46cc85;
  --expenses: #35c2b5;
  --trades: #7d95ff;
  --mood: #f272b2;
  --goals: #f5bf47;

  --chart-grid: #222632;
  --chart-axis: #8f97a8;
  --chart-1: #3987e5;
  --chart-2: #d95926;
  --chart-3: #199e70;
  --chart-4: #c98500;
  --chart-5: #d55181;
  --chart-6: #0ca30c;
  --chart-7: #9085e9;
  --chart-8: #e66767;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.28);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.32), 0 6px 16px -6px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 0 0 1px rgba(255, 255, 255, 0.04), 0 18px 48px -10px rgba(0, 0, 0, 0.7);

  --toast-bg: #2a2f3c;
  --toast-text: #f3f4f8;
  --toast-action: #b4bbff;
  --select-chevron: 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='%238f97a8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

:root[data-theme="light"] {
  color-scheme: light;
}
