/* =====================================================
   SAHAY — GLOBAL RESPONSIVE DESIGN SYSTEM
   Mobile-first breakpoints:
   0–575px    → Mobile
   576–767px  → Large Mobile
   768–991px  → Tablet
   992–1199px → Laptop
   1200px+    → Desktop
   ===================================================== */

/* ── 1. RESET & VIEWPORT SAFETY ────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    min-width: 0; /* prevent flex children from overflowing */
}

html {
    width: 100%;
    overflow-x: hidden;
}

body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

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

/* ── 2. CONTAINER ───────────────────────────────────── */
.container {
    width: min(100% - 32px, 1300px);
    margin-inline: auto;
    padding: 0;
}

@media (max-width: 767px) {
    .container {
        width: calc(100% - 24px);
    }
}

/* ── 3. GLOBAL TYPOGRAPHY — RESPONSIVE ─────────────── */
.hero-title {
    font-size: clamp(2rem, 5vw + 0.5rem, 4.2rem) !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
    letter-spacing: clamp(-1px, -0.02em, -1.5px) !important;
}

.hero-subtitle {
    font-size: clamp(1rem, 2.5vw, 1.6rem) !important;
    max-width: 100% !important;
}

.banner-text h2 {
    font-size: clamp(1.4rem, 3.5vw, 2.2rem) !important;
}

/* ── 4. NAVBAR ─────────────────────────────────────── */
.navbar {
    padding: 14px 0 !important;
}

.nav-container {
    flex-wrap: wrap;
    gap: 12px;
}

.nav-links {
    gap: clamp(16px, 3vw, 40px) !important;
    flex-wrap: wrap;
}

/* Mobile hamburger */
.nav-hamburger {
    display: none;
    background: none;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--gov-navy);
}

@media (max-width: 767px) {
    .nav-hamburger {
        display: block;
    }

    .nav-links {
        display: none;
        width: 100%;
        flex-direction: column;
        gap: 8px !important;
        padding: 12px 0;
        border-top: 1px solid #f1f5f9;
    }

    .nav-links.open {
        display: flex;
    }

    .nav-actions {
        gap: 10px !important;
        flex-wrap: wrap;
    }

    .nav-container {
        align-items: center;
        justify-content: space-between;
    }
}

@media (max-width: 575px) {
    .nav-actions .btn-outline {
        padding: 8px 14px !important;
        font-size: 0.82rem;
    }

    .nav-actions .btn-danger {
        padding: 8px 14px !important;
        font-size: 0.82rem;
    }

    .logo-text h1 {
        font-size: 0.88rem !important;
    }

    .emblem {
        width: 40px !important;
    }
}

/* ── 5. HERO SECTION ────────────────────────────────── */
.hero {
    padding: clamp(40px, 6vw, 60px) 0 clamp(60px, 8vw, 100px) !important;
    overflow: hidden !important;
}

.hero-container {
    flex-wrap: wrap;
    gap: 40px;
}

.hero-content {
    flex: 1 1 min(100%, 55%) !important;
    z-index: 2;
    position: relative;
}


.hero-buttons {
    flex-wrap: wrap;
    gap: 12px !important;
}

/* ── 6. FEATURE STRIP ───────────────────────────────── */
.features-container {
    flex-wrap: wrap;
    gap: 20px !important;
    padding: clamp(20px, 4vw, 24px) clamp(20px, 5vw, 60px) !important;
    justify-content: center !important;
}

.feature-item {
    flex: 1 1 180px;
}

/* ── 7. EMERGENCY BANNER ────────────────────────────── */
.banner-content {
    flex-wrap: wrap;
    gap: 20px !important;
    padding: clamp(24px, 4vw, 40px) clamp(20px, 5vw, 60px) !important;
}

.banner-icon {
    flex-shrink: 0;
    width: clamp(60px, 10vw, 90px) !important;
    height: clamp(60px, 10vw, 90px) !important;
    font-size: clamp(1.5rem, 3vw, 2.5rem) !important;
}

