/* =============================================================================
   V2 Admin — Design Tokens
   ----------------------------------------------------------------------------
   Single source of truth cho color / spacing / type / radii / shadow.
   Semantic naming (not "slate-500" — use "text-muted"). Dark mode swap via
   [data-theme="dark"] attribute on <html>.
   ============================================================================= */

:root {
  /* ── Color: neutrals (graphite scale, professional like Linear) ──────── */
  --gray-50:  #fafafb;
  --gray-100: #f4f5f7;
  --gray-200: #e6e8ec;
  --gray-300: #d3d6dc;
  --gray-400: #9ba1ad;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #353a44;
  --gray-800: #1f232b;
  --gray-900: #11141a;

  /* ── Color: brand — VIASM red (logo color) ─────────────────────────────
     Realiased twice: indigo → navy (2026-05-27 first pass) → red (2026-05-27
     user feedback "tông màu chuyển xanh sang đỏ cho đồng bộ với logo").
     Logo viasm-logo.png là red icosahedron + red wordmark, brand color phải
     khớp. Navy giữ là --navy-* riêng cho text headings + structural surfaces. */
  --brand-50:  #fef2f3;
  --brand-100: #fde2e5;
  --brand-200: #fbc8ce;
  --brand-300: #f59ba6;
  --brand-400: #ec6577;
  --brand-500: #de3852;
  --brand-600: var(--viasm-red);     /* #c41e3a — VIASM logo red */
  --brand-700: var(--viasm-red-dark); /* #951a2c — deeper for hover/active */
  --brand-800: #7a1424;
  --brand-900: #5e0f1c;

  /* ── Color: VIASM brand (matches chat UI) ───────────────────────────────
     Used by knowledge module + future modules requesting brand sync.
     Reference: extensions/chat_api/static/index.html lines 18-42.
     ──────────────────────────────────────────────────────────────────── */
  --navy-50:  #f4f6fa;
  --navy-100: #e6ecf4;
  --navy-200: #c3d0e2;
  --navy-300: #94aac9;
  --navy-400: #5f7fae;
  --navy-500: #335c91;
  --navy-600: #1f4576;
  --navy-700: #143560;  /* VIASM primary (logo navy) */
  --navy-800: #0c264a;
  --navy-900: #061838;

  --viasm-red:      #c41e3a;  /* VIASM logo red */
  --viasm-red-soft: #fbe9ec;
  --viasm-red-dark: #951a2c;

  --highlight:      #b8893a;  /* Academic gold accent */
  --highlight-soft: #f5ecd9;

  --ivory:          #fbfaf6;  /* Warm paper background (vs sterile gray-50) */
  --rule:           #e4e7ed;
  --rule-soft:      #eef0f4;

  /* ── Color: status (WCAG AA contrast on white) ──────────────────────── */
  --success-50:  #ecfdf5;
  --success-100: #d1fae5;
  --success-500: #10b981;
  --success-600: #059669;
  --success-700: #047857;

  --warning-50:  #fffbeb;
  --warning-100: #fef3c7;
  --warning-500: #f59e0b;
  --warning-600: #d97706;
  --warning-700: #b45309;

  --danger-50:  #fef2f2;
  --danger-100: #fee2e2;
  --danger-500: #ef4444;
  --danger-600: #dc2626;
  --danger-700: #b91c1c;

  --info-50:  #eff6ff;
  --info-100: #dbeafe;
  --info-500: #3b82f6;
  --info-600: #2563eb;
  --info-700: #1d4ed8;

  /* ── Semantic colors (light theme) ──────────────────────────────────── */
  --background: var(--gray-50);
  --surface: #ffffff;
  --surface-elevated: #ffffff;
  --surface-sunken: var(--gray-100);
  --surface-hover: var(--gray-100);

  --border-default: var(--gray-200);
  --border-strong: var(--gray-300);
  --border-focus: var(--highlight);   /* VIASM gold focus ring (match chat UI accent) */

  --text-primary: var(--gray-900);
  --text-secondary: var(--gray-700);
  --text-muted: var(--gray-500);
  --text-subtle: var(--gray-400);
  --text-inverse: #ffffff;
  --text-brand: var(--brand-600);
  --text-danger: var(--danger-600);
  --text-success: var(--success-700);
  --text-warning: var(--warning-700);

  --link: var(--brand-600);
  --link-hover: var(--brand-700);

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.04);
  --shadow-md: 0 2px 4px -1px rgb(0 0 0 / 0.06), 0 4px 6px -1px rgb(0 0 0 / 0.04);
  --shadow-lg: 0 4px 6px -2px rgb(0 0 0 / 0.05), 0 10px 15px -3px rgb(0 0 0 / 0.08);
  --shadow-xl: 0 10px 25px -5px rgb(0 0 0 / 0.10), 0 20px 25px -5px rgb(0 0 0 / 0.04);

  /* ── Spacing scale (4px base, follows 4/8/12/16/24/32/48/64) ────────── */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* ── Type scale (1.125 modular, Inter; line-height tuned per size) ───── */
  --font-display: 28px;       --lh-display: 36px;
  --font-h1: 22px;            --lh-h1: 28px;
  --font-h2: 18px;            --lh-h2: 24px;
  --font-h3: 15px;            --lh-h3: 20px;
  --font-body: 14px;          --lh-body: 20px;
  --font-body-sm: 13px;       --lh-body-sm: 18px;
  --font-caption: 12px;       --lh-caption: 16px;
  --font-mono: 12px;          --lh-mono: 16px;

  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono-stack: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;  /* VIASM academic heading */

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

  /* ── Radii ──────────────────────────────────────────────────────────── */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  /* ── Z-index ────────────────────────────────────────────────────────── */
  --z-sticky: 10;
  --z-overlay: 50;
  --z-modal: 60;
  --z-toast: 70;
  --z-cmdk: 80;

  /* ── Transitions ────────────────────────────────────────────────────── */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --duration-fast: 120ms;
  --duration: 180ms;
  --duration-slow: 260ms;

  /* ── Chat-UI semantic aliases (so the chat surface resolves from this file
     with ZERO visual change — identical to chat index.html :root) ──────── */
  --paper:       #ffffff;
  --bg:          var(--ivory);
  --panel:       var(--paper);
  --panel-2:     var(--navy-50);
  --border:      var(--rule);
  --text:        #1a1a1f;
  --text-2:      #44464f;
  --muted:       #74809a;
  --accent:      var(--viasm-red);
  --accent-soft: var(--viasm-red-soft);
  --success:     #1d7f54;
  --warning:     #b97320;
  --error:       #b53c2e;
  --user-bg:     var(--navy-700);
  --user-text:   #ffffff;
  --bot-bg:      var(--paper);
  --bot-text:    var(--text);
  --code-bg:     var(--navy-50);
  --citation:    var(--navy-600);
  --heading:     var(--navy-800);

  /* ── Knowledge-module vars (previously undefined → light-only fallback).
     Aliased to theme-aware admin semantics so dark mode resolves. ──────── */
  --bg-paper:      var(--surface);
  --bg-subtle:     var(--surface-sunken);
  --surface-2:     var(--surface-sunken);
  --surface-card:  var(--surface-elevated);
  --text-strong:   var(--text-primary);
  --border-subtle: var(--rule-soft);
  --font-h4: 14px;  --lh-h4: 19px;

  /* ── Navy-tinted shadows (chat brand standard; override admin black) ─── */
  --shadow-sm: 0 1px 2px rgba(12,38,74,.06);
  --shadow-md: 0 4px 16px rgba(12,38,74,.08), 0 1px 2px rgba(12,38,74,.04);
  --shadow-lg: 0 12px 40px rgba(12,38,74,.12), 0 2px 6px rgba(12,38,74,.06);
}

