/* ============================================================================
   Responsive / mobile layer.

   Loaded after the page-specific stylesheets so it can correct fixed widths
   that predate mobile support. Breakpoints follow Bootstrap 5, which the rest
   of the site already uses.
   ========================================================================= */

/* A phone must never scroll sideways. Wide content scrolls inside its own
   container instead — see .countries-list and .table-responsive below. */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}

img, svg, canvas, video {
    max-width: 100%;
}

/* height:auto only where the markup does not set an explicit height. Applying
   it unconditionally overrides a height="25" attribute and blows the image up
   to its intrinsic size — which is exactly what happened to the footer logo. */
img:not([height]),
svg:not([height]),
video:not([height]) {
    height: auto;
}

/* ── QR cards ─────────────────────────────────────────────────────────────
   These were a hard 250px, which overflows the 320px viewport of a small
   phone once container padding is taken into account. */
.qr-card {
    width: 100%;
    max-width: 250px;
}

.qr-card img {
    width: 100%;
    max-width: 250px;
    height: auto;
    aspect-ratio: 1 / 1;
}

@media (max-width: 575.98px) {
    .qr-grid {
        gap: 15px;
    }

    .qr-card {
        max-width: 100%;
    }
}

/* ── Statistics ───────────────────────────────────────────────────────── */
.stats-container {
    flex-wrap: wrap;
    gap: 24px;
}

@media (max-width: 575.98px) {
    .stats-container {
        gap: 16px;
    }

    .stat-number {
        font-size: 2rem;
    }

    .card-header h3 {
        font-size: 1.2rem;
    }
}

/* ── Filters ──────────────────────────────────────────────────────────────
   The desktop design is a fixed 320px overlay pinned to the right. On a phone
   that covers most of the screen, so it becomes a bottom sheet instead. */
@media (max-width: 767.98px) {
    .filters-toggle {
        top: auto;
        bottom: 16px;
        right: 16px;
    }

    .filters-panel {
        top: auto;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 80vh;
        overflow-y: auto;
        border-radius: 12px 12px 0 0;
    }
}

/* ── Navigation ───────────────────────────────────────────────────────────
   The bar must stay a single row on a phone. Three things pushed it onto
   several lines: the brand is absolutely centred on desktop, the home page
   wraps its title in an <h1> (2rem by default), and project titles are
   arbitrarily long. */
@media (max-width: 991.98px) {
    #top_navbar {
        min-height: 44px;
        padding-top: 0;
        padding-bottom: 0;
        /* Bootstrap's default wrap, so the collapsed menu drops onto its own
           row when opened. Forcing nowrap kept it inline and squeezed the
           title down to a few characters. The top row still stays on one line
           because the brand shrinks with an ellipsis. */
        flex-wrap: wrap;
    }

    /* Keep the brand and toggler together on the first row. */
    #top_navbar > .navbar-brand,
    #top_navbar > .navbar-toggler {
        flex: 0 1 auto;
    }

    #top_navbar .navbar-brand {
        font-size: 1rem;
        line-height: 1.2;
        padding-top: 0;
        padding-bottom: 0;
        margin-right: 0;
        min-width: 0;              /* lets the flex item actually shrink */
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* The home page puts an <h1> inside the brand; drop it to brand size. */
    #top_navbar .navbar-brand h1 {
        font-size: 1rem;
        line-height: 1.2;
        margin: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* The logo carousel is 50px on desktop. */
    #top_navbar #carousel {
        width: 32px;
    }

    #top_navbar .navbar-brand img {
        max-width: 32px !important;
        max-height: 32px !important;
    }

    /* Keep the gap after the QR mark: the brand rule above resets
       margin-right and this file loads after common.css. */
    #top_navbar .qr-logo-link {
        margin-right: 0.6rem;
    }

    #top_navbar .navbar-toggler {
        flex: 0 0 auto;
        padding: 0.25rem 0.5rem;
        font-size: 0.9rem;
    }

    body {
        padding-top: 52px;
    }

    /* home.html sets padding-top:90px inline to clear the taller desktop bar;
       body already reserves 60px for the 52px mobile bar, so keeping it would
       add ~70px of dead space at the top of the page. */
    [data-bs-spy=scroll] {
        padding-top: 0 !important;
    }
}

@media (max-width: 399.98px) {
    #top_navbar .navbar-brand,
    #top_navbar .navbar-brand h1 {
        font-size: 0.85rem;
    }
}

/* ── Footer ───────────────────────────────────────────────────────────────
   Two long credit lines stacked into a column, pinned with fixed-bottom, once
   cost a third of a phone screen permanently. The bar is fixed again now, so
   the thing that must not come back is the stacking: the credits stay on a
   single centred row that is allowed to scroll sideways rather than wrap into
   a second and third line. --app-footer-h is shrunk to match. */
@media (max-width: 767.98px) {
    :root {
        --app-footer-h: 38px;
    }

    .app-footer {
        padding: 6px 12px;
        font-size: 0.65rem;
        line-height: 1.2;
    }

    .app-footer .footer-row {
        flex-wrap: nowrap;
        justify-content: center;
        gap: 4px 10px;
        overflow-x: auto;
        white-space: nowrap;
    }

    .app-footer div {
        float: none !important;
        text-align: center;
    }

    /* The AImageLab logo is 25px tall by default, which alone would exceed the
       bar. Scaled to fit rather than dropped, so the credit survives. */
    .app-footer img {
        height: 18px;
        width: auto;
    }
}

/* ── Touch targets ────────────────────────────────────────────────────────
   44px is the minimum comfortable tap target. The 16px font size on inputs is
   deliberate: iOS Safari zooms the page in when a focused input is smaller. */
@media (max-width: 767.98px) {
    .btn {
        min-height: 44px;
    }


    .form-control,
    .form-select {
        min-height: 44px;
        font-size: 16px;
    }

    .form-check-input {
        width: 1.25rem;
        height: 1.25rem;
    }
}

/* ── Scrollable regions ───────────────────────────────────────────────── */
.countries-list,
.table-responsive {
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 767.98px) {
    .countries-list {
        max-height: 260px;
    }

    .map-section {
        padding: 10px;
    }
}

/* ── Long URLs must wrap rather than widen the page ──────────────────── */
.text-break-anywhere,
.project-link {
    overflow-wrap: anywhere;
    word-break: break-word;
}

