/* ============================================================================
 * Recipe Studio — Deterministic OKLCH Design Tokens (Spec v2.0)
 * Single Source of Truth derived from root DESIGN.md
 * Archetype: Technical Precision, Developer-Native, Restrained Craft
 * ============================================================================ */

:root {
  /* --- 1. Core Semantic Color Tokens (OKLCH Color Space — Light Mode) --- */
  --color-bg: oklch(0.98 0.005 240);
  --color-surface: oklch(1.0 0 0);
  --color-surface-low: oklch(0.96 0.006 240);
  --color-surface-high: oklch(0.93 0.008 240);
  --color-ink: oklch(0.15 0.02 240);
  --color-muted: oklch(0.55 0.01 240);
  --color-muted-aa: oklch(0.45 0.015 240);
  --color-border: oklch(0.88 0.005 240);
  --color-accent: oklch(0.45 0.15 250);
  --color-accent-hover: oklch(0.38 0.15 250);
  --color-accent-subtle: oklch(0.95 0.025 250);
  --color-success: oklch(0.52 0.15 160);
  --color-success-bg: oklch(0.95 0.03 160);
  --color-warning: oklch(0.58 0.16 65);
  --color-warning-bg: oklch(0.96 0.04 75);
  --color-error: oklch(0.55 0.22 25);
  --color-error-bg: oklch(0.95 0.03 25);

  /* --- 2. Typography Constraints (Vietnamese OpenType & Monospace BOM) --- */
  --font-display: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-sans: "Be Vietnam Pro", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "JetBrains Mono", monospace;
  --stitch-font-sans: var(--font-sans);

  --h1: 32px;
  --h2: 24px;
  --h3: 20px;
  --body: 14px;
  --caption: 12px;
  --measure-prose: 70ch;

  /* --- 3. Spacing & Corner Radii Scale (4px/8px Rhythm) --- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;

  --radius-4: 4px;
  --radius-8: 8px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 12px;
  --radius-full: 9999px;

  /* --- 4. Elevation Tokens (Restrained Depth, Zero Blur/Neon) --- */
  --elevation-flat: none;
  --elevation-low: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
  --elevation-high: 0 10px 25px -5px rgba(0, 0, 0, 0.1);

  --shadow-sm: var(--elevation-low);
  --shadow-md: var(--elevation-low);
  --shadow-lg: var(--elevation-high);
  --shadow-xl: var(--elevation-high);
  --shadow-card: var(--elevation-low);
  --shadow-elev: var(--elevation-high);

  /* --- 5. Interactive Motion & Focus Governance --- */
  --ease-standard: cubic-bezier(0.22, 1, 0.36, 1);
  --transition-smooth: background-color 0.16s var(--ease-standard), border-color 0.16s var(--ease-standard), color 0.16s var(--ease-standard), box-shadow 0.16s var(--ease-standard);
  --focus-ring: 2px solid var(--color-accent);
  --focus-offset: 2px;

  /* --- 6. Deterministic sRGB Channel Bridges for Tailwind Alpha Utilities --- */
  --stitch-primary: var(--color-accent);
  --stitch-primary-rgb: 0 88 163;
  --stitch-on-primary: var(--color-surface);
  --stitch-on-primary-rgb: 255 255 255;
  --stitch-primary-container: var(--color-accent-hover);
  --stitch-primary-container-rgb: 0 70 135;
  --stitch-on-primary-container: var(--color-surface);
  --stitch-on-primary-container-rgb: 255 255 255;
  --stitch-primary-fixed: var(--color-accent-subtle);
  --stitch-primary-fixed-rgb: 230 240 250;
  --stitch-primary-fixed-dim: oklch(0.82 0.07 250);
  --stitch-primary-fixed-dim-rgb: 168 205 240;
  --stitch-on-primary-fixed: var(--color-ink);
  --stitch-on-primary-fixed-rgb: 12 18 28;
  --stitch-on-primary-fixed-variant: var(--color-accent);
  --stitch-on-primary-fixed-variant-rgb: 0 88 163;
  --stitch-inverse-primary: oklch(0.78 0.10 250);
  --stitch-inverse-primary-rgb: 140 192 242;

  --stitch-secondary: oklch(0.42 0.04 240);
  --stitch-secondary-rgb: 64 82 102;
  --stitch-on-secondary: var(--color-surface);
  --stitch-on-secondary-rgb: 255 255 255;
  --stitch-secondary-container: var(--color-surface-high);
  --stitch-secondary-container-rgb: 227 232 238;
  --stitch-on-secondary-container: var(--color-ink);
  --stitch-on-secondary-container-rgb: 12 18 28;
  --stitch-secondary-fixed: var(--color-surface-low);
  --stitch-secondary-fixed-rgb: 238 242 246;
  --stitch-secondary-fixed-dim: var(--color-border);
  --stitch-secondary-fixed-dim-rgb: 213 217 223;
  --stitch-on-secondary-fixed: var(--color-ink);
  --stitch-on-secondary-fixed-variant: oklch(0.35 0.03 240);

  --stitch-tertiary: var(--color-warning);
  --stitch-tertiary-rgb: 168 92 0;
  --stitch-on-tertiary: var(--color-surface);
  --stitch-on-tertiary-rgb: 255 255 255;
  --stitch-tertiary-container: oklch(0.48 0.14 65);
  --stitch-tertiary-container-rgb: 138 74 0;
  --stitch-on-tertiary-container: var(--color-surface);
  --stitch-on-tertiary-container-rgb: 255 255 255;
  --stitch-tertiary-fixed: var(--color-warning-bg);
  --stitch-tertiary-fixed-rgb: 252 240 218;
  --stitch-tertiary-fixed-dim: oklch(0.80 0.12 70);
  --stitch-tertiary-fixed-dim-rgb: 238 184 104;
  --stitch-on-tertiary-fixed: var(--color-ink);
  --stitch-on-tertiary-fixed-variant: oklch(0.40 0.12 65);

  --stitch-background: var(--color-bg);
  --stitch-background-rgb: 246 248 250;
  --stitch-on-background: var(--color-ink);
  --stitch-on-background-rgb: 12 18 28;
  --stitch-surface: var(--color-bg);
  --stitch-surface-rgb: 246 248 250;
  --stitch-surface-dim: var(--color-border);
  --stitch-surface-dim-rgb: 213 217 223;
  --stitch-surface-bright: var(--color-surface);
  --stitch-surface-bright-rgb: 255 255 255;
  --stitch-surface-container-lowest: var(--color-surface);
  --stitch-surface-container-lowest-rgb: 255 255 255;
  --stitch-surface-container-low: var(--color-surface-low);
  --stitch-surface-container-low-rgb: 238 242 246;
  --stitch-surface-container: var(--color-surface-low);
  --stitch-surface-container-rgb: 238 242 246;
  --stitch-surface-container-high: var(--color-surface-high);
  --stitch-surface-container-high-rgb: 227 232 238;
  --stitch-surface-container-highest: var(--color-border);
  --stitch-surface-container-highest-rgb: 213 217 223;
  --stitch-surface-variant: var(--color-surface-high);
  --stitch-surface-variant-rgb: 227 232 238;
  --stitch-on-surface: var(--color-ink);
  --stitch-on-surface-rgb: 12 18 28;
  --stitch-on-surface-variant: var(--color-muted-aa);
  --stitch-on-surface-variant-rgb: 76 86 98;
  --stitch-inverse-surface: var(--color-ink);
  --stitch-inverse-surface-rgb: 12 18 28;
  --stitch-inverse-on-surface: var(--color-bg);
  --stitch-inverse-on-surface-rgb: 246 248 250;
  --stitch-outline: var(--color-muted);
  --stitch-outline-rgb: 108 116 126;
  --stitch-outline-variant: var(--color-border);
  --stitch-outline-variant-rgb: 213 217 223;
  --stitch-surface-tint: var(--color-accent);
  --stitch-surface-tint-rgb: 0 88 163;

  --stitch-success: var(--color-success);
  --stitch-success-rgb: 12 132 88;
  --stitch-success-container: var(--color-success-bg);
  --stitch-success-container-rgb: 224 246 236;
  --stitch-on-success-container: oklch(0.32 0.10 160);
  --stitch-on-success-container-rgb: 8 78 52;

  --stitch-warning: var(--color-warning);
  --stitch-warning-rgb: 168 92 0;
  --stitch-warning-container: var(--color-warning-bg);
  --stitch-warning-container-rgb: 252 240 218;
  --stitch-on-warning-container: oklch(0.35 0.10 65);
  --stitch-on-warning-container-rgb: 102 52 8;

  --stitch-error: var(--color-error);
  --stitch-error-rgb: 201 28 28;
  --stitch-on-error: var(--color-surface);
  --stitch-on-error-rgb: 255 255 255;
  --stitch-error-container: var(--color-error-bg);
  --stitch-error-container-rgb: 252 232 232;
  --stitch-on-error-container: oklch(0.35 0.15 25);
  --stitch-on-error-container-rgb: 122 12 12;

  --stitch-btp: var(--color-accent);
  --stitch-btp-rgb: 0 88 163;
  --stitch-btp-light: var(--color-accent-subtle);
  --stitch-btp-light-rgb: 230 240 250;
  --stitch-btp-border: var(--color-border);
  --stitch-btp-border-rgb: 213 217 223;

  /* --- 7. Unified Semantic Component Aliases --- */
  --color-primary: var(--color-accent);
  --color-primary-rgb: 0, 88, 163;
  --color-primary-600: var(--color-accent-hover);
  --color-primary-hover: var(--color-accent-hover);
  --color-primary-subtle: var(--color-accent-subtle);
  --color-secondary: var(--stitch-secondary);
  --color-secondary-rgb: 64, 82, 102;
  --color-tertiary: var(--color-warning);
  --color-tertiary-rgb: 168, 92, 0;
  --color-accent-rgb: 0, 88, 163;
  --accent-2: var(--stitch-secondary);
  --color-ai: var(--color-accent);
  --color-ai-rgb: 0, 88, 163;
  --color-danger: var(--color-error);

  --color-text: var(--color-ink);
  --color-fg: var(--color-ink);
  --text-main: var(--color-ink);
  --text-muted: var(--color-muted-aa);
  --color-surface-container: var(--color-surface-low);
  --color-surface-hover: var(--color-surface-high);
  --surface-1: var(--color-surface);
  --color-sidebar: var(--color-surface-low);
  --link: var(--color-accent);

  --bg: var(--color-bg);
  --fg: var(--color-ink);
  --card: var(--color-surface);
  --muted: var(--color-muted-aa);
  --border: var(--color-border);

  /* Print Fidelity */
  --print-text: oklch(0.0 0 0);
  --print-bg: oklch(1.0 0 0);
  --print-border: oklch(0.80 0.005 240);
}

