/* App-shell layout: centered-triptych split chrome.
   Three fixed regions on one baseline — brand mark (left), navigation
   capsule (center), utility satellite (right) — floating over the lava
   field. Page identity/controls live in the in-flow .page-masthead.
   Must be linked AFTER styles.css/loaders.css — these rules win
   equal-specificity conflicts by source order; glass.css (loaded last)
   owns the surface materials. */

/* ---- Skip link: first tab stop, visible only on focus ---- */

.skip-link {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: calc(var(--z-toast) + 1);
    padding: 0.5rem 0.875rem;
    border-radius: var(--r-md);
    background: var(--surface-1);
    color: var(--text-1);
    border: 1px solid var(--stroke-2);
    transform: translateY(-200%);
}

.skip-link:focus-visible {
    transform: none;
}

.page-masthead:focus {
    outline: none; /* skip-link target, not an interactive surface */
}

/* ---- Fixed shell bar ---- */

.unified-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--dock-h);
    z-index: var(--z-sticky);
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    column-gap: 0.75rem;
    padding: 0 max(1rem, env(safe-area-inset-right)) 0 max(1rem, env(safe-area-inset-left));
    /* The shell itself is a transparent layout layer; only its three
       regions paint and take pointer events. */
    background: transparent;
    pointer-events: none;
}

.unified-header > * {
    pointer-events: auto;
}

/* Reserve the shell's space and keep anchored/focused content clear of it */
body {
    padding-top: var(--dock-h);
}

html {
    scroll-padding-top: calc(var(--dock-h) + 16px);
}

/* ---- Region 1: brand mark ---- */

.shell-brand {
    justify-self: start;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border: none;
    background: transparent; /* material comes from glass.css */
    cursor: pointer;
    height: 40px;
    padding: 0 0.875rem 0 0.625rem;
    border-radius: var(--r-sm);
    color: var(--text-1);
}

.shell-brand-mark {
    color: var(--accent, var(--primary-color));
    flex: none;
}

.shell-brand-name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

/* ---- Region 2: navigation capsule ---- */

.primary-nav {
    display: flex;
    justify-content: center;
    min-width: 0;
}

.nav-buttons {
    display: flex;
    gap: 0.5rem; /* out-cascaded by glass.css; kept as no-glass fallback */
}

/* ---- Region 3: utility satellite ---- */

.shell-utilities {
    justify-self: end;
    position: relative;
    display: flex;
    align-items: center;
}

.utility-satellite {
    display: flex;
    align-items: center;
    gap: 2px;
}

/* Sheet trigger: hidden on wide viewports, becomes the satellite's
   representative below the collapse breakpoint */
