/* =============================================================================
 * QUARVO — Design Tokens
 * =============================================================================
 * Single source of truth for color, type, space, radius, elevation, motion.
 *
 * Two layers:
 *   1. Primitives — the raw ramps + fixed values. Never reference these
 *      from components; they are the palette, not the API.
 *   2. Semantic tokens — what components reference. These resolve per theme.
 *
 * Theme: dark is default (brand identity). Light theme uses the same names
 * with different values under [data-theme="light"]. No token exists in
 * only one theme.
 *
 * Contrast: every text/surface pair verified WCAG 2.1 AA (>=4.5:1 for
 * normal text, >=3:1 for large 18pt+/bold 14pt+ text and UI graphics).
 * Full contrast table in design-system/AUDIT.md.
 * ========================================================================== */

:root {
  /* ─────────────────────────────────────────────────────────────────────────
   * L1 · PRIMITIVES — ramps and raw values
   * These are the palette. Components should reference the semantic tokens
   * below, not these primitives directly.
   * ─────────────────────────────────────────────────────────────────────── */

  /* Brand · Violet ─ 11 steps generated from base #7B2FFF (step 500) */
  --violet-50:  #F4F1F9;
  --violet-100: #E8DFF6;
  --violet-200: #CDB4F9;
  --violet-300: #A676F9;
  --violet-400: #7E35FD;
  --violet-500: #7B2FFF;
  --violet-600: #5300E3;
  --violet-700: #3D00A6;
  --violet-800: #2C0178;
  --violet-900: #1C0348;
  --violet-950: #11032A;

  /* Brand · Cyan ─ 11 steps generated from base #00F5FF (step 500) */
  --cyan-50:   #F1F9F9;
  --cyan-100:  #DFF5F6;
  --cyan-200:  #B4F6F9;
  --cyan-300:  #76F4F9;
  --cyan-400:  #35F5FD;
  --cyan-500:  #00F5FF;
  --cyan-600:  #00B8BF;
  --cyan-700:  #00878C;
  --cyan-800:  #016165;
  --cyan-900:  #033B3D;
  --cyan-950:  #032223;

  /* Neutral · Gray ─ 11 steps generated from base #6A6A88 (step 500)
   * Cool-toned neutral, matches the deep-space aesthetic. */
  --gray-50:   #F4F4F6;
  --gray-100:  #E8E8ED;
  --gray-200:  #D2D2DA;
  --gray-300:  #AFAFC0;
  --gray-400:  #8D8DA5;
  --gray-500:  #6A6A88;
  --gray-600:  #4F4F66;
  --gray-700:  #3A3A4B;
  --gray-800:  #2B2B36;
  --gray-900:  #1B1B22;
  --gray-950:  #101014;

  /* Status · Success (mint) */
  --success-50:  #F1F9F6;
  --success-100: #DFF6EE;
  --success-200: #C0EDDC;
  --success-300: #8DE2C3;
  --success-400: #59D9AA;
  --success-500: #34D399;
  --success-600: #22A374;
  --success-700: #197855;
  --success-800: #13563E;
  --success-900: #0D3426;
  --success-950: #091F17;

  /* Status · Warning (amber) */
  --warning-50:  #F9F7F1;
  --warning-100: #F6F1DF;
  --warning-200: #F6E8B6;
  --warning-300: #F4DA7B;
  --warning-400: #F5CD3D;
  --warning-500: #F5C518;
  --warning-600: #C39A07;
  --warning-700: #8F7105;
  --warning-800: #665105;
  --warning-900: #3E3205;
  --warning-950: #241D04;

  /* Status · Danger (red) */
  --danger-50:  #F9F1F1;
  --danger-100: #F6DFDF;
  --danger-200: #F6B7B7;
  --danger-300: #F37C7C;
  --danger-400: #F43E3E;
  --danger-500: #F75454;
  --danger-600: #EF0909;
  --danger-700: #B00606;
  --danger-800: #7D0707;
  --danger-900: #4C0707;
  --danger-950: #2C0606;

  /* Status · Info (blue) */
  --info-50:  #F1F2F9;
  --info-100: #DFE4F6;
  --info-200: #B7C2F6;
  --info-300: #7C92F4;
  --info-400: #3E5FF4;
  --info-500: #4F6EF7;
  --info-600: #0832EC;
  --info-700: #0625AD;
  --info-800: #071C7C;
  --info-900: #07134B;
  --info-950: #050C2B;

  /* Competitor colors — used in comparison pages, one hue per rival.
   * These are product decisions, not theme tokens: keep exactly. */
  --brand-klarna:   #FFA8CD;
  --brand-affirm:   #4F6EF7;
  --brand-affirm-bright:   #7B93FF;
  --brand-afterpay: #B2FCE4;
  --brand-afterpay-bright: #00E599;
  --brand-splitit:  #F472B6;
  --brand-kasheesh: #34D399;

  /* Pure tokens for on-solid situations */
  --white: #FFFFFF;
  --black: #000000;


  /* ─────────────────────────────────────────────────────────────────────────
   * L2 · SEMANTIC · DARK THEME (default — Quarvo brand)
   * These are what components reference. Do not use L1 primitives directly.
   * ─────────────────────────────────────────────────────────────────────── */

  /* Surfaces (background elevation) */
  --bg:               #06060A;                    /* deepest — page ground */
  --surface:          #0E0E18;                    /* card, panel */
  --surface-raised:   #141428;                    /* raised card, modal */
  --surface-sunken:   #030308;                    /* input, sunken well */

  /* Borders */
  --border:           rgba(255, 255, 255, 0.08);  /* subtle divider */
  --border-strong:    rgba(255, 255, 255, 0.16);  /* focused / hover boundary */
  --border-brand:     rgba(123, 47, 255, 0.28);   /* violet-tinted boundary */
  --border-brand-strong: rgba(123, 47, 255, 0.55);

  /* Text (foreground) — verified vs bg (see AUDIT.md) */
  --fg:               #F0F0F8;                    /* body text — 17.84:1 AA ✓ */
  --fg-muted:         #9090B0;                    /* secondary — 6.55:1 AA ✓ */
  --fg-subtle:        #6A6A88;                    /* tertiary UI — 3.88:1 (large only) */
  --fg-on-accent:     #FFFFFF;                    /* text on violet/success fills */
  --fg-on-cyan:       #06060A;                    /* text on cyan fill (bright bg) */

  /* Brand tokens (surfaces & fills) */
  --brand:            var(--violet-500);          /* primary brand fill */
  --brand-hover:      var(--violet-400);
  --brand-active:     var(--violet-600);
  --brand-soft:       rgba(123, 47, 255, 0.12);   /* tinted background */
  --brand-text:       var(--violet-300);          /* link/text — 6.34:1 AA ✓ */

  --accent:           var(--cyan-500);            /* accent fill */
  --accent-hover:     var(--cyan-400);
  --accent-soft:      rgba(0, 245, 255, 0.10);
  --accent-text:      var(--cyan-500);            /* link/text — 14.93:1 AA ✓ */

  /* Status semantic tokens — resolve to shades that pass AA in this theme */
  --success:          var(--success-500);         /* fill */
  --success-text:     var(--success-400);         /* text on dark bg — 11.49:1 AA ✓ */
  --success-soft:     rgba(52, 211, 153, 0.10);
  --warning:          var(--warning-500);
  --warning-text:     var(--warning-500);         /* 12.41:1 AA ✓ */
  --warning-soft:     rgba(245, 197, 24, 0.10);
  --danger:           var(--danger-500);
  --danger-text:      var(--danger-500);          /* 6.12:1 AA ✓ */
  --danger-soft:      rgba(247, 84, 84, 0.10);
  --info:             var(--info-500);
  --info-text:        var(--info-500);            /* 4.73:1 AA ✓ text */
  --info-soft:        rgba(79, 110, 247, 0.10);

  /* Data semantics (fintech-specific — for cifras de mercado, NOT status).
   * Distinct from success/danger so a green "+2.4%" doesn't read as a
   * success toast, and a red "-1.8%" doesn't read as an error. */
  --positive:         var(--success-500);         /* revenue up, recovered */
  --negative:         #F97316;                    /* revenue down, declined — Tailwind orange-500, distinct from warning amber and from danger red */
  --neutral-data:     var(--gray-400);


  /* ─────────────────────────────────────────────────────────────────────────
   * TYPE (theme-agnostic)
   * ─────────────────────────────────────────────────────────────────────── */

  --font-display:     'Syne', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display-alt: 'Tomorrow', 'Syne', -apple-system, sans-serif;   /* geometric alt */
  --font-body:        'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:        'JetBrains Mono', 'DM Mono', ui-monospace, SFMono-Regular, monospace;

  /* Modular scale (ratio 1.25) — anchored on --fs-base = 16px */
  --fs-1:  0.6875rem;   /* 11px  — micro (labels, code hints) */
  --fs-2:  0.75rem;     /* 12px  — small (captions, meta) */
  --fs-3:  0.875rem;    /* 14px  — small body */
  --fs-4:  1rem;        /* 16px  — body */
  --fs-5:  1.125rem;    /* 18px  — lead body */
  --fs-6:  1.5rem;      /* 24px  — h4 / large lead */
  --fs-7:  1.875rem;    /* 30px  — h3 */
  --fs-8:  2.5rem;      /* 40px  — h2 */
  --fs-9:  clamp(3rem, 6vw, 4.75rem);   /* 48–76px — h1 / display */

  /* Line-heights */
  --lh-tight:   1.1;    /* display */
  --lh-heading: 1.25;   /* h1–h4 */
  --lh-body:    1.6;    /* prose */
  --lh-loose:   1.75;   /* long-read */

  /* Weights (only the ones we ship) */
  --fw-light:     300;
  --fw-regular:   400;
  --fw-medium:    500;
  --fw-bold:      700;
  --fw-black:     800;

  /* Optimal measure for long-form text (60–75ch) */
  --measure:      65ch;


  /* ─────────────────────────────────────────────────────────────────────────
   * SPACE (base-4, theme-agnostic)
   * Use for padding, margin, gap. Do not hard-code px values in components.
   * ─────────────────────────────────────────────────────────────────────── */

  --space-1:   4px;
  --space-2:   8px;
  --space-3:   12px;
  --space-4:   16px;
  --space-5:   20px;
  --space-6:   24px;
  --space-7:   32px;
  --space-8:   40px;
  --space-9:   48px;
  --space-10:  64px;
  --space-11:  80px;
  --space-12:  96px;
  --space-13:  128px;

  /* Container widths */
  --width-prose:    720px;    /* article max-width */
  --width-content:  1080px;   /* page max-width */
  --width-wide:     1280px;   /* hero, wide sections */


  /* ─────────────────────────────────────────────────────────────────────────
   * RADIUS (theme-agnostic)
   * ─────────────────────────────────────────────────────────────────────── */

  --radius-sm:   4px;      /* data cells, small chips */
  --radius:      8px;      /* input, small card */
  --radius-md:   12px;     /* card, button */
  --radius-lg:   20px;     /* modal, hero card */
  --radius-xl:   28px;     /* feature card */
  --radius-full: 9999px;   /* pill, avatar */


  /* ─────────────────────────────────────────────────────────────────────────
   * ELEVATION · shadows as semantic levels (1 = closest to surface, 5 = highest)
   * ─────────────────────────────────────────────────────────────────────── */

  --elevation-1: 0 1px 2px rgba(0, 0, 0, 0.3);
  --elevation-2: 0 4px 12px rgba(0, 0, 0, 0.35);
  --elevation-3: 0 12px 32px rgba(0, 0, 0, 0.45);
  --elevation-4: 0 24px 64px rgba(0, 0, 0, 0.55);
  --elevation-5: 0 40px 96px rgba(0, 0, 0, 0.65);

  /* Brand glows — decorative only, not for elevation */
  --glow-violet: 0 0 40px rgba(123, 47, 255, 0.25);
  --glow-cyan:   0 0 40px rgba(0, 245, 255, 0.15);


  /* ─────────────────────────────────────────────────────────────────────────
   * MOTION — durations + easings named by intent (per ui-animation skill)
   * ─────────────────────────────────────────────────────────────────────── */

  --ease-enter:    cubic-bezier(0.22, 1, 0.36, 1);   /* entrances, hover, transform */
  --ease-move:     cubic-bezier(0.25, 1, 0.5, 1);    /* slides, drawers */
  --ease-drawer:   cubic-bezier(0.32, 0.72, 0, 1);   /* iOS-like sheet */
  --ease-exit:     cubic-bezier(0.4, 0, 1, 1);       /* fast exits */

  --t-press:       140ms;   /* button/tap feedback */
  --t-tooltip:     180ms;   /* tooltip, small popover */
  --t-dropdown:    220ms;   /* dropdown, select */
  --t-hover:       200ms;   /* hover state */
  --t-move:        260ms;   /* slide, translate */
  --t-modal:       320ms;   /* modal, drawer */
  --t-marketing:   800ms;   /* illustrative reveal */

  /* Focus ring — same across themes */
  --focus-ring:    0 0 0 3px rgba(123, 47, 255, 0.55);
  --focus-ring-cyan: 0 0 0 3px rgba(0, 245, 255, 0.55);

  /* Interaction sizes */
  --tap-target: 44px;     /* WCAG 2.1 minimum for touch */

  /* Root colour-scheme hint for form controls */
  color-scheme: dark;
}


