/* ==========================================================================
   Mobile Responsive Overrides — PhoneApp.UI
   Targets: phones (< 768px) and tablets (768px–991px)
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Safe-area insets & CSS Variables
   -------------------------------------------------------------------------- */
: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);
    --bottom-nav-height: 60px;
}

/* --------------------------------------------------------------------------
   2. Master Viewport & Layout Scrolling Architecture
   -------------------------------------------------------------------------- */
html, body {
    height: 100% !important;
    height: 100dvh !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: none;
    width: 100% !important;
}

#app {
    height: 100% !important;
    height: 100dvh !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    width: 100% !important;
}

/* Top Navbar */
.navbar {
    flex-shrink: 0 !important;
    z-index: 1030;
}

/* Middle Content Layout Area */
.page-content {
    flex: 1 1 0% !important;
    min-height: 0 !important;
    display: flex !important;
    position: relative !important;
    overflow: hidden !important;
    width: 100% !important;
}

.content-wrapper {
    flex: 1 1 0% !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    position: relative !important;
    overflow: hidden !important;
    width: 100% !important;
}

/* The actual scrolling container */
.content-inner {
    flex: 1 1 0% !important;
    min-height: 0 !important;
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    position: relative !important;
    width: 100% !important;
}

/* --------------------------------------------------------------------------
   3. Content Spacing on Mobile (Avoid bottom nav overlap)
   -------------------------------------------------------------------------- */
@media (max-width: 991.98px) {
    .content,
    .container-fluid,
    .ai-agent-page,
    .billing-page,
    .downloads-page,
    .chatbot-config-page,
    .owned-numbers-wrapper,
    .buy-numbers-wrapper,
    .contacts-wrapper,
    .settings-card {
        padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom) + 2rem) !important;
    }

    /* Top padding compact */
    .content {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
        padding-top: 0.75rem !important;
    }

    .container-fluid {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }
}

/* --------------------------------------------------------------------------
   4. Top Navbar Compact & Sleek Styling
   -------------------------------------------------------------------------- */
.navbar {
    min-height: 52px !important;
    height: 52px !important;
    max-height: 56px !important;
    padding-top: 0.35rem !important;
    padding-bottom: 0.35rem !important;
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
    flex-shrink: 0 !important;
    z-index: 1030;
}

.navbar .container-fluid {
    height: 100% !important;
    min-height: 44px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 0 !important;
}

.navbar .navbar-brand {
    padding: 0 !important;
    margin: 0 !important;
    display: flex !important;
    align-items: center !important;
}

.navbar .nav {
    margin: 0 !important;
    padding: 0 !important;
}

.navbar .nav-item {
    margin: 0 !important;
    padding: 0 !important;
}

.navbar .navbar-nav-link {
    padding: 0.25rem 0.5rem !important;
    display: flex !important;
    align-items: center !important;
}

.navbar-toggler,
.sidebar-mobile-main-toggle,
.sidebar-main-resize {
    width: 38px !important;
    height: 38px !important;
    min-width: 38px !important;
    min-height: 38px !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.08) !important;
    border: none !important;
    color: #fff !important;
}

@media (min-width: 992px) {
    .sidebar-main-resize {
        display: inline-flex !important;
    }
    .sidebar-mobile-main-toggle,
    .navbar-toggler.sidebar-mobile-main-toggle {
        display: none !important;
    }
}

@media (max-width: 991.98px) {
    .sidebar-main-resize {
        display: none !important;
    }
    .sidebar-mobile-main-toggle,
    .navbar-toggler.sidebar-mobile-main-toggle {
        display: flex !important;
    }
}



/* --------------------------------------------------------------------------
   5. Sidebar Slide-In & Overlay
   -------------------------------------------------------------------------- */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.55);
    z-index: 1039;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: opacity 0.25s ease;
    opacity: 0;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

@media (min-width: 992px) {
    .sidebar-overlay {
        display: none !important;
    }
}

@media (max-width: 991.98px) {
    .sidebar-main {
        position: fixed !important;
        top: 0;
        bottom: 0;
        height: 100vh !important;
        height: 100dvh !important;
        z-index: 1040;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        transform: translateX(-100%);
        left: 0 !important;
        box-shadow: 0 0 24px rgba(0, 0, 0, 0.35);
    }

    .sidebar-main.sidebar-mobile-expanded {
        transform: translateX(0);
    }

    .nav-sidebar .nav-link {
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
        min-height: 48px;
        display: flex;
        align-items: center;
    }
}

/* --------------------------------------------------------------------------
   6. Bottom Navigation Bar (Mobile Tab Bar)
   -------------------------------------------------------------------------- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    padding-bottom: var(--safe-area-bottom);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-top: 1px solid #e2e8f0;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 1028;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 48px;
    height: 100%;
    padding: 4px 6px;
    text-decoration: none;
    color: #94a3b8;
    border-radius: 8px;
    transition: all 0.2s ease;
    cursor: pointer;
    background: none;
    border: none;
    outline: none;
    flex: 1;
    max-width: 72px;
}

.bottom-nav-item:hover,
.bottom-nav-item:active {
    color: #6366f1;
    text-decoration: none;
}

.bottom-nav-item.active {
    color: #6366f1;
    font-weight: 700;
}

.bottom-nav-item.active .bottom-nav-icon {
    background: rgba(99, 102, 241, 0.12);
    transform: translateY(-2px);
    color: #6366f1;
}

.bottom-nav-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 1.15rem;
    transition: all 0.2s ease;
}

.bottom-nav-label {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    line-height: 1;
}

@media (min-width: 992px) {
    .bottom-nav {
        display: none !important;
    }
}

/* --------------------------------------------------------------------------
   7. Chat Page (/messages) Mobile Responsiveness
   -------------------------------------------------------------------------- */
