/* Shared Styles for Resampling Statistics Pages */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #f5f7fa 0%, #faf9f7 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Header & Navigation ──────────────────────────────────────────── */
header {
    background: #1e3a5f;
    color: white;
    padding: 12px 20px;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    position: relative;
}

header h1 {
    font-size: 2em;
    margin-bottom: 5px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

header p { font-size: 0.95em; opacity: 0.9; }

header nav {
    position: absolute;
    top: 50%;
    right: max(30px, calc((100% - 1520px) / 2 + 30px));
    transform: translateY(-50%);
    display: flex;
    gap: 10px;
    align-items: center;
}

header nav a {
    color: white;
    text-decoration: none;
    font-size: 0.95em;
    padding: 6px 5px;
    border-radius: 4px;
    transition: background 0.2s;
}

header nav a:hover { background: rgba(212,175,55,0.5); }

header nav a.active {
    background: #d4af37;
    color: #1e3a5f;
    font-weight: 600;
}

.hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    cursor: pointer;
    background: none;
    border: none;
    padding: 5px;
    position: absolute;
    top: 50%;
    right: max(20px, calc((100% - 1520px) / 2 + 20px));
    transform: translateY(-50%);
    z-index: 10;
}

.hamburger span {
    display: block;
    width: 25px;
    height: 3px;
    background: white;
    margin: 4px 0;
    border-radius: 2px;
    transition: all 0.3s ease;
}

.hamburger.open span:nth-child(1) { transform: translateY(11px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.hamburger.open span:nth-child(3) { transform: translateY(-11px) rotate(-45deg); }

header.nav-collapsed .hamburger { display: flex; }

/* Reserve the hamburger's own footprint (its 35px box + the 20px it sits off
   the edge) out of the centered title/subtitle text's box, so text-align:center
   centers in the space actually left over instead of running up to — or on
   narrow phones, under — the icon. */
header.nav-collapsed { padding-right: 55px; }

header.nav-collapsed nav {
    position: absolute;
    top: 100%;
    left: 0;
    transform: none;
    flex-direction: column;
    width: 100%;
    display: none;
    padding: 6px 0;
    gap: 0;
    align-items: stretch;
    background: rgba(20,44,72,0.97);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    border-top: 2px solid rgba(212,175,55,0.4);
    z-index: 100;
}

header.nav-collapsed nav.open { display: flex; }

header.nav-collapsed nav a {
    text-align: left;
    padding: 13px 28px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    border-radius: 0;
    transition: background 0.2s ease, padding-left 0.2s ease;
}

header.nav-collapsed nav a:hover { background: rgba(212,175,55,0.12); padding-left: 36px; }

header.nav-collapsed nav a.active {
    background: rgba(212,175,55,0.18);
    color: #f0c845;
    border-left: 3px solid #d4af37;
    font-weight: 600;
    padding-left: 25px;
}

/* ── Container ────────────────────────────────────────────────────── */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px 40px;
}

/* Higher specificity ensures flex:1 isn't cancelled by local .container overrides.
   width:100% is also load-bearing here: body is a column flexbox, and .container's
   margin:0 auto (for centering) disables the default cross-axis stretch, so without
   an explicit width the container shrinks to fit its content instead of the
   viewport — on narrow screens that means everything overflows horizontally
   instead of wrapping. width:100% forces it back to the viewport width (still
   capped by max-width, still centered by the auto margins). */
body > .container { flex: 1; width: 100%; }

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 24px 0 20px;
    color: #555;
    text-decoration: none;
    font-size: 0.9em;
    font-weight: 500;
    transition: color 0.2s, transform 0.2s;
}