/* --- MOBILE SPECIFIC OVERRIDES --- */
@media (max-width: 767px) {
    .hero {
        padding: 20px 0 40px !important;
    }
    .hero-container {
        gap: 20px;
    }
    .hero-content {
        flex: 1 1 100% !important;
        text-align: center;
    }
    .hero-image {
        position: relative !important;
        right: auto !important;
        top: auto !important;
        flex: 1 1 100% !important;
        max-width: 320px !important;
        margin: 20px auto 0 auto !important;
        display: block;
    }
    .hero-buttons {
        flex-direction: column;
        width: 100%;
    }
    .hero-buttons .btn {
        width: 100%;
        justify-content: center;
    }
    .badge {
        margin: 0 auto 20px auto !important;
        width: fit-content;
    }
    .hero-bullets {
        justify-content: center;
    }
    .features {
        margin-top: 0 !important;
        padding: 20px !important;
    }
    .features-container {
        flex-direction: column;
        padding: 24px !important;
    }
    .feature-item {
        flex: 1 1 100%;
        flex-direction: column;
        text-align: center;
    }
    .banner-content {
        flex-direction: column;
        text-align: center;
        align-items: center;
        padding: 30px 20px !important;
    }
    .banner-icon {
        width: 70px !important;
        height: 70px !important;
        font-size: 2rem !important;
    }
    .banner-content::after {
        display: none !important;
    }
}

/* ── 8. TABLES — HORIZONTAL SCROLL WRAPPER ──────────── */
table {
    width: 100%;
    border-collapse: collapse;
}

/* Wrap ALL tables in a scrollable div via JS if on mobile */
.table-scroll-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
}

@media (max-width: 767px) {
    table {
        min-width: 560px;
    }
}

/* ── 9. LOGIN PAGE ──────────────────────────────────── */
.login-wrapper {
    display: flex;
    flex-wrap: wrap;
    min-height: 100dvh;
}

.login-left {
    flex: 1 1 380px;
    min-height: 220px;
}

.login-right {
    flex: 1 1 340px;
    overflow-y: auto;
}

.login-form-wrapper {
    width: min(100%, 480px) !important;
    padding: clamp(20px, 4vw, 40px) !important;
    margin-inline: auto;
}

@media (max-width: 767px) {
    .login-left {
        display: none;
    }

    .login-right {
        flex: 1 1 100%;
        min-height: 100dvh;
    }

    .login-form-wrapper {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* ── 10. SIDEBAR DASHBOARD ──────────────────────────── */
.dashboard-layout {
    display: flex;
    min-height: 100dvh;
    position: relative;
}

.sidebar {
    width: clamp(220px, 22vw, 280px);
    flex-shrink: 0;
    overflow-y: auto;
    position: sticky;
    top: 0;
    height: 100dvh;
}

.main-content {
    flex: 1 1 0%;
    min-width: 0;
    overflow-x: hidden;
    padding: clamp(20px, 3vw, 40px) !important;
}

@media (max-width: 991px) {
    .sidebar {
        width: 220px;
    }
}

@media (max-width: 767px) {
    .dashboard-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        padding: 16px 0;
    }

    .sidebar-nav {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        padding: 0 12px !important;
    }

    .sidebar-nav li {
        flex: 1 1 auto;
    }

    .sidebar-nav li a {
        padding: 10px 12px !important;
        font-size: 0.82rem;
        justify-content: center;
        text-align: center;
        flex-direction: column;
        gap: 4px !important;
        transform: none !important;
    }

    .sidebar-nav li a:hover {
        transform: none !important;
    }

    .main-content {
        padding: 16px !important;
    }
}

/* ── 11. STATS GRID ─────────────────────────────────── */
.stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important;
}

.stat-value {
    font-size: clamp(1.4rem, 4vw, 2rem) !important;
}

/* ── 12. CASES GRID (CARDS) ─────────────────────────── */
.cases-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)) !important;
}

.case-card {
    min-width: 0;
}

/* ── 13. DASHBOARD TABS ─────────────────────────────── */
.dashboard-tabs {
    flex-wrap: wrap !important;
    width: 100% !important;
}

.dash-tab {
    flex: 1 1 auto;
    text-align: center;
    padding: 10px 14px !important;
    font-size: clamp(0.78rem, 2vw, 0.95rem) !important;
}

/* ── 14. TWO-COLUMN GRID ─────────────────────────────── */
.grid-2 {
    display: grid;
    gap: 24px;
}

@media (max-width: 767px) {
    .grid-2 {
        grid-template-columns: 1fr !important;
    }
}

