/* ============================================
   MLNavigator Design Tokens
   ============================================
   Three-layer token architecture:
     1. Primitive  — raw values, never applied directly
     2. Semantic   — intent-mapped, used in base/layout CSS
     3. Component  — scoped to specific UI elements
   ============================================ */

/* --------------------------------------------
   1. Primitive Tokens
   -------------------------------------------- */

:root {
    /* Spacing scale (4px base) */
    --space-px: 1px;
    --space-0: 0;
    --space-0-5: 0.125rem;  /*  2px */
    --space-1: 0.25rem;     /*  4px */
    --space-1-5: 0.375rem;  /*  6px */
    --space-2: 0.5rem;      /*  8px */
    --space-3: 0.75rem;     /* 12px */
    --space-4: 1rem;        /* 16px */
    --space-5: 1.25rem;     /* 20px */
    --space-6: 1.5rem;      /* 24px */
    --space-8: 2rem;        /* 32px */
    --space-10: 2.5rem;     /* 40px */
    --space-12: 3rem;       /* 48px */
    --space-16: 4rem;       /* 64px */
    --space-20: 5rem;       /* 80px */
    --space-24: 6rem;       /* 96px */

    /* Radius scale */
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-2xl: 2rem;
    --radius-full: 9999px;

    /* Shadow primitives — editorial paper leans on ruled borders, not heavy shadows */
    --shadow-sm: 0 1px 2px rgba(27, 26, 23, 0.05);
    --shadow-md: 0 1px 3px rgba(27, 26, 23, 0.07), 0 1px 2px rgba(27, 26, 23, 0.04);
    --shadow-lg: 0 8px 28px rgba(27, 26, 23, 0.10), 0 2px 6px rgba(27, 26, 23, 0.06);
    --shadow-glow: 0 0 0 1px var(--blue-trace-bd);
    --shadow-inset-glass: inset 0 0 0 1px rgba(27, 26, 23, 0.04);

    /* Color primitives — "Line Back to Paper": warm off-white paper, ink, muted-blue source trace */
    --paper-50: #faf8f3;   /* page background */
    --paper-100: #f4f1e9;  /* panel / card / alt-section surface */
    --paper-200: #ece7db;  /* deeper band / hover */
    --ink-900: #1b1a17;    /* primary text */
    --ink-700: #3c3a34;    /* secondary text */
    --ink-500: #6c6960;    /* muted text / metadata */
    --ink-400: #8c887d;    /* subtle text */
    --rule: rgba(27, 26, 23, 0.12);          /* thin ruled border */
    --rule-strong: rgba(27, 26, 23, 0.22);   /* stronger rule / dashed egress marker */
    --ink-veil: rgba(27, 26, 23, 0.035);     /* faint panel fill (replaces white veils) */
    --ink-veil-strong: rgba(27, 26, 23, 0.06);

    /* Brand teal (favicon ramp) — the accent + accent-trace tint. teal-700 is AA-safe on paper. */
    --teal-500: #14b8a6;
    --teal-600: #0d9488;
    --teal-700: #0f766e;
    --teal-800: #115e59;
    --teal-dim: rgba(15, 118, 110, 0.10);
    --teal-bd: rgba(15, 118, 110, 0.32);

    /* Accent trace (the line back to the record) = brand teal. Token names kept as
       --blue-trace* for the ~30 main.css references; values are the teal above
       (was muted blue #3a5a8c). The semantic source-status badge stays blue below. */
    --blue-trace: var(--teal-700);
    --blue-trace-hover: var(--teal-800);
    --blue-trace-dim: var(--teal-dim);
    --blue-trace-bd: var(--teal-bd);

    /* Semantic status set — AA-safe on paper (neon hues fail contrast on off-white) */
    --status-source: #3a5a8c;    --status-source-dim: rgba(58, 90, 140, 0.10);    --status-source-bd: rgba(58, 90, 140, 0.32);
    --status-review: #3f7d54;    --status-review-dim: rgba(63, 125, 84, 0.12);    --status-review-bd: rgba(63, 125, 84, 0.34);
    --status-partial: #9a6a1d;   --status-partial-dim: rgba(154, 106, 29, 0.12);  --status-partial-bd: rgba(154, 106, 29, 0.34);
    --status-unsup: #a8443a;     --status-unsup-dim: rgba(168, 68, 58, 0.12);     --status-unsup-bd: rgba(168, 68, 58, 0.34);
    --status-excluded: #7d7a70;  --status-excluded-dim: rgba(125, 122, 112, 0.12); --status-excluded-bd: rgba(125, 122, 112, 0.34);

    /* Typography primitives */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-md: 1.0625rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;
    --text-4xl: 2.25rem;
    --text-5xl: 2.5rem;

    --leading-tight: 1.2;
    --leading-snug: 1.4;
    --leading-normal: 1.7;
    --leading-relaxed: 1.75;
    --leading-loose: 1.8;

    --tracking-tight: -0.03em;
    --tracking-snug: -0.02em;
    --tracking-normal: 0.01em;
    --tracking-wide: 0.02em;
    --tracking-wider: 0.04em;
    --tracking-widest: 0.06em;

    /* Font stacks */
    --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'IBM Plex Mono', 'SF Mono', 'Monaco', 'Fira Code', monospace;

    /* Transition primitives */
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-spring: cubic-bezier(0.33, 1, 0.68, 1);
    --duration-fast: 0.15s;
    --duration-normal: 0.2s;
    --duration-slow: 0.35s;
    --duration-animation: 0.65s;
}

