/**
 * Talk With Me - Master Responsive Breakpoints & Mobile UI/UX Engine
 * Optimized for Modern Mobile Devices (iOS & Android), Safe Areas, and Touch UX
 */

/* ==========================================================================
   1. GLOBAL MOBILE RESET & UTILITIES
   ========================================================================== */
:root {
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
}

/* Prevent iOS Safari auto-zoom on input focus by ensuring 16px font-size */
@media (max-width: 767.98px) {
    input[type="text"],
    input[type="password"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    input[type="url"],
    input[type="search"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* Touch Friendly Utilities */
.touch-target {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Smooth momentum scrolling for mobile overflow containers */
.smooth-scroll-x {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

.smooth-scroll-y {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* ==========================================================================
   2. LARGE TABLET & MOBILE BREAKPOINTS (max-width: 991.98px)
   ========================================================================== */
@media (max-width: 991.98px) {
    /* Base Body Spacing */
    body:not(.page-chat):not(.admin-body) {
        padding-bottom: calc(75px + var(--safe-area-bottom));
    }

    body.page-chat,
    body.admin-body {
        padding-bottom: 0 !important;
        height: 100%;
        overflow: hidden;
    }

    /* Ambient glow orbs - reduce size and opacity on mobile for performance */
    .ambient-glow {
        filter: blur(70px);
        opacity: 0.28;
    }
    .orb-1 { width: 300px; height: 300px; }
    .orb-2 { width: 350px; height: 350px; }
    .orb-3 { width: 280px; height: 280px; }

    /* Header & Brand */
    .site-header {
        padding: 10px 0;
    }

    .brand-title {
        font-size: 1.25rem;
    }

    /* Hero Section */
    .hero-section {
        padding: 40px 0 30px;
        text-align: center;
    }

    .hero-pill-badge {
        margin-left: auto;
        margin-right: auto;
        font-size: 0.8rem;
        padding: 5px 14px;
    }

    .hero-title {
        font-size: clamp(1.85rem, 5.5vw, 2.75rem);
        line-height: 1.22;
        margin-bottom: 18px;
    }

    .hero-subtitle {
        font-size: 1rem;
        margin-left: auto;
        margin-right: auto;
        line-height: 1.6;
        margin-bottom: 26px;
    }

    .hero-cta-group {
        justify-content: center;
        gap: 12px !important;
    }

    .chat-preview-box {
        margin-top: 32px;
        padding: 18px;
    }

    /* Trust & Problem Cards */
    .trust-bar {
        margin-top: 20px;
        margin-bottom: 40px;
    }

    .trust-card {
        padding: 12px 14px;
        gap: 10px;
    }

    .trust-icon-box {
        width: 38px;
        height: 38px;
        font-size: 1rem;
        border-radius: 10px;
    }

    .glass-card {
        padding: 22px 18px;
        border-radius: 18px;
    }

    .step-card {
        padding: 26px 18px;
    }

    /* Footer Mobile Adjustments */
    .footer-top {
        padding-top: 35px !important;
        padding-bottom: 30px !important;
    }

    /* Mobile Sticky CTA Bar */
    .mobile-sticky-cta {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(18, 5, 11, 0.95);
        backdrop-filter: blur(18px);
        -webkit-backdrop-filter: blur(18px);
        border-top: 1px solid var(--border-glass);
        padding: 10px 0 calc(10px + var(--safe-area-bottom));
        z-index: 1025;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.6);
    }

    body.page-chat .mobile-sticky-cta,
    body.admin-body .mobile-sticky-cta {
        display: none !important;
    }

    /* Location Consent Banner on Mobile */
    .location-consent-banner {
        bottom: calc(75px + var(--safe-area-bottom) + 12px);
        left: 12px;
        right: 12px;
        max-width: none;
        padding: 14px 16px;
        border-radius: 14px;
    }

    /* ======================================================================
       USER LIVE CHAT APPLICATION MOBILE RESPONSIVENESS
       ====================================================================== */
    .chat-app-wrapper {
        height: 100dvh;
        height: calc(100vh - 60px);
        overflow: hidden;
        position: relative;
    }

    /* Chat Drawer Sidebar */
    .chat-sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: 82%;
        max-width: 320px;
        height: 100dvh;
        height: 100vh;
        z-index: 1050;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
        box-shadow: 10px 0 35px rgba(0, 0, 0, 0.7);
        background: rgba(22, 7, 15, 0.98);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }

    .chat-sidebar.open {
        transform: translateX(0);
    }

    /* Chat Drawer Backdrop Overlay */
    .chat-sidebar-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.65);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 1040;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .chat-sidebar-backdrop.active {
        opacity: 1;
        visibility: visible;
    }

    .chat-header {
        padding: 10px 14px;
        gap: 8px;
    }

    .chat-partner-info {
        gap: 10px;
        min-width: 0;
    }

    .chat-partner-name {
        font-size: 0.92rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 140px;
    }

    .chat-partner-status {
        font-size: 0.72rem;
    }

    .user-active-loc-badge {
        font-size: 0.7rem;
        padding: 2px 6px;
        max-width: 110px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .chat-messages-container {
        padding: 14px 12px;
        gap: 12px;
    }

    .message-wrapper {
        max-width: 88%;
    }

    .message-bubble {
        padding: 10px 14px;
        font-size: 0.9rem;
        border-radius: 16px;
    }

    .quick-topics-row {
        padding: 8px 12px;
        gap: 6px;
    }

    .topic-chip {
        font-size: 0.76rem;
        padding: 5px 11px;
    }

    .chat-input-area {
        padding: 8px 12px calc(8px + var(--safe-area-bottom));
    }

    .chat-input-box {
        padding: 6px 12px;
        gap: 8px;
    }

    .chat-textarea {
        font-size: 0.92rem;
    }

    .btn-send-msg {
        width: 36px;
        height: 36px;
        font-size: 0.9rem;
    }

    /* ======================================================================
       ADMIN CONSOLE MOBILE RESPONSIVENESS & OFFCANVAS DRAWER
       ====================================================================== */
    .admin-layout {
        position: relative;
        flex-direction: column;
        min-height: 100dvh;
        min-height: 100vh;
    }

    /* Hide static sidebar on mobile; convert to full slide-out offcanvas */
    .admin-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        height: 100dvh;
        height: 100vh;
        z-index: 1060;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
        box-shadow: 10px 0 35px rgba(0, 0, 0, 0.8);
        background: rgba(18, 5, 12, 0.98);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }

    .admin-sidebar.open {
        transform: translateX(0);
    }

    .admin-sidebar-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.7);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 1055;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .admin-sidebar-backdrop.active {
        opacity: 1;
        visibility: visible;
    }

    /* Show all labels in mobile sidebar offcanvas */
    .admin-brand .brand-title,
    .admin-brand small,
    .admin-nav-item span,
    .admin-user-badge div:not(.avatar-circle) {
        display: block !important;
    }

    .admin-nav-item {
        justify-content: flex-start !important;
        padding: 11px 14px !important;
    }

    .admin-nav-item i {
        font-size: 1.05rem !important;
        margin-right: 0 !important;
    }

    /* Admin Topbar Mobile */
    .admin-topbar {
        height: 60px;
        padding: 0 14px;
        position: sticky;
        top: 0;
        z-index: 1020;
    }

    .admin-topbar h5 {
        font-size: 1rem;
        max-width: 180px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .admin-content {
        padding: 16px 12px calc(24px + var(--safe-area-bottom));
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* Admin 2-Panel Live Chat Master-Detail Mobile UI */
    .admin-chat-workspace {
        height: calc(100dvh - 80px);
        height: calc(100vh - 80px);
        flex-direction: row;
        border-radius: 14px;
        position: relative;
        overflow: hidden;
    }

    .admin-chat-queue {
        width: 100% !important;
        height: 100% !important;
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        z-index: 2;
        transition: transform 0.28s ease;
        background: rgba(15, 4, 10, 0.95);
    }

    .admin-chat-active-panel {
        width: 100% !important;
        height: 100% !important;
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        z-index: 1;
        transform: translateX(100%);
        transition: transform 0.28s ease;
    }

    /* When conversation is selected on mobile, slide in active panel */
    .admin-chat-workspace.mobile-show-chat .admin-chat-queue {
        transform: translateX(-100%);
        pointer-events: none;
    }

    .admin-chat-workspace.mobile-show-chat .admin-chat-active-panel {
        transform: translateX(0);
        z-index: 3;
    }

    /* Mobile Back Button in Admin Chat Header */
    .btn-admin-back-to-queue {
        display: inline-flex !important;
    }

    /* Leaflet Map Mobile sizing */
    .leaflet-map-container {
        height: 320px !important;
        border-radius: 14px;
    }

    .map-filter-toolbar {
        padding: 10px 12px;
        gap: 10px;
    }

    /* KPI Cards in Admin Grid */
    .admin-stat-card {
        padding: 16px 18px;
    }

    .stat-val {
        font-size: 1.65rem;
    }
}

/* ==========================================================================
   3. SMALL MOBILE BREAKPOINTS (max-width: 575.98px)
   ========================================================================== */
@media (max-width: 575.98px) {
    .container {
        padding-left: 14px;
        padding-right: 14px;
    }

    .hero-title {
        font-size: 1.75rem;
    }

    .btn-romantic-cta,
    .btn-romantic-secondary {
        width: 100%;
        padding: 12px 18px;
        font-size: 0.92rem;
    }

    .hero-cta-group {
        flex-direction: column;
        width: 100%;
    }

    /* Modal Mobile Adjustments */
    .location-mandatory-modal .modal-dialog {
        margin: 10px;
    }

    .location-mandatory-modal .modal-body {
        padding: 16px 12px !important;
    }

    #modalInteractiveMap {
        height: 180px !important;
    }

    .badge-city-chip {
        font-size: 0.72rem;
        padding: 3px 8px;
    }

    /* Compact Admin KPI Grid */
    .analytics-kpi-card {
        padding: 12px 14px;
        min-height: 96px;
    }

    .analytics-kpi-card .stat-val-number {
        font-size: 1.45rem;
    }

    .analytics-kpi-card .stat-val-text {
        font-size: 0.95rem;
    }

    /* Admin Table Mobile Adjustments */
    .admin-table th,
    .admin-table td {
        padding: 10px 12px;
        font-size: 0.82rem;
    }

    .admin-form-card {
        padding: 20px 14px;
        border-radius: 14px;
    }
}

/* Auth Page Centered Wrapper without footer */
.auth-page-wrapper {
    min-height: calc(100dvh - 72px);
    min-height: calc(100vh - 72px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 0;
}

@media (max-width: 576px) {
    .auth-page-wrapper {
        min-height: calc(100dvh - 65px);
        min-height: calc(100vh - 65px);
        padding: 10px 0;
    }

    #modalInteractiveMap {
        height: 200px !important;
    }
}
