/* Mobile Optimization for CION CRM */
/* Hamburger Menu, Touch Screen, and Responsive Design */

/* ==================== MOBILE BACKGROUND ==================== */
@media (max-width: 768px) {
    body {
        background: url('https://res.cloudinary.com/dafsv1e1n/image/upload/v1759412700/mobi_background_syn3rx.jpg') center/cover no-repeat fixed !important;
    }
}

/* ==================== HAMBURGER MENU ==================== */

.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 10001;
    background: linear-gradient(135deg, #4A90E2, #87CEEB);
    border: none;
    border-radius: 12px;
    width: 50px;
    height: 50px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transition: transform 0.2s;
}

.mobile-menu-toggle:active {
    transform: scale(0.95);
}

.hamburger-icon {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    gap: 5px;
}

.hamburger-icon span {
    display: block;
    width: 24px;
    height: 3px;
    background: white;
    border-radius: 2px;
    transition: all 0.3s ease;
}

.mobile-menu-toggle.active .hamburger-icon span:nth-child(1) {
    transform: rotate(45deg) translate(7px, 7px);
}

.mobile-menu-toggle.active .hamburger-icon span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active .hamburger-icon span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
}

/* Mobile Overlay */
.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-overlay.active {
    opacity: 1;
}

/* ==================== MOBILE RESPONSIVE ==================== */

@media (max-width: 768px) {
    /* SAFETY: ensure the main app is visible on mobile */
    #mainAppContainer {
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
    }

    /* SAFETY: hide potential full-screen blockers if they get stuck */
    #loader,
    #splashScreen,
    .mobile-overlay,
    .modal[style*="display: block"][data-mobile-global] {
        display: none !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }

    
    /* Show hamburger menu */
    .mobile-menu-toggle {
        display: flex;
    }
    
    /* Hide sidebar by default on mobile */
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        width: 280px;
        height: 100vh;
        z-index: 10000;
        transition: left 0.3s ease;
        box-shadow: 2px 0 12px rgba(0,0,0,0.2);
    }
    
    .sidebar.mobile-open {
        left: 0;
    }
    
    /* Adjust main content for mobile */
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 80px 12px 12px 12px !important;
    }
    
    /* Section headers */
    .section-header {
        flex-direction: column;
        gap: 12px;
        padding: 12px !important;
    }
    
    .section-title {
        font-size: 24px !important;
    }
    
    /* Buttons stack on mobile */
    .section-actions {
        width: 100%;
        flex-direction: column;
    }
    
    .section-actions .btn {
        width: 100%;
        justify-content: center;
    }
    
    /* Tables scroll horizontally */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    table {
        min-width: 600px;
    }
    
    /* Cards stack on mobile */
    .dashboard-stats,
    .dashboard-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }
    
    /* Forms full width */
    .form-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* Modal adjustments */
    .modal-content {
        width: 95% !important;
        max-width: 95% !important;
        margin: 20px auto !important;
        max-height: 90vh;
        overflow-y: auto;
    }

    /* CANDIDATE FORM MOBILE FIXES */
    /* Force all form fields visible and accessible */
    .form-container input,
    .form-container select,
    .form-container textarea,
    .modal input:not([type="search"]),
    .modal select,
    .modal textarea {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        width: 100% !important;
        min-height: 44px !important;
        position: relative !important;
        z-index: 1 !important;
    }

    /* Ensure owner field and ALL selects work */
    #newOwner,
    #newOwner_select,
    select[id*="Owner"],
    select[id*="owner"],
    .form-container select,
    .modal select {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        width: 100% !important;
        min-height: 44px !important;
        font-size: 16px !important;
        padding: 12px !important;
        background: white !important;
        border: 1px solid #ddd !important;
        border-radius: 4px !important;
        position: relative !important;
        z-index: 10 !important;
        pointer-events: auto !important;
    }

    /* Hide unwanted search bars in form modals */
    .modal .search-container,
    .modal .search-bar,
    .modal input[type="search"],
    .form-container .search-container,
    .form-container .search-bar,
    .form-container input[type="search"] {
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
        overflow: hidden !important;
    }

    /* Ensure save buttons are visible and clickable */
    .modal button[type="submit"],
    .form-container button[type="submit"],
    button[onclick*="saveCandidate"],
    button[onclick*="save"],
    .form-actions button {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        min-height: 48px !important;
        width: 100% !important;
        margin-top: 16px !important;
        font-size: 16px !important;
        padding: 14px !important;
        background: #4A90E2 !important;
        color: white !important;
        border: none !important;
        border-radius: 8px !important;
        z-index: 10 !important;
        position: relative !important;
    }
    
    /* Profile modal */
    #profileModal .modal-content {
        width: 100% !important;
        height: 100vh !important;
        max-height: 100vh !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }
    
    /* Search bar */
    .search-container {
        width: 100% !important;
    }
    
    /* Login box */
    .login-box {
        width: 95% !important;
        padding: 24px !important;
    }
    
    /* Maps layout */
    .maps-layout {
        flex-direction: column !important;
        height: auto !important;
    }
    
    #mapsSidebar {
        width: 100% !important;
        max-height: 300px;
        overflow-y: auto;
    }
    
    .maps-mapwrap {
        min-width: 100% !important;
        height: 60vh !important;
        min-height: 500px !important;
    }
    
    /* Calendar */
    .calendar-grid {
        grid-template-columns: repeat(7, minmax(50px, 1fr)) !important;
    }
    
    .calendar-day-cell {
        min-height: 80px !important;
        font-size: 12px !important;
    }
    
    /* Sidebar navigation items - larger touch targets */
    .nav-item {
        padding: 16px 20px !important;
        font-size: 16px !important;
    }
    
    /* Footer buttons */
    .sidebar-footer {
        padding: 16px !important;
    }
    
    .logout-btn {
        padding: 14px !important;
        font-size: 16px !important;
    }
}

