/* =============================================================
   mobile.css — St. Thomas School Mobile Responsive Fix
   ============================================================= */

/* ══════════════════════════════════════════════════════════
   FIX 1: PREVENT PAGE ZOOM-OUT & HORIZONTAL SCROLL SHIFT
   Using 'clip' not 'hidden' — hidden breaks sticky navbar!
   ══════════════════════════════════════════════════════════ */
html {
    overflow-x: clip !important;   /* clip = no horizontal scroll, sticky still works */
    max-width: 100% !important;
}
body {
    overflow-x: clip !important;
    max-width: 100vw !important;
    position: relative !important;
}

/* Prevent any element from being wider than the screen */
*, *::before, *::after {
    box-sizing: border-box !important;
}

/* Fix common overflow culprits */
img, video, iframe, embed, object, table, pre {
    max-width: 100% !important;
}

/* Fix ticker / marquee overflow */
.ticker-wrap, .ticker-wrapper, .news-ticker,
.ticker-content, .ticker-container {
    max-width: 100vw !important;
    overflow: hidden !important;
}

/* Fix wide grids from causing scroll */
.container, .section-container,
[class*="grid"], [class*="row"] {
    max-width: 100% !important;
}

/* ══════════════════════════════════════════════════════════
   FIX 2: STICKY NAVBAR — stays sharp & fixed after scroll
   ══════════════════════════════════════════════════════════ */
.main-header {
    position: sticky !important;
    top: 0 !important;
    z-index: 1200 !important;
    width: 100% !important;
    left: 0 !important;
    /* Fix blur/rendering on mobile */
    -webkit-transform: translateZ(0) !important;
    transform: translateZ(0) !important;
    -webkit-backface-visibility: hidden !important;
    backface-visibility: hidden !important;
    will-change: transform !important;
}

/* Hamburger button sharp rendering */
.mobile-nav-toggle {
    -webkit-transform: translateZ(0) !important;
    transform: translateZ(0) !important;
    image-rendering: crisp-edges !important;
    -webkit-tap-highlight-color: transparent !important;
    touch-action: manipulation !important;
}

.mobile-nav-toggle span {
    -webkit-transform: translateZ(0) !important;
    transform: translateZ(0) !important;
}

/* ══════════════════════════════════════════════════════════
   FIX 3: NAV OVERLAY — properly covers entire screen
   ══════════════════════════════════════════════════════════ */
.nav-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(0, 0, 0, 0.65) !important;
    z-index: 1100 !important;
    opacity: 0 !important;
    visibility: hidden !important;
    transition: opacity 0.3s ease !important;
    pointer-events: none !important;
}
.nav-overlay.active {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
}

/* ── NAV MENU SLIDE-IN ── */
@media (max-width: 1200px) {
    .nav-menu {
        position: fixed !important;
        top: 0 !important;
        right: -100% !important;
        width: min(300px, 85vw) !important;
        height: 100vh !important;
        background: #fff !important;
        z-index: 1150 !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        padding: 80px 1.5rem 2rem !important;
        overflow-y: auto !important;
        box-shadow: -4px 0 20px rgba(0,0,0,0.15) !important;
        transition: right 0.35s ease !important;
    }
    .nav-menu.open {
        right: 0 !important;
    }
    .mobile-nav-toggle {
        display: flex !important;
    }
    .nav-item { width: 100% !important; }
    .nav-link {
        display: block !important;
        width: 100% !important;
        font-size: 1rem !important;
        padding: 0.75rem 0 !important;
        border-bottom: 1px solid #f1f5f9 !important;
    }
    .dropdown-menu {
        position: static !important;
        box-shadow: none !important;
        opacity: 1 !important;
        visibility: visible !important;
        transform: none !important;
        padding-left: 1rem !important;
        display: none !important;
        border-left: 2px solid #e2e8f0 !important;
    }
    .nav-item-dropdown.active-drop .dropdown-menu {
        display: block !important;
    }
}

