/* ————————————————————————————————————————
   LAYOUT — responsive sidebar + main
   ———————————————————————————————————————— */
.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

@media (min-width: 768px) {
    .app {
        flex-direction: row;
    }
}


/* ———————————————————————
   SIDEBAR
   ——————————————————————— */
.sidebar {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 50;
}

@media (min-width: 768px) {
    .sidebar {
        width: var(--sidebar-w);
        height: 100vh;
        border-bottom: none;
        border-right: 1px solid var(--border);
        display: flex;
        flex-direction: column;
    }
}

/* Sidebar head — hidden on mobile, visible on desktop */
.sidebar-head {
    padding: var(--s-6) var(--s-5) var(--s-5);
    border-bottom: 1px solid var(--border);
}

@media (max-width: 767px) {
    .sidebar-head {
        display: none;
    }
}

.sidebar-title {
    font-size: var(--t-lg);
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.sidebar-sub {
    font-size: var(--t-xs);
    color: var(--text-tertiary);
    margin-top: 3px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}


/* ———————————————————————
   MOBILE NAV TOGGLE
   ——————————————————————— */
.mobile-nav-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 12px var(--s-4);
    border: none;
    background: var(--bg-secondary);
    font-family: var(--sans);
    font-size: var(--t-base);
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.mobile-nav-toggle .nav-icon {
    width: 18px;
    height: 18px;
    color: var(--text-tertiary);
}

.mobile-nav-label {
    display: flex;
    align-items: center;
    gap: var(--s-2);
}

.mobile-nav-chevron {
    width: 16px;
    height: 16px;
    color: var(--text-tertiary);
    transition: transform 200ms ease;
}

.sidebar.is-open .mobile-nav-chevron {
    transform: rotate(180deg);
}

@media (min-width: 768px) {
    .mobile-nav-toggle {
        display: none;
    }
}


/* ———————————————————————
   SIDEBAR NAV
   ——————————————————————— */
.sidebar-nav {
    display: none;
    flex-direction: column;
    gap: 2px;
    padding: var(--s-2) var(--s-3);
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-bottom: 1px solid var(--border);
}

.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

/* Mobile: show when sidebar is open */
.sidebar.is-open .sidebar-nav {
    display: flex;
}

/* Desktop: always show as vertical column */
@media (min-width: 768px) {
    .sidebar-nav {
        display: flex;
        flex-direction: column;
        padding: var(--s-2) var(--s-3);
        overflow-y: auto;
        max-height: none;
        flex: 1;
        border-bottom: none;
    }
}


/* ———————————————————————
   NAV ITEMS
   ——————————————————————— */
.nav-item {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: 10px var(--s-3);
    border: none;
    border-radius: var(--r-md);
    background: none;
    font-family: var(--sans);
    font-size: var(--t-sm);
    font-weight: 400;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--ease), color var(--ease);
    white-space: nowrap;
    text-align: left;
    width: 100%;
    line-height: 1.4;
    min-height: 40px;
    -webkit-tap-highlight-color: transparent;
}

@media (min-width: 768px) {
    .nav-item {
        padding: 10px 14px;
        white-space: normal;
        min-height: auto;
    }
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.is-active {
    background: var(--nav-active);
    color: var(--nav-active-text);
    font-weight: 600;
}

.nav-item.is-active .nav-icon {
    color: var(--nav-active-text);
    opacity: 0.85;
}

.nav-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--text-tertiary);
}

.nav-item:hover .nav-icon {
    color: var(--text-secondary);
}


/* ———————————————————————
   SIDEBAR FOOTER
   ——————————————————————— */
.sidebar-foot {
    padding: var(--s-4) var(--s-5);
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-tertiary);
    line-height: 1.5;
    display: none;
}

@media (min-width: 768px) {
    .sidebar-foot {
        display: block;
    }
}


/* ———————————————————————
   MAIN CONTENT
   ——————————————————————— */
.main {
    flex: 1;
    min-width: 0;
    padding: var(--s-6) var(--s-4);
}

@media (min-width: 768px) {
    .main {
        padding: var(--s-10) var(--s-10);
        overflow-y: auto;
        height: 100vh;
    }
}

@media (min-width: 1100px) {
    .main {
        padding: var(--s-10) var(--s-8);
    }
}

.main-inner {
    max-width: var(--content-w);
    margin: 0 auto;
}


/* ————————————————————————————————————————
   SECTIONS
   ———————————————————————————————————————— */
.section {
    display: none;
}

.section.is-active {
    display: block;
    animation: enter 200ms ease;
}

@keyframes enter {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.section-head {
    margin-bottom: var(--s-8);
}

@media (min-width: 768px) {
    .section-head {
        margin-bottom: var(--s-10);
    }
}

.section-title {
    font-size: var(--t-2xl);
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.025em;
    line-height: 1.2;
}

@media (min-width: 768px) {
    .section-title {
        font-size: var(--t-3xl);
    }
}

.section-desc {
    margin-top: var(--s-3);
    font-size: var(--t-base);
    color: var(--text-secondary);
    line-height: 1.65;
    max-width: 640px;
}


/* ————————————————————————————————————————
   MOBILE-SPECIFIC OVERRIDES
   ———————————————————————————————————————— */
@media (max-width: 767px) {
    /* Stat cards: force readable layout */
    .stat .stat-value {
        font-size: var(--t-xl);
    }

    /* Tables: ensure scroll wrapper works */
    .table-wrap {
        margin-left: calc(-1 * var(--s-4));
        margin-right: calc(-1 * var(--s-4));
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    /* Cols: force stack below 580px already handled in components */

    /* Dark blocks: slightly less padding */
    .dark-block {
        padding: var(--s-4);
    }

    .dark-inner {
        padding: var(--s-4);
    }

    /* Cards: slightly less padding */
    .card {
        padding: var(--s-4);
    }

    /* Org chart: allow horizontal scroll */
    .org {
        padding: var(--s-4) 0;
    }

    .org-branch {
        gap: var(--s-2);
    }

    .org-node {
        min-width: 120px;
        font-size: var(--t-xs);
        padding: var(--s-2) var(--s-3);
    }

    /* Calculator forms: better touch targets */
    .form-input {
        padding: 10px var(--s-3);
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    select.form-input {
        font-size: 16px;
    }

    /* Bracket bar: taller for touch */
    .bracket-bar {
        height: 40px;
    }

    /* Range slider: larger touch target */
    .range-slider {
        height: 6px;
    }

    /* Result values: scale down if needed */
    .result-value {
        font-size: var(--t-lg);
    }

    /* Section head: less bottom margin */
    .section-head {
        margin-bottom: var(--s-6);
    }

    /* Callout: less padding */
    .callout {
        padding: var(--s-5) var(--s-4);
    }

    /* Code block: allow wrap */
    .code {
        word-break: break-word;
        white-space: pre-wrap;
    }

    /* Schedule grid: smaller */
    .schedule {
        font-size: 10px;
        gap: 2px;
    }

    .schedule-day {
        padding: var(--s-1) 2px;
    }

    /* Split layout: already stacks via flex-direction:column */
}