/* --------------------------------------------
   2. Semantic Tokens
   -------------------------------------------- */

:root {
    /* Backgrounds */
    --color-bg: var(--paper-50);
    --color-bg-secondary: var(--paper-100);
    --color-bg-tertiary: var(--paper-100);

    /* Text */
    --color-text: var(--ink-900);
    --color-text-secondary: var(--ink-700);
    --color-text-muted: var(--ink-500);
    --color-text-subtle: var(--ink-400);

    /* Accent = brand teal (favicon) */
    --color-accent: var(--teal-700);
    --color-accent-dim: var(--teal-dim);
    --color-accent-hover: var(--teal-800);

    /* Feedback */
    --color-error: var(--status-unsup);
    --color-error-dim: var(--status-unsup-dim);

    /* Borders */
    --color-border: var(--rule);

    /* Shadows */
    --shadow-button-glow: var(--shadow-glow);
    --shadow-card-hover: var(--shadow-lg);

    /* Layout */
    --container-max: 1200px;
    --content-narrow-max: 600px;
    --content-mid-max: 900px;
    --content-wide-max: 1100px;
    --prose-max: 65ch;
    --prose-article-max: clamp(70ch, 72vw, 1100px);
    --container-padding-x: var(--space-6);

    /* Section spacing */
    --section-padding-y: var(--space-20);
}

/* --------------------------------------------
   3. Component Tokens
   -------------------------------------------- */

:root {
    /* Card */
    --card-bg: var(--color-bg-tertiary);
    --card-border: var(--color-border);
    --card-radius: var(--radius-lg);
    --card-padding: var(--space-8) var(--space-6);
    --card-shadow: var(--shadow-md);

    /* Button */
    --btn-height: 44px;
    --btn-padding: var(--space-3) var(--space-6);
    --btn-radius: var(--radius-md);
    --btn-font-size: var(--text-sm);

    /* Proof box */
    --proof-bg: var(--color-accent-dim);
    --proof-border: var(--teal-bd);
    --proof-radius: var(--radius-md);
    --proof-padding: var(--space-8) var(--space-6);
    --proof-shadow: 0 1px 3px rgba(27, 26, 23, 0.06);

    /* Tag */
    --tag-bg: var(--color-accent-dim);
    --tag-radius: var(--radius-sm);
    --tag-padding: var(--space-1) var(--space-2);
    --tag-font-size: var(--text-xs);

    /* Navigation */
    --nav-padding-y: var(--space-4);
    --nav-link-gap: var(--space-8);

    /* Input */
    --input-padding: var(--space-3) var(--space-4);
    --input-radius: var(--radius-md);
    --input-min-height: 44px;
}

/* --------------------------------------------
   Responsive Token Overrides
   -------------------------------------------- */

@media (min-width: 1536px) {
    :root {
        --container-max: 1400px;
        --container-padding-x: var(--space-8);
        --content-wide-max: 1280px;
        --content-mid-max: 1100px;
    }
}

@media (min-width: 1920px) {
    :root {
        --container-max: 1560px;
        --container-padding-x: var(--space-8);
        --content-narrow-max: 640px;
        --content-mid-max: 1200px;
        --content-wide-max: 1400px;
        --prose-article-max: clamp(70ch, 72vw, 1200px);
    }
}

@media (min-width: 2560px) {
    :root {
        --container-max: 1680px;
        --content-narrow-max: 680px;
        --content-mid-max: 1280px;
        --content-wide-max: 1520px;
        --prose-article-max: clamp(72ch, 70vw, 1280px);
    }
}

@media (min-width: 3200px) {
    :root {
        --container-max: 1760px;
        --content-narrow-max: 720px;
        --content-mid-max: 1360px;
        --content-wide-max: 1600px;
        --prose-article-max: clamp(72ch, 68vw, 1360px);
    }
}

@media (max-width: 768px) {
    :root {
        --section-padding-y: var(--space-12);
        --container-padding-x: var(--space-5);
        --card-padding: var(--space-5) var(--space-4);
        --proof-padding: var(--space-5) var(--space-4);
        --btn-padding: var(--space-3) var(--space-5);
    }
}

@media (max-width: 640px) {
    :root {
        --section-padding-y: var(--space-10);
        --container-padding-x: var(--space-4);
        --card-padding: var(--space-5) var(--space-4);
        --proof-padding: var(--space-5) var(--space-4);
        --input-padding: var(--space-4);
        --input-min-height: 48px;
    }
}