/* ── MAIN WEBSITE — TABLET (≤ 900px) ── */
@media (max-width: 900px) {
    .container { padding: 0 1rem !important; }
    section, .section { padding: 2.5rem 0 !important; }

    /* Grids */
    .leaders-grid, .features-grid, .info-grid,
    .two-col, .three-col, .four-col {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
    .announcements-grid { grid-template-columns: 1fr !important; }

    /* Faculty & Gallery — 2 columns */
    .faculty-grid { grid-template-columns: 1fr 1fr !important; }
    .gallery-grid { grid-template-columns: 1fr 1fr !important; }

    /* Stats */
    .stats-row, .key-stats { grid-template-columns: 1fr 1fr !important; }

    /* Footer */
    .footer-grid, .footer-content {
        grid-template-columns: 1fr !important;
        gap: 1.5rem !important;
    }

    /* Headings */
    .section-title { font-size: 1.6rem !important; }
    .section-subtitle { font-size: 0.92rem !important; }
}

/* ── MAIN WEBSITE — MOBILE (≤ 600px) ── */
@media (max-width: 600px) {
    .container { padding: 0 0.85rem !important; }
    section, .section { padding: 2rem 0 !important; }

    /* Typography */
    h1, .hero-content h1 { font-size: 1.6rem !important; }
    h2 { font-size: 1.3rem !important; }
    h3 { font-size: 1.1rem !important; }
    .section-title { font-size: 1.35rem !important; }

    /* Hero */
    .hero { min-height: 350px !important; height: 60vh !important; }
    .hero-ctas { flex-direction: column !important; gap: 0.6rem !important; }
    .hero-ctas .btn { width: 100% !important; justify-content: center !important; }

    /* Cards */
    .card, .info-card { padding: 1rem !important; }

    /* Gallery & Faculty — 2 columns on phone */
    .faculty-grid { grid-template-columns: 1fr 1fr !important; }
    .gallery-grid { grid-template-columns: 1fr 1fr !important; }

    /* Homepage leader cards — keep 2 columns side by side */
    #communitySection .grid-2,
    .grid-2[style*="max-width: 800px"] {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.75rem !important;
    }
    #communitySection .leader-card {
        padding: 1rem 0.75rem !important;
    }
    #communitySection .leader-img-wrapper {
        width: 80px !important;
        height: 80px !important;
    }
    #communitySection .leader-info h4 {
        font-size: 0.8rem !important;
    }
    #communitySection .leader-role {
        font-size: 0.7rem !important;
    }
    #communitySection .btn-sm {
        font-size: 0.72rem !important;
        padding: 0.3rem 0.5rem !important;
    }

    /* Management page leader portrait cards — compact */
    .leader-portrait-card {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        text-align: left !important;
        gap: 1rem !important;
        padding: 1rem !important;
    }
    .leader-img-box {
        width: 90px !important;
        height: 90px !important;
        flex-shrink: 0 !important;
        margin: 0 !important;
    }
    .leader-card-body {
        padding: 0 !important;
        flex: 1 !important;
    }
    .leader-card-body h3 {
        font-size: 1rem !important;
    }

    /* Filter tabs */
    .filter-bar, .gallery-filters, .tab-list {
        flex-wrap: wrap !important;
        gap: 0.4rem !important;
        justify-content: center !important;
    }
    .filter-btn, .tab-btn {
        font-size: 0.78rem !important;
        padding: 0.35rem 0.75rem !important;
    }

    /* Tables */
    table { display: block !important; overflow-x: auto !important; width: 100% !important; }

    /* Forms */
    input, select, textarea { font-size: 16px !important; }
    .form-row, .form-grid { grid-template-columns: 1fr !important; }

    /* Page banner */
    .page-banner { padding: 1.75rem 0 !important; }
    .page-banner h1 { font-size: 1.4rem !important; }

    /* Leader cards */
    .leader-img-box img { width: 90px !important; height: 90px !important; }
}

