/* ============================================
   RESPONSIVE FIXES FOR ADMIN & USER PAGES
   Mobile-First Design - All Devices
   ============================================ */

/* Mobile Menu Overlay */
@media (max-width: 767px) {
    /* Sidebar - Mobile Hidden by Default */
    .sidebar-container {
        position: fixed !important;
        top: 0;
        left: 0;
        width: 85vw !important;
        max-width: 320px;
        height: 100vh;
        z-index: 9999;
        transform: translateX(-100%) !important;
        transition: transform 0.3s ease-in-out;
        display: block;
    }
    
    .sidebar-container.mobile-open {
        transform: translateX(0) !important;
    }
    
    /* Main Content - Full Width on Mobile */
    body.has-sidebar main.sidebar-enabled,
    .has-sidebar main,
    main.sidebar-enabled,
    main {
        padding-left: 0 !important;
        width: 100% !important;
        margin-left: 0 !important;
    }
    
    /* Public pages do not include #adminSidebar / #userSidebar — no hide rule needed.
       Do not use body:not(.has-sidebar): that class is on an inner wrapper and hid all sidebars. */
    
    /* Mobile Menu Toggle Button - Top Left */
    #mobileMenuBtn {
        display: flex !important;
        position: fixed;
        top: 1rem;
        left: 1rem;
        z-index: 10000;
        width: 3rem;
        height: 3rem;
        background: linear-gradient(135deg, #0ea5e9, #6366f1);
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 12px;
        align-items: center;
        justify-content: center;
        color: white;
        cursor: pointer;
        box-shadow: 0 10px 30px rgba(14, 165, 233, 0.3);
        transition: all 0.2s ease-in-out;
    }
    
    #mobileMenuBtn:active {
        transform: scale(0.95);
    }
    
    /* Backdrop Overlay */
    #sidebarBackdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.7);
        backdrop-filter: blur(4px);
        z-index: 9998;
        opacity: 0;
        transition: opacity 0.3s ease-in-out;
    }
    
    #sidebarBackdrop.active {
        display: block !important;
        opacity: 1;
    }
    
    /* Hide Desktop Toggle Button on Mobile */
    .sidebar-toggle-btn {
        display: none !important;
    }
    
    /* Adjust Main Content Padding - No sidebar padding on mobile */
    .has-sidebar main > *:first-child,
    main.sidebar-enabled > *:first-child {
        padding-top: 4.5rem !important;
    }
    
    /* Ensure full-width content */
    .has-sidebar,
    body.has-sidebar {
        overflow-x: hidden;
    }
    
    /* Force full width for all pages on mobile */
    body,
    html {
        overflow-x: hidden !important;
        width: 100vw !important;
    }
    
    /* Remove any left padding/margin on main content for mobile */
    body.has-sidebar main,
    main {
        margin-left: 0 !important;
        padding-left: 0 !important;
    }
}

/* ============================================
   USER / ADMIN APP SHELL (md+)
   Sidebar is in-flow (sticky), main flexes beside it.
   This prevents the classic "fixed sidebar overlaps content" bug.
   ============================================ */
