/* ==========================================================================
 * Xiaozhai Dev UI (XUI) — Design Tokens v1.0
 *
 * Orthogonal 4-Axis Visual Contract on <html>:
 *   data-theme   = "dark" (default) | "light"
 *   data-skin    = "amber" (default) | "jade" | "azure" | "violet" | "crimson" | "slate" | "custom"
 *   data-density = "default" | "compact" | "comfortable"
 *   data-motion  = "full" (default) | "subtle" | "reduced"
 *
 * 100% compatible with XPlayer tokens; designed for Editors, NLEs, Chat,
 * Cloud Drives, Audio Players, and frameless Desktop (WebView2 / Tauri) apps.
 * ========================================================================== */

:root {
  color-scheme: dark;

  /* ---------- Palette: Dark Theme (Default) ---------- */
  --bg-base: #0B0C0E;
  --bg-elev-1: #14161A;
  --bg-elev-2: #1C1F25;
  --bg-elev-3: #242830;
  --bg-elev-4: #2D323C;

  --line: #262A31;
  --line-subtle: #1D2026;
  --line-strong: #39404D;

  --text-1: #F2F3F5;
  --text-2: #A8AFBA;
  --text-3: #8A93A3;
  --text-on-accent: #0B0C0E;
  --text-pure: #FFFFFF;

  /* ---------- Accent: Amber (Default) ---------- */
  --accent: #FF7A45;
  --accent-hover: #FF8E61;
  --accent-active: #E86835;
  --accent-soft: rgba(255, 122, 69, 0.14);
  --accent-ring: rgba(255, 122, 69, 0.38);
  /* Text/icon color for elements sitting on --accent-soft: brighter on dark surfaces
   * so contrast stays >= 4.5:1. Skin overrides redefine --accent-hover and this tracks it. */
  --accent-on-soft: var(--accent-hover);

  /* ---------- Semantic Status ---------- */
  --info: #4DA3FF;
  --info-soft: rgba(77, 163, 255, 0.14);
  --success: #3DDC97;
  --success-soft: rgba(61, 220, 151, 0.14);
  --warn: #FFB020;
  --warn-soft: rgba(255, 176, 32, 0.14);
  --danger: #FF5C5C;
  --danger-hover: #FF7373;
  --danger-soft: rgba(255, 92, 92, 0.14);

  /* ---------- Surfaces & Chrome ---------- */
  --scrim: rgba(7, 8, 10, 0.72);
  --surface-overlay: rgba(20, 22, 26, 0.92);
  --surface-code: #0F1115;
  --surface-selection: rgba(255, 122, 69, 0.24);
  --skeleton-a: #1C1F25;
  --skeleton-b: #262A32;
  --scrollbar-thumb: #2D323C;
  --scrollbar-thumb-hover: #3D4452;

  /* ---------- Deterministic 6-Tone Avatar / Thumbnail / Track Gradients ---------- */
  --tone-grad-0: linear-gradient(135deg, #4A251B 0%, #241411 100%);
  --tone-grad-1: linear-gradient(135deg, #273733 0%, #141D1B 100%);
  --tone-grad-2: linear-gradient(135deg, #46351E 0%, #21190F 100%);
  --tone-grad-3: linear-gradient(135deg, #353942 0%, #1B1E24 100%);
  --tone-grad-4: linear-gradient(135deg, #472228 0%, #221114 100%);
  --tone-grad-5: linear-gradient(135deg, #2A3526 0%, #161C14 100%);
  --tone-0: #D97652;
  --tone-1: #5BA392;
  --tone-2: #D4A159;
  --tone-3: #8F99AB;
  --tone-4: #CF6674;
  --tone-5: #7EA368;

  /* ---------- Typography ---------- */
  --font-ui: "Microsoft YaHei UI", "PingFang SC", "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Mono", "Consolas", "SFMono-Regular", ui-monospace, monospace;

  --t-display-size: 28px;
  --t-display-lh: 1.2;
  --t-display-w: 600;

  --t-h1-size: 20px;
  --t-h1-lh: 1.3;
  --t-h1-w: 600;

  --t-h2-size: 16px;
  --t-h2-lh: 1.4;
  --t-h2-w: 600;

  --t-body-size: 14px;
  --t-body-lh: 1.5;
  --t-body-w: 400;

  --t-small-size: 13px;
  --t-small-lh: 1.4;
  --t-small-w: 400;

  --t-caption-size: 12px;
  --t-caption-lh: 1.4;
  --t-caption-w: 400;

  --t-micro-size: 11px;
  --t-micro-lh: 1.2;

  --t-weight-regular: 400;
  --t-weight-medium: 500;
  --t-weight-semibold: 600;
  --t-weight-bold: 700;

  /* ---------- Spacing Scale (4px grid with half steps) ---------- */
  --s-0: 0px;
  --s-0-5: 2px;
  --s-1: 4px;
  --s-1-5: 6px;
  --s-2: 8px;
  --s-2-5: 10px;
  --s-3: 12px;
  --s-3-5: 14px;
  --s-4: 16px;
  --s-4-5: 20px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 64px;

  /* ---------- Border Radius (Restrained: cards never exceed 14px) ---------- */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-pill: 999px;

  /* ---------- Motion ----------
   * Budgeted by trigger frequency (R-MOTION-02: any repeatable interaction <= 500ms):
   *   instant / fast  -> 100+/day keys & hovers, must feel 0-latency
   *   switch / base   -> panel & overlay enter
   *   exit            -> overlay leave, always <= its matching enter (R-MOTION-01)
   */
  --d-instant: 75ms;
  --d-fast: 120ms;
  --d-switch: 180ms;
  --d-base: 200ms;
  --d-slow: 320ms;
  --d-exit: 140ms;
  --d-skeleton: 1400ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  --motion-scale: 1;
  /* Tactile feedback: multiplied by --motion-scale so reduced motion becomes a no-op */
  --press-scale: 0.975;
  --hover-lift: -1px;

  /* ---------- Layout & Component Dimensions (Default Density) ---------- */
  --sidebar-w: 228px;
  --sidebar-w-collapsed: 56px;
  --inspector-w: 280px;
  --topbar-h: 48px;
  --statusbar-h: 26px;
  --row-h: 40px;
  --row-h-compact: 32px;
  --drawer-w: 360px;
  --dialog-w: 440px;
  --dialog-w-lg: 580px;
  --cmdk-w: 560px;
  --menu-min-w: 208px;
  --popover-min-w: 180px;
  --toast-max-w: 380px;

  --btn-h-sm: 28px;
  --btn-h: 34px;
  --btn-h-lg: 42px;
  --input-h: 34px;
  --icon-btn-sm: 28px;
  --icon-btn-size: 32px;
  --toggle-w: 38px;
  --toggle-h: 22px;
  --toggle-knob: 16px;
  --scrollbar-w: 8px;
  --border-accent-w: 3px;
  --focus-ring-w: 2px;
  --focus-ring-offset: 2px;
  --panel-pad: var(--s-4);
  --card-pad: var(--s-4);

  /* ---------- Elevation Shadows ---------- */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.42);
  --shadow-menu: 0 12px 32px rgba(0, 0, 0, 0.52);
  --shadow-dialog: 0 20px 56px rgba(0, 0, 0, 0.62);
  --shadow-toast: 0 8px 24px rgba(0, 0, 0, 0.48);

  /* ---------- Z-Index Layers ---------- */
  --z-sticky: 10;
  --z-topbar: 20;
  --z-dock: 30;
  --z-drawer: 40;
  --z-popover: 45;
  --z-menu: 50;
  --z-drag: 55;
  --z-dialog: 60;
  --z-cmdk: 65;
  --z-toast: 70;
  --z-tooltip: 80;
}

/* ==========================================================================
 * Light Theme (Day Mode)
 * ========================================================================== */
:root[data-theme="light"] {
  color-scheme: light;

  --bg-base: #F2F4F7;
  --bg-elev-1: #FFFFFF;
  --bg-elev-2: #FFFFFF;
  --bg-elev-3: #EDEFF3;
  --bg-elev-4: #E1E5EB;

  --line: #DDE1E8;
  --line-subtle: #E9ECF1;
  --line-strong: #C4CBD6;

  --text-1: #171A1F;
  --text-2: #555D6B;
  --text-3: #626976;
  --text-on-accent: #FFFFFF;
  --text-pure: #000000;

  /* Calibrated Amber for WCAG AA contrast on light surfaces */
  --accent: #C84A17;
  --accent-hover: #B34012;
  --accent-active: #9A350E;
  --accent-soft: rgba(200, 74, 23, 0.12);
  --accent-ring: rgba(200, 74, 23, 0.34);
  /* On light surfaces the accent-soft tint is near-white; darken the accent text
   * (toward --accent-active) so contrast stays >= 4.5:1. */
  --accent-on-soft: var(--accent-active);

  --info: #2563EB;
  --info-soft: rgba(37, 99, 235, 0.11);
  --success: #169B66;
  --success-soft: rgba(22, 155, 102, 0.11);
  --warn: #C87A00;
  --warn-soft: rgba(200, 122, 0, 0.12);
  --danger: #DC3545;
  --danger-hover: #C22A39;
  --danger-soft: rgba(220, 53, 69, 0.11);

  --scrim: rgba(23, 26, 31, 0.42);
  --surface-overlay: rgba(255, 255, 255, 0.94);
  --surface-code: #F7F8FA;
  --surface-selection: rgba(217, 86, 32, 0.18);
  --skeleton-a: #E5E8ED;
  --skeleton-b: #D6DAE1;
  --scrollbar-thumb: #C7CDD6;
  --scrollbar-thumb-hover: #ACB4C0;

  --shadow-sm: 0 2px 8px rgba(20, 24, 32, 0.08);
  --shadow-md: 0 8px 22px rgba(20, 24, 32, 0.12);
  --shadow-menu: 0 12px 30px rgba(20, 24, 32, 0.16);
  --shadow-dialog: 0 20px 50px rgba(20, 24, 32, 0.2);
  --shadow-toast: 0 8px 22px rgba(20, 24, 32, 0.14);
}

/* ==========================================================================
 * Accent Skins — Dark Mode (Default) + Light Mode Calibration
 * ========================================================================== */

/* Jade */
:root[data-skin="jade"] {
  --accent: #2FB98A;
  --accent-hover: #45CE9C;
  --accent-active: #269C74;
  --accent-soft: rgba(47, 185, 138, 0.14);
  --accent-ring: rgba(47, 185, 138, 0.38);
  --surface-selection: rgba(47, 185, 138, 0.24);
}
:root[data-theme="light"][data-skin="jade"] {
  --accent: #13825D;
  --accent-hover: #0F7050;
  --accent-active: #0B5E42;
  --accent-soft: rgba(19, 130, 93, 0.12);
  --accent-ring: rgba(19, 130, 93, 0.34);
  --surface-selection: rgba(19, 130, 93, 0.18);
}

/* Azure */
:root[data-skin="azure"] {
  --accent: #3E8EF7;
  --accent-hover: #5AA0F9;
  --accent-active: #2F79D8;
  --accent-soft: rgba(62, 142, 247, 0.14);
  --accent-ring: rgba(62, 142, 247, 0.38);
  --surface-selection: rgba(62, 142, 247, 0.24);
}
:root[data-theme="light"][data-skin="azure"] {
  --accent: #1E6CE0;
  --accent-hover: #175BC4;
  --accent-active: #124BA6;
  --accent-soft: rgba(30, 108, 224, 0.12);
  --accent-ring: rgba(30, 108, 224, 0.34);
  --surface-selection: rgba(30, 108, 224, 0.18);
}

/* Violet */
:root[data-skin="violet"] {
  --accent: #9B6BFF;
  --accent-hover: #AD85FF;
  --accent-active: #8557E6;
  --accent-soft: rgba(155, 107, 255, 0.14);
  --accent-ring: rgba(155, 107, 255, 0.38);
  --surface-selection: rgba(155, 107, 255, 0.24);
}
:root[data-theme="light"][data-skin="violet"] {
  --accent: #6E3EE0;
  --accent-hover: #5D2FD1;
  --accent-active: #4E24B8;
  --accent-soft: rgba(110, 62, 224, 0.12);
  --accent-ring: rgba(110, 62, 224, 0.34);
  --surface-selection: rgba(110, 62, 224, 0.18);
}

/* Crimson */
:root[data-skin="crimson"] {
  --accent: #F2555A;
  --accent-hover: #F57176;
  --accent-active: #D9454A;
  --accent-soft: rgba(242, 85, 90, 0.14);
  --accent-ring: rgba(242, 85, 90, 0.38);
  --surface-selection: rgba(242, 85, 90, 0.24);
}
:root[data-theme="light"][data-skin="crimson"] {
  --accent: #D13038;
  --accent-hover: #BA262D;
  --accent-active: #9E1E24;
  --accent-soft: rgba(209, 48, 56, 0.12);
  --accent-ring: rgba(209, 48, 56, 0.34);
  --surface-selection: rgba(209, 48, 56, 0.18);
}

/* Slate — Neutral color-accurate pro studio skin (ideal for video & photo editors) */
:root[data-skin="slate"] {
  --accent: #9AA3B5;
  --accent-hover: #B0B8C7;
  --accent-active: #828B9E;
  --accent-soft: rgba(154, 163, 181, 0.16);
  --accent-ring: rgba(154, 163, 181, 0.38);
  --surface-selection: rgba(154, 163, 181, 0.24);
}
:root[data-theme="light"][data-skin="slate"] {
  --accent: #3A4250;
  --accent-hover: #2B323E;
  --accent-active: #1F242D;
  --accent-soft: rgba(58, 66, 80, 0.11);
  --accent-ring: rgba(58, 66, 80, 0.32);
  --surface-selection: rgba(58, 66, 80, 0.16);
}

/* ==========================================================================
 * Density Scales
 *   compact     -> IDEs, Video Editors, Audio Mixers, Pro Tools
 *   default     -> Desktop productivity, Cloud Drives, Chat
 *   comfortable -> Touchscreens, Tablets, Reading-focused views
 * ========================================================================== */
:root[data-density="compact"] {
  --topbar-h: 40px;
  --statusbar-h: 22px;
  --sidebar-w: 204px;
  --row-h: 32px;
  --row-h-compact: 26px;
  --btn-h-sm: 24px;
  --btn-h: 28px;
  --btn-h-lg: 34px;
  --input-h: 28px;
  --icon-btn-sm: 24px;
  --icon-btn-size: 28px;
  --panel-pad: var(--s-3);
  --card-pad: var(--s-3);
  --t-body-size: 13px;
}

:root[data-density="comfortable"] {
  --topbar-h: 56px;
  --statusbar-h: 30px;
  --sidebar-w: 256px;
  --row-h: 48px;
  --row-h-compact: 40px;
  --btn-h-sm: 32px;
  --btn-h: 40px;
  --btn-h-lg: 48px;
  --input-h: 40px;
  --icon-btn-sm: 34px;
  --icon-btn-size: 38px;
  --panel-pad: var(--s-5);
  --card-pad: var(--s-5);
  --t-body-size: 15px;
}

/* ==========================================================================
 * Motion Tiers
 * ========================================================================== */
:root[data-motion="subtle"] {
  --d-instant: 40ms;
  --d-fast: 80ms;
  --d-switch: 120ms;
  --d-base: 140ms;
  --d-slow: 200ms;
  --d-exit: 90ms;
  --ease-spring: cubic-bezier(0.2, 0, 0, 1);
  --motion-scale: 0.5;
  --press-scale: 0.99;
  --hover-lift: 0px;
}

:root[data-motion="reduced"] {
  --d-instant: 0.01ms;
  --d-fast: 0.01ms;
  --d-switch: 0.01ms;
  --d-base: 0.01ms;
  --d-slow: 0.01ms;
  --d-exit: 0.01ms;
  --motion-scale: 0;
  --press-scale: 1;
  --hover-lift: 0px;
}
