/* ==========================================================================
   Anoven — Colors & Type
   Single source of truth for CSS variables.
   --------------------------------------------------------------------------
   Marketing #423 interim palette — warm paper + terracotta.
   - Light is the default (marketing surfaces convert better light, 2026).
   - Dark via @media (prefers-color-scheme: dark) AND via [data-theme] override
     so consumers can switch manually too.
   - Token names: NEW canonical (--bg-base / --bg-surface / --bg-elevated,
     --fg-primary / --fg-secondary / --fg-muted, --border-subtle / --border-strong)
     are the source of truth. Legacy names (--bg-0..4, --fg-1..5, --border)
     are kept as aliases so existing callers don't break — DEPRECATED, migrate.
   - This is an INTERIM palette. Definitive identity v1 (custom letterforms,
     full brand kit) lands in 2–3 weeks. Do NOT iterate intermediate versions.
   ========================================================================== */

/* ───── Webfonts ─────────────────────────────────────────────────────── */
@font-face {
  font-family: "Inter";
  src: url("fonts/Inter-Regular.ttf") format("truetype");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("fonts/Inter-Medium.ttf") format("truetype");
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("fonts/Inter-SemiBold.ttf") format("truetype");
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("fonts/Inter-Bold.ttf") format("truetype");
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/JetBrainsMono-Regular.ttf") format("truetype");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/JetBrainsMono-Medium.ttf") format("truetype");
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/JetBrainsMono-Bold.ttf") format("truetype");
  font-weight: 700; font-style: normal; font-display: swap;
}

