/* ============================================
   Base styles: reset, type, layout, loading states
   Every value comes from a role of tokens.css (loaded before this file).
   This file never holds a literal design value.
   ============================================ */

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

/* `clip`, not `hidden`: `overflow-x: hidden` turns html and body into scroll
   containers, and the sticky sidebar would then stick to the body box instead
   of the viewport (it scrolls away with the page). */
html {
    overflow-x: clip;
    scroll-padding-top: 5rem;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    font-size: var(--text-md);
    line-height: var(--leading-normal);
    color: var(--text-primary);
    background-color: var(--bg-primary);
    min-height: 100vh;
    overflow-x: clip;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-feature-settings: 'kern' 1;
}

/* Form controls do not inherit the page font: without this a <button> renders
   in the system face and a change of --font-sans skips it. Family only: each
   control sets its own font-size. */
button, input, select, textarea { font-family: inherit; }

h1, h2, h3, h4, h5, h6 {
    font-weight: var(--font-weight-bold);
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-tight);
    text-wrap: balance;
}
h1 { font-family: var(--font-display); letter-spacing: var(--tracking-tighter); }
p { text-wrap: pretty; }

a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition-fast);
}
a:hover { color: var(--accent-strong); text-decoration: underline; }

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

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

:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

/* Small uppercase monospace kicker: section labels, metadata, counters.
   --text-secondary: it says what a section is, so it takes the stronger grey.
   .eyebrow-accent is for the one kicker per screen that must carry the brand. */
.eyebrow {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: var(--font-weight-medium);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    color: var(--text-secondary);
}
.eyebrow-accent { color: var(--accent); }

/* Figures in the mono face: counters, metrics, ids. */
.figure {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    color: var(--accent);
}

/* Utility classes */
.d-none { display: none !important; }
.mb-0 { margin-bottom: 0; }
.mb-sm { margin-bottom: var(--space-xs); }
.mb-md { margin-bottom: 0.75rem; }
.mt-sm { margin-top: var(--space-xs); }
.mt-md { margin-top: var(--space-sm); }
.mt-lg { margin-top: 1.5rem; }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); font-size: var(--text-sm); }

/* Grid */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

/* ============================================
   Page header: left-aligned title under a hairline
   (eyebrow optional, h1, subtitle)
   ============================================ */
.page-header {
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--border-color);
    max-width: 100%;
    overflow-wrap: break-word;
}
.page-header h1 {
    color: var(--text-primary);
    margin-bottom: 0.4rem;
    font-size: var(--text-3xl);
    letter-spacing: var(--tracking-tighter);
    hyphens: auto;
}
.page-header .subtitle,
.page-header p:not(.eyebrow) {
    color: var(--text-secondary);
    font-size: var(--text-md);
    max-width: 62ch;
}
.page-header .eyebrow {
    display: block;
    margin-bottom: 0.6rem;
}

/* ============================================
   Loading overlay
   ============================================ */
.loading-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--veil);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}
.loading-overlay.active { display: flex; }
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--accent-soft);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Skeleton loading */
.skeleton {
    background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--bg-primary) 50%, var(--bg-secondary) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
}
@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.skeleton-chart { height: 400px; }
.skeleton-table { height: 300px; }
.skeleton-text { height: 1rem; margin-bottom: var(--space-xs); width: 80%; }

/* ============================================
   Thin scrollbar (apply via .styled-scroll)
   ============================================ */
.styled-scroll {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}
.styled-scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.styled-scroll::-webkit-scrollbar-track { background: transparent; }
.styled-scroll::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: var(--radius-full);
    border: 2px solid transparent;
    background-clip: padding-box;
}
.styled-scroll::-webkit-scrollbar-thumb:hover { background-color: var(--fill-muted); }
.styled-scroll::-webkit-scrollbar-thumb:active { background-color: var(--text-tertiary); }

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    .grid-2 { grid-template-columns: 1fr; }
    .page-header h1 { font-size: var(--text-2xl); }
    .page-header .subtitle,
    .page-header p:not(.eyebrow) { font-size: var(--text-base); }
}
@media (max-width: 480px) {
    .page-header h1 { font-size: var(--text-xl); }
}
