/* Mobile-specific fixes and improvements */

/* Ensure proper mobile viewport */
@viewport {
    width: device-width;
    zoom: 1.0;
}

/* Base mobile optimizations */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* Mobile breakpoints */
@media screen and (max-width: 1024px) {
    /* Force hide desktop sidebar */
    .desktop-sidebar {
        display: none !important;
    }
    
    /* Force show mobile elements */
    .mobile-header {
        display: flex !important;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 30;
        height: 4rem;
        padding: 1rem;
        background: rgba(22, 33, 62, 0.95);
        backdrop-filter: blur(10px);
        border-bottom: 1px solid #0f3460;
    }
    
    /* Main content with proper mobile spacing */
    .main-content {
        padding-top: 4rem !important;
        min-height: calc(100vh - 4rem);
        width: 100%;
    }
    
    .content-wrapper {
        padding: 0.75rem;
        max-width: 100%;
        overflow-x: hidden;
    }
    
    /* Mobile sidebar */
    .mobile-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        background: rgba(22, 33, 62, 0.98);
        backdrop-filter: blur(10px);
        border-right: 1px solid #0f3460;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Mobile submenu styles */
    .mobile-sidebar .submenu {
        max-height: 0 !important;
        overflow: hidden !important;
        transition: max-height 0.3s ease-out !important;
        background: rgba(15, 52, 96, 0.5);
        margin-left: 0 !important;
        border-left: none !important;
    }
    
    .mobile-sidebar .submenu.expanded,
    .mobile-sidebar .submenu.force-expanded,
    .mobile-sidebar #submenu-my-account.expanded,
    .mobile-sidebar #submenu-my-account.force-expanded {
        max-height: 500px !important;
        transition: max-height 0.3s ease-in !important;
        overflow: visible !important;
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        height: auto !important;
    }
    
    /* Nuclear override - maximum specificity */
    .mobile-sidebar .submenu#submenu-my-account.expanded.force-expanded {
        max-height: 500px !important;
        overflow: visible !important;
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        height: auto !important;
    }
    
    .mobile-sidebar .submenu-toggle {
        cursor: pointer;
        user-select: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        min-height: 48px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 12px 16px !important;
        touch-action: manipulation;
    }
    
    .mobile-sidebar .submenu-arrow {
        transition: transform 0.2s ease;
        font-size: 0.75rem;
        color: #c0c0c0;
    }
    
    .mobile-sidebar .submenu-item {
        padding: 12px 20px 12px 40px;
        font-size: 0.9rem;
        color: #c0c0c0;
        text-decoration: none;
        display: flex;
        align-items: center;
        min-height: 44px;
        transition: all 0.2s ease;
        border-left: 3px solid transparent;
        touch-action: manipulation;
    }
    
    .mobile-sidebar .submenu-item:hover,
    .mobile-sidebar .submenu-item:active {
        background: rgba(255, 215, 0, 0.1);
        color: #ffd700;
        border-left-color: #ffd700;
    }
    
    .mobile-sidebar .submenu-item.active {
        background: #ffd700;
        color: #1a1a2e;
        font-weight: 500;
        border-left-color: #ffd700;
    }
    
    .mobile-sidebar.open {
        transform: translateX(0);
    }
    
    /* Mobile overlay */
    .mobile-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 40;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease-in-out;
    }
    
    .mobile-overlay.show {
        opacity: 1;
        visibility: visible;
    }
}

/* Tablet breakpoint */
@media screen and (max-width: 768px) {
    .content-wrapper {
        padding: 0.5rem;
    }
    
    /* Better card spacing on mobile */
    .card {
        margin-bottom: 1rem;
        border-radius: 0.5rem;
        padding: 1rem;
    }
    
    /* Responsive tables */
    .overflow-x-auto {
        -webkit-overflow-scrolling: touch;
    }
    
    table {
        min-width: 100%;
        font-size: 0.875rem;
    }
    
    th, td {
        padding: 0.5rem !important;
        white-space: nowrap;
    }
    
    /* Device history table mobile optimization */
    .device-history-mobile th:nth-child(n+4),
    .device-history-mobile td:nth-child(n+4) {
        display: none;
    }
    
    .device-history-mobile th:first-child,
    .device-history-mobile td:first-child,
    .device-history-mobile th:nth-child(2),
    .device-history-mobile td:nth-child(2),
    .device-history-mobile th:nth-child(7),
    .device-history-mobile td:nth-child(7) {
        display: table-cell;
    }
}