:root {
  /* ───── NEW canonical surface tokens (Marketing #423) — warm paper ───── */
  --bg-base:       #faf8f5;   /* page canvas */
  --bg-surface:    #f3efe8;   /* sidebar / section / sunken */
  --bg-elevated:   #ffffff;   /* cards, modals, login box, message bubble */
  --fg-primary:    #1a1815;   /* primary text */
  --fg-secondary:  #57534e;   /* secondary text, button-on-paper */
  --fg-muted:      #6f6a62;   /* muted body / placeholder / hint / eyebrow */
  --border-subtle: #e8e3da;   /* default border, app-wide */
  --border-strong: #d6cfc2;   /* hovered / elevated border */

  /* ───── Brand & semantic accents — terracotta primary ───── */
  --accent:           #c2410c;   /* primary brand terracotta — buttons, focus */
  --accent-hover:     #9a330a;
  --success:          #4d7c0f;   /* "Nuevo", progress complete */
  --success-hover:    #3f6710;
  --warning:          #b45309;   /* tool output, low-balance */
  --warning-fg:       #92400e;   /* bold/highlight inside assistant text */
  --danger:           #b91c1c;   /* error, insufficient balance */
  --danger-fg:        #991b1b;
  --danger-bg:        #fee2e2;   /* error surface fill (light) */
  --danger-border:    #fca5a5;

  /* Soft accent (user message bubble background) — light terracotta tint */
  --accent-soft:      #fbe9d8;
  --accent-soft-fg:   #7c2d12;
  --accent-link:      #c2410c;   /* links match accent in light */

  /* ───── Legacy surface aliases (DEPRECATED — migrate to --bg-*/--fg-*) ───── */
  --bg-deep:      var(--bg-base);
  --bg-0:         var(--bg-base);
  --bg-1:         var(--bg-surface);
  --bg-2:         var(--bg-elevated);
  --bg-3:         var(--bg-surface);
  --bg-4:         var(--border-subtle);
  --bg-code:      var(--bg-surface);
  --border:        var(--border-subtle);
  --border-muted:  var(--border-strong);
  --fg-1:          var(--fg-primary);
  --fg-2:          var(--fg-secondary);
  --fg-3:          var(--fg-muted);
  --fg-4:          var(--fg-muted);
  --fg-5:          var(--fg-muted);
  --fg-on-accent:  #ffffff;

  /* ───── Type families ───── */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Code", "SFMono-Regular", Menlo, monospace;

  /* ───── Type scale (px) — 12 px is the floor (WCAG AA). ───── */
  /* --fs-11 is deprecated; kept only so legacy refs don't 404. Do not use. */
  --fs-11: 12px;   /* DEPRECATED → 12 (alias). Migrate callers to --fs-12. */
  --fs-12: 12px;   /* eyebrow / hint / tag — the system floor */
  --fs-13: 13px;   /* meta, secondary */
  --fs-14: 14px;   /* default body small */
  --fs-15: 15px;   /* base body */
  --fs-16: 16px;
  --fs-18: 18px;   /* brand wordmark in topbar */
  --fs-20: 20px;   /* modal heading */
  --fs-26: 26px;   /* welcome H1 */
  --fs-28: 28px;   /* login H1 */

  /* ───── Marketing display scale (px) ───── */
  /* Used on anoven.ai landing surfaces only. NOT in-product. */
  --fs-mkt-h2:        28px;  /* section H2 */
  --fs-mkt-h1-mobile: 32px;  /* section H1, mobile */
  --fs-mkt-h1:        40px;  /* section H1, desktop & hero mobile */
  --fs-mkt-hero:      64px;  /* hero, desktop */

  /* ───── Weights ───── */
  --w-regular:  400;
  --w-medium:   500;
  --w-semibold: 600;
  --w-bold:     700;

  /* ───── Letter spacing ───── */
  --ls-tight:    -0.5px;   /* large display */
  --ls-snug:     -0.4px;
  --ls-base:     -0.3px;   /* topbar brand */
  --ls-wide:     0.4px;    /* uppercase meta */
  --ls-wider:    0.5px;    /* sidebar / progress headers */

  /* ───── Line heights ───── */
  --lh-tight:    1.2;
  --lh-snug:     1.4;
  --lh-base:     1.5;     /* body default */
  --lh-loose:    1.6;     /* dense paragraph */

  /* ───── Radii ───── */
  /* Marketing #423: 9-step scale paired with sizing system (sm/md/lg). */
  --radius-0:    0px;
  --radius-1:    2px;     /* barely rounded — dense chips/badges */
  --radius-2:    4px;     /* sm components — buttons sm, inputs sm, cards sm */
  --radius-3:    6px;     /* md components — buttons md, inputs md */
  --radius-4:    8px;     /* cards md, message bubbles */
  --radius-5:    12px;    /* lg components, badges, login box */
  --radius-6:    16px;    /* feature cards lg, hero containers */
  --radius-7:    24px;    /* empty-state, hero panels, image containers */
  --radius-full: 9999px;  /* avatars, pills, toggles */

  /* ───── Legacy radii (DEPRECATED). ─────
     Aliased to the new scale; migrate. */
  --radius-xs:    2px;    /* DEPRECATED → --radius-1 (was 3) */
  --radius-sm:    4px;    /* DEPRECATED → --radius-2 */
  --radius-md:    6px;    /* DEPRECATED → --radius-3 */
  --radius-lg:    8px;    /* DEPRECATED → --radius-4 */
  --radius-xl:    8px;    /* DEPRECATED → --radius-4 (was 10, not in scale) */
  --radius-2xl:   12px;   /* DEPRECATED → --radius-5 */
  --radius-3xl:   16px;   /* DEPRECATED → --radius-6 (was 14, not in scale) */
  --radius-pill:  9999px; /* DEPRECATED → --radius-full */

  /* ───── Spacing scale (px) — Tailwind-style, atom=4px. ───── */
  /* Marketing #423: everything builds in multiples of 4. */
  /* Exception: button md horizontal padding is 14px for optical balance — */
  /* the ONLY tolerated non-multiple in the system. Documented in README §2.3. */
  --space-0:  0px;
  --space-1:  4px;     /* atom */
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;    /* rhythm base — paragraph spacing */
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-9:  36px;    /* heading top margin after paragraph 24 — vertical rhythm step */
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;
  --space-24: 96px;
  --space-32: 128px;   /* max — large section dividers */

  /* ───── Legacy spacing tokens (DEPRECATED). ─────
     Keep aliased to the new scale so existing callers don't 404. Migrate. */
  --sp-1:  2px;        /* DEPRECATED → not a system multiple; do not use */
  --sp-2:  4px;        /* DEPRECATED → --space-1 */
  --sp-3:  6px;        /* DEPRECATED → not a system multiple; do not use */
  --sp-4:  8px;        /* DEPRECATED → --space-2 */
  --sp-5:  10px;       /* DEPRECATED → not a system multiple; do not use */
  --sp-6:  12px;       /* DEPRECATED → --space-3 */
  --sp-7:  14px;       /* DEPRECATED → only allowed inside button md */
  --sp-8:  16px;       /* DEPRECATED → --space-4 */
  --sp-9:  20px;       /* DEPRECATED → --space-5 */
  --sp-10: 24px;       /* DEPRECATED → --space-6 */
  --sp-11: 28px;       /* DEPRECATED → not a system multiple; do not use */
  --sp-12: 32px;       /* DEPRECATED → --space-8 */
  --sp-13: 36px;       /* DEPRECATED → not a system multiple; do not use */
  --sp-14: 40px;       /* DEPRECATED → --space-10 */

  /* ───── Shadows — light theme (terracotta-tinted, soft) ───── */
  --shadow-sm:   0 1px 2px  rgba(26, 24, 21, 0.06);
  --shadow-md:   0 4px 12px rgba(26, 24, 21, 0.08);
  --shadow-lg:   0 8px 24px rgba(26, 24, 21, 0.10);
  --shadow-xl:   0 16px 40px rgba(26, 24, 21, 0.12);
  --shadow-2xl:  0 24px 60px rgba(26, 24, 21, 0.16);
  --shadow-aside:-4px 0 20px rgba(26, 24, 21, 0.12);

  /* ───── Motion ───── */
  /* Marketing #423: 4 durations + 4 easings. Editorial restraint, not Material spring. */
  --duration-instant: 0ms;
  --duration-fast:    100ms;   /* hover, focus, color, border */
  --duration-base:    200ms;   /* fade, slide, tab/state change */
  --duration-slow:    400ms;   /* modal enter, drawer slide */

  --ease-linear:  cubic-bezier(0, 0, 1, 1);          /* progress + spinners only */
  --ease-out:     cubic-bezier(0.16, 1, 0.3, 1);     /* elements ENTERING view */
  --ease-in:      cubic-bezier(0.7, 0, 0.84, 0);     /* elements LEAVING view */
  --ease-in-out:  cubic-bezier(0.65, 0, 0.35, 1);    /* stationary state changes */

  /* ───── Legacy motion tokens (DEPRECATED). ───── */
  --ease-base:   cubic-bezier(0.4, 0, 0.2, 1);  /* DEPRECATED → --ease-in-out */
  --dur-instant: 100ms;                          /* DEPRECATED → --duration-fast */
  --dur-fast:    150ms;                          /* DEPRECATED → --duration-fast (100) */
  --dur-base:    300ms;                          /* DEPRECATED → --duration-base (200) */

  /* ───── Breakpoints (px) — Tailwind-aligned, mobile-first ───── */
  /* Marketing #423: 4 breakpoints, no bp-2xl. Design must feel complete at xl. */
  --bp-sm: 640px;   /* mobile landscape, small tablets */
  --bp-md: 768px;   /* tablets portrait */
  --bp-lg: 1024px;  /* tablets landscape, small laptops */
  --bp-xl: 1280px;  /* desktop standard */

  /* ───── Container max-widths ───── */
  --container-narrow: 640px;   /* reading, single-column, login */
  --container-base:   1024px;  /* standard app, sidebar + main */
  --container-wide:   1280px;  /* landing hero, marketing */
  --container-full:   100%;    /* full-bleed sections with bg */
}