/* --- Dark Mode Calibration (OKLCH Developer-Native Slate) --- */
:root[data-theme='dark'],
[data-theme='dark'],
html.dark {
  --color-bg: oklch(0.16 0.015 240);
  --color-surface: oklch(0.20 0.015 240);
  --color-surface-low: oklch(0.18 0.015 240);
  --color-surface-high: oklch(0.25 0.018 240);
  --color-ink: oklch(0.95 0.005 240);
  --color-muted: oklch(0.70 0.012 240);
  --color-muted-aa: oklch(0.74 0.012 240);
  --color-border: oklch(0.30 0.015 240);
  --color-accent: oklch(0.72 0.13 250);
  --color-accent-hover: oklch(0.78 0.13 250);
  --color-accent-subtle: oklch(0.26 0.04 250);
  --color-success: oklch(0.74 0.14 160);
  --color-success-bg: oklch(0.25 0.05 160);
  --color-warning: oklch(0.78 0.14 70);
  --color-warning-bg: oklch(0.26 0.05 70);
  --color-error: oklch(0.72 0.18 25);
  --color-error-bg: oklch(0.26 0.06 25);

  --elevation-low: 0 1px 3px 0 rgba(0, 0, 0, 0.35);
  --elevation-high: 0 10px 25px -5px rgba(0, 0, 0, 0.55);

  --stitch-primary-rgb: 112 178 240;
  --stitch-on-primary: oklch(0.16 0.02 250);
  --stitch-on-primary-rgb: 10 22 36;
  --stitch-primary-container-rgb: 0 75 135;
  --stitch-on-primary-container-rgb: 224 240 255;
  --stitch-background-rgb: 15 20 26;
  --stitch-on-background-rgb: 238 242 248;
  --stitch-surface-rgb: 15 20 26;
  --stitch-surface-container-lowest-rgb: 22 28 36;
  --stitch-surface-container-low-rgb: 18 24 31;
  --stitch-surface-container-rgb: 26 33 42;
  --stitch-surface-container-high-rgb: 34 42 54;
  --stitch-surface-container-highest-rgb: 44 54 68;
  --stitch-on-surface-rgb: 238 242 248;
  --stitch-on-surface-variant-rgb: 168 178 192;
  --stitch-outline-rgb: 122 132 146;
  --stitch-outline-variant-rgb: 44 54 68;

  --color-primary-rgb: 112, 178, 240;
  --color-accent-rgb: 112, 178, 240;

  --bg: var(--color-bg);
  --fg: var(--color-ink);
  --card: var(--color-surface);
  --muted: var(--color-muted-aa);
  --border: var(--color-border);
}