@media (min-width: 768px) {
    .has-sidebar {
        display: flex !important;
        align-items: stretch !important;
        min-height: 100vh !important;
    }

    #mobileMenuBtn {
        display: none !important;
    }

    #sidebarBackdrop,
    #sidebarBackdrop:not(.hidden),
    #sidebarBackdrop.active {
        display: none !important;
        pointer-events: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
    }

    .has-sidebar > #userSidebar,
    .has-sidebar > #adminSidebar,
    .has-sidebar > aside.sidebar-container {
        position: sticky !important;
        top: 0 !important;
        left: auto !important;
        bottom: auto !important;
        align-self: flex-start !important;
        display: flex !important;
        flex-direction: column !important;
        flex: 0 0 16rem !important;
        width: 16rem !important;
        max-width: 16rem !important;
        height: 100vh !important;
        max-height: 100vh !important;
        transform: none !important;
        transition: flex-basis 0.3s ease, width 0.3s ease, max-width 0.3s ease !important;
        z-index: 30 !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
    }

    /* Keep backdrop/menu button out of the flex row */
    .has-sidebar > #sidebarBackdrop,
    .has-sidebar > #mobileMenuBtn {
        display: none !important;
        flex: 0 0 0 !important;
        width: 0 !important;
        height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
    }

    .has-sidebar > #userSidebar.sidebar-collapsed,
    .has-sidebar > #adminSidebar.sidebar-collapsed,
    .has-sidebar > aside.sidebar-container.sidebar-collapsed {
        flex: 0 0 4.5rem !important;
        width: 4.5rem !important;
        max-width: 4.5rem !important;
    }

    .has-sidebar > #userSidebar.sidebar-hidden,
    .has-sidebar > #adminSidebar.sidebar-hidden,
    .has-sidebar > aside.sidebar-container.sidebar-hidden {
        flex: 0 0 0 !important;
        width: 0 !important;
        max-width: 0 !important;
        opacity: 0 !important;
        pointer-events: none !important;
        border: 0 !important;
        overflow: hidden !important;
    }

    /* Page main sits beside sidebar — never under it */
    .has-sidebar > main,
    .has-sidebar > main.sidebar-enabled,
    main.sidebar-enabled {
        flex: 1 1 auto !important;
        min-width: 0 !important;
        width: auto !important;
        max-width: 100% !important;
        padding-left: 0 !important;
        margin-left: 0 !important;
    }

    main.sidebar-enabled.sidebar-collapsed-main,
    main.sidebar-enabled.sidebar-hidden-main {
        padding-left: 0 !important;
        margin-left: 0 !important;
    }
}

