/*
 * x99 design tokens — Opção B (Warmer + balanced)
 * Fonte canonical: docs/theme/conventions.md + ADR 0002 (copy conventions)
 *
 * Estratégia: :root contém tokens dark (default) + compartilhados (spacing,
 * radius, font, animation). :root[data-theme="light"] sobrescreve só cores
 * + shadows + glass.
 *
 * Consumo: zero hardcoded color/sp/radius/fs/shadow em CSS x99. Sempre
 * var(--c-*) / var(--sp-*) / var(--r-*) / var(--fs-*) / var(--sh-*).
 */

/* ==========================================================================
 * DEFAULTS (dark) + tokens compartilhados
 * ========================================================================== */
:root {
  /* ---- Cores base (dark) ---- */
  --c-bg-base: #0d0e11;
  --c-bg-elevated: #191b21;
  --c-surface: rgba(255, 255, 255, 0.035);
  --c-surface-hover: rgba(255, 255, 255, 0.065);
  --c-border: rgba(255, 255, 255, 0.08);
  --c-border-strong: rgba(255, 255, 255, 0.14);

  /* ---- Texto (dark) ---- */
  --c-text-primary: #f5f5f7;
  --c-text-secondary: rgba(245, 245, 247, 0.78);
  --c-text-muted: rgba(245, 245, 247, 0.50);
  --c-text-inverse: #0d0e11;

  /* ---- Accent + semantic (dark) ---- */
  --c-accent: #f87171;
  --c-accent-soft: rgba(248, 113, 113, 0.14);
  --c-accent-warm: #fca5a5;
  --c-success: #4ade80;
  --c-success-soft: rgba(74, 222, 128, 0.16);
  --c-warning: #fbbf24;
  --c-warning-soft: rgba(251, 191, 36, 0.16);
  --c-danger: #ef4444;
  --c-danger-soft: rgba(239, 68, 68, 0.16);
  --c-info: #60a5fa;
  --c-info-soft: rgba(96, 165, 250, 0.18);

  /* ---- Glass effects (dark) ---- */
  --glass-blur: blur(20px) saturate(160%);
  --glass-tint: rgba(15, 15, 17, 0.55);
  --glass-border: rgba(255, 255, 255, 0.08);

  /* ---- RGB channels (pra rgba() com alpha variável) ---- */
  /* Dark: texto branco sobre fundo escuro */
  --text-rgb: 255, 255, 255;
  --bg-rgb: 13, 14, 17;
  --accent-rgb: 248, 113, 113;
  --accent-warm-rgb: 252, 165, 165;
  --success-rgb: 74, 222, 128;
  --warning-rgb: 251, 191, 36;
  --danger-rgb: 239, 68, 68;
  --info-rgb: 96, 165, 250;

  /* ---- Shadows (dark) ---- */
  --sh-card: 0 2px 8px rgba(0, 0, 0, 0.35);
  --sh-card-hover: 0 4px 14px rgba(0, 0, 0, 0.45);
  --sh-sticky: 0 0 32px rgba(248, 113, 113, 0.22);
  --sh-modal: 0 10px 40px rgba(0, 0, 0, 0.60);
  --sh-focus: 0 0 0 3px rgba(248, 113, 113, 0.40);

  /* ==========================================================================
   * COMPARTILHADOS (dark + light) — spacing, radius, font, animation
   * ========================================================================== */

  /* ---- Tipografia ---- */
  --font-ui: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "Share Tech Mono", ui-monospace, Menlo, Consolas, monospace;
  --font-code: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Scale (px declarado pra clareza; em produção consumir via var) */
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-base: 13px;
  --fs-md: 15px;
  --fs-lg: 18px;
  --fs-xl: 22px;
  --fs-2xl: 28px;
  --fs-3xl: 36px;

  /* Line-heights (multipliers) */
  --lh-tight: 1.2;
  --lh-base: 1.4;
  --lh-loose: 1.5;
  --lh-looser: 1.55;

  /* Weights */
  --fw-normal: 400;
  --fw-medium: 500;
  --fw-semi: 600;
  --fw-bold: 700;
  --fw-extra: 800;

  /* Letter-spacing */
  --ls-tight: -0.01em;
  --ls-normal: 0;
  --ls-kicker: 0.08em;

  /* ---- Spacing scale ---- */
  --sp-0: 0;
  --sp-1: 4px;
  --sp-2: 6px;
  --sp-3: 8px;
  --sp-4: 10px;
  --sp-5: 12px;
  --sp-6: 16px;
  --sp-7: 20px;
  --sp-8: 24px;
  --sp-9: 32px;
  --sp-10: 48px;

  /* ---- Border radius ---- */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 12px;
  --r-xl: 14px;
  --r-2xl: 16px;
  --r-full: 999px;

  /* ---- Animation tokens ---- */
  --dur-fast: 150ms;
  --dur-base: 200ms;
  --dur-med: 300ms;
  --dur-slow: 600ms;
  --dur-enter: 400ms;

  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-in-out: cubic-bezier(0.45, 0, 0.55, 1);
  --ease-back: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-linear: linear;
}