/* Optional WCAG High-Contrast Mode */
:root[data-contrast='high'],
html.kitchen-high-contrast {
  --color-border: oklch(0.50 0.01 240) !important;
  --color-muted: var(--color-ink) !important;
  --color-muted-aa: var(--color-ink) !important;
}

/* Financial Shield / Privacy Screen Masking (Alt+P) */
.privacy-masked-mode .financial-sensitive,
body.privacy-masked-mode .financial-sensitive {
  filter: blur(8px) !important;
  user-select: none !important;
  pointer-events: none !important;
  transition: filter 0.16s var(--ease-standard);
  position: relative;
}

/* Kitchen High-Contrast Mode Enhancements */
html.kitchen-high-contrast button,
html.kitchen-high-contrast .card-border {
  border-width: 1.5px !important;
  border-color: var(--color-ink) !important;
}

/* Information Density Tiers (4px/8px Rhythm) */
[data-density='compact'] .recipe-row,
[data-density='compact'] table td,
[data-density='compact'] table th {
  padding-top: 4px !important;
  padding-bottom: 4px !important;
  font-size: 12px !important;
}

[data-density='comfortable'] .recipe-row,
[data-density='comfortable'] table td,
[data-density='comfortable'] table th {
  padding-top: 8px !important;
  padding-bottom: 8px !important;
}

[data-density='spacious'] .recipe-row,
[data-density='spacious'] table td,
[data-density='spacious'] table th {
  padding-top: 12px !important;
  padding-bottom: 12px !important;
  font-size: 14px !important;
}
