/*
 * Global responsive sweep for the RAE Portal.
 *
 * Layout history: every page was authored as a desktop layout with a
 * 260px fixed sidebar. This file overlays small-screen behaviour so
 * the same HTML stays usable on tablets and phones without rewriting
 * each page.
 *
 * Approach:
 *   - Hamburger toggle for the sidebar on screens < 900px.
 *   - Tables: ensure horizontal scroll rather than viewport overflow.
 *   - Modals: cap at viewport size.
 *   - Forms: collapse multi-column grids to a single column.
 *   - Increase touch targets where they were obviously desktop-sized.
 *
 * Loaded by every HTML page via <link rel="stylesheet"
 * href="/css/responsive.css"> after the page's own <style> block,
 * so these rules win on screen-size match.
 */

/* ─── Hamburger toggle button (injected by /js/responsive-nav.js) ─── */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    border: 1px solid var(--gray-300, #d1d5db);
    background: white;
    color: var(--primary, #009DD1);
    font-size: 1.4rem;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99;
}

/* ─── Tablet / phone (< 900px) ──────────────────────────────────── */
@media (max-width: 899px) {
    /* Show hamburger; hide sidebar by default */
    .sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        width: 280px;
        max-width: 85vw;
        z-index: 150; /* above .sidebar-backdrop (99) so links are clickable */
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar.open ~ .sidebar-backdrop,
    body.sidebar-open .sidebar-backdrop {
        display: block;
    }

    /* Main content no longer offset by sidebar */
    .main-content {
        margin-left: 0 !important;
        padding: 4rem 1rem 1.5rem;
    }

    /* Headings */
    .page-header h1 {
        font-size: 1.5rem;
    }
    .page-header p {
        font-size: 0.9rem;
    }

    /* Tables horizontally scrollable, never break layout */
    .data-table,
    .scroll-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    table {
        min-width: 600px; /* Prevent column-collapse spaghetti */
    }
    th,
    td {
        white-space: nowrap;
    }

    /* Modals */
    .modal-content,
    .modal-box {
        width: 95vw !important;
        max-width: 95vw !important;
        max-height: 92vh !important;
    }

    /* Forms: collapse known 2-column grids */
    .form-row,
    .form-row-3,
    .studio-grid {
        grid-template-columns: 1fr !important;
    }

    /* Toolbar wraps; buttons full-width for thumb-reach */
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .toolbar .btn,
    .toolbar .file-input-label {
        width: 100%;
        text-align: center;
    }
    .search-box {
        min-width: 0;
    }

    /* Stats cards stay readable */
    .stats-row {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    }

    /* Info-icon (admin notes) stays clickable */
    .info-btn {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }

    /* Tab nav scrolls horizontally rather than overflowing */
    .tab-bar,
    .sc-tabs,
    .tabs-nav {
        overflow-x: auto;
        flex-wrap: nowrap;
    }
    .tab,
    .sc-tab,
    .tab-button {
        flex: 0 0 auto;
        white-space: nowrap;
    }
}

/* ─── Phone (< 600px) — extra-tight ────────────────────────────── */
@media (max-width: 599px) {
    .main-content {
        padding: 3.5rem 0.75rem 1rem;
    }
    .page-header h1 {
        font-size: 1.25rem;
    }
    /* Hide low-value columns on the narrowest screens — let pages
       opt-in by adding .col-hide-sm to specific <th>/<td> */
    .col-hide-sm {
        display: none !important;
    }
}

/* ─── Print fallback — no sidebar, no toolbar ──────────────────── */
@media print {
    .sidebar,
    .sidebar-toggle,
    .sidebar-backdrop,
    .toolbar,
    .info-btn,
    .reviewer-panel {
        display: none !important;
    }
    .main-content {
        margin-left: 0 !important;
    }
}
