/*!
 * IPMC University College — Shared Modern UI Layer (V11.0)
 * ---------------------------------------------------------------------------------
 * Purely additive presentation layer, loaded AFTER each page's own <style>.
 * It never changes page logic, data or behaviour. It only:
 *   - makes every page fit any screen (phones from 320px to large desktops),
 *   - gives pages without a phone menu an off-canvas sidebar + menu button,
 *   - turns data tables into readable glass cards on phones,
 *   - sharpens glass edges, focus states and text rendering,
 *   - respects iPhone notches / home bar and prevents iOS input zoom.
 * Low-specificity selectors (:where) are used wherever a page might style the
 * same element, so each page's own design always wins.
 * ---------------------------------------------------------------------------------
 */

/* ---------- 1. Rendering & accessibility ---------- */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 2px solid rgba(235, 77, 75, 0.55);
    outline-offset: 2px;
}
:where(table) { font-variant-numeric: tabular-nums; }

/* ---------- 2. Sharper glass edges (zero-specificity: page styles win) ---------- */
:where(.sleek-card, .glass-card, .table-container, .glass-modal, .glass-dialog-box, .stat-card, .metric-card, .kpi-card, .filter-card, .summary-card) {
    outline: 1px solid rgba(255, 255, 255, 0.55);
    outline-offset: -1px;
}

/* ---------- 3. Full-height panels on mobile browsers (address bar aware) ---------- */
@supports (height: 100dvh) {
    :where(aside) { max-height: 100dvh; }
}
:where(aside) { overscroll-behavior: contain; }

/* ---------- 4. Phone menu for pages that had none (html[data-ipmc-nav="inject"]) ---------- */
.ipmc-menu-btn {
    display: none; width: 40px; height: 40px; flex-shrink: 0; margin-right: 10px; border-radius: 12px; cursor: pointer;
    place-items: center; color: #2d3436; background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.9);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.7), 0 4px 14px rgba(0,0,0,0.06);
    -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.ipmc-menu-btn svg { width: 19px; height: 19px; }
.ipmc-menu-btn.is-floating { position: fixed; top: calc(12px + env(safe-area-inset-top, 0px)); left: 12px; z-index: 1150; margin: 0; }
.ipmc-scrim {
    position: fixed; inset: 0; z-index: 1190; background: rgba(45, 52, 54, 0.24);
    -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
    opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
@media (max-width: 1024px) {
    html[data-ipmc-nav="inject"] .ipmc-menu-btn { display: grid; }
    html[data-ipmc-nav="inject"] aside {
        display: flex !important; visibility: visible !important;
        position: fixed !important; top: 0; left: 0; z-index: 1200 !important;
        width: min(280px, 84vw) !important; height: 100vh; height: 100dvh;
        transform: translateX(-105%) !important;
        transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1) !important;
        overflow-y: auto;
    }
    html[data-ipmc-nav="inject"] body.ipmc-nav-open aside {
        transform: none !important;
        background: rgba(255, 255, 255, 0.86) !important;
        box-shadow: 20px 0 50px rgba(0, 0, 0, 0.14) !important;
    }
    html[data-ipmc-nav="inject"] body.ipmc-nav-open .ipmc-scrim { opacity: 1; pointer-events: auto; }
    html[data-ipmc-nav="inject"] main { margin-left: 0 !important; width: 100% !important; }
}

/* ---------- 4b. Collapsed phone sidebar repair (class added by ipmc-ui.js) ---------- */
@media (max-width: 1024px) {
    aside.ipmc-aside-fix {
        width: min(280px, 84vw) !important; overflow-y: auto; overflow-x: hidden;
        background: rgba(255, 255, 255, 0.9) !important;
        box-shadow: 20px 0 50px rgba(0, 0, 0, 0.12);
    }
    aside.ipmc-aside-hide { transform: translateX(-105%); }
}

/* ---------- 5. Overflow guards (no sideways scrolling on any phone) ---------- */
@media (max-width: 760px) {
    :where(main) { min-width: 0; max-width: 100vw; }
    :where(main img) { max-width: 100%; }
    :where(.header-section, .top-bar, .header-flex, .page-header, .dashboard-header) { flex-wrap: wrap; row-gap: 10px; }
    :where(.admin-profile-card, .user-meta-group, .profile-card) { min-width: 0; flex-wrap: wrap; }
    :where(.admin-name) { overflow-wrap: anywhere; }
    :where(.header-text, .page-title, .title-group) { min-width: 0; max-width: 100%; }
    main .top-bar > div, main .header-section > div { min-width: 0; max-width: 100%; flex-wrap: wrap; row-gap: 8px; }
    :where(.header-text h1, .header-text h2, .header-text p) { overflow-wrap: anywhere; }

    /* Filter bars: long option text must never push a dropdown wider than the screen */
    main select, main input:not([type="checkbox"]):not([type="radio"]), main textarea { max-width: 100%; min-width: 0; }
    main .filter-container, main .filter-grid, main .filter-bar, main .filters { flex-wrap: wrap; }
    main .filter-group { min-width: 0; flex-basis: 100%; }
    main .filter-group > select, main .filter-group > input { width: 100%; }

    /* iOS: 16px form text prevents the automatic zoom-in when a field is tapped */
    :where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]), select, textarea) { font-size: 16px !important; }

    /* Pop-ups always fit the screen */
    .swal2-popup { max-width: 94vw !important; }
    /* Tall dialogs: the backdrop scrolls (dialogs themselves are never clipped) */
    :where(.glass-overlay, .modal-overlay, .overlay, .rr-overlay) { overflow-y: auto; align-items: safe center; }
}

