/**
 * Dialed Mobile Responsive CSS
 * ONLY handles responsive layout - no custom mobile UI overlay
 * Makes desktop pages fit mobile screens without horizontal scroll
 * Version 1.0 - March 2026
 */

/* ============================================
   MOBILE BREAKPOINT (< 900px)
   ============================================ */
@media (max-width: 900px) {
    /* Prevent horizontal overflow */
    html {
        overflow-x: hidden;
    }

    body {
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    /* Hide desktop sidebar on mobile - use existing sidebar nav instead of hiding */
    .sidebar,
    .portal-sidebar,
    .admin-sidebar,
    aside.sidebar,
    nav.sidebar {
        position: fixed !important;
        left: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        width: 280px !important;
        z-index: 1000 !important;
        transform: translateX(-100%) !important;
        transition: transform 0.3s ease !important;
    }

    /* Show sidebar when toggled */
    .sidebar.mobile-open,
    .portal-sidebar.mobile-open,
    .admin-sidebar.mobile-open {
        transform: translateX(0) !important;
    }

    /* Sidebar overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

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

    /* Reset sidebar width variable */
    :root {
        --sidebar-width: 0px !important;
    }

    /* Main content - full width */
    .portal-layout {
        display: block !important;
    }

    .portal-main,
    main.portal-main,
    .main-content,
    main {
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding: 16px !important;
        width: 100% !important;
        max-width: 100vw !important;
        min-height: 100vh;
        box-sizing: border-box;
    }

    .portal-content {
        padding: 0 !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }

    /* ============================================
       PAGE HEADERS - Stack vertically
       ============================================ */
    .page-header,
    .samples-header,
    .content-header,
    .section-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
        padding: 0 !important;
        margin-bottom: 16px !important;
    }

    .page-header h1,
    .page-title,
    .samples-title h1,
    .page-header-left h1 {
        font-size: 1.5rem !important;
        line-height: 1.25 !important;
    }

    .header-actions,
    .samples-actions,
    .page-header .actions {
        width: 100% !important;
        display: flex !important;
        gap: 8px !important;
        flex-wrap: wrap !important;
    }

    .header-actions .btn,
    .samples-actions .btn {
        flex: 1 !important;
        min-width: 120px !important;
        justify-content: center !important;
    }

    /* ============================================
       STAT GRIDS - 2 columns
       ============================================ */
    .stats-row,
    .stat-grid,
    .quick-stats {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    .stat-card,
    .metric-card {
        padding: 14px !important;
        border-radius: 12px !important;
    }

    .stat-value {
        font-size: 1.25rem !important;
    }

    .stat-label {
        font-size: 0.75rem !important;
    }

    /* Content cards - single column */
    .samples-grid,
    .dashboard-grid,
    .cards-grid,
    .metrics-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
    }

    /* ============================================
       FILTER TABS - Horizontal scroll
       ============================================ */
    .filter-tabs,
    .category-tabs,
    .tabs,
    .tab-nav {
        display: flex !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
        gap: 6px !important;
        padding: 4px 0 !important;
        margin-bottom: 16px !important;
    }

    .filter-tabs::-webkit-scrollbar,
    .category-tabs::-webkit-scrollbar,
    .tabs::-webkit-scrollbar {
        display: none;
    }

    .filter-tab,
    .category-tab,
    .tab {
        flex-shrink: 0 !important;
        white-space: nowrap !important;
        padding: 10px 16px !important;
        font-size: 0.875rem !important;
        min-height: 44px !important;
    }

    /* ============================================
       FORMS - iOS zoom prevention
       ============================================ */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="tel"],
    input[type="number"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px !important; /* Prevents iOS zoom */
        padding: 12px !important;
        border-radius: 8px !important;
        min-height: 44px !important;
        -webkit-appearance: none;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .form-row,
    .form-grid,
    .input-row {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    .form-group {
        margin-bottom: 16px !important;
        width: 100% !important;
    }

    /* ============================================
       TABLES - Horizontal scroll
       ============================================ */
    .table-container,
    .docs-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        margin: 0 -16px !important;
        padding: 0 16px !important;
    }

    table,
    .data-table {
        min-width: 600px !important;
        font-size: 0.875rem !important;
    }

    /* ============================================
       BUTTONS - Touch optimized
       ============================================ */
    .btn,
    button {
        min-height: 44px !important;
        padding: 12px 20px !important;
        border-radius: 10px !important;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        cursor: pointer;
    }

    .btn:active,
    button:active {
        transform: scale(0.98);
        opacity: 0.9;
    }

    /* ============================================
       MODALS - Full width
       ============================================ */
    .modal-content,
    .modal-dialog,
    .modal > div {
        width: calc(100% - 32px) !important;
        max-width: 100% !important;
        margin: 16px !important;
        border-radius: 16px !important;
    }

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

    /* ============================================
       TYPOGRAPHY
       ============================================ */
    h1 { font-size: 1.5rem !important; }
    h2 { font-size: 1.25rem !important; }
    h3 { font-size: 1.125rem !important; }

    /* ============================================
       UTILITY CLASSES
       ============================================ */
    .desktop-only,
    .hide-mobile {
        display: none !important;
    }

    /* Prevent any element from causing horizontal scroll */
    .portal-content > *,
    .page-content > * {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    img {
        max-width: 100% !important;
        height: auto !important;
    }

    /* Search inputs */
    .search-wrapper,
    .search-container {
        width: 100% !important;
        min-width: unset !important;
    }

    /* Toolbars */
    .docs-toolbar,
    .toolbar {
        flex-direction: column !important;
        gap: 12px !important;
        align-items: stretch !important;
    }
}

/* ============================================
   SMALL MOBILE (< 400px)
   ============================================ */
@media (max-width: 400px) {
    .stats-row,
    .quick-stats {
        grid-template-columns: 1fr !important;
    }

    .page-header h1,
    .page-title {
        font-size: 1.25rem !important;
    }

    .stat-value {
        font-size: 1.125rem !important;
    }

    .header-actions .btn,
    .samples-actions .btn {
        min-width: 100px !important;
        padding: 10px 12px !important;
        font-size: 0.875rem !important;
    }
}

/* ============================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .btn,
    button,
    a,
    .nav-item,
    .menu-item,
    .file-row,
    .filter-tab {
        min-height: 44px;
    }

    /* Remove hover states that cause sticky on touch */
    .btn:hover,
    button:hover {
        transform: none !important;
    }
}

/* ============================================
   MOBILE MENU TOGGLE BUTTON
   Add this to pages that need sidebar toggle
   ============================================ */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    /* 2026-05-30 Elle: was bottom:20px right:20px which covered the Log Call
       button on contact cards AND Save Changes on modal footers. Top-left is
       the conventional hamburger position and stays out of content. */
    top: 12px;
    left: 12px;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, #2D2438 0%, #1A1520 100%);
    color: white;
    border: 1px solid rgba(255,255,255,0.10);
    box-shadow: 0 6px 20px rgba(45,36,56,0.32);
    z-index: 998;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

@media (max-width: 900px) {
    .mobile-menu-toggle {
        display: flex;
    }
}

/* Hide hamburger when an iframe modal is open (so it doesn't visually compete
   with the modal). Modal owns the screen at that point. */
body.iframe-modal-open .mobile-menu-toggle {
    display: none !important;
}

.mobile-menu-toggle svg {
    width: 24px;
    height: 24px;
}

.mobile-menu-toggle:active {
    transform: scale(0.95);
}
