/* ============================================================
   Responsive / Mobile-first Styles
   RiskPonse Emergency Response System
   ============================================================

   The primary user is a resident standing in the street with a phone,
   often one-handed, often in a hurry. Everything here serves that:
   big tap targets, short scroll, no horizontal overflow, no hover-only
   affordances.

   Verified at 360px, 768px and 1280px.

   NOTE: this file previously targeted class names that no longer exist in
   the markup (.stat-card, .navbar-riskponse, #mapContainer, .incidents-table).
   Those rules were dead. Selectors below match the current templates.
   ============================================================ */

/* ------------------------------------------------------------
   1. GLOBAL - applies at every width
   ------------------------------------------------------------ */

/* Nothing may push the page sideways. A single wide table or long
   tracking number used to cause a horizontal scrollbar on 360px. */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}

/* Wide content scrolls inside its own box, never the page. */
.table-responsive,
.overflow-scroll-x {
    -webkit-overflow-scrolling: touch;
}

img,
.leaflet-container {
    max-width: 100%;
}

/* Long unbroken strings (tracking numbers, emails) must wrap. */
.font-monospace,
code {
    overflow-wrap: anywhere;
}

/* ------------------------------------------------------------
   2. TOUCH TARGETS
   ------------------------------------------------------------
   WCAG 2.5.5 asks for 44x44 CSS px. Bootstrap's default small
   controls land around 31px, which is a miss on a moving jeepney. */
@media (max-width: 991.98px) {
    .btn,
    .form-control,
    .form-select,
    .nav-link,
    .dropdown-item {
        min-height: 44px;
    }

    /* PHONE LINKS ARE THE MOST IMPORTANT TAP TARGETS IN THE WHOLE APP.
       Measured at 21-26px before this rule - too small to hit reliably while
       walking, and the one thing a person must not miss in an emergency. */
    a[href^="tel:"] {
        display: inline-flex;
        align-items: center;
        min-height: 44px;
        padding: .35rem .15rem;
        font-weight: 600;
    }

    /* Footer navigation links measured 26px tall. The 44px target goes on the LINK
       only - never on the <li>, and never as plain `flex`.
       A flex <li> makes "BPSO:" and the number beside it two independent flex items
       that size and align separately, and it drops the whitespace between them, so
       the row renders as "BPSO:8-655-1679". Plain `flex` on the link makes it
       block-level, which pushes the footer email onto its own line away from its
       icon. inline-flex keeps the link in the text flow, align-items centres its
       text inside the 44px box, and vertical-align centres that box on the line -
       so the label and its number stay level at any width. */
    .footer a {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        vertical-align: middle;
    }
    .footer .list-unstyled li {
        margin-bottom: .15rem;
    }

    .btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Icon-only buttons need width too, not just height. */
    .btn-icon,
    .btn.btn-sm > i:only-child {
        min-width: 44px;
    }

    /* Keep small buttons visually small but still tappable. */
    .btn-sm {
        padding-top: .5rem;
        padding-bottom: .5rem;
    }

    /* Checkboxes and radios are tiny by default. */
    .form-check-input {
        width: 1.35rem;
        height: 1.35rem;
        margin-top: .15rem;
    }
    .form-check-label {
        padding-left: .25rem;
        min-height: 1.35rem;
    }
}

/* iOS zooms the page when a focused input is under 16px. Applied up to 991px,
   not 767px: a 768px tablet is still a touch device and zooms the same way. */
@media (max-width: 991.98px) {
    .form-control,
    .form-select,
    textarea,
    input[type="text"],
    input[type="tel"],
    input[type="email"],
    input[type="password"],
    input[type="datetime-local"],
    input[type="file"] {
        font-size: 16px;
    }
}

/* ------------------------------------------------------------
   3. NAVBAR
   ------------------------------------------------------------ */

/* ---- Desktop alignment ----
   The links sat unevenly because two labels ("Report an Incident",
   "Track a Report") wrapped onto a second line while the rest stayed on one,
   and the list items stretched instead of centring. Result: icons and text at
   different heights across the bar.

   Fix: keep every label on one line and centre each link's contents. */
@media (min-width: 992px) {
    .navbar-expand-lg .navbar-nav {
        align-items: center;
    }
    .navbar-expand-lg .navbar-nav .nav-link {
        display: flex;
        align-items: center;
        white-space: nowrap;
        padding-top: .5rem;
        padding-bottom: .5rem;
        line-height: 1.2;
    }
    .navbar-expand-lg .navbar-nav .nav-link > i {
        flex: 0 0 auto;
    }

    /* Tighten spacing so the extra width from nowrap does not overflow. */
    .navbar-expand-lg .navbar-nav .nav-link {
        padding-left: .6rem;
        padding-right: .6rem;
    }

    /* The clock is the widest, least useful item in the bar. Keep it, but only
       where there is genuinely room for it. */
    #realtime-clock {
        white-space: nowrap;
    }
}

/* Below 1400px the full date string crowds the links off the bar. Hide the
   whole list item, not just the span - otherwise its me-3 margin remains. */
@media (max-width: 1399.98px) {
    .nav-clock {
        display: none !important;
    }
}