/* =============================================================================
 * LIGHT THEME — same semantic names, different values
 * Enabled via <html data-theme="light"> or prefers-color-scheme: light on the
 * root. Quarvo default stays dark; light exists for admin/dashboard surfaces
 * and for users who explicitly opt in.
 * ========================================================================== */

:root[data-theme="light"] {
  /* Surfaces */
  --bg:               #FAFAFB;
  --surface:          #FFFFFF;
  --surface-raised:   #FFFFFF;
  --surface-sunken:   #F1F1F5;

  /* Borders */
  --border:           rgba(10, 10, 18, 0.08);
  --border-strong:    rgba(10, 10, 18, 0.18);
  --border-brand:     rgba(83, 0, 227, 0.25);
  --border-brand-strong: rgba(83, 0, 227, 0.55);

  /* Text */
  --fg:               #0A0A12;                    /* 18.90:1 AA ✓ */
  --fg-muted:         #55556A;                    /* 6.96:1 AA ✓ */
  --fg-subtle:        #7A7A94;                    /* 4.00:1 (large only) */
  --fg-on-accent:     #FFFFFF;                    /* text on violet fills */
  --fg-on-cyan:       #06060A;                    /* text on cyan fill */

  /* Brand tokens */
  --brand:            var(--violet-600);          /* darker step for light bg */
  --brand-hover:      var(--violet-700);
  --brand-active:     var(--violet-800);
  --brand-soft:       rgba(83, 0, 227, 0.06);
  --brand-text:       var(--violet-700);          /* 11.51:1 AA ✓ */

  --accent:           var(--cyan-700);
  --accent-hover:     var(--cyan-800);
  --accent-soft:      rgba(0, 135, 140, 0.06);
  --accent-text:      var(--cyan-800);            /* 4.16:1 large text */

  /* Status */
  --success:          var(--success-600);
  --success-text:     var(--success-700);         /* 5.22:1 AA ✓ */
  --success-soft:     rgba(34, 163, 116, 0.06);
  --warning:          var(--warning-600);
  --warning-text:     var(--warning-700);
  --warning-soft:     rgba(195, 154, 7, 0.06);
  --danger:           var(--danger-600);
  --danger-text:      var(--danger-700);          /* darker for light bg */
  --danger-soft:      rgba(239, 9, 9, 0.06);
  --info:             var(--info-600);
  --info-text:        var(--info-600);            /* 7.52:1 AA ✓ */
  --info-soft:        rgba(8, 50, 236, 0.06);

  /* Data — same intent, resolves to shades that pass on light */
  --positive:         var(--success-600);
  --negative:         #C2410C;                    /* Tailwind orange-700 — darker for light bg */
  --neutral-data:     var(--gray-500);

  /* Shadow scale — softer on light theme */
  --elevation-1: 0 1px 2px rgba(10, 10, 18, 0.06);
  --elevation-2: 0 4px 12px rgba(10, 10, 18, 0.08);
  --elevation-3: 0 12px 32px rgba(10, 10, 18, 0.12);
  --elevation-4: 0 24px 64px rgba(10, 10, 18, 0.16);
  --elevation-5: 0 40px 96px rgba(10, 10, 18, 0.20);

  color-scheme: light;
}


/* =============================================================================
 * MOTION SAFETY — respect user preference
 * ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  :root {
    --t-press:     0ms;
    --t-tooltip:   0ms;
    --t-dropdown:  0ms;
    --t-hover:     0ms;
    --t-move:      0ms;
    --t-modal:     0ms;
    --t-marketing: 0ms;
  }
  /* Also disable long CSS animations — keep only essential feedback */
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}


/* =============================================================================
 * FOCUS-VISIBLE utility — required on every interactive component
 * ========================================================================== */

.focus-ring:focus-visible,
:where(a, button, [role="button"], input, select, textarea, [tabindex="0"]):focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}