/* ── MAIN WEBSITE — SMALL PHONES (≤ 420px) ── */
@media (max-width: 420px) {
    .gallery-grid { grid-template-columns: 1fr !important; }
    .faculty-grid { grid-template-columns: 1fr !important; }
    h1, .hero-content h1 { font-size: 1.35rem !important; }
}

/* ── ADMIN PANEL — TABLET (≤ 900px) ── */
@media (max-width: 900px) {
    .dashboard-layout {
        grid-template-columns: 1fr !important;
        min-height: auto !important;
    }
    .dashboard-sidebar {
        position: sticky !important;
        top: 0 !important;
        z-index: 99 !important;
        border-right: none !important;
        border-bottom: 2px solid #e2e8f0 !important;
        padding: 0.5rem 0.75rem !important;
        background: #fff !important;
    }
    .sidebar-menu {
        flex-direction: row !important;
        overflow-x: auto !important;
        flex-wrap: nowrap !important;
        gap: 4px !important;
        margin-bottom: 0 !important;
        padding-bottom: 4px !important;
        -webkit-overflow-scrolling: touch !important;
    }
    .sidebar-item { flex-shrink: 0 !important; }
    .sidebar-item button {
        white-space: nowrap !important;
        font-size: 0.78rem !important;
        padding: 0.4rem 0.75rem !important;
        border-radius: 20px !important;
    }
    .sidebar-title { display: none !important; }
    .nav-badge { display: none !important; }
    .dashboard-main { padding: 0.85rem !important; }
    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.65rem !important;
        margin-bottom: 0.75rem !important;
    }
}

/* ── ADMIN PANEL — MOBILE (≤ 600px) ── */
@media (max-width: 600px) {
    /* Top Nav — 1 compact row, no overflow */
    .dashboard-nav { padding: 0.5rem 0.75rem !important; }
    .dashboard-nav-container {
        flex-wrap: nowrap !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 0.4rem !important;
    }
    .dashboard-brand { gap: 6px !important; flex-shrink: 1 !important; min-width: 0 !important; }
    .dashboard-brand img { height: 28px !important; flex-shrink: 0 !important; }
    .dashboard-brand span {
        font-size: 0.72rem !important;
        line-height: 1.2 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        max-width: 90px !important;
    }
    .dashboard-nav-right {
        flex-wrap: nowrap !important;
        gap: 0.3rem !important;
        flex-shrink: 0 !important;
    }
    /* Status dot only */
    .system-health-pill { padding: 4px 6px !important; }
    .system-health-pill span:not(.dot) { display: none !important; }
    /* Visit website — icon only */
    .dashboard-nav-right > a.btn-primary-action {
        padding: 0.35rem 0.5rem !important;
        font-size: 0 !important;
    }
    .dashboard-nav-right > a.btn-primary-action i { font-size: 0.9rem !important; }

    /* Stats */
    .stat-card { padding: 0.7rem !important; gap: 0.5rem !important; }
    .stat-icon { width: 34px !important; height: 34px !important; font-size: 0.9rem !important; }
    .stat-details h3 { font-size: 1.1rem !important; }
    .stat-details p { font-size: 0.7rem !important; }

    /* Content area */
    .dashboard-main { padding: 0.6rem !important; }
    .dashboard-header-block {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.5rem !important;
        margin-bottom: 0.65rem !important;
    }
    .dashboard-header-block h1 { font-size: 0.95rem !important; }
    .btn-primary-action { width: 100% !important; justify-content: center !important; }

    /* Search & filters */
    .card-header-bar {
        flex-direction: column !important;
        align-items: stretch !important;
        padding: 0.65rem !important;
        gap: 0.5rem !important;
    }
    .search-filter-box { flex-direction: column !important; width: 100% !important; gap: 0.4rem !important; }
    .search-input-wrapper { width: 100% !important; }
    .search-input-wrapper input { width: 100% !important; }
    .filter-select { width: 100% !important; }
    .card-header-title h2 { font-size: 0.9rem !important; }

    /* Table */
    .admin-table-wrapper { overflow-x: auto !important; -webkit-overflow-scrolling: touch !important; }
    .admin-table { min-width: 450px !important; font-size: 0.76rem !important; }
    .admin-table th, .admin-table td {
        padding: 0.45rem 0.6rem !important;
        white-space: nowrap !important;
    }

    /* Pagination */
    .pagination-footer {
        flex-direction: column !important;
        align-items: center !important;
        gap: 0.4rem !important;
        padding: 0.6rem !important;
        font-size: 0.76rem !important;
    }
    .pagination-controls { justify-content: center !important; }

    /* CRUD modal — bottom sheet */
    .admin-modal-overlay { align-items: flex-end !important; }
    .admin-modal.dashboard-modal-container {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 20px 20px 0 0 !important;
        max-height: 92vh !important;
        overflow-y: auto !important;
        margin: 0 !important;
        padding: 1.25rem 1rem 1rem !important;
    }
    .dashboard-form-grid { grid-template-columns: 1fr !important; gap: 0.65rem !important; }
    .dashboard-form-full { grid-column: 1 !important; }
    .dashboard-form-group input,
    .dashboard-form-group select,
    .dashboard-form-group textarea { font-size: 16px !important; }
    .dashboard-modal-body { max-height: 60vh !important; padding-right: 0 !important; }
    .dashboard-modal-footer { flex-direction: column !important; gap: 0.5rem !important; }
    .dashboard-modal-footer button,
    .dashboard-modal-footer .admin-login-submit { width: 100% !important; }

    /* Toast */
    .admin-toast { right: 0.5rem !important; left: 0.5rem !important; bottom: 0.75rem !important; }
}

