/* =============================================================================
   Theme — Songon Manage (2026 bento look), light + dark.

   Loaded right after variables.css (which is byte-locked to portal by
   tools/drift, so it is never edited for manage's look). This file overrides its
   semantic tokens and adds the few new ones the components need. The shell's
   theme-boot.js sets <html data-theme="light|dark"> and
   <html data-density="comfortable|compact"> before paint, so there is no media
   query here: light is the default and :root[data-theme="dark"] redefines.

   RULES
   1. Pages are flat. Tiles are white (light) or a step lighter than the canvas
      (dark), separated by 1px borders, not shadows. Only menus, popovers,
      drawers, modals and toasts are raised (--elev-3/--elev-4).
   2. The navy accent is reserved for primary actions, selection and focus.
      Headings and values are neutral text (--text-brand = --text-primary).
   3. Status colours (success/danger/warning/info) are separate from the accent
      and NEVER carry meaning alone: every status colour ships with an icon or a
      text label (▲/▼, "Error", a lucide icon...).
   4. Type: six sizes only — 12 / 14 / 16 / 20 / 24 / 32 px
      (--text-xs / -sm / -base=-lg / -xl / -2xl / -3xl=-4xl). Body and table
      text 14px or more; nothing under 12px.
   5. Spacing is the 4px grid (--space-*). Tile radius 16px, controls 8px.
   6. Motion: 150–250ms, state changes only (reset.css cancels it under
      prefers-reduced-motion).

   MEASURED CONTRAST (WCAG 2.x, OKLCH→sRGB, scratchpad ui/contrast.ts)
   Light                                   Dark
   text-primary / canvas       16.84       text-primary / canvas       16.89
   text-secondary / tile       10.87       text-primary / tile         15.48
   text-muted / canvas          5.38       text-secondary / tile       10.26
   text-muted / sunken          5.27       text-muted / tile            6.96
   text-subtle / tile           5.07       text-muted / popover         6.30
   border-control / tile        3.11       text-subtle / tile           5.76
   white on accent (button)     9.32       border-control / tile        3.25
   accent-text / tile           8.56       border-control / sunken      3.41
   accent-text / accent-wash    7.51       on-accent on accent          9.55
   focus / canvas               5.46       accent-text / tile           8.93
   focus / tile                 6.10       accent-text / accent-wash    7.81
   success-fg / success-bg      7.07       focus / tile                 7.73
   danger-fg / danger-bg        7.01       focus / canvas               8.43
   warning-fg / warning-bg      6.20       white on --brand-700         5.58
   info-fg / info-bg            8.16       success-fg / success-bg      8.53
   white on danger solid        6.55       danger-fg / danger-bg        7.91
   white on success solid       6.16       warning-fg / warning-bg      8.88
   warning icon / tile          3.77       info-fg / info-bg            8.64
                                           white on danger solid        5.23
                                           white on success solid       5.24
                                           warning icon / tile          9.45
   ============================================================================= */

