/* ============================================================
   FRONTEND MOBILE UX OVERRIDES
   Loaded AFTER each page's inline <style>, so its rules win.
   Targets phones (<=768px) and small phones (<=480px).
   Goal: tighter layout, larger tap targets, no horizontal scroll,
   readable type, accessible nav, no iOS-zoom-on-focus.
   ============================================================ */

/* Global safety: stop horizontal overflow that breaks on phones */
html, body { overflow-x: hidden; max-width: 100%; }
img, video, iframe { max-width: 100%; height: auto; }

/* ---------- TABLET / LARGE PHONE (<= 1024px) ---------- */
@media (max-width: 1024px) {
    .header-inner { gap: 12px; }
    .nav-link-a { padding: 18px 12px; font-size: 13px; }
    .logo-text-name { font-size: 18px; }
    .section { padding: 56px 18px; }
    .section-header { margin-bottom: 36px; }
}

/* ---------- PHONE (<= 768px) ---------- */
@media (max-width: 768px) {
    /* Allow the topbar to stay (it has helpful login/contact links) — keep it compact and scrollable instead of hidden */
    .topbar { display: block !important; padding: 6px 0; font-size: 11px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .topbar-inner { padding: 0 12px; gap: 6px; flex-wrap: nowrap; min-width: max-content; justify-content: flex-start; }
    .topbar-left { gap: 10px; flex-shrink: 0; }
    .topbar-right { gap: 4px; flex-shrink: 0; }
    .topbar-link { padding: 2px 8px; font-size: 11px; }
    .topbar-left a { font-size: 11px; gap: 4px; }

    /* Header layout: logo + hamburger only, hide desktop nav + actions */
    .header-inner { padding: 0 12px; gap: 8px; min-height: 60px; }
    .nav { display: none !important; }
    .nav-actions { display: none !important; }
    .hamburger { display: flex !important; align-items: center; justify-content: center; width: 44px; height: 44px; font-size: 22px; margin-left: auto; }

    .logo-wrap { gap: 8px; padding: 8px 0; min-width: 0; flex: 1; }
    .logo-img { width: 44px; height: 44px; font-size: 14px; flex-shrink: 0; }
    .logo-text { min-width: 0; overflow: hidden; }
    .logo-text-name { font-size: 14px; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .logo-text-sub { font-size: 10px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

    /* Mobile menu: full-width, larger tap targets, smooth */
    .mobile-menu { padding: 8px 0 14px; max-height: calc(100vh - 60px); overflow-y: auto; -webkit-overflow-scrolling: touch; }
    .mobile-menu a { padding: 14px 18px; font-size: 14px; min-height: 44px; display: flex; align-items: center; }

    /* Notice ticker: readable text, slower so users can read */
    .notice-bar { padding: 8px 0; }
    .notice-bar-inner { padding: 0 12px; gap: 10px; }
    .notice-label { font-size: 10px; padding: 2px 10px; }
    .notice-item { font-size: 12px; }
    .notice-ticker-inner { animation-duration: 60s; gap: 36px; }

    /* Sections: tighter vertical rhythm */
    .section { padding: 44px 16px; }
    .section-header { margin-bottom: 28px; }
    .section-tag { font-size: 10px; padding: 3px 10px; }
    .section-title { font-size: 22px; }
    .section-subtitle { font-size: 13px; line-height: 1.65; }

    /* Hero: tighter padding, hide decorative mosque, stats compact */
    .hero { min-height: auto; }
    .hero-inner { padding: 44px 16px !important; }
    .hero-mosque { display: none; }
    .hero-content { max-width: 100%; }
    .hero-badge { font-size: 11px; padding: 4px 12px; margin-bottom: 14px; }
    .hero-title { font-size: 24px; margin-bottom: 10px; }
    .hero-title-en { font-size: 13px; margin-bottom: 14px; }
    .hero-recog { font-size: 12px; padding: 8px 12px; margin-bottom: 20px; }
    .hero-buttons { gap: 8px; margin-bottom: 28px; }
    .hero-buttons .btn { width: 100%; justify-content: center; padding: 12px 20px; font-size: 13px; }
    .hero-stats { gap: 14px; justify-content: space-between; width: 100%; }
    .hero-stat { flex: 1 1 calc(50% - 8px); text-align: center; min-width: 0; }
    .hero-stat-num { font-size: 20px; }
    .hero-stat-lbl { font-size: 10px; }
    .hero-stat-divider { display: none; }
    .hero-nav { width: 36px; height: 36px; font-size: 13px; }
    .hero-prev { left: 8px; }
    .hero-next { right: 8px; }
    .hero-dots { bottom: 10px; gap: 6px; }
    .hero-dot { width: 8px; height: 8px; }

    /* Generic page hero (interior pages) */
    .page-hero { padding: 36px 16px !important; }
    .page-hero h1 { font-size: 22px !important; }
    .page-hero p { font-size: 13px !important; }
    .breadcrumb { font-size: 12px; }

    /* Buttons: ensure 44px tap target */
    .btn { min-height: 44px; padding: 11px 18px; font-size: 13px; }
    .btn-primary, .btn-orange, .btn-outline-white, .btn-white, .btn-orange-outline { min-height: 44px; }

    /* Forms: 16px font on inputs prevents iOS zoom-on-focus */
    .form-input, .form-textarea, input[type="text"], input[type="email"], input[type="tel"], input[type="password"], input[type="search"], input[type="number"], input[type="date"], select, textarea {
        font-size: 16px !important;
        min-height: 44px;
    }
    .form-textarea, textarea { min-height: 120px; }
    .form-card, .info-panel { padding: 22px 18px !important; }
    .form-row { grid-template-columns: 1fr !important; gap: 12px !important; }
    .submit-btn { min-height: 48px; font-size: 15px; }

    /* Cards: tighter inner spacing */
    .course-card-header { padding: 16px 16px 12px; }
    .course-card-title { font-size: 15px; }
    .course-card-body { padding: 14px; gap: 12px; }
    .course-student-num { font-size: 18px; }
    .course-subject-item { font-size: 12px; }

    /* Departments grid: 2 cols on tablet/phone */
    .depts-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 12px; }
    .dept-card { padding: 18px 12px; }
    .dept-icon { width: 48px; height: 48px; font-size: 20px; margin-bottom: 10px; }
    .dept-name { font-size: 12px; }

    /* Why-IOM grid */
    .why-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 12px; }
    .why-card { padding: 18px 14px; }
    .why-icon { width: 52px; height: 52px; font-size: 22px; margin-bottom: 12px; }

    /* Scholars / testimonials */
    .scholars-grid { grid-template-columns: 1fr !important; gap: 14px; }
    .scholar-card { padding: 20px 16px; }
    .scholar-avatar { width: 64px; height: 64px; font-size: 22px; }

    /* Services */
    .services-grid { grid-template-columns: 1fr !important; gap: 12px; }
    .service-card { padding: 16px; }

    /* Notice item rows: tighter */
    .notice-item-row { gap: 10px; padding: 12px 0; }
    .notice-date { padding: 6px 8px; min-width: 46px; }
    .notice-date-day { font-size: 16px; }
    .notice-date-month { font-size: 9px; }
    .notice-item-title { font-size: 13px; }

    /* Quick links */
    .quick-links-box { padding: 18px; }
    .quick-link-item { padding: 12px 14px; min-height: 44px; }

    /* Info-cards (contact) */
    .info-cards { grid-template-columns: 1fr !important; gap: 12px !important; }

    /* CTA */
    .cta-section { padding: 48px 16px !important; }
    .cta-title { font-size: 22px !important; }
    .cta-desc { font-size: 14px !important; margin-bottom: 22px; }
    .cta-btns { gap: 10px; flex-direction: column; }
    .cta-btns .btn { width: 100%; justify-content: center; }

    /* Footer */
    .footer { padding: 40px 16px 0 !important; }
    .footer-grid { grid-template-columns: 1fr !important; gap: 28px !important; margin-bottom: 28px; }
    .footer-logo-name { font-size: 16px; }
    .footer-tagline { max-width: 100%; font-size: 12px; }
    .footer-link { font-size: 13px; min-height: 36px; align-items: center; }
    .footer-bottom { flex-direction: column; text-align: center; gap: 10px !important; padding: 16px 0; }
    .footer-bottom-links { justify-content: center; }
    .footer-copy { font-size: 11px; }

    /* Tables (results pages, etc.) — wrap in scrollable container */
    table { font-size: 13px; }
    .table-responsive, .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table td, table th { padding: 8px 10px; white-space: nowrap; }

    /* Map */
    .map-frame, .map iframe { height: 280px !important; }

    /* Back-to-top: don't crowd thumb-zone */
    .back-top { width: 40px; height: 40px; bottom: 16px; right: 16px; font-size: 16px; }

    /* Generic grids that show up across pages */
    .teachers-grid, .staffs-grid, .gallery-grid, .books-grid, .albums-grid, .q-grid, .exams-grid, .info-grid, .summary-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }

    /* Make all anchor/button tap targets at least 44px tall */
    a.btn, button.btn, .donate-btn { min-height: 44px; display: inline-flex; align-items: center; }
}

