/* ═══════════════════════════════════════════════════════════════════════════
   FLAIR UI 1.0 — Design System Extension
   Extends flair-v9.css (Dark Nebula) without replacing it.
   Adds: utility classes, spacing scale, elevation, layout helpers,
         AI-specific tokens, responsive grid, print-safe resets.
   Import AFTER flair-v9.css.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Extended Design Tokens ──────────────────────────────────────────────── */
:root {
  /* Spacing scale */
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3:  12px;
  --sp-4:  16px;
  --sp-5:  20px;
  --sp-6:  24px;
  --sp-8:  32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;

  /* Typography scale */
  --text-xs:   .7rem;
  --text-sm:   .8rem;
  --text-base: .875rem;
  --text-md:   1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;
  --text-3xl:  1.875rem;

  /* Elevation (shadows) */
  --elev-1: 0 1px 3px rgba(0,0,0,.35), 0 1px 2px rgba(0,0,0,.4);
  --elev-2: 0 4px 12px rgba(0,0,0,.4), 0 2px 4px rgba(0,0,0,.3);
  --elev-3: 0 8px 24px rgba(0,0,0,.45), 0 4px 8px rgba(0,0,0,.3);
  --elev-4: 0 16px 48px rgba(0,0,0,.5), 0 8px 16px rgba(0,0,0,.35);
  --elev-float: 0 20px 60px rgba(0,0,0,.6);

  /* Glow variants */
  --glow-violet: 0 0 20px rgba(124,58,237,.35), 0 0 60px rgba(124,58,237,.12);
  --glow-cyan:   0 0 20px rgba(6,182,212,.35),  0 0 60px rgba(6,182,212,.12);
  --glow-pink:   0 0 20px rgba(236,72,153,.35),  0 0 60px rgba(236,72,153,.12);
  --glow-green:  0 0 20px rgba(16,185,129,.35),  0 0 60px rgba(16,185,129,.12);
  --glow-amber:  0 0 20px rgba(245,158,11,.35),  0 0 60px rgba(245,158,11,.12);

  /* Transitions */
  --trans-fast:   .12s cubic-bezier(.4,0,.2,1);
  --trans-base:   .2s  cubic-bezier(.4,0,.2,1);
  --trans-slow:   .35s cubic-bezier(.4,0,.2,1);
  --trans-spring: .4s  cubic-bezier(.34,1.56,.64,1);

  /* AI-specific tokens */
  --ai-pulse-color: rgba(124,58,237,.6);
  --ai-surface:     rgba(124,58,237,.08);
  --ai-border:      rgba(124,58,237,.3);
  --ai-text:        #c4b5fd;

  /* Status colors with alpha */
  --status-success-bg:  rgba(16,185,129,.12);
  --status-success-border: rgba(16,185,129,.3);
  --status-warning-bg:  rgba(245,158,11,.12);
  --status-warning-border: rgba(245,158,11,.3);
  --status-error-bg:    rgba(239,68,68,.12);
  --status-error-border: rgba(239,68,68,.3);
  --status-info-bg:     rgba(99,102,241,.12);
  --status-info-border: rgba(99,102,241,.3);

  /* Sidebar collapsed width */
  --sidebar-w-collapsed: 64px;

  /* Content max-width */
  --content-max: 1400px;
}