/* Desktop width bump */
@media (min-width: 1024px) {
    .has-sidebar > #userSidebar:not(.sidebar-collapsed):not(.sidebar-hidden),
    .has-sidebar > #adminSidebar:not(.sidebar-collapsed):not(.sidebar-hidden),
    .has-sidebar > aside.sidebar-container:not(.sidebar-collapsed):not(.sidebar-hidden) {
        flex: 0 0 17.5rem !important;
        width: 17.5rem !important;
        max-width: 17.5rem !important;
    }

    /* Public pages omit sidebar partials — keep layout shell main full-width */
    body:not(:has(#adminSidebar)):not(:has(#userSidebar)) > #app > main {
        padding-left: 0 !important;
        margin-left: 0 !important;
    }
}

/* App shell background — avoid white gap beside sidebar */
body:has(#adminSidebar),
body:has(#userSidebar),
body:has(.has-sidebar) {
    background: #020617 !important;
}

body:has(#adminSidebar) #app,
body:has(#userSidebar) #app,
body:has(.has-sidebar) #app,
body:has(#adminSidebar) #app > main,
body:has(#userSidebar) #app > main {
    background: transparent !important;
}


/* Responsive Typography */
@media (max-width: 640px) {
    h1 {
        font-size: 1.5rem !important;
    }
    
    h2 {
        font-size: 1.25rem !important;
    }
    
    h3 {
        font-size: 1.125rem !important;
    }
}

/* Responsive Tables */
@media (max-width: 768px) {
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    table {
        min-width: 600px;
    }
}

/* Responsive Cards/Grid */
@media (max-width: 768px) {
    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4 {
        grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
    }

    /* Data Search stats — keep Total / Net New / Saved on one row */
    .stats-cards-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    }
    
    .lg\\:grid-cols-2 {
        grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
    }
}

/* Responsive Padding/Spacing */
@media (max-width: 640px) {
    .px-6,
    .px-8 {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    .py-8,
    .py-10 {
        padding-top: 1.5rem !important;
        padding-bottom: 1.5rem !important;
    }
}

/* File Upload Dropzone - Mobile */
@media (max-width: 640px) {
    #dropZone {
        padding: 2rem 1rem !important;
    }
    
    #dropZone svg {
        width: 3rem !important;
        height: 3rem !important;
    }
}

/* Data Type Buttons - Mobile Stack */
@media (max-width: 640px) {
    .data-type-btn {
        font-size: 0.75rem !important;
        padding: 0.5rem 0.75rem !important;
    }
}

/* Modal/Popup - Mobile Full Width (exclude Data Search download overlay — it is full-bleed) */
@media (max-width: 640px) {
    [role="dialog"]:not(.download-modal-overlay):not(.employees-range-popover),
    .modal:not(.download-modal-panel),
    .popup {
        width: 95% !important;
        max-width: 95% !important;
        margin: 1rem auto !important;
    }

    .download-modal-overlay[role="dialog"] {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
    }
}

/* Responsive Buttons — do not override Data Search compact controls */
@media (max-width: 640px) {
    button:not(.data-search-root button):not(.download-modal-overlay button):not(.data-search-mobile-toolbar__filters):not(.data-search-mobile-toolbar__btn):not(.results-table-toolbar__btn):not(.results-table-pagination__btn),
    .btn {
        font-size: 0.875rem !important;
        padding: 0.625rem 1rem !important;
    }
    
    button.btn-lg {
        font-size: 1rem !important;
        padding: 0.75rem 1.25rem !important;
    }
}

/* Credits Card - Mobile Optimization */
@media (max-width: 640px) {
    .sidebar-container .rounded-2xl {
        padding: 0.75rem !important;
    }
    
    .sidebar-container .text-3xl {
        font-size: 1.875rem !important;
    }
}

/* Navigation Links - Touch Friendly */
@media (max-width: 767px) {
    nav a {
        padding: 0.875rem 0.75rem !important;
        font-size: 0.9375rem !important;
    }
}

/* Stats Cards - Mobile Grid */
@media (max-width: 640px) {
    .grid-cols-2 > div {
        font-size: 0.875rem !important;
    }
    
    .grid-cols-2 > div .text-lg {
        font-size: 1.125rem !important;
    }
}

/* Import Jobs Table - Mobile Scroll */
@media (max-width: 768px) {
    #importJobsTable {
        overflow-x: auto;
        display: block;
    }
    
    #importJobsTable table {
        min-width: 800px;
    }
}

/* Form Elements - Mobile Friendly */
@media (max-width: 640px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px !important; /* Prevents zoom on iOS */
    }
}

/* Sticky Header - Mobile Height (exclude Data Search header — it manages its own spacing) */
@media (max-width: 640px) {
    .sticky.top-0:not(.search-header) {
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }
}

/* Smooth Scrolling */
html {
    scroll-behavior: smooth;
}

/* Mobile only: full-width main under drawer sidebar */
@media (max-width: 767px) {
    .has-sidebar > main,
    main.sidebar-enabled {
        padding-left: 0 !important;
        margin-left: 0 !important;
        width: 100% !important;
    }
}

/* ============================================
   NAVBAR MOBILE FIXES
   ============================================ */

@media (max-width: 767px) {
    /* Navbar - Full width on mobile */
    #siteNavbar {
        width: 100vw !important;
        left: 0 !important;
        margin-left: 0 !important;
        padding-left: 0 !important;
    }
    
    /* Navbar container */
    #siteNavbar .max-w-7xl {
        margin-left: 0 !important;
        padding-left: 1rem !important;
        padding-right: 1rem !important;
        max-width: 100% !important;
    }
    
    /* Mobile menu toggle button */
    #mobileMenuToggle {
        min-width: 40px !important;
        min-height: 40px !important;
    }
}

/* Touch Optimization */
@media (hover: none) and (pointer: coarse) {
    button,
    a,
    [onclick] {
        -webkit-tap-highlight-color: rgba(14, 165, 233, 0.2);
    }
}

/* Loading States */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Animation Performance */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   COMPACT HEADER DESIGN - Data Search Page
   Sleek, Modern, Space-Efficient
   ============================================ */

/* Scrollbar Hide Utility */
.scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.scrollbar-hide::-webkit-scrollbar {
    display: none;
}

/* Base Header Styles - All Screens */
.sticky.top-0 {
    transition: all 0.2s ease;
}

/* Header Title - Compact sizing */
.sticky.top-0 h1 {
    line-height: 1.2 !important;
}

/* Header Buttons - Compact and elegant */
.sticky.top-0 button {
    transition: all 0.2s ease;
    line-height: 1.2;
}

.sticky.top-0 button:hover {
    transform: translateY(-1px);
}

.sticky.top-0 button:active {
    transform: translateY(0);
}

/* Dropdown positioning */
#listsDropdown,
#downloadsDropdown {
    animation: slideDown 0.2s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Data Type Tabs - Sleek design */
#dataTypeTabs button {
    transition: all 0.2s ease;
}

