/* ================================================================
   base.css — design tokens, reset, typography, global defaults
   ================================================================
   Foundation layer. Every other stylesheet reads from these tokens.

   Design principles:
     - Light theme default (dark is the override)
     - Inter for UI text, Manrope for headings
     - No borders on surfaces — separation is background shade only
     - 1px focus outline on interactive elements (accessibility)
     - Phone-first typography — 13px base scales up at 768px
     - Muted accent (#4a7edb) — cold, professional, not saturated
     - Dark theme: near-black canvas, muted light-gray text, no glow
     - Colored text limited to profit/loss and parity even/odd

   Font links required in every HTML <head>:
     <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Manrope:wght@600;700;800&display=swap" rel="stylesheet">
   ================================================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ----------------------------------------------------------------
   Light theme (default)
   ---------------------------------------------------------------- */

:root {
  color-scheme: light;

  /* Surfaces */
  --bg-base: #f5f7fa;
  --bg-surface: #ffffff;
  --bg-elevated: #eef2f7;
  --bg-input: #f8fafc;
  --bg-subtle: #e8ecf2;

  /* Text — cool grays, not pure black */
  --text-primary: #0d1520;
  --text-secondary: #5a6b80;
  --text-muted: #8a97a8;
  --text-subtle: #b8c1ce;

  /* Accent — muted blue (default) */
  --accent: #4a7edb;
  --accent-hover: #3d6fc7;
  --accent-active: #335fb0;
  --accent-fg: #ffffff;
  --accent-subtle: rgba(74, 126, 219, 0.10);

  /* Semantic — profit/loss/warning only */
  --profit: #16a34a;
  --profit-subtle: rgba(22, 163, 74, 0.10);
  --loss: #dc2626;
  --loss-subtle: rgba(220, 38, 38, 0.10);
  --warning: #d97706;
  --warning-subtle: rgba(217, 119, 6, 0.10);

  /* Separators (used for divider lines inside surfaces, not for borders) */
  --divider: rgba(13, 21, 32, 0.06);
  --divider-strong: rgba(13, 21, 32, 0.12);

  /* Shadows — soft, diffuse, no harsh edges */
  --shadow-sm: 0 1px 2px rgba(13, 21, 32, 0.04);
  --shadow-md: 0 4px 12px rgba(13, 21, 32, 0.06);
  --shadow-float: 0 12px 32px rgba(13, 21, 32, 0.10);

  /* Typography */
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Manrope', 'Inter', system-ui, sans-serif;
  /* compat shim — legacy files reference --font-mono. Inter renders
     with tabular figures via font-feature-settings, so numeric
     alignment is preserved. This token stays until every legacy
     usage is removed across batches 2-12, then it is simply unused. */
  --font-mono: 'Inter', ui-monospace, 'SF Mono', monospace;

  /* Font size scale — phone-first, bumped at 768px */
  --text-2xs: 0.625rem;   /* 10px */
  --text-xs: 0.6875rem;   /* 11px */
  --text-sm: 0.75rem;     /* 12px */
  --text-base: 0.8125rem; /* 13px */
  --text-md: 0.875rem;    /* 14px */
  --text-lg: 1rem;        /* 16px */
  --text-xl: 1.125rem;    /* 18px */
  --text-2xl: 1.375rem;   /* 22px */
  --text-3xl: 1.75rem;    /* 28px */
  --text-4xl: 2.25rem;    /* 36px */

  /* Line heights */
  --leading-tight: 1.2;
  --leading-snug: 1.35;
  --leading-base: 1.5;
  --leading-relaxed: 1.65;

  /* Weights */
  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;
  --weight-extrabold: 800;

  /* Radii — tighter scale, soft via smooth corners */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --radius-xl: 12px;
  --radius-2xl: 14px;
  --radius-full: 9999px;

  /* Spacing — 4px base */
  --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;

  /* Layout — phone-first */
  --header-height: 56px;
  --sidebar-width: 232px;

  /* Motion — no overshoot, no bounce */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --duration-fast: 120ms;
  --duration-base: 180ms;
  --duration-slow: 240ms;

  /* Focus — 1px outline, 2px offset for accessibility */
  --focus-ring-width: 1px;
  --focus-ring-offset: 2px;
}

/* ----------------------------------------------------------------
   Dark theme — near-black canvas, muted text, no glow
   ---------------------------------------------------------------- */

[data-theme='dark'] {
  color-scheme: dark;

  --bg-base: #000000;
  --bg-surface: #0a0b0d;
  --bg-elevated: #14161a;
  --bg-input: #0d0f12;
  --bg-subtle: #050608;

  --text-primary: #d6dae0;
  --text-secondary: #8a939f;
  --text-muted: #5a6270;
  --text-subtle: #3d4450;

  --accent: #4a7edb;
  --accent-hover: #5a8de3;
  --accent-active: #3d6fc7;
  --accent-subtle: rgba(74, 126, 219, 0.16);

  --profit: #22c55e;
  --profit-subtle: rgba(34, 197, 94, 0.12);
  --loss: #ef4444;
  --loss-subtle: rgba(239, 68, 68, 0.12);
  --warning: #f59e0b;
  --warning-subtle: rgba(245, 158, 11, 0.12);

  --divider: rgba(255, 255, 255, 0.05);
  --divider-strong: rgba(255, 255, 255, 0.09);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-float: 0 12px 32px rgba(0, 0, 0, 0.6);
}

