/* ===========================================================================
   SchoolRadar — mobile optimizations (phones / PWA standalone)
   Loaded after Bootstrap + site CSS. Desktop is unaffected (rules are gated
   to <= 991.98px or to standalone display mode).
   ========================================================================= */

/* Respect device safe areas (notches, home indicator) in installed PWA */
@media (display-mode: standalone) {
    body { padding-top: env(safe-area-inset-top); }
}

/* ---------- Phone bottom navigation bar ---------- */
.mobile-bottom-nav { display: none; }

@media (max-width: 991.98px) {
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        z-index: 1040;
        background: #ffffff;
        border-top: 1px solid var(--border-color, #e2e8f0);
        box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .mobile-bottom-nav a {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 8px 0 6px;
        color: var(--text-secondary, #64748b);
        text-decoration: none;
        font-size: 0.68rem;
        font-weight: 600;
        min-height: 56px;            /* comfortable touch target */
        position: relative;
    }
    .mobile-bottom-nav a i { font-size: 1.25rem; }
    .mobile-bottom-nav a.active { color: var(--primary, #1a3a6b); }
    .mobile-bottom-nav a .nav-badge {
        position: absolute;
        top: 4px;
        inset-inline-end: calc(50% - 22px);
        background: var(--danger, #ef4444);
        color: #fff;
        border-radius: 999px;
        font-size: 0.6rem;
        line-height: 1;
        padding: 3px 5px;
        min-width: 16px;
        text-align: center;
    }

    /* Keep page content clear of the fixed bar */
    body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }

    /* The desktop top-nav links are redundant on phones; keep brand + language + bell */
    #navbarNav .navbar-nav.me-auto { display: none; }
}

/* ---------- General phone polish ---------- */
@media (max-width: 767.98px) {
    /* Tighter container gutters */
    .container, .container-fluid { padding-left: 14px; padding-right: 14px; }

    /* Reduce oversized vertical paddings used for desktop hero/sections */
    .py-5 { padding-top: 2rem !important; padding-bottom: 2rem !important; }

    /* Bigger, thumb-friendly primary actions */
    .btn { min-height: 44px; }
    .btn-sm { min-height: 36px; }

    /* Headings scale down a touch */
    h1, .h1 { font-size: 1.6rem; }
    h2, .h2 { font-size: 1.35rem; }

    /* Comparison & data tables: shrink the fixed label column, allow scroll */
    .table-responsive table th[style*="width:200px"],
    .table-responsive table th[style*="width: 200px"] { width: 120px !important; min-width: 120px; }
    .table-responsive { -webkit-overflow-scrolling: touch; }

    /* Cards a little tighter */
    .school-card { border-radius: 14px; }

    /* Forms: avoid iOS zoom-on-focus by keeping inputs >= 16px */
    .form-control, .form-select { font-size: 16px; }
}

/* ---------- Page-specific polish (phones) ---------- */
@media (max-width: 767.98px) {
    /* Home hero: trim the tall desktop padding, tighten the glass search panel */
    .hero-gradient { padding: 44px 0 64px !important; }
    .hero-gradient h1, .hero-gradient .display-4, .hero-gradient .display-5 { font-size: 1.9rem !important; line-height: 1.25; }
    .search-glass { padding: 16px !important; border-radius: 18px; }

    /* School detail: shorter cover + map so content is reachable with less scroll */
    .school-cover { height: 180px !important; }
    #map { height: 190px !important; }

    /* Results: tighter grid, sort bar sits inline (no desktop pull-up overlap) */
    #resultsGrid { --bs-gutter-x: 0.6rem; }
    .sort-bar { margin-top: 0 !important; padding: 10px 12px !important; border-radius: 14px; position: sticky; top: 8px; }
    .sort-bar .btn { padding: 4px 10px; }

    /* Score progress bars + fee tables stay readable */
    .school-card { padding: 16px !important; }

    /* Media thumbnail strip scrolls horizontally instead of wrapping huge */
    .media-strip { display: flex; gap: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .media-strip > * { flex: 0 0 auto; }

    /* Star-rating inputs: bigger tap targets */
    .star-input { font-size: 1.9rem !important; padding: 2px; }
}

/* Sticky bottom action bar on detail (optional hook; sits above the bottom nav) */
@media (max-width: 991.98px) {
    .detail-action-bar {
        position: fixed;
        left: 0; right: 0;
        bottom: calc(64px + env(safe-area-inset-bottom));
        z-index: 1039;
        background: #fff;
        border-top: 1px solid var(--border-color, #e2e8f0);
        display: flex; gap: 8px;
        padding: 8px 12px;
    }
    .detail-action-bar .btn { flex: 1; min-height: 44px; }
}

/* ---------- Install prompt chip ---------- */
#pwaInstallBtn {
    display: none;
    position: fixed;
    z-index: 1045;
    inset-inline-end: 14px;
    bottom: calc(72px + env(safe-area-inset-bottom));
    background: var(--secondary, #059669);
    color: #fff;
    border: 0;
    border-radius: 999px;
    padding: 10px 18px;
    font-weight: 700;
    box-shadow: 0 8px 20px rgba(5,150,105,0.35);
}
@media (min-width: 992px) {
    #pwaInstallBtn { bottom: 20px; }
}