:root {
  color-scheme: light;

  /* ---- Type: six fixed sizes (12/14/16/20/24/32) ------------------------- */
  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;
  --text-3xl:  2rem;
  --text-4xl:  2rem;

  /* ---- Geometry ---------------------------------------------------------- */
  --radius-md:   8px;
  --radius:      8px;
  --radius-lg:   12px;
  --radius-xl:   16px;
  --tile-radius: 16px;
  --tile-pad:    var(--space-5);   /* 20px; 24px from 1280px up (below) */
  --tile-gap:    var(--space-4);   /* 16px between bento tiles */
  --control-h:   40px;             /* buttons, inputs */
  --row-h:       48px;             /* comfortable table row */
  --cell-py:     var(--space-3);
  --form-max:    720px;

  /* ---- Motion: 150–250ms, state changes only ----------------------------- */
  --duration-fast: 150ms;
  --duration-base: 200ms;
  --duration-slow: 250ms;
  --transition:    150ms;

  /* ---- Surfaces ---------------------------------------------------------- */
  --surface-canvas:   oklch(0.962 0.004 75);  /* neutral canvas between tiles */
  --surface-raised:   #ffffff;                /* tiles, cards, inputs */
  --surface-sunken:   oklch(0.955 0.004 75);  /* table head, wells */
  --surface-popover:  #ffffff;                /* menus, drawers, modals (+elev) */
  --surface-hover:    oklch(0.972 0.004 75);  /* row / item hover */
  --surface-selected: var(--accent-wash);
  --surface-overlay:  oklch(0.18 0.02 260 / 0.45);
  --surface-inverse:  oklch(0.22 0.010 260);

  /* ---- Text -------------------------------------------------------------- */
  --text-primary:   oklch(0.18 0.007 75);
  --text-secondary: oklch(0.36 0.010 75);
  --text-muted:     oklch(0.50 0.011 75);
  --text-subtle:    oklch(0.54 0.011 75);   /* placeholders: still ≥ 4.5 */
  --text-inverse:   #ffffff;
  --text-brand:     var(--text-primary);    /* headings are neutral (rule 2) */
  --text-link:      var(--accent-text);

  /* ---- Borders ----------------------------------------------------------- */
  --border-subtle:  oklch(0.915 0.005 75);  /* tile edges, row rules */
  --border-default: oklch(0.875 0.007 75);  /* dividers, chips */
  --border-strong:  oklch(0.76 0.010 75);
  --border-control: oklch(0.66 0.010 75);   /* input/checkbox edge, ≥ 3:1 */
  --border-focus:   var(--focus);

  /* ---- Accent (actions, selection, focus only) --------------------------- */
  --accent:        oklch(0.40 0.110 260);
  --accent-hover:  oklch(0.34 0.100 260);
  --accent-active: oklch(0.30 0.090 260);
  --on-accent:     #ffffff;
  --accent-text:   oklch(0.42 0.110 260);
  --accent-wash:   oklch(0.955 0.018 260);  /* selected row, active item */
  --accent-border: oklch(0.62 0.090 260);
  --focus:         oklch(0.50 0.140 260);

  /* ---- Status (never colour alone — rule 3) ------------------------------ */
  --success-fg: oklch(0.42 0.110 155);
  --success-bg: oklch(0.955 0.035 155);
  --success-border: oklch(0.80 0.070 155);
  --success-default: oklch(0.48 0.120 155); /* solid fill, white text 6.16 */
  --danger-fg:  oklch(0.45 0.160 25);
  --danger-bg:  oklch(0.955 0.025 25);
  --danger-border: oklch(0.80 0.080 25);
  --danger-default: oklch(0.50 0.170 25);   /* solid fill, white text 6.55 */
  --warning-fg: oklch(0.47 0.110 60);
  --warning-bg: oklch(0.960 0.045 75);
  --warning-border: oklch(0.82 0.100 75);
  --warning-default: oklch(0.62 0.140 65);  /* icon / edge on tile 3.77 */
  --info-fg:    oklch(0.40 0.100 260);
  --info-bg:    oklch(0.955 0.020 260);
  --info-border: oklch(0.82 0.050 260);
  --on-solid:   #ffffff;

  /* ---- Skeleton ---------------------------------------------------------- */
  --skeleton-base:  oklch(0.925 0.005 75);
  --skeleton-shine: oklch(0.955 0.004 75);

  /* ---- Elevation: flat pages, raised overlays only ----------------------- */
  --elev-1: none;
  --elev-2: none;
  --elev-3: 0 2px 4px oklch(0.20 0.04 260 / 0.06),
            0 8px 24px oklch(0.20 0.04 260 / 0.12);
  --elev-4: 0 4px 8px oklch(0.20 0.04 260 / 0.08),
            0 24px 48px oklch(0.20 0.04 260 / 0.18);

  --focus-ring: 0 0 0 2px var(--surface-canvas), 0 0 0 4px var(--focus);

  /* ---- Legacy aliases the components and pages still use ----------------- */
  --color-primary:   var(--accent-text);
  --color-dark-blue: var(--accent-text);
  --color-blue:      var(--focus);
  --color-success:   var(--success-fg);
  --color-warning:   var(--warning-default);
  --color-danger:    var(--danger-default);
  --color-error:     var(--danger-default);
  --color-red:       var(--danger-default);
  --color-white:     var(--surface-raised);
}

@media (min-width: 1280px) {
  :root { --tile-pad: var(--space-6); }
}

:root[data-density="compact"] {
  --row-h:     38px;
  --cell-py:   var(--space-2);
  --control-h: 36px;
}

/* =============================================================================
   Dark — designed on its own terms: near-black neutral canvas, tiles one step
   lighter, borders that read, desaturated status, a light accent that passes
   on dark. The primitive ramps are remapped too, so page CSS that still names
   --gray-100 or --brand-50 for a surface lands on a dark value.
   ============================================================================= */