/* ----------------------------------------------------------------
   Accent palettes — 4 colors × 2 themes
   ----------------------------------------------------------------
   Blue is defined in :root and [data-theme='dark']. Teal, slate,
   and rose are overrides. Light variants are darker (contrast on
   white). Dark variants are slightly lighter (contrast on black).
   ---------------------------------------------------------------- */

[data-accent='teal'] {
  --accent: #2d8a8a;
  --accent-hover: #237777;
  --accent-active: #1b6464;
  --accent-subtle: rgba(45, 138, 138, 0.10);
}

[data-theme='dark'][data-accent='teal'] {
  --accent: #3a9fa0;
  --accent-hover: #48b1b2;
  --accent-active: #2d8485;
  --accent-subtle: rgba(58, 159, 160, 0.16);
}

[data-accent='slate'] {
  --accent: #6b7a8c;
  --accent-hover: #566778;
  --accent-active: #475667;
  --accent-subtle: rgba(107, 122, 140, 0.10);
}

[data-theme='dark'][data-accent='slate'] {
  --accent: #8c9aab;
  --accent-hover: #9dabba;
  --accent-active: #7a889a;
  --accent-subtle: rgba(140, 154, 171, 0.16);
}

[data-accent='rose'] {
  --accent: #c94b6d;
  --accent-hover: #b03e5d;
  --accent-active: #983450;
  --accent-subtle: rgba(201, 75, 109, 0.10);
}

[data-theme='dark'][data-accent='rose'] {
  --accent: #d85f7e;
  --accent-hover: #e37390;
  --accent-active: #c94b6d;
  --accent-subtle: rgba(216, 95, 126, 0.16);
}

/* ----------------------------------------------------------------
   Phone-first type scale — bump at tablet/desktop
   ---------------------------------------------------------------- */

@media (min-width: 768px) {
  :root {
    --text-base: 0.875rem; /* 14px */
    --text-md: 0.9375rem;  /* 15px */
    --header-height: 64px;
    --sidebar-width: 240px;
  }
}

/* ----------------------------------------------------------------
   Document
   ---------------------------------------------------------------- */

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--leading-base);
  font-weight: var(--weight-normal);
  color: var(--text-primary);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
  text-rendering: optimizeLegibility;
  transition:
    background-color var(--duration-base) var(--ease),
    color var(--duration-base) var(--ease);
}

/* ----------------------------------------------------------------
   Typography — Manrope headings, Inter body
   ---------------------------------------------------------------- */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: var(--leading-tight);
}

h1 {
  font-size: var(--text-2xl);
  font-weight: var(--weight-extrabold);
}

h2 {
  font-size: var(--text-xl);
  line-height: var(--leading-snug);
}

h3 {
  font-size: var(--text-lg);
  line-height: var(--leading-snug);
}

h4 {
  font-size: var(--text-md);
  line-height: var(--leading-base);
}

h5,
h6 {
  font-size: var(--text-base);
  line-height: var(--leading-base);
}

p {
  margin: 0 0 var(--space-3);
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
}

p:last-child {
  margin-bottom: 0;
}

small,
.small {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

strong,
b {
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

em,
i {
  font-style: italic;
}

code,
pre {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

ul,
ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease);
}

a:hover {
  color: var(--accent-hover);
}

a:active {
  color: var(--accent-active);
}

/* ----------------------------------------------------------------
   Focus — 1px outline on interactive elements
   ----------------------------------------------------------------
   The outline is applied only via :focus-visible (keyboard nav),
   not on mouse click. Opt out per element with data-no-outline
   for circular digit inputs that use background change instead.
   ---------------------------------------------------------------- */

:focus {
  outline: none;
}

:focus-visible {
  outline: var(--focus-ring-width) solid var(--accent);
  outline-offset: var(--focus-ring-offset);
  border-radius: inherit;
}

[data-no-outline]:focus-visible {
  outline: none;
  background: var(--bg-elevated);
}

/* ----------------------------------------------------------------
   Hidden attribute — display: none !important so it beats any
   display: flex/grid on the element
   ---------------------------------------------------------------- */

[hidden] {
  display: none !important;
}

/* ----------------------------------------------------------------
   Selection
   ---------------------------------------------------------------- */

::selection {
  background: var(--accent-subtle);
  color: var(--text-primary);
}

/* ----------------------------------------------------------------
   Scrollbars — subtle, cool-toned
   ---------------------------------------------------------------- */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--divider-strong);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--divider-strong) transparent;
}

/* ----------------------------------------------------------------
   Images and media
   ---------------------------------------------------------------- */

img,
svg,
canvas,
video {
  display: block;
  max-width: 100%;
  height: auto;
}

img {
  border-style: none;
}

/* ----------------------------------------------------------------
   Buttons — reset only; appearance handled in components.css
   ---------------------------------------------------------------- */

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: transparent;
  border: none;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

/* ----------------------------------------------------------------
   Form elements — reset only; appearance handled in components.css
   ---------------------------------------------------------------- */

input,
textarea,
select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: transparent;
  border: none;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

/* ----------------------------------------------------------------
   Reduced motion
   ---------------------------------------------------------------- */

@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;
  }
}