/* ---------- 6. Phone table cards (applied by ipmc-ui.js as table.ipmc-stack) ---------- */
@media (max-width: 760px) {
    table.ipmc-stack { min-width: 0 !important; width: 100% !important; table-layout: auto !important; border-collapse: separate !important; }
    table.ipmc-stack thead { display: none; }
    table.ipmc-stack, table.ipmc-stack tbody { display: block; }
    table.ipmc-stack tbody tr {
        display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 12px;
        padding: 12px 13px; margin: 0 0 10px; border-radius: 14px;
        background: rgba(255, 255, 255, 0.62);
        border: 1px solid rgba(255, 255, 255, 0.88);
        box-shadow: inset 0 1px 0 rgba(255,255,255,0.7), 0 6px 18px rgba(0, 0, 0, 0.04);
    }
    table.ipmc-stack tbody tr[hidden] { display: none !important; }
    table.ipmc-stack tbody td {
        display: block; padding: 0 !important; border: 0 !important; text-align: left !important;
        white-space: normal !important; overflow-wrap: anywhere; min-width: 0; max-width: none !important; width: auto !important;
        position: static !important; height: auto !important;
    }
    table.ipmc-stack td[data-label]::before {
        content: attr(data-label); display: block; margin-bottom: 2px;
        font-size: 10px; font-weight: 800; letter-spacing: 0.8px; text-transform: uppercase; color: #636e72; opacity: 0.85;
    }
    table.ipmc-stack td[colspan], table.ipmc-stack td.ipmc-wide { grid-column: 1 / -1; }
    table.ipmc-stack td.ipmc-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding-top: 4px !important; }
    table.ipmc-stack td.ipmc-actions::before { width: 100%; }
    :where(.table-container, .table-mini-container, .table-wrapper, .table-responsive):has(table.ipmc-stack) {
        overflow-x: visible; background: transparent; border-color: transparent; box-shadow: none; outline: 0;
        -webkit-backdrop-filter: none; backdrop-filter: none;
    }
}

/* ---------- 7. Motion & print ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
@media print {
    .ipmc-menu-btn, .ipmc-scrim { display: none !important; }
    :where(.sleek-card, .glass-card, .table-container) { outline: 0; }
}