.messages-page-wrapper {
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
}

@media (max-width: 767.98px) {
    /* Hide content-inner padding for messages page so it fills the screen */
    .content-inner:has(.messages-page-wrapper) {
        padding: 0 !important;
        overflow: hidden !important;
    }

    .messages-page-wrapper .chat-sidebar {
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
        border-right: none !important;
        height: 100% !important;
    }

    .messages-page-wrapper .chat-sidebar .chat-list {
        height: calc(100dvh - var(--bottom-nav-height) - 170px) !important;
        overflow-y: auto !important;
    }

    .messages-page-wrapper .chat-main-area {
        width: 100% !important;
        height: 100% !important;
    }

    .messages-page-wrapper .messages-container {
        padding: 0.75rem !important;
        height: calc(100dvh - var(--bottom-nav-height) - 190px) !important;
        overflow-y: auto !important;
    }

    .messages-page-wrapper .message-bubble {
        max-width: 88% !important;
    }

    .messages-page-wrapper .message-input-area {
        padding: 0.5rem 0.75rem calc(var(--bottom-nav-height) + 0.5rem) !important;
        background: #fff;
    }
}

/* --------------------------------------------------------------------------
   8. Floating AI Chat Widget (ChatBubble.razor) on Mobile
   -------------------------------------------------------------------------- */
@media (max-width: 767.98px) {
    .chat-fab {
        bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom) + 12px) !important;
        right: 14px !important;
        width: 52px !important;
        height: 52px !important;
        font-size: 1.25rem !important;
    }

    .chat-window {
        position: fixed !important;
        inset: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-width: 100vw !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        margin: 0 !important;
        z-index: 10000 !important;
        bottom: 0 !important;
        right: 0 !important;
    }

    .cw-head {
        padding: 0.85rem 1rem !important;
        padding-top: calc(var(--safe-area-top) + 0.85rem) !important;
    }

    .cw-body {
        padding: 0.75rem !important;
    }

    .cw-input-area {
        padding: 0.75rem !important;
        padding-bottom: calc(var(--safe-area-bottom) + 0.75rem) !important;
    }
}

/* --------------------------------------------------------------------------
   9. Tables — Horizontal Scrolling & Touch Friendly
   -------------------------------------------------------------------------- */
.table-responsive {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    border-radius: 8px;
}

@media (max-width: 767.98px) {
    .table tbody td,
    .table thead th {
        padding: 0.6rem 0.65rem;
        font-size: 0.8rem;
    }

    .audio-player {
        width: 140px !important;
        max-width: 140px !important;
        height: 30px !important;
    }

    .status-badge,
    .direction-badge,
    .badge-direction {
        font-size: 0.65rem;
        padding: 0.2rem 0.45rem;
    }
}

/* --------------------------------------------------------------------------
   10. Filter Cards & Forms on Mobile
   -------------------------------------------------------------------------- */
@media (max-width: 767.98px) {
    .filter-card .row > [class*="col-"] {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    .filter-card .col-auto {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    .filter-card .col-auto .btn {
        flex: 1;
    }

    .filter-bar {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.5rem !important;
    }

    .filter-bar .form-select,
    .filter-bar .form-control {
        max-width: 100% !important;
        height: 38px !important;
        font-size: 16px !important;
    }

    /* Prevent iOS Auto-Zoom */
    .form-control,
    .form-select,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="date"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* --------------------------------------------------------------------------
   11. Page Headers & Action Buttons on Mobile
   -------------------------------------------------------------------------- */
@media (max-width: 767.98px) {
    .page-header-block,
    .recordings-header,
    .call-log-header,
    .page-header,
    .downloads-header {
        flex-wrap: wrap !important;
        gap: 0.75rem !important;
    }

    .page-header-block .ms-auto,
    .recordings-header .d-flex,
    .call-log-header .d-flex,
    .page-header .btn {
        width: 100%;
        display: flex;
        justify-content: flex-start;
    }

    .page-header-block .btn,
    .recordings-header .btn,
    .call-log-header .btn,
    .page-header .btn {
        width: 100%;
        text-align: center;
        justify-content: center;
    }

    .plan-grid {
        grid-template-columns: 1fr !important;
    }
}

/* --------------------------------------------------------------------------
   12. Modals & Dialogs on Mobile
   -------------------------------------------------------------------------- */
@media (max-width: 767.98px) {
    .modal-dialog {
        margin: 0.5rem !important;
        max-width: calc(100vw - 1rem) !important;
    }

    .modal-content {
        border-radius: 16px !important;
    }

    .modal-body {
        max-height: 70vh !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
}