/* ==========================================================================
   Dark mode — applied when user has prefers-color-scheme: dark OR when a
   parent element carries [data-theme="dark"] (manual toggle).
   Warm-paper inverted to warm-charcoal. Terracotta brightens for contrast.
   ========================================================================== */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-base:       #1a1815;
    --bg-surface:    #28241f;
    --bg-elevated:   #3a342d;
    --fg-primary:    #faf8f5;
    --fg-secondary:  #c2bcb0;
    --fg-muted:      #8a857c;
    --border-subtle: #3a342d;
    --border-strong: #57534e;

    --accent:           #e85d2c;
    --accent-hover:     #f47a4d;
    --accent-soft:      #4a2415;   /* dark terracotta tint for user bubble bg */
    --accent-soft-fg:   #fbe9d8;
    --accent-link:      #f47a4d;

    --success:          #84cc16;
    --success-hover:    #65a30d;
    --warning:          #d97706;
    --warning-fg:       #fbbf24;
    --danger:           #ef4444;
    --danger-fg:        #fca5a5;
    --danger-bg:        #4a1818;
    --danger-border:    #7f1d1d;

    /* Shadow ladder darkens too — dark theme can carry deeper drops. */
    --shadow-sm:   0 1px 2px  rgba(0, 0, 0, 0.30);
    --shadow-md:   0 4px 12px rgba(0, 0, 0, 0.40);
    --shadow-lg:   0 8px 24px rgba(0, 0, 0, 0.50);
    --shadow-xl:   0 16px 40px rgba(0, 0, 0, 0.60);
    --shadow-2xl:  0 24px 60px rgba(0, 0, 0, 0.65);
    --shadow-aside:-4px 0 20px rgba(0, 0, 0, 0.50);
  }
}

