/*
 * Design tokens: type, elevation, spacing, radii, motion and the brand palette.
 * Docs: docs/design/tokens.md. The legacy --ap-color-* fallbacks in styles.css
 * track this palette.
 *
 * Two modes, one system. Dark is the default: deep slate/ink, rich and layered —
 * pure black reads as a terminal, not a boardroom. Light is warm paper with a
 * premium-fintech feel. The primary
 * accent is lagoon teal — distinctive, trustworthy, never generic blue.
 *
 * Color ramps (--ap-teal-*, --ap-emerald-*, --ap-amber-*, --ap-rose-*) are
 * mode-independent tonal scales (50 lightest → 950 darkest). Semantic tokens
 * (--ap-bg, --ap-ink, --ap-brand, …) are defined per mode below and reference
 * the ramps where it reads well. Every text/background pairing in this file
 * holds at least 4.5:1 contrast — see src/palette.test.ts.
 */
:root {
  --ap-font-body:
    var(--ap-font-loaded-body, Inter), ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    sans-serif;
  --ap-font-display:
    var(--ap-font-loaded-display, var(--ap-font-loaded-body, Inter)), ui-sans-serif, system-ui,
    -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Canonical home of --ap-font-sans (UN-2148): one definition, aliased to the body stack.
     Per-app local redefinitions are legacy; new code references the token file. */
  --ap-font-sans: var(--ap-font-body);

  --ap-text-xs: 0.75rem;
  --ap-text-sm: 0.875rem;
  --ap-text-md: 1rem;
  --ap-text-lg: 1.125rem;
  --ap-text-xl: 1.375rem;
  --ap-text-2xl: 1.75rem;
  --ap-text-3xl: 2.25rem;
  --ap-text-4xl: 3rem;
  --ap-leading-tight: 1.15;
  --ap-leading-snug: 1.35;
  --ap-leading-body: 1.55;
  --ap-tracking-caps: 0.08em;

  --ap-space-0: 0;
  --ap-space-1: 4px;
  --ap-space-2: 8px;
  --ap-space-3: 12px;
  --ap-space-4: 16px;
  --ap-space-5: 20px;
  --ap-space-6: 24px;
  --ap-space-8: 32px;
  --ap-space-10: 40px;
  --ap-space-12: 48px;
  --ap-space-16: 64px;
  --ap-tap: 44px;

  --ap-radius-xs: 6px;
  --ap-radius-sm: 8px;
  --ap-radius-md: 12px;
  --ap-radius-lg: 20px;
  --ap-radius-xl: 28px;
  --ap-radius-pill: 999px;

  --ap-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ap-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ap-dur-fast: 120ms;
  --ap-dur: 220ms;
  --ap-dur-slow: 450ms;

  /* ---- Ramps: mode-independent tonal scales, 50 (lightest) → 950 (darkest) ---- */
  --ap-teal-50: #f0fdfa;
  --ap-teal-100: #ccfbf1;
  --ap-teal-200: #99f6e4;
  --ap-teal-300: #5eead4;
  --ap-teal-400: #2dd4bf;
  --ap-teal-500: #14b8a6;
  --ap-teal-600: #0d9488;
  --ap-teal-700: #0f766e;
  --ap-teal-800: #115e59;
  --ap-teal-900: #134e4a;
  --ap-teal-950: #042f2e;

  --ap-emerald-50: #ecfdf5;
  --ap-emerald-100: #d1fae5;
  --ap-emerald-200: #a7f3d0;
  --ap-emerald-300: #6ee7b7;
  --ap-emerald-400: #34d399;
  --ap-emerald-500: #10b981;
  --ap-emerald-600: #059669;
  --ap-emerald-700: #047857;
  --ap-emerald-800: #065f46;
  --ap-emerald-900: #064e3b;
  --ap-emerald-950: #022c22;

  --ap-amber-50: #fffbeb;
  --ap-amber-100: #fef3c7;
  --ap-amber-200: #fde68a;
  --ap-amber-300: #fcd34d;
  --ap-amber-400: #fbbf24;
  --ap-amber-500: #f59e0b;
  --ap-amber-600: #d97706;
  --ap-amber-700: #b45309;
  --ap-amber-800: #92400e;
  --ap-amber-900: #78350f;
  --ap-amber-950: #451a03;

  --ap-rose-50: #fff1f2;
  --ap-rose-100: #ffe4e6;
  --ap-rose-200: #fecdd3;
  --ap-rose-300: #fda4af;
  --ap-rose-400: #fb7185;
  --ap-rose-500: #f43f5e;
  --ap-rose-600: #e11d48;
  --ap-rose-700: #be123c;
  --ap-rose-800: #9f1239;
  --ap-rose-900: #881337;
  --ap-rose-950: #4c0519;

  /* ---- Dark (default): deep slate/ink. Layered, never pure black. ---- */
  --ap-bg: #14161b;
  --ap-surface: #1c1f26;
  --ap-surface-2: #252932;
  --ap-surface-3: #30363f;
  --ap-line: #363d48;
  --ap-ink: #f4f2eb;
  --ap-ink-2: #b8b5a9;
  --ap-ink-3: #a3a096;
  /* Brand hooks: an app re-colours the accent by setting --app-brand-dark / -light (and
     the -strong / -soft / on- variants) on :root, never --ap-brand itself, so one plain
     :root rule wins in both modes. Fallbacks are lagoon teal. Docs: tokens.md. */
  --ap-brand: var(--app-brand-dark, #2ed3b7);
  --ap-brand-strong: var(--app-brand-strong-dark, #83f0db);
  --ap-brand-soft: var(--app-brand-soft-dark, rgba(46, 211, 183, 0.14));
  --ap-on-brand: var(--app-on-brand-dark, #052e2a);
  --ap-good: #34d399;
  --ap-good-strong: #6ee7b7;
  --ap-good-soft: rgba(52, 211, 153, 0.14);
  --ap-on-good: #06281d;
  --ap-warn: #fbbf24;
  --ap-warn-strong: #fcd34d;
  --ap-warn-soft: rgba(251, 191, 36, 0.14);
  --ap-on-warn: #3f1e02;
  --ap-bad: #fb7185;
  --ap-bad-strong: #fda4af;
  --ap-bad-soft: rgba(251, 113, 133, 0.14);
  --ap-on-bad: #4a0a1c;
  --ap-purple: #a371f7;
  --ap-purple-strong: #c68dff;
  --ap-purple-soft: rgba(163, 113, 247, 0.14);
  --ap-on-purple: #260a4d;

  --ap-shadow-0: none;
  --ap-shadow-1: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 1px 2px rgba(4, 6, 10, 0.5);
  --ap-shadow-2: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 8px 24px rgba(4, 6, 10, 0.5);
  --ap-shadow-3: 0 1px 0 rgba(255, 255, 255, 0.07) inset, 0 20px 48px rgba(4, 6, 10, 0.6);
  /* Derived from the accent, so a brand hook re-colours glow and focus ring too. */
  --ap-glow:
    0 0 0 1px var(--ap-brand-soft), 0 8px 28px color-mix(in srgb, var(--ap-brand) 22%, transparent);
  --ap-focus: 0 0 0 3px color-mix(in srgb, var(--ap-brand) 50%, transparent);
}

/* Light is warm paper, not stark white — premium fintech, Ramp/Mercury warmth. */
:root[data-theme="light"],
.ap-light {
  --ap-bg: #faf7f1;
  --ap-surface: #ffffff;
  --ap-surface-2: #f3efe6;
  --ap-surface-3: #e9e2d2;
  --ap-line: #e3d9c4;
  --ap-ink: #201d15;
  --ap-ink-2: #59544a;
  --ap-ink-3: #655f52;
  --ap-brand: var(--app-brand-light, #0c7a6e);
  --ap-brand-strong: var(--app-brand-strong-light, #095d55);
  --ap-brand-soft: var(--app-brand-soft-light, rgba(12, 122, 110, 0.12));
  --ap-on-brand: var(--app-on-brand-light, #ffffff);
  --ap-good: #047857;
  --ap-good-strong: #065f46;
  --ap-good-soft: rgba(4, 120, 87, 0.1);
  --ap-on-good: #ffffff;
  --ap-warn: #a64908;
  --ap-warn-strong: #92400e;
  --ap-warn-soft: rgba(166, 73, 8, 0.1);
  --ap-on-warn: #ffffff;
  --ap-bad: #ce1a45;
  --ap-bad-strong: #ad1437;
  --ap-bad-soft: rgba(206, 26, 69, 0.1);
  --ap-on-bad: #ffffff;
  --ap-purple: #8934b5;
  --ap-purple-strong: #6c258f;
  --ap-purple-soft: rgba(137, 52, 181, 0.12);
  --ap-on-purple: #ffffff;
  --ap-shadow-1: 0 1px 2px rgba(46, 38, 24, 0.07), 0 1px 1px rgba(46, 38, 24, 0.05);
  --ap-shadow-2: 0 6px 18px rgba(46, 38, 24, 0.09), 0 2px 4px rgba(46, 38, 24, 0.06);
  --ap-shadow-3: 0 18px 44px rgba(46, 38, 24, 0.15), 0 3px 8px rgba(46, 38, 24, 0.07);
  --ap-glow:
    0 0 0 1px var(--ap-brand-soft), 0 8px 24px color-mix(in srgb, var(--ap-brand) 18%, transparent);
  --ap-focus: 0 0 0 3px color-mix(in srgb, var(--ap-brand) 35%, transparent);
}

.ap-display {
  font-family: var(--ap-font-display);
  line-height: var(--ap-leading-tight);
  letter-spacing: -0.02em;
  font-weight: 700;
}
.ap-eyebrow {
  font-size: var(--ap-text-xs);
  text-transform: uppercase;
  letter-spacing: var(--ap-tracking-caps);
  color: var(--ap-ink-3);
  font-weight: 600;
}
.ap-card {
  background: var(--ap-surface);
  border: 1px solid var(--ap-line);
  border-radius: var(--ap-radius-lg);
  box-shadow: var(--ap-shadow-1);
  padding: var(--ap-space-4);
  transition:
    transform var(--ap-dur) var(--ap-ease),
    box-shadow var(--ap-dur) var(--ap-ease);
}
.ap-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--ap-shadow-2);
}
.ap-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--ap-space-1);
  min-height: 24px;
  padding: 0 var(--ap-space-3);
  border-radius: var(--ap-radius-pill);
  font-size: var(--ap-text-xs);
  font-weight: 600;
  background: var(--ap-brand-soft);
  color: var(--ap-brand-strong);
}
@media (prefers-reduced-motion: reduce) {
  .ap-card {
    transition: none;
  }
  .ap-card:hover {
    transform: none;
  }
}