:root[data-theme="dark"] {
  color-scheme: dark;

  /* Primitive neutral ramp, dark (0 = canvas … 950 = brightest ink). */
  --gray-50:  oklch(0.155 0.004 260);
  --gray-100: oklch(0.190 0.005 260);
  --gray-200: oklch(0.245 0.006 260);
  --gray-300: oklch(0.300 0.006 260);
  --gray-400: oklch(0.420 0.007 260);
  --gray-500: oklch(0.580 0.007 260);
  --gray-600: oklch(0.680 0.006 260);
  --gray-700: oklch(0.780 0.005 260);
  --gray-800: oklch(0.860 0.004 260);
  --gray-900: oklch(0.940 0.003 260);
  --gray-950: oklch(0.970 0.002 260);

  /* Brand ramp, dark. 500 = focus/fill accent, 700 = solid fill under white. */
  --brand-50:  oklch(0.250 0.030 260);
  --brand-100: oklch(0.290 0.045 260);
  --brand-300: oklch(0.450 0.080 260);
  --brand-500: oklch(0.740 0.120 260);
  --brand-600: oklch(0.600 0.130 260);
  --brand-700: oklch(0.520 0.130 260);
  --brand-900: oklch(0.900 0.040 260);

  /* Status primitives, desaturated for dark. */
  --green-100: oklch(0.260 0.035 155);
  --green-500: oklch(0.680 0.110 155);
  --green-600: oklch(0.520 0.100 155);
  --green-700: oklch(0.460 0.090 155);
  --red-100:   oklch(0.270 0.045 25);
  --red-500:   oklch(0.680 0.130 25);
  --red-600:   oklch(0.550 0.150 25);
  --red-700:   oklch(0.490 0.140 25);
  --amber-100: oklch(0.270 0.040 70);
  --amber-500: oklch(0.760 0.120 75);
  --amber-700: oklch(0.830 0.100 75);
  --gold-100:  oklch(0.280 0.040 80);
  --gold-300:  oklch(0.600 0.090 80);
  --gold-500:  oklch(0.760 0.110 80);
  --gold-700:  oklch(0.830 0.090 80);

  --surface-canvas:   oklch(0.155 0.004 260);
  --surface-raised:   oklch(0.205 0.005 260);
  --surface-sunken:   oklch(0.180 0.005 260);
  --surface-popover:  oklch(0.245 0.006 260);
  --surface-hover:    oklch(0.235 0.006 260);
  --surface-overlay:  oklch(0.05 0.01 260 / 0.65);
  --surface-inverse:  oklch(0.930 0.004 260);

  --text-primary:   oklch(0.950 0.003 260);
  --text-secondary: oklch(0.820 0.005 260);
  --text-muted:     oklch(0.710 0.006 260);
  --text-subtle:    oklch(0.660 0.006 260);
  --text-inverse:   oklch(0.160 0.010 260);

  --border-subtle:  oklch(0.290 0.006 260);
  --border-default: oklch(0.330 0.007 260);
  --border-strong:  oklch(0.420 0.008 260);
  --border-control: oklch(0.520 0.008 260);

  --accent:        oklch(0.780 0.095 260);
  --accent-hover:  oklch(0.840 0.080 260);
  --accent-active: oklch(0.720 0.100 260);
  --on-accent:     oklch(0.170 0.040 260);
  --accent-text:   oklch(0.780 0.095 260);
  --accent-wash:   oklch(0.280 0.040 260);
  --accent-border: oklch(0.600 0.100 260);
  --focus:         oklch(0.740 0.120 260);

  --success-fg: oklch(0.800 0.095 155);
  --success-bg: oklch(0.260 0.035 155);
  --success-border: oklch(0.420 0.060 155);
  --success-default: oklch(0.520 0.100 155);
  --danger-fg:  oklch(0.800 0.090 25);
  --danger-bg:  oklch(0.270 0.045 25);
  --danger-border: oklch(0.450 0.090 25);
  --danger-default: oklch(0.550 0.150 25);
  --warning-fg: oklch(0.830 0.100 75);
  --warning-bg: oklch(0.270 0.040 70);
  --warning-border: oklch(0.480 0.080 70);
  --warning-default: oklch(0.800 0.120 75);
  --info-fg:    oklch(0.820 0.070 260);
  --info-bg:    oklch(0.270 0.040 260);
  --info-border: oklch(0.450 0.070 260);

  --skeleton-base:  oklch(0.260 0.006 260);
  --skeleton-shine: oklch(0.300 0.006 260);

  --elev-3: 0 2px 4px oklch(0 0 0 / 0.30),
            0 8px 24px oklch(0 0 0 / 0.45);
  --elev-4: 0 4px 8px oklch(0 0 0 / 0.35),
            0 24px 48px oklch(0 0 0 / 0.55);

  --focus-ring-inverse: 0 0 0 2px var(--surface-canvas), 0 0 0 4px var(--focus);
}

:root[data-theme="dark"] ::selection {
  background: var(--brand-300);
  color: var(--text-primary);
}

/* Native controls follow the accent in both themes. */
:root { accent-color: var(--accent); }