/* Manual dark override — same values, no media query gate. */
[data-theme="dark"] {
  --bg-base:       #1a1815;
  --bg-surface:    #28241f;
  --bg-elevated:   #3a342d;
  --fg-primary:    #faf8f5;
  --fg-secondary:  #c2bcb0;
  --fg-muted:      #8a857c;
  --border-subtle: #3a342d;
  --border-strong: #57534e;

  --accent:           #e85d2c;
  --accent-hover:     #f47a4d;
  --accent-soft:      #4a2415;
  --accent-soft-fg:   #fbe9d8;
  --accent-link:      #f47a4d;

  --success:          #84cc16;
  --success-hover:    #65a30d;
  --warning:          #d97706;
  --warning-fg:       #fbbf24;
  --danger:           #ef4444;
  --danger-fg:        #fca5a5;
  --danger-bg:        #4a1818;
  --danger-border:    #7f1d1d;

  --shadow-sm:   0 1px 2px  rgba(0, 0, 0, 0.30);
  --shadow-md:   0 4px 12px rgba(0, 0, 0, 0.40);
  --shadow-lg:   0 8px 24px rgba(0, 0, 0, 0.50);
  --shadow-xl:   0 16px 40px rgba(0, 0, 0, 0.60);
  --shadow-2xl:  0 24px 60px rgba(0, 0, 0, 0.65);
  --shadow-aside:-4px 0 20px rgba(0, 0, 0, 0.50);
}

/* Manual light override (overrides prefers-color-scheme: dark when user picks light). */
[data-theme="light"] {
  --bg-base:       #faf8f5;
  --bg-surface:    #f3efe8;
  --bg-elevated:   #ffffff;
  --fg-primary:    #1a1815;
  --fg-secondary:  #57534e;
  --fg-muted:      #8a857c;
  --border-subtle: #e8e3da;
  --border-strong: #d6cfc2;

  --accent:           #c2410c;
  --accent-hover:     #9a330a;
  --accent-soft:      #fbe9d8;
  --accent-soft-fg:   #7c2d12;
  --accent-link:      #c2410c;

  --success:          #4d7c0f;
  --success-hover:    #3f6710;
  --warning:          #b45309;
  --warning-fg:       #92400e;
  --danger:           #b91c1c;
  --danger-fg:        #991b1b;
  --danger-bg:        #fee2e2;
  --danger-border:    #fca5a5;
}

/* ==========================================================================
   prefers-reduced-motion — WCAG 2.3.3. Non-negotiable; some users with
   vestibular disorders get motion-sick from UI animation. We collapse all
   transitions and animations to a single frame, and turn off smooth scroll.
   Loading spinners survive because they carry meaning, not decoration.
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  /* Spinners are functional — keep them spinning, but slower so they feel
     less twitchy for users who opted into reduced motion. */
  [data-anoven-spinner], .anoven-spinner {
    animation-duration: 1400ms !important;
    animation-iteration-count: infinite !important;
  }
}

/* ==========================================================================
   Semantic element styles — use these vars (or apply these classes) directly.
   ========================================================================== */

html, body { background: var(--bg-0); color: var(--fg-1); }
body {
  font-family: var(--font-sans);
  font-size: var(--fs-15);
  line-height: var(--lh-base);
  -webkit-font-smoothing: antialiased;
}

/* Headings */
.h-display, h1 {
  font-family: var(--font-sans);
  font-weight: var(--w-bold);
  font-size: var(--fs-28);
  letter-spacing: var(--ls-tight);
  line-height: var(--lh-tight);
  color: var(--fg-1);
}
.h-1 {
  font-weight: var(--w-bold);
  font-size: var(--fs-26);
  letter-spacing: var(--ls-snug);
  line-height: var(--lh-tight);
}
.h-2, h2 {
  font-weight: var(--w-semibold);
  font-size: var(--fs-20);
  letter-spacing: var(--ls-base);
  line-height: var(--lh-snug);
}
.h-3, h3 {
  font-weight: var(--w-semibold);
  font-size: var(--fs-18);
  letter-spacing: var(--ls-base);
}

/* "Eyebrow" — uppercase meta labels used in sidebars, progress, meta rows.
   Note: bumped to 12 px to clear WCAG AA per Marketing #423. */
.eyebrow {
  font-size: var(--fs-12);
  font-weight: var(--w-semibold);
  text-transform: uppercase;
  letter-spacing: var(--ls-wider);
  color: var(--fg-5);
}

/* Body copy */
.body, p {
  font-size: var(--fs-14);
  line-height: var(--lh-loose);
  color: var(--fg-3);
}
.body-strong {
  color: var(--fg-1);
  font-weight: var(--w-medium);
}
.caption, small {
  font-size: var(--fs-13);
  color: var(--fg-3);
}
.hint {
  font-size: var(--fs-12);
  color: var(--fg-5);
}

/* Code / tool output */
code, .code-inline {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-code);
  color: var(--accent-link);
  padding: 1px 5px;
  border-radius: var(--radius-xs);
}
pre, .code-block {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg-code);
  color: var(--fg-1);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  overflow-x: auto;
}
.mono {
  font-family: var(--font-mono);
  font-feature-settings: "ss01", "cv11";   /* JetBrains stylistic alts */
}

/* Links */
a {
  color: var(--accent-link);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* Focus ring (single, consistent) */
:where(button, input, textarea, select, a):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}