/* ══════════════════════════════════════════════════════════
   FIX 4: SCROLL-TO-TOP ARROW & WHATSAPP — bottom right
   ══════════════════════════════════════════════════════════ */

/* Back-to-top arrow — always visible at bottom right */
#backToTop,
.back-to-top {
    position: fixed !important;
    bottom: 90px !important;   /* above WhatsApp */
    right: 20px !important;
    z-index: 9999 !important;
    width: 44px !important;
    height: 44px !important;
    border-radius: 50% !important;
    -webkit-transform: translateZ(0) !important;
    transform: translateZ(0) !important;
}

/* WhatsApp button — fixed at bottom right corner */
.whatsapp-float,
.whatsapp-btn,
a[href*="wa.me"],
a[href*="whatsapp"] {
    position: fixed !important;
    bottom: 24px !important;
    right: 20px !important;
    z-index: 9998 !important;
    -webkit-transform: translateZ(0) !important;
    transform: translateZ(0) !important;
}

@media (max-width: 600px) {
    #backToTop, .back-to-top {
        bottom: 85px !important;
        right: 16px !important;
        width: 40px !important;
        height: 40px !important;
        font-size: 0.85rem !important;
    }
    .whatsapp-float, .whatsapp-btn,
    a[href*="wa.me"], a[href*="whatsapp"] {
        bottom: 20px !important;
        right: 16px !important;
        width: 48px !important;
        height: 48px !important;
    }
}

/* ══════════════════════════════════════════════════════════
   FIX 5: LOCK BODY SCROLL WHEN NAV IS OPEN
   ══════════════════════════════════════════════════════════ */
body.nav-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
}

/* ══════════════════════════════════════════════════════════
   FIX 6: SMALL PHONES (≤ 380px)
   ══════════════════════════════════════════════════════════ */
@media (max-width: 380px) {
    .container { padding: 0 0.65rem !important; }
    .section-title { font-size: 1.2rem !important; }
    h1 { font-size: 1.25rem !important; }
    .gallery-grid { grid-template-columns: 1fr !important; }
    .faculty-grid { grid-template-columns: 1fr !important; }
    .nav-menu { width: 92vw !important; }
    .hero { min-height: 300px !important; height: 55vh !important; }
}