/* ==================== TOUCH SCREEN OPTIMIZATION ==================== */

/* Larger touch targets (minimum 44x44px per Apple/Google guidelines) */
@media (hover: none) and (pointer: coarse) {
    
    /* All buttons */
    .btn, button {
        min-height: 44px;
        padding: 12px 20px;
        font-size: 16px;
    }
    
    /* Navigation items */
    .nav-item {
        min-height: 48px;
        padding: 14px 20px;
    }
    
    /* Table rows */
    .table-row {
        min-height: 48px;
        cursor: pointer;
    }
    
    /* Form inputs */
    input, select, textarea {
        min-height: 44px;
        font-size: 16px; /* Prevents iOS zoom */
        padding: 12px;
    }
    
    /* Disable hover effects on touch devices */
    .btn:hover,
    .nav-item:hover,
    .table-row:hover {
        transform: none;
    }
    
    /* Add active/pressed states instead */
    .btn:active {
        transform: scale(0.98);
        opacity: 0.8;
    }
    
    .nav-item:active {
        background: rgba(255, 255, 255, 0.1);
    }
    
    .table-row:active {
        background: #f3f4f6;
    }
    
    /* Smooth scrolling */
    * {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Remove tap highlight */
    * {
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Fast click (remove 300ms delay) */
    a, button, input, select, textarea {
        touch-action: manipulation;
    }
}

/* ==================== TABLET (768px - 1024px) ==================== */

@media (min-width: 769px) and (max-width: 1024px) {
    
    .sidebar {
        width: 220px;
    }
    
    .main-content {
        margin-left: 220px;
    }
    
    .nav-item span {
        font-size: 14px;
    }
    
    .dashboard-stats,
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .form-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ==================== SMALL MOBILE (< 480px) ==================== */

@media (max-width: 480px) {
    
    .mobile-menu-toggle {
        width: 44px;
        height: 44px;
        top: 12px;
        left: 12px;
    }
    
    .hamburger-icon span {
        width: 20px;
        height: 2px;
    }
    
    .sidebar {
        width: 260px;
    }
    
    .section-title {
        font-size: 20px !important;
    }
    
    .btn {
        font-size: 14px !important;
        padding: 10px 16px !important;
    }
    
    .modal-content {
        padding: 16px !important;
    }
    
    .form-group label {
        font-size: 13px !important;
    }
    
    .table-container {
        font-size: 13px !important;
    }
    
    .calendar-day-cell {
        min-height: 60px !important;
        font-size: 11px !important;
        padding: 4px !important;
    }
    
    .login-box h2 {
        font-size: 24px !important;
    }
}

/* ==================== LANDSCAPE MOBILE ==================== */

@media (max-height: 500px) and (orientation: landscape) {
    
    .sidebar {
        overflow-y: auto;
    }
    
    .modal-content {
        max-height: 95vh;
        overflow-y: auto;
    }
    
    .section-header {
        padding: 8px !important;
    }
}

/* ==================== PWA STANDALONE MODE ==================== */

@media (display-mode: standalone) {
    
    /* Add safe area padding for notched devices */
    .sidebar {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .main-content {
        padding-top: calc(20px + env(safe-area-inset-top));
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .mobile-menu-toggle {
        top: calc(16px + env(safe-area-inset-top));
        left: calc(16px + env(safe-area-inset-left));
    }
}

/* ==================== ACCESSIBILITY ==================== */

/* Focus visible for keyboard navigation */
@media (hover: hover) and (pointer: fine) {
    
    button:focus-visible,
    a:focus-visible,
    input:focus-visible,
    select:focus-visible,
    textarea:focus-visible {
        outline: 3px solid #4A90E2;
        outline-offset: 2px;
    }
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .sidebar,
    .mobile-overlay,
    .hamburger-icon span {
        transition: none !important;
    }
}

/* ==================== PRINT STYLES ==================== */

@media print {
    
    .sidebar,
    .mobile-menu-toggle,
    .section-actions,
    .logout-btn,
    .btn {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }
    
    .modal {
        position: relative !important;
        display: block !important;
    }
    
    .modal-content {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }
}