#dataTypeTabs button:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* Mobile Optimizations */
@media (max-width: 640px) {
    /* Ultra-compact header (exclude Data Search — it owns its chrome) */
    .sticky.top-0:not(.search-header) {
        padding: 0 !important;
    }
    
    .sticky.top-0:not(.search-header) > div:first-child {
        padding: 0.5rem 0.75rem !important;
    }
    
    /* Compact title */
    .sticky.top-0:not(.search-header) h1 {
        font-size: 1rem !important;
    }
    
    /* Button sizing - compact but touch-friendly */
    .sticky.top-0:not(.search-header) button {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.75rem !important;
        min-height: 2rem !important;
    }
    
    .sticky.top-0:not(.search-header) button svg {
        width: 0.875rem !important;
        height: 0.875rem !important;
    }
    
    /* Dropdown menus on mobile */
    #listsDropdown,
    #downloadsDropdown {
        right: 0.5rem !important;
        left: 0.5rem !important;
        width: auto !important;
    }
    
    /* Data Type Tabs - horizontal scroll */
    #dataTypeTabs {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    #dataTypeTabs button {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.75rem !important;
    }
}

/* Tiny screens - even more compact */
@media (max-width: 375px) {
    .sticky.top-0:not(.search-header) h1 {
        font-size: 0.875rem !important;
    }
    
    .sticky.top-0:not(.search-header) button {
        padding: 0.375rem 0.625rem !important;
        min-height: 1.75rem !important;
    }
    
    .sticky.top-0:not(.search-header) button svg {
        width: 0.75rem !important;
        height: 0.75rem !important;
    }
}

/* Tablet and up - comfortable spacing (exclude Data Search header) */
@media (min-width: 641px) and (max-width: 1024px) {
    .sticky.top-0:not(.search-header) > div:first-child {
        padding: 0.75rem 1rem !important;
    }
    
    .sticky.top-0:not(.search-header) h1 {
        font-size: 1.25rem !important;
    }
}

/* Desktop - standard spacing (exclude Data Search header) */
@media (min-width: 1025px) {
    .sticky.top-0:not(.search-header) > div:first-child {
        padding: 0.875rem 1.25rem !important;
    }
}

/* ============================================
   SIDEBAR VISIBILITY ENFORCEMENT
   Sizing/position owned by app-shell rules above.
   ============================================ */
#adminSidebar,
#userSidebar,
aside.sidebar-container {
    opacity: 1;
    visibility: visible;
}

@media (min-width: 768px) {
    #adminSidebar:not(.sidebar-hidden),
    #userSidebar:not(.sidebar-hidden),
    aside.sidebar-container:not(.sidebar-hidden) {
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
    }
}

/* ============================================
   PWA / MOBILE SHELL POLISH
   ============================================ */

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Comfortable touch targets on phones */
@media (max-width: 767px) {
    button,
    .btn,
    a.inline-flex,
    a.rounded-xl,
    input[type="submit"],
    select,
    summary {
        min-height: 44px;
    }

    input,
    select,
    textarea {
        font-size: 16px !important; /* prevents iOS zoom on focus */
    }

    /* Finance / employees / roles dense tables */
    .overflow-x-auto {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
    }

    table {
        font-size: 0.875rem;
    }

    /* Page header stacks: keep action buttons usable */
    .finance-export-actions a,
    main .flex.flex-wrap.gap-2 > a,
    main .flex.flex-wrap.gap-2 > button {
        flex: 1 1 auto;
        min-width: 5.5rem;
        justify-content: center;
    }

    /* Reduce horizontal bleed on admin cards */
    main.sidebar-enabled > .p-4,
    main.sidebar-enabled > .p-6,
    main.sidebar-enabled .px-6 {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    /* Sticky filter bars feel more native */
    .sticky-mobile-bar {
        position: sticky;
        top: 0;
        z-index: 20;
        backdrop-filter: blur(10px);
        background: rgba(7, 17, 38, 0.88);
        padding: 0.75rem 0;
    }
}

/* Standalone PWA: add a little top safe-area for notches */
@media (display-mode: standalone) {
    body {
        padding-top: env(safe-area-inset-top, 0);
    }

    #mobileMenuBtn {
        top: calc(1rem + env(safe-area-inset-top, 0px));
    }
}