@media (max-width: 991.98px) {
    .navbar-collapse {
        max-height: 75vh;
        overflow-y: auto;
        margin-top: .5rem;
        padding: .5rem 0;
        border-top: 1px solid rgba(255, 255, 255, .12);
    }

    .navbar-nav .nav-link {
        padding: .75rem .5rem;
        border-bottom: 1px solid rgba(255, 255, 255, .07);
    }
    .navbar-nav:last-child .nav-link:last-child {
        border-bottom: none;
    }

    .navbar-toggler {
        min-width: 44px;
        min-height: 44px;
    }

    /* The clock eats a whole row on a phone and tells the user nothing
       they cannot see in their status bar. */
    #realtime-clock {
        display: none !important;
    }
}

/* ------------------------------------------------------------
   4. HERO
   ------------------------------------------------------------ */
@media (max-width: 767.98px) {
    .hero-section {
        padding: 2rem 0 1.5rem;
    }
    .hero-section .py-5 {
        padding-top: 1.5rem !important;
        padding-bottom: 1.5rem !important;
    }
    .hero-section h1 {
        font-size: 1.75rem;
    }
    .hero-section h1 img {
        height: 40px;
    }
    .hero-section .lead {
        font-size: 1rem;
    }
    .hero-section .fs-5 {
        font-size: 1rem !important;
    }

    /* Report and Track are the two things that matter - make them
       full-width and thumb-sized, stacked in priority order. */
    .hero-section .btn-lg {
        width: 100%;
        font-size: 1.05rem;
        padding: .85rem 1rem;
    }

    /* 2x2 stat grid instead of a long column. */
    .hero-stat {
        flex: 0 0 calc(50% - .75rem);
    }
    .hero-stat .fs-2 {
        font-size: 1.5rem !important;
    }
}

/* ------------------------------------------------------------
   5. EMERGENCY HOTLINE BAR
   ------------------------------------------------------------
   This is the most important thing on the page during an emergency.
   Every entry is a tel: link and must be comfortably tappable. */
@media (max-width: 991.98px) {
    .hotline-bar a {
        min-height: 52px;
        display: flex !important;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        line-height: 1.25;
        border-radius: .4rem;
    }
    .hotline-bar a:active {
        background: rgba(255, 255, 255, .18);
    }
}

/* ------------------------------------------------------------
   6. FEATURE CARDS
   ------------------------------------------------------------
   Stacked full-width cards produced roughly one card per screen -
   six screens of scrolling to read six short blurbs. On phones the
   layout flips to icon-left / text-right, which is far more compact
   and scans like a list. */
@media (max-width: 767.98px) {
    .feature-card .card-body {
        display: flex;
        align-items: flex-start;
        gap: .9rem;
        text-align: left !important;
        padding: 1rem !important;
    }

    .feature-card .feature-icon {
        flex: 0 0 46px;
        width: 46px;
        height: 46px;
        margin: 0 !important;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .feature-card .feature-icon .fa-2x {
        font-size: 1.25rem;
    }

    .feature-card h5 {
        font-size: 1rem;
        margin-bottom: .2rem;
    }
    .feature-card p {
        font-size: .875rem;
        margin-bottom: 0;
        line-height: 1.45;
    }

    /* Tighten the gaps between them. */
    .feature-card {
        margin-bottom: 0;
    }
}

/* ------------------------------------------------------------
   6b. EMERGENCY CONTACT CARDS
   ------------------------------------------------------------
   Six full-width cards measured ~110px each. Compacted to list rows,
   which also makes the phone number the obvious tap target. */
@media (max-width: 767.98px) {
    .contact-card .card-body {
        padding: .65rem .85rem !important;
    }
    .contact-card .fa-2x {
        font-size: 1.35rem;
    }
    .contact-card h6 {
        font-size: .95rem;
        margin-bottom: 0;
    }
    .contact-card .text-muted.small {
        font-size: .78rem;
    }
}

/* ------------------------------------------------------------
   7. SECTION RHYTHM
   ------------------------------------------------------------ */
@media (max-width: 767.98px) {
    section.py-5 {
        padding-top: 2rem !important;
        padding-bottom: 2rem !important;
    }
    section h2,
    section h3 {
        font-size: 1.35rem;
    }
    .display-4 {
        font-size: 1.9rem;
    }
}

/* ------------------------------------------------------------
   8. REPORT FORM - the critical one-handed flow
   ------------------------------------------------------------ */
@media (max-width: 767.98px) {
    #reportForm .card-body {
        padding: 1rem !important;
    }
    #reportForm .card-header {
        padding: .85rem 1rem;
    }
    #reportForm .card-header h5 {
        font-size: 1rem;
        margin: 0;
    }
    #reportForm .form-label {
        margin-bottom: .3rem;
    }
    #reportForm .form-text {
        font-size: .8rem;
    }

    /* Submit stays reachable without scrolling back down. */
    .report-actions {
        position: sticky;
        bottom: 0;
        z-index: 1020;
        background: var(--rp-body-bg, #f0f2f5);
        padding: .75rem 0;
        margin: 0 -.75rem;
        padding-left: .75rem;
        padding-right: .75rem;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, .08);
    }
    .report-actions .btn {
        flex: 1 1 auto;
    }
    .report-actions .btn-lg {
        font-size: 1.05rem;
        padding: .8rem 1rem;
    }
}