/* ---------- SMALL PHONE (<= 480px) ---------- */
@media (max-width: 480px) {
    .header-inner { padding: 0 10px; }
    .logo-img { width: 38px; height: 38px; font-size: 12px; }
    .logo-text-name { font-size: 13px; }
    .logo-text-sub { display: none; }

    .section { padding: 36px 14px; }
    .section-title { font-size: 19px; }
    .section-subtitle { font-size: 12px; }

    .hero-inner { padding: 32px 14px !important; }
    .hero-title { font-size: 20px; }
    .hero-recog { font-size: 11px; }
    .hero-stat-num { font-size: 17px; }
    .hero-stat-lbl { font-size: 9px; }

    .page-hero { padding: 28px 14px !important; }
    .page-hero h1 { font-size: 19px !important; }
    .page-hero p { font-size: 12px !important; }

    /* Single-column grids on small phones for readability */
    .courses-grid { grid-template-columns: 1fr !important; }
    .why-grid { grid-template-columns: 1fr !important; }
    .scholars-grid { grid-template-columns: 1fr !important; }
    .teachers-grid, .staffs-grid, .gallery-grid, .books-grid, .albums-grid, .q-grid, .exams-grid, .info-grid, .summary-grid {
        grid-template-columns: 1fr !important;
    }
    /* Departments stay 2-col since they're small icons */
    .depts-grid { grid-template-columns: repeat(2, 1fr) !important; }

    .form-card, .info-panel { padding: 18px 14px !important; }

    .footer { padding: 32px 14px 0 !important; }
    .footer-grid { gap: 24px !important; }
}

/* Print: hide nav, ticker, back-to-top */
@media print {
    .topbar, .header, .mobile-menu, .notice-bar, .back-top, .footer, .hero-nav, .hero-dots { display: none !important; }
    .section { padding: 16px 0 !important; }
}
