/* ============================================================================
   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: 52px;
        padding-top: 0;
        padding-bottom: 0;
        flex-wrap: nowrap;
    }

    /* Undo the desktop absolute centring — it overlaps the toggler here. */
    #top_navbar .navbar-brand:nth-child(2) {
        position: static;
        transform: none;
    }

    #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;
    }

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

    body {
        padding-top: 60px;
    }

    /* 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, cost
   a third of a phone screen permanently. On mobile it stops being fixed and
   scrolls with the content, and the two lines sit on one compact row. */
@media (max-width: 767.98px) {
    .app-footer.fixed-bottom {
        position: static;
    }

    .app-footer {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 4px 12px;
        padding: 8px 12px;
        font-size: 0.7rem;
        line-height: 1.3;
    }

    .app-footer .container {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
        gap: 4px 12px;
    }

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

    body {
        padding-bottom: 0;
    }
}

/* ── 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;
}

/* ── Single sign-on button ───────────────────────────────────────────── */
.btn-sso {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 44px;
    font-weight: 600;
}

.sso-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 18px 0;
    color: #6c757d;
    font-size: 0.875rem;
}

.sso-divider::before,
.sso-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: #dee2e6;
}