/* ------------------------------------------------------------
   9. MAPS
   ------------------------------------------------------------ */
@media (max-width: 767.98px) {
    #location-map {
        height: 260px !important;
    }
    #incidents-map {
        height: 60vh !important;
        min-height: 320px;
    }
    #hero-map {
        height: 220px !important;
    }

    /* Leaflet's default zoom buttons are ~26px - too small to hit. */
    .leaflet-touch .leaflet-bar a {
        width: 40px;
        height: 40px;
        line-height: 40px;
        font-size: 1.2rem;
    }
    .leaflet-popup-content {
        margin: .65rem .75rem;
        font-size: .875rem;
    }
}

/* Deliberately NOT overriding touch-action on .leaflet-container.
   Leaflet sets it itself to manage drag/pinch; overriding it hands the
   gesture back to the browser and breaks panning the pin on a phone.
   The map is kept short (260px) instead, so there is always page above
   and below it to scroll with. */

/* ------------------------------------------------------------
   10. TRACKING PAGE
   ------------------------------------------------------------ */
@media (max-width: 575.98px) {
    /* The progress stepper must stay on one line at 360px. */
    .track-stepper .small {
        font-size: .68rem !important;
    }
    .track-stepper span.rounded-circle {
        width: 20px !important;
        height: 20px !important;
    }

    /* dl rows read better stacked than as two cramped columns. */
    .track-details dt {
        margin-bottom: .1rem;
    }
    .track-details dd {
        margin-bottom: .75rem;
    }
}

/* ------------------------------------------------------------
   11. TABLES
   ------------------------------------------------------------
   Staff screens are laptop-first, but a responder on the road still
   needs them. Tables scroll horizontally inside their container. */
@media (max-width: 767.98px) {
    .table {
        font-size: .82rem;
    }
    .table th,
    .table td {
        padding: .5rem .4rem;
        white-space: nowrap;
    }
    .table td .badge {
        font-size: .7rem;
    }
}

/* ------------------------------------------------------------
   12. CHATBOT WIDGET
   ------------------------------------------------------------ */
@media (max-width: 575.98px) {
    .chatbot-panel {
        width: calc(100vw - 16px);
        right: 8px;
        left: 8px;
        bottom: 76px;
        max-height: 70vh;
    }
    .chatbot-fab {
        width: 52px;
        height: 52px;
        bottom: 14px;
        right: 14px;
    }
    .chatbot-quick-actions .btn {
        font-size: .78rem;
        padding: .45rem .6rem;
        min-height: 40px;
    }
}

/* ------------------------------------------------------------
   13. FOOTER
   ------------------------------------------------------------ */
@media (max-width: 767.98px) {
    .footer .col-md-4 {
        margin-bottom: 1.25rem;
    }
    /* Padding only - do NOT set `display` here.
       This block used to add `display: inline-block`, which quietly overrode the
       `display: flex` set at the 992px breakpoint above (same specificity, later in
       the file). The link kept its 44px min-height but lost `align-items: center`,
       which only applies to a flex container. So the number sat at the TOP of its
       44px box while its label, a plain text flex item, centred in the row - and
       every hotline number rendered visibly higher than the label it belonged to. */
    .footer a {
        padding: .15rem 0;
    }
}

/* ------------------------------------------------------------
   14. TABLET
   ------------------------------------------------------------ */
@media (min-width: 768px) and (max-width: 991.98px) {
    .hero-section h1 {
        font-size: 2.25rem;
    }
    #location-map {
        height: 300px !important;
    }
    .chatbot-panel {
        width: 360px;
    }
}

/* ------------------------------------------------------------
   15. LARGE SCREENS
   ------------------------------------------------------------ */
@media (min-width: 1200px) {
    .container-fluid {
        max-width: 1400px;
    }
}

/* ------------------------------------------------------------
   16. TOUCH DEVICES - remove hover-only behaviour
   ------------------------------------------------------------
   On touch, :hover sticks after a tap, leaving cards visually stuck
   in a hovered state. */
@media (hover: none) {
    .card:hover,
    .feature-card:hover {
        transform: none;
        box-shadow: var(--rp-card-shadow);
    }
    .feature-card:hover .feature-icon {
        transform: none;
    }
    /* Give a real press response instead. */
    .btn:active {
        transform: scale(.985);
    }
}

/* ------------------------------------------------------------
   17. PRINT - staff sometimes print an incident for the logbook
   ------------------------------------------------------------ */
@media print {
    .navbar,
    .footer,
    .chatbot-fab,
    .chatbot-panel,
    .report-actions,
    .btn {
        display: none !important;
    }
    body {
        background: #fff;
    }
    .card {
        border: 1px solid #ccc !important;
        box-shadow: none !important;
        break-inside: avoid;
    }
}

/* ------------------------------------------------------------
   18. REDUCED MOTION
   ------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}