/* ── Dark theme (toggled via [data-theme="dark"] on <html>) ──────────── */
:root[data-theme="dark"] {
  --background: var(--gray-900);
  --surface: var(--gray-800);
  --surface-elevated: #2a2e38;
  --surface-sunken: var(--gray-900);
  --surface-hover: #2a2e38;

  --border-default: #2d3340;
  --border-strong: #3a4151;
  --border-focus: var(--brand-400);

  --text-primary: var(--gray-50);
  --text-secondary: var(--gray-200);
  --text-muted: #9aa1ae;
  --text-subtle: #6c7382;
  --text-inverse: var(--gray-900);
  --text-brand: var(--brand-300);
  --text-danger: #f87171;
  --text-success: #34d399;
  --text-warning: #fbbf24;

  --link: var(--brand-300);
  --link-hover: var(--brand-200);

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow-md: 0 2px 4px -1px rgb(0 0 0 / 0.4), 0 4px 6px -1px rgb(0 0 0 / 0.3);
  --shadow-lg: 0 4px 6px -2px rgb(0 0 0 / 0.4), 0 10px 15px -3px rgb(0 0 0 / 0.5);
  --shadow-xl: 0 10px 25px -5px rgb(0 0 0 / 0.6), 0 20px 25px -5px rgb(0 0 0 / 0.3);

  /* VIASM brand — dark mode mirror (lighter navy for readability) */
  --navy-50:  #1a2540;
  --navy-100: #1f2c4a;
  --navy-200: #2b3a5d;

  /* --brand-* dark mirror — VIASM red soft tones cho dark bg */
  --brand-50:  #2d141a;
  --brand-100: #3a1a22;
  --brand-200: #4f2230;
  --brand-300: #6a2e3f;
  --brand-400: #944253;
  --brand-500: #c25a6c;
  --brand-600: #e74c5b;             /* viasm-red dark variant */
  --brand-700: #f07585;
  --brand-800: #f5a3ad;
  --brand-900: #fbc8ce;
  --navy-300: #3c4d72;
  --navy-400: #54688a;
  --navy-500: #7286a8;
  --navy-600: #94a5c2;
  --navy-700: #b5c2d8;
  --navy-800: #d4dcea;
  --navy-900: #ebeff6;

  --viasm-red:      #e74c5b;
  --viasm-red-soft: #3a1a22;
  --viasm-red-dark: #c41e3a;

  --highlight:      #d4a960;
  --highlight-soft: #2d2519;

  --ivory:          #0a1226;
  --rule:           #1f2c4a;
  --rule-soft:      #172139;

  /* ── Chat-UI semantic aliases — dark (identical to chat index.html dark) ── */
  --paper:       #0e1730;
  --bg:          var(--ivory);
  --panel:       var(--paper);
  --panel-2:     #131e3a;
  --border:      var(--rule);
  --text:        #e6ebf5;
  --text-2:      #b5c2d8;
  --muted:       #7286a8;
  --accent:      var(--viasm-red);
  --accent-soft: var(--viasm-red-soft);
  --success:     #4ade80;
  --warning:     #fbbf24;
  --error:       #f87171;
  --user-bg:     var(--navy-500);
  --user-text:   #0a1226;
  --bot-bg:      var(--paper);
  --bot-text:    var(--text);
  --code-bg:     #0a1226;
  --citation:    var(--navy-600);
  --heading:     var(--navy-800);

  /* Knowledge-module vars (dark resolves via admin semantics) */
  --bg-paper:      var(--surface);
  --bg-subtle:     var(--surface-sunken);
  --surface-2:     var(--surface-sunken);
  --surface-card:  var(--surface-elevated);
  --text-strong:   var(--text-primary);
  --border-subtle: var(--rule-soft);

  /* Dark shadows (chat brand standard) */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.2);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.5), 0 2px 6px rgba(0,0,0,.3);
}

/* Auto-apply dark theme if user prefers (unless explicit override) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* mirror the dark block (kept minimal — uses same vars) */
    color-scheme: dark;
  }
}

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

/* ── Base reset / element styles ──────────────────────────────────────── */
html, body {
  font-family: var(--font-sans);
  font-size: var(--font-body);
  line-height: var(--lh-body);
  background: var(--background);
  color: var(--text-primary);
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';   /* Inter ligatures */
  -webkit-font-smoothing: antialiased;
}

/* Tabular numerals for cost/latency cells */
.tabular { font-variant-numeric: tabular-nums; }

/* Mono font + tabular for IDs and numeric data */
.mono { font-family: var(--font-mono-stack); font-size: var(--font-mono); }

/* Focus ring everywhere — accessible + branded */
*:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Selection color */
::selection { background: var(--brand-200); color: var(--brand-900); }
:root[data-theme="dark"] ::selection { background: var(--brand-700); color: var(--brand-50); }

/* Smooth bg/color transition on theme switch */
html { transition: background-color var(--duration) var(--ease-out), color var(--duration) var(--ease-out); }