.back-link:hover { color: #222; transform: translateX(-3px); }

/* ── Page Header ──────────────────────────────────────────────────── */
.page-header {
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    padding: 10px 10px 10px 28px;
    margin-bottom: 12px;
    border-left: 5px solid #d4af37;
}

.page-header-top {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.page-header h2 { color: #1e3a5f; font-size: 2.2em; margin: 0; }

.remix-note {
    background: #faf6e8;
    border-radius: 8px;
    padding: 10px 16px;
    margin: 0 0 20px;
    color: #5a3f0a;
    font-size: 0.92em;
    line-height: 1.6;
    box-shadow: 0 4px 16px rgba(30, 58, 95, 0.1);
}
.remix-note strong { color: #1e3a5f; }

.sim-tag {
    background: #1e3a5f;
    color: #d4af37;
    padding: 4px 13px;
    border-radius: 20px;
    font-size: 0.82em;
    font-weight: 700;
    letter-spacing: 0.4px;
    white-space: nowrap;
}

.page-header p { color: #666; font-size: 1em; line-height: 1.75; }

/* ── Simulation Card ──────────────────────────────────────────────── */
.sim-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    padding: 30px;
    margin-bottom: 28px;
}

/* ── Controls ────────────────────────────────────────────────────────── */
.sim-controls-row {
    display: flex;
    align-items: flex-end;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.control-group { display: flex; flex-direction: column; gap: 5px; }

.control-group label {
    font-size: 0.78em;
    color: #777;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    text-align: center;
}

.control-group input[type="number"],
.control-group input[type="text"] {
    width: 90px;
    padding: 8px 10px;
    border: 2px solid #dde3ea;
    border-radius: 7px;
    font-size: 1em;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

/* Spinner arrows styling for number inputs */
.control-group input[type="number"]::-webkit-outer-spin-button,
.control-group input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: inner-spin-button;
    width: 25px;
    opacity: 1;
}

.control-group input:focus { border-color: #1e3a5f; }

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn-sim {
    padding: 8px 16px;
    border: none;
    border-radius: 7px;
    font-size: 0.93em;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    font-family: inherit;
    transition: all 0.2s;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-primary { background: #1e3a5f; color: white; }
.btn-primary:hover { background: #2a4d7a; transform: translateY(-1px); }

.btn-secondary { background: white; color: #1e3a5f; border: 2px solid #1e3a5f; }
.btn-secondary:hover { background: #f0f4f8; }

.btn-toggle { background: #d4af37; color: #1e3a5f; }
.btn-toggle.animate-mode { background: white; color: #1e3a5f; border: 2px solid #d4af37; }
.btn-toggle:hover { opacity: 0.85; }

/* ── Toggle group ─────────────────────────────────────────────────── */
.btn-toggle-group {
    display: inline-flex;
    border: 2px solid #1e3a5f;
    border-radius: 7px;
    overflow: hidden;
    background: white;
}

.btn-toggle-option {
    flex: 1;
    padding: 9px 16px;
    border: none;
    border-radius: 0;
    font-size: 0.93em;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    font-family: inherit;
    background: white;
    color: #1e3a5f;
    transition: all 0.2s;
    border-right: 1px solid #1e3a5f;
}

.btn-toggle-option:last-child { border-right: none; }

.btn-toggle-option.active {
    background: #1e3a5f;
    color: white;
    font-weight: 700;
}

.btn-toggle-option:hover:not(.active) { background: #f0f4f8; }

/* ── Stats panel ──────────────────────────────────────────────────── */
.sim-stats-panel {
    display: flex;
    gap: 28px;
    flex-wrap: wrap;
    padding: 14px 20px;
    background: #f5f7fa;
    border-radius: 8px;
    margin-bottom: 20px;
    border-left: 4px solid #d4af37;
}

.stat-item { display: flex; flex-direction: column; gap: 1px; }

.stat-label {
    font-size: 0.74em;
    color: #999;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value { font-size: 1.45em; font-weight: 700; color: #1e3a5f; line-height: 1.2; }
.stat-unit  { font-size: 0.78em; color: #bbb; }

/* ── SVG wrapper ──────────────────────────────────────────────────── */
.svg-wrapper {
    width: 100%;
    background: #fafbfc;
    border-radius: 8px;
    border: 1px solid #eaecef;
    overflow: hidden;
}

.svg-wrapper svg { width: 100%; height: auto; display: block; }

.axis text { font-size: 0.8rem; }

/* ── Tooltip ──────────────────────────────────────────────────────── */
.sim-tooltip {
    position: absolute;
    background: rgba(30,58,95,0.92);
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85em;
    pointer-events: none;
    opacity: 0;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    font-family: inherit;
}

/* ── Explainer box ────────────────────────────────────────────────── */
.explainer {
    background: white;
    border-radius: 12px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.1);
    padding: 28px 30px;
    margin-bottom: 28px;
    border-top: 3px solid #d4af37;
}

.explainer h3 { color: #1e3a5f; margin-bottom: 14px; font-size: 1.3em; }

.explainer p { color: #555; margin-bottom: 12px; font-size: 0.97em; line-height: 1.75; }
.explainer p:last-child { margin-bottom: 0; }

.explainer strong { color: #1e3a5f; }

/* ── Footer ───────────────────────────────────────────────────────── */
footer {
    background: #1e3a5f;
    color: white;
    padding: 40px 20px;
    margin-top: auto;
    border-top: 3px solid #d4af37;
}

footer p { max-width: 1200px; margin: 0 auto; text-align: center; font-size: 0.95em; line-height: 1.8; }
footer a { color: #d4af37; text-decoration: none; font-weight: 500; white-space: nowrap; }
footer a:hover { color: #e8bd47; }

/* ── Page Layout Container ──────────────────────────────────────────– */
.page-layout {
    display: flex;
    flex-direction: row;
    gap: 0;
    position: relative;
    width: 100%;
    max-width: 1520px;
    min-height: calc(100vh - 100px);
    margin: 0 auto;
    padding: 0;
    background: white;
    align-items: flex-start;
}

/* ── Sidebar Navigation ────────────────────────────────────────────── */
#sidebar-nav {
    width: 260px;
    min-width: 260px;
    background: white;
    border-right: 2px solid #e0e0e0;
    padding: 0;
    margin: 0;
    height: auto;
    min-height: 100%;
    overflow-y: auto;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-self: flex-start;
}

/* ── Sidebar wrapper (desktop: transparent pass-through) ──────────── */
#sidebar-wrapper {
    display: flex;
    flex-shrink: 0;
    align-self: stretch;
    margin-left: 10px;
}

/* ── Pull-tab (hidden on desktop) ──────────────────────────────────── */
.sidebar-pull-tab { display: none; }

.nav-section {
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    flex-direction: column;
    width: 100%;
    flex-shrink: 0;
    margin: 0;
    padding: 0;
    position: relative;
}

.nav-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    cursor: pointer;
    transition: background 0.2s;
    margin: 0;
    position: relative;
}

.nav-section-header:hover { background: #f5f5f5; }

.nav-section-title {
    flex: 1;
    color: #1e3a5f;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95em;
    transition: color 0.2s;
    margin: 0;
    padding: 0;
}

.nav-section-title:hover { color: #d4af37; }

.nav-section-title.active {
    color: #1e3a5f;
    border-left: 3px solid #d4af37;
    padding-left: 17px;
    margin-left: -20px;
    padding-right: 0;
    margin-right: 0;
}

.nav-toggle {
    font-size: 1.1em;
    color: #999;
    display: inline-block;
    transition: transform 0.3s ease-in-out;
    margin-left: 8px;
    will-change: transform;
}

.nav-toggle.rotated { transform: rotate(90deg); }

.nav-children {
    max-height: 500px;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    opacity: 1;
    background: #fafafa;
    margin: 0;
    padding: 0;
}

.nav-children.collapsed {
    max-height: 0;
    opacity: 0;
}

.nav-child {
    display: block;
    padding: 10px 20px 10px 40px;
    color: #555;
    text-decoration: none;
    font-size: 0.9em;
    border-left: 3px solid transparent;
    transition: all 0.2s;
}

.nav-child:hover {
    background: #f0f0f0;
    color: #1e3a5f;
    border-left-color: #d4af37;
    padding-left: 36px;
}

.nav-child.active {
    background: #e8f4f8;
    color: #1e3a5f;
    border-left-color: #d4af37;
    font-weight: 600;
    padding-left: 36px;
}

.main-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* ── Media Queries ────────────────────────────────────────────────── */
@media (max-width: 768px) {
    /* Tighter edge gutter site-wide — 20px on each side was fine on desktop,
       but on a ~400px phone it's a meaningful chunk of the usable width.
       body > .container (like the flex:1 rule above) beats every page's
       local, unconditional `.container { padding: 0 20px ... }` override,
       since equal-specificity rules otherwise lose to whichever comes later
       in the cascade — and the local rule always comes after this stylesheet. */
    body > .container { padding-left: 12px; padding-right: 12px; }

    /* Sidebar wrapper becomes a fixed off-screen panel */
    #sidebar-wrapper {
        position: fixed;
        top: 80px;
        bottom: 0;
        left: -260px;
        z-index: 500;
        transition: left 0.3s ease;
        display: flex;
        align-items: center;
        align-self: auto;
    }

    #sidebar-wrapper.mobile-open { left: 0; }

    #sidebar-nav {
        width: 260px;
        height: 100%;
        overflow-y: auto;
        padding-top: 20px;
        align-self: stretch;
        border-right: 2px solid #e0e0e0;
    }

    .sidebar-pull-tab {
        display: flex;
        align-items: center;
        justify-content: center;
        writing-mode: vertical-rl;
        transform: rotate(180deg);
        padding: 20px 6px;
        background: #1e3a5f;
        color: white;
        border: none;
        border-radius: 6px 0 0 6px;
        cursor: pointer;
        font-family: inherit;
        font-size: 0.72em;
        font-weight: 700;
        letter-spacing: 1.5px;
        text-transform: uppercase;
        flex-shrink: 0;
        align-self: center;
        box-shadow: -3px 0 10px rgba(0,0,0,0.2);
    }

    .sidebar-pull-tab:hover { background: #2a4d7a; }

    #sidebar-wrapper.mobile-open .sidebar-pull-tab {
        background: #d4af37;
        color: #1e3a5f;
    }

    .page-layout { min-height: auto; }

    .main-content { width: 100%; }

    .page-layout { flex-direction: column; }

    header h1 { font-size: 1.5em; }
    header p { font-size: 0.75em; }

    .page-header { padding: 10px 20px 10px 28px; }
    .page-header h2 { font-size: 1.8em; }

    .sim-card { padding: 18px; }

    .sim-controls-row { gap: 8px; flex-wrap: wrap; }

    .control-group label { font-size: 0.7em; }

    .control-group input[type="number"],
    .control-group input[type="text"] { width: 60px; font-size: 0.9em; padding: 6px 6px; }

    .btn-sim { padding: 6px 12px; font-size: 0.85em; white-space: nowrap; height: auto; }

    .btn-toggle-option { padding: 6px 8px; font-size: 0.8em; }
}