/* Phone breakpoint */
@media screen and (max-width: 640px) {
    .mobile-header h1 {
        font-size: 1.125rem;
        margin-left: 0.75rem;
    }
    
    .content-wrapper {
        padding: 0.75rem 0.5rem;
    }
    
    /* Responsive grids */
    .grid {
        grid-template-columns: 1fr !important;
        gap: 0.75rem;
    }
    
    .md\\:grid-cols-2,
    .sm\\:grid-cols-2,
    .lg\\:grid-cols-2,
    .grid-cols-2 {
        grid-template-columns: 1fr !important;
    }
    
    /* Stack form fields vertically */
    .space-x-6 > * {
        margin-left: 0 !important;
        margin-right: 0 !important;
        margin-bottom: 1rem;
    }
    
    /* Better button sizing */
    .btn-primary,
    .btn-secondary {
        width: 100%;
        padding: 0.75rem 1rem;
        font-size: 1rem;
        text-align: center;
        display: block;
    }
    
    /* Mobile-friendly text sizes */
    h1 {
        font-size: 1.75rem !important;
    }
    
    h2 {
        font-size: 1.5rem !important;
    }
    
    h3 {
        font-size: 1.25rem !important;
    }
    
    /* Better spacing for profile sections */
    .border-t {
        margin-top: 1.5rem;
        padding-top: 1.5rem;
    }
}

/* Extra small phones */
@media screen and (max-width: 480px) {
    .mobile-sidebar {
        width: 100vw;
    }
    
    .content-wrapper {
        padding: 0.5rem 0.25rem;
    }
    
    /* Smaller text for very small screens */
    .text-xs {
        font-size: 0.7rem;
    }
    
    .text-sm {
        font-size: 0.8rem;
    }
}

/* Touch improvements */
@media (hover: none) and (pointer: coarse) {
    /* Touch-friendly tap targets */
    button,
    .menu-item,
    .submenu-item,
    a {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding: 0.75rem 1rem;
    }
    
    .mobile-menu-btn {
        min-height: 44px;
        min-width: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* Landscape orientation fixes */
@media screen and (max-height: 500px) and (orientation: landscape) {
    .mobile-header {
        height: 3rem;
        padding: 0.5rem 1rem;
    }
    
    .main-content {
        padding-top: 3rem !important;
    }
    
    .mobile-sidebar {
        padding-top: 0.5rem;
    }
}

/* Device-specific fixes */
/* iOS Safari fixes */
@supports (-webkit-appearance: none) {
    .mobile-sidebar {
        height: -webkit-fill-available;
        height: 100vh;
    }
    
    .main-content {
        min-height: -webkit-fill-available;
        min-height: calc(100vh - 4rem);
    }
}

/* Android Chrome fixes */
@media screen and (max-width: 768px) {
    /* Prevent zoom on input focus */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    textarea,
    select {
        font-size: 16px !important;
        -webkit-appearance: none;
        border-radius: 0.375rem;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .mobile-sidebar {
        border-right: 0.5px solid #0f3460;
    }
    
    .mobile-header {
        border-bottom: 0.5px solid #0f3460;
    }
}

/* Dark mode improvements for mobile */
@media (prefers-color-scheme: dark) {
    .mobile-header {
        background: rgba(22, 33, 62, 0.98);
    }
    
    .mobile-sidebar {
        background: rgba(22, 33, 62, 0.98);
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    .mobile-sidebar,
    .mobile-overlay {
        transition: none;
    }
}

/* Focus improvements for mobile */
@media screen and (max-width: 1024px) {
    button:focus,
    a:focus,
    input:focus,
    select:focus,
    textarea:focus {
        outline: 2px solid #ffd700;
        outline-offset: 2px;
    }
}