.utility-sheet-trigger {
    display: none;
    border: none;
    background: transparent;
    color: var(--text-3, #6b7280);
    border-radius: var(--r-sm);
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.theme-picker-slot {
    display: flex;
    align-items: center;
}

/* Satellite controls: icon-only, circular, visibly subordinate to the
   nav capsule (~75% of its height), one shared quiet hover treatment. */
.utility-satellite .btn-icon-guidebook,
.utility-satellite .btn-icon-utility:not(.hidden) {
    background: transparent;
    border: none;
    color: var(--text-3, #6b7280);
    border-radius: var(--r-sm);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    margin: 0;
    transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

.utility-satellite .btn-icon-guidebook:hover,
.utility-satellite .btn-icon-utility:hover {
    background: color-mix(in srgb, var(--text-1) 9%, transparent);
    color: var(--text-1);
    transform: none;
    box-shadow: none;
}

/* Data-freshness chip: green dot + relative time, red on refresh failure.
   Stays display:none until refreshStatus.js records the first attempt
   (has-data) AND app.js says the page wants it (not .hidden). */
.refresh-status-chip {
    display: none;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 10px;
    border-radius: var(--r-sm);
    font-size: 12px;
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    cursor: default;
}

.refresh-status-chip.has-data {
    display: inline-flex;
}

.refresh-status-chip.hidden {
    display: none;
}

.refresh-status-chip .chip-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--status-gain);
    flex: none;
}

.refresh-status-chip.error {
    color: var(--status-loss-text);
    background: var(--status-loss-bg);
    border: 1px solid var(--status-loss-border);
}

.refresh-status-chip.error .chip-dot {
    width: 7px;
    height: 7px;
    background: var(--status-loss);
}

/* ---- Page masthead (in content flow) ---- */

.page-masthead {
    padding: 1.25rem 1rem 0.5rem 1rem;
    min-height: 76px; /* single-line masthead since subtitles retired 2026-08-17 */
}

.page-content {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    max-width: 1280px;
    margin: 0 auto;
    gap: 2rem;
}

.header-info {
    flex: 1;
    min-width: 0;
}

.header-info h1 {
    font-size: 1.875rem;
    font-weight: bold;
    color: #1f2937;
    margin-bottom: 0.125rem;
}

.header-extra {
    margin-top: 0.25rem;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Hide duplicated per-page nav groups */
.page-nav { display: none !important; }
.page-toggle { display: none !important; }

/* ---- Responsive ---- */

/* Align masthead with main content on larger screens */
@media (min-width: 768px) {
    .page-content {
        width: 90%;
        margin: 0 auto;
        max-width: 1280px; /* Ensure consistency with main content */
    }

    .page-masthead {
        padding-left: 0;
        padding-right: 0;
    }
}

/* Wordmark yields before the regions can collide */
@media (max-width: 1140px) {
    .shell-brand-name {
        display: none;
    }
}

/* Satellite collapses behind the sheet trigger before it can collide
   with the centered capsule. Same DOM nodes: the satellite pill becomes
   an anchored panel opened by the trigger. */
@media (max-width: 900px) {
    .utility-sheet-trigger {
        display: flex;
    }

    .utility-satellite {
        display: none;
    }

    .shell-utilities[data-open="true"] .utility-satellite {
        display: flex;
        position: absolute;
        top: calc(100% + 8px);
        right: 0;
        z-index: var(--z-popover);
    }
}

@media (max-width: 1024px) {
    .page-content {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .header-info {
        text-align: center;
    }

    .header-controls {
        justify-content: center;
    }
}

/* ---- Mobile: labeled bottom tab bar ----
   The SAME five nav nodes leave the top shell and pin to the bottom edge
   (native tab-bar convention). Top shell slims to brand + sheet trigger. */
@media (max-width: 640px) {
    :root {
        --dock-h: 56px;
    }

    .primary-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        z-index: var(--z-sticky);
        padding: 0.25rem
                 max(0.5rem, env(safe-area-inset-right))
                 max(0.25rem, env(safe-area-inset-bottom))
                 max(0.5rem, env(safe-area-inset-left));
        pointer-events: auto;
    }

    .nav-buttons {
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        width: 100%;
        gap: 2px;
        border-radius: var(--r-xl);
    }

    /* Button box/typography for the tab-bar transform lives in glass.css
       (it must out-cascade the desktop capsule button rules there) */

    .nav-icon {
        display: block;
    }

    .nav-label-long {
        display: none;
    }

    .nav-label-short {
        display: inline;
    }

    /* Badges hang off the tab corner so counts can't change column width */
    .nav-buttons .btn .badge-count {
        position: absolute;
        top: 2px;
        right: max(2px, calc(50% - 22px));
    }

    /* Content and floating UI clear the tab bar */
    body {
        padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px);
    }

    .save-indicator {
        bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
    }

    .page-masthead {
        padding: 0.75rem 0.5rem 0.5rem;
        min-height: 0;
    }
}

/* Desktop/tablet: icons live only in the bottom tab bar */
@media (min-width: 641px) {
    .nav-icon {
        display: none;
    }

    .nav-label-short {
        display: none;
    }
}
