/* ═══════════════════════════════════════════════════════════════════════
   MOBILE / IPHONE OPTIMIZATIONS
   Targets: iPhone SE (375px) through iPhone Pro Max (430px)
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {

    /* ── Layout ──────────────────────────────────────────────────────── */
    .container-fluid.mt-4.px-4 {
        padding-left: 12px !important;
        padding-right: 12px !important;
        margin-top: 12px !important;
    }

    /* ── Navbar ──────────────────────────────────────────────────────── */
    .navbar {
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .navbar .container-fluid {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    .navbar-brand {
        font-size: 1.1rem;
    }

    /* Collapsed menu: stack links vertically with generous touch targets */
    .navbar-collapse .nav-link {
        font-family: system-ui, -apple-system, sans-serif !important;
        padding: 10px 8px !important;
        font-size: 1rem;
        border-bottom: 1px solid rgba(255,255,255,0.08);
    }

    .navbar-collapse .navbar-nav:last-child .nav-link {
        border-bottom: none;
    }

    /* Active indicator: left bar instead of bottom border on mobile */
    .navbar .nav-link.active {
        border-bottom: none !important;
        border-left: 3px solid white;
        padding-left: 12px !important;
    }

    /* ── Cards ───────────────────────────────────────────────────────── */
    .card {
        border-radius: 10px;
        margin-top: 16px;
    }

    .card-body {
        padding: 14px !important;
    }

    .card-header {
        padding: 10px 14px !important;
        font-size: 0.9rem;
    }

    /* ── Typography ──────────────────────────────────────────────────── */
    body {
        font-size: 1rem !important;
        -webkit-text-size-adjust: 100%;
    }

    h1 { font-size: 1.5rem !important; }
    h2 { font-size: 1.3rem !important; }
    h3 { font-size: 1.15rem !important; }
    h4 { font-size: 1.05rem !important; }
    h5 { font-size: 0.95rem !important; }

    /* ── Forms & Inputs ──────────────────────────────────────────────── */
    /* iOS prevents zooming on inputs < 16px */
    input, select, textarea,
    .form-control, .form-select {
        font-size: 16px !important;
        min-height: 44px;
        border-radius: 8px !important;
    }

    .form-label {
        font-size: 0.875rem;
        margin-bottom: 4px;
    }

    /* ── Buttons ─────────────────────────────────────────────────────── */
    .btn {
        min-height: 44px;
        padding: 10px 18px;
        font-size: 0.95rem;
        border-radius: 8px !important;
        touch-action: manipulation;
    }

    .btn-sm {
        min-height: 36px;
        padding: 6px 12px;
        font-size: 0.85rem;
    }

    /* Full-width buttons in tight containers */
    .btn-block-mobile {
        width: 100%;
    }

    /* ── Tables ──────────────────────────────────────────────────────── */
    /* Scroll horizontally rather than overflow */
    .table-responsive-mobile {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Make tables smaller on mobile */
    .table {
        font-size: 0.78rem;
    }

    .table td, .table th {
        padding: 6px 8px !important;
        white-space: nowrap;
    }

    /* ── Alerts ──────────────────────────────────────────────────────── */
    .alert {
        font-size: 0.9rem;
        padding: 10px 12px;
        border-radius: 8px;
    }

    /* ── Modals ──────────────────────────────────────────────────────── */
    .modal-dialog {
        margin: 8px;
    }

    .modal-content {
        border-radius: 16px;
    }

    .modal-body {
        padding: 16px;
    }

    /* ── Grid spacing ────────────────────────────────────────────────── */
    .row {
        --bs-gutter-x: 12px;
    }

    .col, [class*="col-"] {
        padding-left: 6px;
        padding-right: 6px;
    }

    /* Stack 2-column layouts on mobile */
    .col-md-6, .col-md-4, .col-md-3 {
        margin-bottom: 12px;
    }

    /* ── Dashboard cards ─────────────────────────────────────────────── */
    .gdp-card, .chart-wrapper {
        margin-bottom: 16px !important;
    }

    /* ── Select2 dropdowns ───────────────────────────────────────────── */
    .select2-container .select2-selection--single {
        min-height: 44px !important;
        line-height: 44px !important;
        font-size: 16px !important;
    }

    .select2-container .select2-selection__rendered {
        line-height: 44px !important;
        padding-left: 12px !important;
    }

    .select2-container .select2-selection__arrow {
        height: 44px !important;
    }

    /* ── Safe area insets (notch / home indicator) ───────────────────── */
    body {
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    .navbar {
        padding-top: max(8px, env(safe-area-inset-top));
    }

    /* ── Scrollable panels ───────────────────────────────────────────── */
    .overflow-auto, .scrollable {
        -webkit-overflow-scrolling: touch;
    }

    /* ── Reduce excessive whitespace ─────────────────────────────────── */
    .mb-4 { margin-bottom: 1rem !important; }
    .mb-5 { margin-bottom: 1.25rem !important; }
    .mt-4 { margin-top: 1rem !important; }
    .py-4 { padding-top: 1rem !important; padding-bottom: 1rem !important; }
    .px-4 { padding-left: 12px !important; padding-right: 12px !important; }

    /* ── Metros page specific ────────────────────────────────────────── */
    .metro-tab-btn {
        font-size: 0.75rem !important;
        padding: 6px 10px !important;
        min-height: 36px;
    }

    /* Rank tables: allow horizontal scroll */
    .rank-table {
        font-size: 0.72rem !important;
    }

    /* ── Data page chart ─────────────────────────────────────────────── */
    .chart-container {
        min-height: 280px !important;
    }

    /* ── Hide low-priority columns on tiny screens ───────────────────── */
    @media (max-width: 430px) {
        .hide-xs { display: none !important; }
    }
}

/* ── Smooth scrolling & tap highlight ───────────────────────────────── */
* {
    -webkit-tap-highlight-color: rgba(44, 82, 130, 0.15);
}

html {
    scroll-behavior: smooth;
}

/* Prevent double-tap zoom on buttons/links */
a, button, .btn, [role="button"] {
    touch-action: manipulation;
}

/* ── Chart & map button font — matches body Garamond ────────────────── */
.chart-toggle-btn,
.time-range-btn,
.map-legend-btn,
.map-ctrl-btn {
    font-family: 'EB Garamond', Georgia, 'Times New Roman', serif !important;
    font-size: 0.95rem !important;
    letter-spacing: 0.01em;
}
