/* =============================================================================
 * base.css — resets, @font-face, base element styles, master layout shell
 * =============================================================================
 *
 * Load order is always tokens.css → base.css → components/*.css. Nothing in
 * this file references a raw colour, size, or radius; everything resolves
 * through custom properties declared in tokens.css.
 *
 * The @font-face declarations point at the five Montserrat .woff2 files
 * vendored under static/fonts/. Hashes for each are recorded in
 * DEPENDENCIES.md and re-verified in CI by scripts/verify_vendored.py. No
 * external font origin — the Phase 7 CSP will formalise this at the browser
 * level; the rule holds in dev so Phase 7 is a policy paste-in.
 *
 * The layout shell (.layout, .layout__sidebar, .layout__main, .layout__topbar,
 * .layout__content) matches the diagram in design-system-spec.md §5:
 *
 *     ┌──────────────┬──────────────────────────────────────┐
 *     │              │  Top bar                              │
 *     │  Sidebar     ├──────────────────────────────────────┤
 *     │  (dark,      │                                      │
 *     │   fixed)     │  Page content                         │
 *     │              │  (max-width, horizontal padding)      │
 *     └──────────────┴──────────────────────────────────────┘
 * ============================================================================= */

/* --- Font faces (self-hosted Montserrat, 5 weights) --- */

@font-face {
    font-family: 'Montserrat';
    src: url("/static/fonts/Montserrat-Regular.f417dfd230ca.woff2") format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Montserrat';
    src: url("/static/fonts/Montserrat-Medium.74bb862a9324.woff2") format('woff2');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Montserrat';
    src: url("/static/fonts/Montserrat-SemiBold.b3af5ff809bc.woff2") format('woff2');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Montserrat';
    src: url("/static/fonts/Montserrat-Bold.4f74439d19aa.woff2") format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Montserrat';
    src: url("/static/fonts/Montserrat-ExtraBold.813f0c6e6587.woff2") format('woff2');
    font-weight: 800;
    font-style: normal;
    font-display: swap;
}


/* --- Minimal reset --- */

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

html,
body {
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    font-size: var(--text-base);
    font-weight: var(--weight-regular);
    line-height: var(--leading-normal);
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    margin: 0;
    font-weight: var(--weight-bold);
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-tight);
    color: var(--color-text);
}

p {
    margin: 0;
}

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

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

img,
svg {
    display: block;
    max-width: 100%;
}

button {
    font-family: inherit;
}

/* The [hidden] attribute is a UI-state primitive used by toggle widgets
 * (deactivate confirm strip, bulk-import panel, etc.). The user-agent
 * default `[hidden] { display: none }` is overridden by component
 * classes that set `display:` (e.g. `.btn { display: inline-flex }`) —
 * same specificity, author wins. The `!important` here pins
 * display:none on any [hidden] element regardless of which class it
 * carries, so JS-driven `el.hidden = true` reliably removes the
 * element from the layout. Standard CSS-reset pattern. */
[hidden] {
    display: none !important;
}


/* --- Typographic roles (from design-system-spec §2) --- */

.type-hero {
    font-size: var(--text-5xl);
    font-weight: var(--weight-extrabold);
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-tight);
}

.type-page-title {
    font-size: var(--text-3xl);
    font-weight: var(--weight-bold);
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-tight);
}

.type-section-title {
    font-size: var(--text-2xl);
    font-weight: var(--weight-semibold);
    line-height: var(--leading-snug);
    letter-spacing: var(--tracking-tight);
}

.type-caption {
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    letter-spacing: var(--tracking-wide);
    color: var(--color-text-secondary);
}


/* --- Master layout shell ---
 * Empty {% block %}s in base.html mean Phase 0b can ship the shell with no
 * content; Phase 1 auth screens fill the slots (sidebar nav items, topbar
 * user menu, content area).
 */

.layout {
    min-height: 100vh;
}

/* Sidebar: fixed expanded by default. A toggle button in the sidebar
 * header switches the body.sidebar-collapsed class (via inline script
 * in base.html); when set, sidebar narrows to --sidebar-collapsed and
 * main content's margin-left matches, so layout reflows with the
 * sidebar rather than overlaying it.
 *
 * Ground: the settled matte-black panel (owner pick, 2026-08-02,
 * promoted from the six-trial block that used to sit at the end of
 * this file). All theme values live in the --color-sidebar-* tokens
 * (tokens.css records the story + the liked flat-charcoal-800
 * fallback); the on-dark ink rules sit with their components in
 * screens/dashboard.css. No border — the dark ground IS the
 * separation from the cream canvas.
 *
 * Top padding is 0 (owner alignment pin, 2026-08-02): the brand row
 * inside owns its offset — its margin-top drops the wordmark onto
 * the page title's line (see .sidebar-brand, screens/dashboard.css). */
.layout__sidebar {
    width: var(--sidebar-width);
    background: var(--color-sidebar);
    color: var(--color-sidebar-text);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    padding: 0 var(--space-4) var(--space-6);
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow: hidden;
    white-space: nowrap;
    transition: width var(--transition-slow);
}

.layout__main {
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left var(--transition-slow);
}

body.sidebar-collapsed .layout__sidebar {
    width: var(--sidebar-collapsed);
}

body.sidebar-collapsed .layout__main {
    margin-left: var(--sidebar-collapsed);
}

.layout__topbar {
    height: var(--space-16);
    background: transparent;
    padding: var(--space-6) var(--space-8);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-3);
}

.layout__content {
    flex: 1;
    padding: var(--space-8);
    max-width: 1440px;
    width: 100%;
    margin: 0 auto;
}

/* Laptop scale-down: below 1450px viewport, everything tightens —
 * base font drops to 14px (scales all rem values), content max-width
 * narrows to 1200px, and content padding reduces. The cutoff covers
 * 13″ laptops (an M1 Air renders at 1440 effective), which previously
 * fell just outside the tier and got the full desktop chrome at the
 * narrowest width it fits. */
@media (max-width: 1449px) {
    html {
        font-size: 14px;
    }

    /* Cap the column well below the available width so the cards float
     * on visible cream margins instead of running wall-to-wall into the
     * sidebar — breathing room comes from space AROUND the cards, not
     * inside them. */
    .layout__content {
        max-width: 1060px;
        padding: var(--space-6);
    }

    .layout__topbar {
        padding: var(--space-6);
    }
}


/* --- Tiny layout utilities (kept minimal to avoid reinventing a framework) --- */

.stack > * + * {
    margin-top: var(--space-6);
}

.button-group {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
}

/* =============================================================================
 * HTMX swap animation — design-system-spec.md §9
 * =============================================================================
 * During a swap HTMX adds .htmx-swapping (fade out) to the outgoing
 * element, then after the DOM swap adds .htmx-settling (fade in) to the
 * incoming one. Paired with `hx-swap="... swap:150ms settle:200ms"` this
 * reads as a smooth ~350ms cross-fade rather than a hard content pop —
 * scoped to the swapped element, so the surrounding page stays put.
 * ============================================================================= */
.htmx-swapping {
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.htmx-settling {
    opacity: 1;
    transition: opacity var(--transition-base);
}

@media (prefers-reduced-motion: reduce) {
    .htmx-swapping,
    .htmx-settling {
        transition: none;
    }
    /* The Analytics date-range crossfade uses the View Transitions API
     * (HTMX hx-swap="…transition:true"); its transition groups are not
     * covered by the .htmx-swapping reset above, so stop them animating
     * under reduced-motion (docs/design-language-rollout.md). */
    ::view-transition-group(*) {
        animation: none;
    }
}