/* ==========================================================================
 * LIGHT MODE — override colors + shadows + glass (ADR 0002)
 * ========================================================================== */
:root[data-theme="light"] {
  /* ---- Cores base ---- */
  --c-bg-base: #fafafb;
  --c-bg-elevated: #f6f7f9;                   /* Cards/sidebar flutuando */
  --c-surface: rgba(17, 24, 39, 0.05);        /* +contraste vs 0.035 */
  --c-surface-hover: rgba(17, 24, 39, 0.09);
  --c-border: rgba(17, 24, 39, 0.14);         /* +definição vs 0.10 */
  --c-border-strong: rgba(17, 24, 39, 0.22);

  /* ---- Texto (alto contraste sobre cinza) ---- */
  --c-text-primary: #111216;
  --c-text-secondary: rgba(17, 18, 22, 0.80);
  --c-text-muted: rgba(17, 18, 22, 0.56);
  --c-text-inverse: #f5f5f7;

  /* ---- Accent + semantic (soft mais saturado pra destacar no cinza) ---- */
  --c-accent: #dc2626;
  --c-accent-soft: rgba(220, 38, 38, 0.12);
  --c-accent-warm: #ef4444;
  --c-success: #16a34a;
  --c-success-soft: rgba(22, 163, 74, 0.14);
  --c-warning: #d97706;
  --c-warning-soft: rgba(217, 119, 6, 0.14);
  --c-danger: #dc2626;
  --c-danger-soft: rgba(220, 38, 38, 0.12);
  --c-info: #2563eb;
  --c-info-soft: rgba(37, 99, 235, 0.14);

  /* ---- Glass effects ---- */
  --glass-blur: blur(20px) saturate(130%);
  --glass-tint: rgba(246, 247, 249, 0.80);
  --glass-border: rgba(17, 24, 39, 0.14);

  /* ---- RGB channels (light: texto escuro sobre fundo cinza) ---- */
  --text-rgb: 17, 24, 39;
  --bg-rgb: 230, 232, 238;
  --accent-rgb: 220, 38, 38;
  --accent-warm-rgb: 239, 68, 68;
  --success-rgb: 22, 163, 74;
  --warning-rgb: 217, 119, 6;
  --danger-rgb: 220, 38, 38;
  --info-rgb: 37, 99, 235;

  /* ---- Shadows (light, mais visíveis pra distinguir elevação em cinza) ---- */
  --sh-card: 0 2px 6px rgba(17, 24, 39, 0.08), 0 1px 2px rgba(17, 24, 39, 0.05);
  --sh-card-hover: 0 6px 16px rgba(17, 24, 39, 0.12), 0 2px 4px rgba(17, 24, 39, 0.06);
  --sh-sticky: 0 0 24px rgba(220, 38, 38, 0.18);
  --sh-modal: 0 20px 48px rgba(17, 24, 39, 0.22);
  --sh-focus: 0 0 0 3px rgba(220, 38, 38, 0.30);
}

/* ==========================================================================
 * prefers-reduced-motion — respeita user setting
 * ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-fast: 0.01ms;
    --dur-base: 0.01ms;
    --dur-med: 0.01ms;
    --dur-slow: 0.01ms;
    --dur-enter: 0.01ms;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