/* ── Dark theme is default (matches flair-v9.css) ────────────────────────── */
[data-theme="dark"], :root {
  --ui-bg:        var(--bg,   #04040f);
  --ui-bg2:       var(--bg2,  #07071e);
  --ui-surface:   var(--surface,  #0c0c28);
  --ui-surface2:  var(--surface2, #111135);
  --ui-border:    var(--border,   rgba(108,99,255,.18));
  --ui-border2:   var(--border2,  rgba(108,99,255,.38));
  --ui-t1:        var(--t1, #e2e8f0);
  --ui-t2:        var(--t2, #94a3b8);
  --ui-t3:        var(--t3, #475569);
  --ui-glass:     rgba(12,12,40,.75);
  --ui-glass2:    rgba(7,7,30,.88);
  --ui-input-bg:  rgba(255,255,255,.04);
  --ui-overlay:   rgba(0,0,8,.72);
}

/* ── Light "Lumière Aurora" theme ────────────────────────────────────────── */
[data-theme="light"] {
  --ui-bg:       #f8f9ff;
  --ui-bg2:      #f0f1f9;
  --ui-surface:  #ffffff;
  --ui-surface2: #f4f5fe;
  --ui-border:   rgba(99,102,241,.15);
  --ui-border2:  rgba(99,102,241,.35);
  --ui-t1:       #1e1e3f;
  --ui-t2:       #4b5563;
  --ui-t3:       #9ca3af;
  --ui-glass:    rgba(255,255,255,.85);
  --ui-glass2:   rgba(248,249,255,.92);
  --ui-input-bg: rgba(99,102,241,.05);
  --ui-overlay:  rgba(15,15,60,.55);

  /* Override flair-v9 bg variables for light mode */
  --bg:       #f8f9ff;
  --bg2:      #f0f1f9;
  --surface:  #ffffff;
  --surface2: #f4f5fe;
  --border:   rgba(99,102,241,.15);
  --border2:  rgba(99,102,241,.35);
  --t1:       #1e1e3f;
  --t2:       #4b5563;
  --t3:       #9ca3af;

  /* Light mode shadow adjustments */
  --elev-1: 0 1px 3px rgba(99,102,241,.1),  0 1px 2px rgba(99,102,241,.08);
  --elev-2: 0 4px 12px rgba(99,102,241,.12), 0 2px 4px rgba(99,102,241,.08);
  --elev-3: 0 8px 24px rgba(99,102,241,.15), 0 4px 8px rgba(99,102,241,.08);

  /* Light mode AI tokens */
  --ai-surface: rgba(124,58,237,.06);
  --ai-text:    #7c3aed;
}

/* Apply light-mode overrides to body elements */
[data-theme="light"] body {
  background: var(--ui-bg);
  color: var(--ui-t1);
}

[data-theme="light"] .sidebar {
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(24px);
  border-right-color: var(--border);
  box-shadow: 2px 0 16px rgba(99,102,241,.08);
}

[data-theme="light"] .sidebar-brand .brand-sub { color: #9ca3af; }

[data-theme="light"] .nav-link {
  color: #4b5563;
}
[data-theme="light"] .nav-link:hover {
  color: #1e1e3f;
  background: rgba(124,58,237,.06);
}
[data-theme="light"] .nav-link.active {
  color: #7c3aed;
  background: rgba(124,58,237,.1);
  border-color: rgba(124,58,237,.3);
}

[data-theme="light"] .header {
  background: rgba(248,249,255,.92);
  backdrop-filter: blur(24px);
  border-bottom-color: var(--border);
  box-shadow: 0 1px 12px rgba(99,102,241,.08);
}
[data-theme="light"] .header-title { color: #1e1e3f; }
[data-theme="light"] .header-search { background: rgba(99,102,241,.05); }

[data-theme="light"] .glass {
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(18px);
  border-color: rgba(99,102,241,.15);
  box-shadow: var(--elev-2);
}
[data-theme="light"] .glass:hover {
  border-color: rgba(124,58,237,.3);
  box-shadow: var(--elev-3);
}

[data-theme="light"] #bg-canvas { opacity: .08; }

/* ── Utility Classes ─────────────────────────────────────────────────────── */

/* Display */
.d-flex     { display: flex; }
.d-grid     { display: grid; }
.d-block    { display: block; }
.d-none     { display: none; }
.d-inline   { display: inline; }
.d-if       { display: inline-flex; }

/* Flex helpers */
.flex-1     { flex: 1; }
.flex-shrink-0 { flex-shrink: 0; }
.flex-wrap  { flex-wrap: wrap; }
.flex-col   { flex-direction: column; }
.items-center { align-items: center; }
.items-start  { align-items: flex-start; }
.items-end    { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.justify-end     { justify-content: flex-end; }

/* Gap */
.gap-1 { gap: var(--sp-1); }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }
.gap-6 { gap: var(--sp-6); }
.gap-8 { gap: var(--sp-8); }

/* Padding */
.p-1  { padding: var(--sp-1);  }
.p-2  { padding: var(--sp-2);  }
.p-3  { padding: var(--sp-3);  }
.p-4  { padding: var(--sp-4);  }
.p-5  { padding: var(--sp-5);  }
.p-6  { padding: var(--sp-6);  }
.px-3 { padding-left: var(--sp-3); padding-right: var(--sp-3); }
.px-4 { padding-left: var(--sp-4); padding-right: var(--sp-4); }
.px-6 { padding-left: var(--sp-6); padding-right: var(--sp-6); }
.py-2 { padding-top: var(--sp-2); padding-bottom: var(--sp-2); }
.py-3 { padding-top: var(--sp-3); padding-bottom: var(--sp-3); }
.py-4 { padding-top: var(--sp-4); padding-bottom: var(--sp-4); }

/* Margin */
.mb-2  { margin-bottom: var(--sp-2); }
.mb-3  { margin-bottom: var(--sp-3); }
.mb-4  { margin-bottom: var(--sp-4); }
.mb-6  { margin-bottom: var(--sp-6); }
.mt-2  { margin-top: var(--sp-2); }
.mt-4  { margin-top: var(--sp-4); }
.mt-6  { margin-top: var(--sp-6); }
.ml-auto { margin-left: auto; }
.mr-auto { margin-right: auto; }
.mx-auto { margin-left: auto; margin-right: auto; }

/* Typography */
.text-xs   { font-size: var(--text-xs); }
.text-sm   { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-md   { font-size: var(--text-md); }
.text-lg   { font-size: var(--text-lg); }
.text-xl   { font-size: var(--text-xl); }
.text-2xl  { font-size: var(--text-2xl); }
.fw-400    { font-weight: 400; }
.fw-500    { font-weight: 500; }
.fw-600    { font-weight: 600; }
.fw-700    { font-weight: 700; }
.fw-800    { font-weight: 800; }
.fw-900    { font-weight: 900; }
.uppercase { text-transform: uppercase; letter-spacing: .08em; }
.truncate  { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-muted { color: var(--ui-t2); }
.text-dim   { color: var(--ui-t3); }
.text-primary { color: var(--ui-t1); }
.text-violet  { color: var(--violet); }
.text-cyan    { color: var(--cyan); }
.text-green   { color: var(--green); }
.text-amber   { color: var(--amber); }
.text-red     { color: var(--red); }
.text-pink    { color: var(--pink); }

/* Gradients text */
.grad-vc  {
  background: linear-gradient(135deg, var(--violet), var(--cyan));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.grad-vcp {
  background: linear-gradient(135deg, var(--violet), var(--cyan) 50%, var(--pink));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.grad-cg  {
  background: linear-gradient(135deg, var(--cyan), var(--green));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}

/* Borders & radius */
.r-sm { border-radius: 6px; }
.r    { border-radius: var(--r); }
.r-l  { border-radius: var(--rl); }
.r-x  { border-radius: var(--rx); }
.r-full { border-radius: 9999px; }

/* Widths */
.w-full { width: 100%; }
.max-content { max-width: var(--content-max); }

/* Position */
.relative  { position: relative; }
.absolute  { position: absolute; }
.sticky    { position: sticky; }
.inset-0   { inset: 0; }

/* Overflow */
.overflow-hidden { overflow: hidden; }
.overflow-auto   { overflow: auto; }
.overflow-x-auto { overflow-x: auto; }

/* Cursor */
.pointer { cursor: pointer; }

/* Opacity */
.op-50 { opacity: .5; }
.op-70 { opacity: .7; }

/* Background surfaces */
.bg-surface  { background: var(--ui-surface);  }
.bg-surface2 { background: var(--ui-surface2); }
.bg-ai       { background: var(--ai-surface); border: 1px solid var(--ai-border); border-radius: var(--rl); }

/* ── Responsive Grid ─────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-4); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--sp-4); }
.grid-auto-sm { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--sp-3); }

@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .main { padding: 16px; }
}

/* ── Sidebar Collapse Mode ───────────────────────────────────────────────── */
.sidebar-collapsed .sidebar {
  width: var(--sidebar-w-collapsed);
  overflow: visible;
}
.sidebar-collapsed .sidebar .nav-link span,
.sidebar-collapsed .sidebar .nav-section-label,
.sidebar-collapsed .sidebar .brand-sub,
.sidebar-collapsed .sidebar .nbadge {
  display: none;
}
.sidebar-collapsed .sidebar .brand-name {
  font-size: .9rem;
  letter-spacing: 0;
}
.sidebar-collapsed .sidebar .nav-link {
  justify-content: center;
  padding: 9px;
}
.sidebar-collapsed .sidebar .nav-link .ni {
  width: auto;
  font-size: 1.1rem;
}
.sidebar-collapsed .page {
  margin-left: var(--sidebar-w-collapsed);
}

/* Tooltip for collapsed nav links */
.sidebar-collapsed .nav-link { position: relative; }
.sidebar-collapsed .nav-link::after {
  content: attr(data-label);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%; transform: translateY(-50%);
  background: var(--surface2);
  color: var(--t1);
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: .78rem;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--trans-fast);
  z-index: 200;
  box-shadow: var(--elev-2);
}
.sidebar-collapsed .nav-link:hover::after { opacity: 1; }

/* ── Mobile Sidebar Drawer ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform var(--trans-base);
    z-index: 200;
  }
  .sidebar.open { transform: translateX(0); }
  .page { margin-left: 0 !important; }
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--ui-overlay);
    z-index: 199;
    backdrop-filter: blur(2px);
  }
  .sidebar.open ~ .sidebar-overlay { display: block; }
}

/* ── Scrollbar styling ───────────────────────────────────────────────────── */
::-webkit-scrollbar         { width: 6px; height: 6px; }
::-webkit-scrollbar-track   { background: transparent; }
::-webkit-scrollbar-thumb   { background: rgba(108,99,255,.3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(108,99,255,.5); }

/* ── Selection ───────────────────────────────────────────────────────────── */
::selection { background: rgba(124,58,237,.35); color: #fff; }

/* ── Focus visible ───────────────────────────────────────────────────────── */
:focus-visible { outline: 2px solid var(--violet); outline-offset: 2px; border-radius: 4px; }

/* ── Print ───────────────────────────────────────────────────────────────── */
@media print {
  .sidebar, .header, #bg-canvas, .hbtn, .nav-link, .sidebar-overlay { display: none !important; }
  .page { margin-left: 0 !important; }
  body  { background: white !important; color: black !important; }
  .glass { background: white !important; border: 1px solid #ccc !important; }
}