/* ── 15. PAGE HEADER ─────────────────────────────────── */
.page-header {
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h1 {
    font-size: clamp(1.4rem, 4vw, 2.2rem) !important;
}

/* ── 16. GLASS CONTAINER ─────────────────────────────── */
.glass-container {
    padding: clamp(16px, 3vw, 30px) !important;
    overflow-x: hidden;
}

/* ── 17. MODALS ──────────────────────────────────────── */
[id$="Modal"],
.modal,
.modal-overlay {
    padding: 16px !important;
}

[id$="Modal"] > div,
.modal-content {
    width: min(92vw, 600px) !important;
    max-height: 90dvh !important;
    overflow-y: auto !important;
    padding: clamp(20px, 4vw, 32px) !important;
}

/* ── 18. CHAT PAGE ───────────────────────────────────── */
.voice-container {
    padding-bottom: max(100px, env(safe-area-inset-bottom) + 100px) !important;
}

.controls-container {
    bottom: max(30px, env(safe-area-inset-bottom) + 20px) !important;
    padding: 0 16px;
}

.counselor-avatar-voice {
    width: clamp(200px, 50vw, 360px) !important;
    height: clamp(200px, 50vw, 360px) !important;
}

.counselor-status-label {
    max-width: min(90vw, 500px) !important;
    text-align: center;
}

/* ── 19. LEAFLET MAP ─────────────────────────────────── */
#monitoringMap {
    height: clamp(250px, 40vh, 450px) !important;
}

/* ── 20. VICTIM HOME / CARDS ─────────────────────────── */
.services-grid,
.resource-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
    gap: 20px;
}

/* ── 21. FORM CONTROLS ───────────────────────────────── */
input,
select,
textarea,
button {
    max-width: 100%;
}

.form-control {
    width: 100% !important;
    min-width: 0 !important;
}

/* ── 22. SAFE AREA (NOTCH PHONES) ────────────────────── */
@supports (padding: env(safe-area-inset-bottom)) {
    .navbar,
    header.navbar {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }

    .controls-container {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ── 23. OVERFLOW FIXES FOR SPECIFIC PATTERNS ────────── */

/* Fix: absolute hero image causing horizontal scroll */
.hero {
    overflow: hidden !important;
}

/* Fix: login page fixed background */
.login-page-bg {
    width: 100% !important;
    min-width: 0 !important;
}

/* Fix: info rows inside cards */
.info-row {
    flex-wrap: wrap;
}

.info-text {
    min-width: 0;
    word-break: break-word;
}

/* Fix: status badges */
.status-badge {
    flex-shrink: 0;
    white-space: nowrap;
    flex-wrap: wrap;
}

@media (max-width: 575px) {
    .status-badge {
        font-size: 0.78rem !important;
        padding: 6px 10px !important;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* ── 24. NATIONAL DASHBOARD ──────────────────────────── */
.national-grid,
.district-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
    gap: 20px;
}

/* ── 25. CONSENT PAGE ────────────────────────────────── */
.consent-wrapper {
    width: min(100% - 32px, 720px) !important;
    margin-inline: auto;
    padding: clamp(20px, 4vw, 40px) !important;
}

/* ── 26. CHECKIN PAGE ────────────────────────────────── */
.checkin-container {
    width: min(100% - 32px, 680px) !important;
    margin-inline: auto;
}

/* ── 27. SUPPORT PAGE HOTLINES ───────────────────────── */
.hotline-grid,
.support-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
    gap: 20px;
}

/* ── 28. TEXT-CHAT PAGE ──────────────────────────────── */
.chat-layout {
    max-width: min(100% - 32px, 900px) !important;
    margin-inline: auto;
    height: calc(100dvh - 80px);
    display: flex;
    flex-direction: column;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.chat-input-area {
    flex-shrink: 0;
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}

/* ── 29. AI REPORT CARD ──────────────────────────────── */
.ai-report-card {
    overflow: hidden;
}

.ai-report-body {
    overflow-wrap: anywhere;
}

/* ── 30. FINAL SAFETY NET ────────────────────────────── */
@media (max-width: 575px) {
    /* Stack any remaining flex rows */
    [style*="display: flex"],
    [style*="display:flex"] {
        flex-wrap: wrap !important;
    }

    /* Remove horizontal padding that pushes content out */
    [style*="padding: 40px"],
    [style*="padding:40px"] {
        padding: 20px !important;
    }
}
