/* =========================================================
   ResQAI Mobile System Plan
   Breakpoints:
   - Mobile: <768px
   - Tablet: 768px to 1024px
   ========================================================= */

:root {
    --mobile-header-offset: 5rem;
    --mobile-space-1: 0.75rem;
    --mobile-space-2: 1rem;
    --mobile-space-3: 1.25rem;
    --mobile-card-radius: 0.95rem;
    --mobile-card-padding: 0.9rem;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    max-width: 100%;
}

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

/* Global no-overflow guardrails */
main,
section,
article,
aside,
header,
footer,
div {
    max-width: 100%;
}

/* Reusable drawer controls injected by mobile-ui.js */
body.mobile-drawer-active .mobile-drawer-overlay {
    position: fixed;
    inset: 0;
    z-index: 39;
    background: rgba(0, 0, 0, 0.58);
    backdrop-filter: blur(1px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.22s ease, visibility 0.22s ease;
}

body.mobile-drawer-open .mobile-drawer-overlay {
    opacity: 1;
    visibility: visible;
}

.mobile-drawer-trigger {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 45;
    width: 3rem;
    height: 3rem;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    background: rgba(16, 20, 26, 0.92);
    color: #dfe2eb;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.36);
}

.mobile-drawer-trigger:focus-visible {
    outline: 2px solid #14d1ff;
    outline-offset: 2px;
}

@media (max-width: 1024px) {

    html,
    body {
        overflow-x: hidden !important;
    }

    body {
        font-size: 15px;
        line-height: 1.45;
        touch-action: manipulation;
    }

    .mobile-drawer-trigger {
        display: inline-flex;
    }

    body.mobile-drawer-active aside.mobile-drawer {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        z-index: 40 !important;
        width: min(84vw, 320px) !important;
        max-width: 100% !important;
        height: 100dvh !important;
        display: flex !important;
        transform: translateX(-108%) !important;
        transition: transform 0.24s ease !important;
        overflow-y: auto !important;
    }

    body.mobile-drawer-open aside.mobile-drawer {
        transform: translateX(0) !important;
    }

    .ml-72,
    .ml-64,
    .lg\:ml-64,
    .md\:ml-72,
    .lg\:ml-72 {
        margin-left: 0 !important;
    }

    .h-screen {
        height: auto !important;
        min-height: calc(100dvh - var(--mobile-header-offset));
    }

    .max-w-7xl,
    .max-w-6xl,
    .max-w-5xl,
    .max-w-4xl,
    .max-w-3xl,
    .max-w-2xl {
        max-width: 100% !important;
    }

    /* Tablet grid strategy (768-1024): reduce dense layouts */
    .grid.grid-cols-12,
    .grid.grid-cols-4,
    .grid.grid-cols-5,
    .grid.grid-cols-6 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    [class*='col-span-'] {
        grid-column: auto !important;
    }

    /* Adaptive cards on tablet */
    .card,
    .glass-card,
    .alert-card,
    .summary-card,
    .system-card,
    .panel-card,
    .status-card,
    .scenario-card,
    .hotel-card,
    .guest-info-card,
    [class*='card '] {
        border-radius: 1rem !important;
        padding: 1rem !important;
    }

    button,
    .btn,
    .btn-primary,
    .btn-secondary,
    .action-btn,
    .nav-link,
    .nav-tab,
    a[role='button'] {
        min-height: 44px;
        min-width: 44px;
    }

    input,
    textarea,
    select {
        font-size: 16px !important;
    }

    .resq-footer-container {
        grid-template-columns: 1fr 1fr !important;
        gap: var(--mobile-space-2) !important;
    }

    table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 767px) {
    :root {
        --mobile-header-offset: 4.75rem;
    }

    body {
        font-size: 14px;
        line-height: 1.5;
    }

    .mobile-drawer-trigger {
        right: 0.75rem;
        bottom: 0.75rem;
    }

    /* Mobile grid strategy: stack everything */
    .grid,
    .grid.grid-cols-12,
    .grid.grid-cols-6,
    .grid.grid-cols-5,
    .grid.grid-cols-4,
    .grid.grid-cols-3,
    .grid.grid-cols-2 {
        grid-template-columns: 1fr !important;
    }

    .sm\:grid-cols-2,
    .sm\:grid-cols-3,
    .sm\:grid-cols-4,
    .md\:grid-cols-2,
    .md\:grid-cols-3,
    .md\:grid-cols-4,
    .lg\:grid-cols-2,
    .lg\:grid-cols-3,
    .lg\:grid-cols-4,
    .lg\:grid-cols-12 {
        grid-template-columns: 1fr !important;
    }

    [class*='col-span-'] {
        grid-column: 1 / -1 !important;
    }

    .p-8,
    .px-8,
    .py-8,
    .p-6,
    .px-6,
    .py-6,
    .p-5,
    .px-5,
    .py-5 {
        padding: var(--mobile-space-2) !important;
    }

    .gap-8,
    .gap-7,
    .gap-6,
    .gap-5 {
        gap: var(--mobile-space-2) !important;
    }

    /* Mobile card strategy: compact but readable */
    .card,
    .glass-card,
    .alert-card,
    .summary-card,
    .system-card,
    .panel-card,
    .status-card,
    .scenario-card,
    .hotel-card,
    .guest-info-card,
    [class*='card '] {
        border-radius: var(--mobile-card-radius) !important;
        padding: var(--mobile-card-padding) !important;
    }

    .text-8xl,
    .text-7xl,
    .text-6xl,
    .text-5xl {
        font-size: clamp(1.75rem, 9vw, 2.3rem) !important;
        line-height: 1.15 !important;
    }

    .text-4xl {
        font-size: clamp(1.4rem, 6vw, 1.8rem) !important;
        line-height: 1.2 !important;
    }

    .text-3xl {
        font-size: clamp(1.2rem, 5vw, 1.5rem) !important;
    }

    .text-lg {
        font-size: 1rem !important;
    }

    .resq-footer-container {
        grid-template-columns: 1fr !important;
    }
}

/* =========================================================
   Module-specific compact mode (attached 3 targets)
   ========================================================= */

@media (max-width: 767px) {

    /* ---------- Module Selection ---------- */
    body.mobile-module-selection main {
        padding-top: 5.2rem !important;
    }

    body.mobile-module-selection nav>div {
        padding: 0.65rem 0.85rem !important;
    }

    body.mobile-module-selection section.max-w-7xl {
        padding-left: 0.85rem !important;
        padding-right: 0.85rem !important;
    }

    body.mobile-module-selection section.max-w-7xl.mx-auto.px-8.pt-16.pb-8 {
        padding-top: 0.85rem !important;
        padding-bottom: 0.5rem !important;
    }

    body.mobile-module-selection section.max-w-7xl.mx-auto.px-8.py-8>.grid.grid-cols-1.md\:grid-cols-3 {
        display: flex !important;
        grid-template-columns: none !important;
        gap: 0.75rem !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        padding-bottom: 0.45rem;
    }

    body.mobile-module-selection section.max-w-7xl.mx-auto.px-8.py-8>.grid.grid-cols-1.md\:grid-cols-3>div {
        min-width: 84vw;
        max-width: 84vw;
        scroll-snap-align: start;
    }

    body.mobile-module-selection .glass-card {
        padding: 0.9rem !important;
        border-radius: 0.9rem !important;
    }

    body.mobile-module-selection .glass-card p {
        margin-bottom: 0.75rem !important;
        line-height: 1.35 !important;
        display: -webkit-box;
        line-clamp: 2;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    body.mobile-module-selection section.max-w-7xl.mx-auto.px-8.py-24.mb-24 {
        padding-top: 0.9rem !important;
        padding-bottom: 1rem !important;
        margin-bottom: 1.2rem !important;
    }

    body.mobile-module-selection section.max-w-7xl.mx-auto.px-8.py-24.mb-24 .grid.grid-cols-1.md\:grid-cols-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.75rem !important;
    }

    /* ---------- Crisis Portal ---------- */
    body.mobile-crisis-portal main {
        min-height: calc(100dvh - 4rem);
    }

    body.mobile-crisis-portal main>[data-section] {
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    body.mobile-crisis-portal main>[data-section]>div {
        padding: 0.75rem !important;
        gap: 0.75rem !important;
    }

    body.mobile-crisis-portal .grid.grid-cols-2.sm\:grid-cols-4,
    body.mobile-crisis-portal .grid.grid-cols-2.md\:grid-cols-4,
    body.mobile-crisis-portal .grid.grid-cols-1.md\:grid-cols-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.6rem !important;
    }

    body.mobile-crisis-portal #main-sos-btn {
        height: 9.5rem !important;
    }

    body.mobile-crisis-portal #main-sos-btn .w-24.h-24 {
        width: 4.1rem !important;
        height: 4.1rem !important;
        margin-bottom: 0.45rem !important;
    }

    body.mobile-crisis-portal #alerts-container,
    body.mobile-crisis-portal #archive-content,
    body.mobile-crisis-portal #signal-feed,
    body.mobile-crisis-portal #intel-ai-area {
        max-height: 28dvh;
        overflow-y: auto;
        padding-right: 0.2rem;
    }

    body.mobile-crisis-portal #ai-response-content {
        max-height: 20dvh;
        overflow-y: auto;
    }

    body.mobile-crisis-portal .h-64 {
        height: 11.5rem !important;
    }

    /* ---------- Rescue Builder ---------- */
    body.mobile-rescue-builder .card,
    body.mobile-rescue-builder .alert-card {
        border-radius: 0.85rem !important;
        padding: 0.75rem !important;
    }

    body.mobile-rescue-builder main {
        padding: 0.75rem !important;
    }

    body.mobile-rescue-builder .text-3xl {
        font-size: 1.28rem !important;
    }

    body.mobile-rescue-admin .flex.pt-16.h-screen.overflow-hidden {
        height: calc(100dvh - 4rem) !important;
    }

    body.mobile-rescue-admin #section-overview>.grid.grid-cols-2.md\:grid-cols-4,
    body.mobile-rescue-admin #emergency-buttons-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.55rem !important;
    }

    body.mobile-rescue-admin #live-feed-list,
    body.mobile-rescue-admin #activity-logs-list,
    body.mobile-rescue-admin #emergency-log-list,
    body.mobile-rescue-admin #alert-history-list,
    body.mobile-rescue-admin #sos-events-list,
    body.mobile-rescue-admin #staff-roster {
        max-height: 30dvh !important;
        overflow-y: auto !important;
    }

    body.mobile-rescue-admin header {
        padding: 0.6rem 0.75rem !important;
    }

    body.mobile-rescue-admin header>div:first-child {
        gap: 0.45rem !important;
        min-width: 0;
    }

    body.mobile-rescue-admin header>div:first-child>div.h-4,
    body.mobile-rescue-admin header>div:first-child>div.flex.items-center.gap-2.px-3.py-1\.5,
    body.mobile-rescue-admin #system-name-badge {
        display: none !important;
    }

    body.mobile-rescue-admin header>div:last-child {
        gap: 0.45rem !important;
    }

    body.mobile-rescue-admin header>div:last-child>button:not(:last-child) {
        display: none !important;
    }

    body.mobile-rescue-admin header>div:last-child>button:last-child {
        padding: 0.5rem 0.7rem !important;
        font-size: 0.58rem !important;
        letter-spacing: 0.08em !important;
    }

    body.mobile-rescue-admin #section-alerts .flex.gap-3.items-center,
    body.mobile-rescue-admin #section-ai .flex.gap-3.mb-4 {
        flex-wrap: wrap !important;
        align-items: stretch !important;
    }

    body.mobile-rescue-admin #btn-broadcast,
    body.mobile-rescue-admin #section-ai .flex.gap-3.mb-4>button {
        width: 100%;
        margin-left: 0 !important;
        justify-content: center;
    }

    body.mobile-rescue-admin #broadcast-severity,
    body.mobile-rescue-admin #ai-query-input {
        width: 100%;
    }

    body.mobile-rescue-user .grid.grid-cols-3,
    body.mobile-rescue-user #sos-type-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.5rem !important;
    }

    body.mobile-rescue-user #all-alerts-list,
    body.mobile-rescue-user #home-alerts-preview,
    body.mobile-rescue-user #evac-steps,
    body.mobile-rescue-user #sos-history,
    body.mobile-rescue-user #activity-list,
    body.mobile-rescue-user #chat-messages {
        max-height: 30dvh;
        overflow-y: auto;
    }

    body.mobile-rescue-user header {
        padding: 0.55rem 0.7rem !important;
    }

    body.mobile-rescue-user header>div:first-child {
        min-width: 0;
        gap: 0.4rem !important;
    }

    body.mobile-rescue-user #hdr-org {
        max-width: 42vw !important;
    }

    body.mobile-rescue-user header>div:last-child>button {
        padding: 0.45rem 0.6rem !important;
        font-size: 0.56rem !important;
        letter-spacing: 0.08em !important;
        gap: 0.2rem !important;
    }

    body.mobile-rescue-user header>div:last-child>button .material-symbols-outlined {
        font-size: 0.95rem !important;
    }

    body.mobile-rescue-user .fixed.top-14.left-0.w-full.z-40 {
        padding: 0.35rem 0.45rem !important;
        gap: 0.35rem !important;
    }

    body.mobile-rescue-user .nav-tab {
        padding: 0.45rem 0.55rem !important;
        font-size: 0.55rem !important;
        letter-spacing: 0.05em !important;
        white-space: nowrap;
        gap: 0.2rem !important;
    }

    body.mobile-rescue-user .pt-28.pb-8.px-4.max-w-2xl.mx-auto {
        padding-top: 6.4rem !important;
        padding-left: 0.65rem !important;
        padding-right: 0.65rem !important;
        padding-bottom: 0.8rem !important;
    }

    body.mobile-rescue-user #section-ai .flex.gap-2.items-end {
        align-items: stretch;
    }

    body.mobile-rescue-user #section-ai #btn-send-chat {
        width: 2.6rem;
        height: auto;
        min-height: 2.6rem;
    }

    body.mobile-rescue-home .systems-grid {
        display: flex !important;
        grid-template-columns: none !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        gap: 0.7rem !important;
        padding-bottom: 0.4rem;
    }

    body.mobile-rescue-home .systems-grid>.system-card,
    body.mobile-rescue-home .systems-grid>.empty-state {
        min-width: 86vw;
        max-width: 86vw;
        scroll-snap-align: start;
    }

    body.mobile-rescue-home .summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.6rem !important;
    }

    body.mobile-rescue-dashboard #systemsList,
    body.mobile-rescue-org-select .grid.grid-cols-1.md\:grid-cols-2.lg\:grid-cols-3 {
        display: flex !important;
        grid-template-columns: none !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 0.7rem !important;
        padding-bottom: 0.5rem;
    }

    body.mobile-rescue-dashboard #systemsList>*,
    body.mobile-rescue-org-select .grid.grid-cols-1.md\:grid-cols-2.lg\:grid-cols-3>div {
        min-width: 84vw;
        max-width: 84vw;
    }

    body.mobile-rescue-org-select .glass-card,
    body.mobile-rescue-entry .card {
        padding: 1rem !important;
        border-radius: 0.9rem !important;
    }
}