/**
 * Comprehensive Responsive Styles for Nexperie
 * PWA-Enhanced Mobile Experience
 */

/* PWA Status Bar Area */
@supports (padding: max(0px)) {
    body {
        padding-top: max(env(safe-area-inset-top), 0px);
        padding-bottom: max(env(safe-area-inset-bottom), 0px);
    }
    
    header {
        padding-top: max(env(safe-area-inset-top), 0px);
    }
}

/* Mobile Menu Toggle Button */
.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-color);
    cursor: pointer;
    padding: 0.5rem;
    min-width: 44px;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}

.mobile-menu-toggle:hover,
.mobile-menu-toggle:active {
    color: var(--primary-color);
    background: var(--light-color);
    border-radius: 4px;
}

/* Base Mobile Styles (Tablets and below) */
@media (max-width: 1024px) {
    .container {
        padding: 0 15px;
    }
    
    /* Tables - make scrollable */
    table {
        font-size: 0.9rem;
    }
    
    /* Forms */
    .form-group {
        margin-bottom: 1rem;
    }
    
    /* Grid layouts */
    .stats-grid,
    [style*="grid-template-columns"] {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) !important;
    }
}

/* Tablet and Mobile (768px and below) */
@media (max-width: 768px) {
    /* Ensure all interactive elements work on mobile */
    * {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
        touch-action: manipulation;
    }
    
    /* Ensure html and body can scroll */
    html, body {
        overflow-x: hidden !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        height: auto !important;
        position: relative !important;
    }
    
    /* Ensure main content can scroll */
    main, .container, .events-section {
        overflow: visible !important;
        position: relative !important;
    }
    
    /* Force all nav-menu styles to be visible and functional */
    .nav-menu,
    .nav-menu * {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
    
    /* Ensure buttons and links are clickable */
    button, a, input, select, textarea, [role="button"] {
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(76, 175, 80, 0.2);
        cursor: pointer;
    }
    
    /* Ensure forms work properly */
    form {
        touch-action: manipulation;
    }
    
    /* Prevent text selection on buttons */
    button, .btn {
        -webkit-user-select: none;
        user-select: none;
    }
    /* Mobile Header Redesign */
    header {
        background: white;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        position: sticky;
        top: 0;
        z-index: 1000;
        padding-top: env(safe-area-inset-top);
    }
    
    .navbar {
        padding: 0.75rem 0;
    }
    
    .navbar .container {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 1rem;
        position: relative;
    }
    
    .nav-brand {
        flex: 1;
        order: 1;
    }
    
    .nav-brand a {
        font-size: 1.5rem;
        font-weight: 700;
        color: var(--primary-color);
        text-decoration: none;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }
    
    /* Mobile Menu Toggle - Redesigned */
    .mobile-menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        order: 2;
        background: #f5f5f5;
        border: 1px solid #e0e0e0;
        width: 44px;
        height: 44px;
        border-radius: 8px;
        cursor: pointer;
        padding: 0;
        transition: all 0.2s ease;
        -webkit-tap-highlight-color: rgba(76, 175, 80, 0.2);
        position: relative;
        z-index: 1001;
        -webkit-appearance: none;
        appearance: none;
        touch-action: manipulation;
    }
    
    .mobile-menu-toggle:active {
        background: #4CAF50;
        transform: scale(0.95);
    }
    
    .mobile-menu-toggle.active {
        background: #4CAF50;
    }
    
    .mobile-menu-toggle:focus {
        outline: 2px solid var(--primary-color);
        outline-offset: 2px;
    }
    
    .mobile-menu-toggle span {
        font-size: 1.5rem;
        color: #333;
        transition: color 0.2s ease;
        display: block;
        pointer-events: none;
        user-select: none;
        line-height: 1;
    }
    
    .mobile-menu-toggle.active span {
        color: white;
    }
    
    .mobile-menu-toggle:active span {
        color: white;
    }
    
    /* Mobile Menu Overlay - Redesigned */
    .nav-menu-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        height: 100dvh;
        background: rgba(0, 0, 0, 0.6);
        z-index: 9999;
        opacity: 0;
        transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        pointer-events: none;
        will-change: opacity;
    }
    
    .nav-menu-overlay.active {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }
    
    /* Mobile Sidebar - Redesigned */
    .nav-menu {
        position: fixed !important;
        top: 0 !important;
        right: -100% !important;
        width: 300px !important;
        max-width: 85vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        background: #ffffff !important;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15) !important;
        z-index: 10000 !important;
        margin: 0 !important;
        padding: 0 !important;
        list-style: none !important;
        display: flex !important;
        flex-direction: column !important;
        transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        visibility: visible !important;
        opacity: 1 !important;
        will-change: right !important;
    }
    
    .nav-menu.active {
        right: 0 !important;
        display: flex !important;
    }
    
    /* Simple Close Button */
    .nav-menu-close {
        position: absolute !important;
        top: 1rem !important;
        right: 1rem !important;
        background: #f5f5f5 !important;
        border: 1px solid #ddd !important;
        font-size: 1.2rem !important;
        color: #333 !important;
        cursor: pointer !important;
        padding: 0 !important;
        width: 36px !important;
        height: 36px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        z-index: 10001 !important;
        border-radius: 6px !important;
        transition: background 0.2s ease !important;
        pointer-events: auto !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    .nav-menu-close:hover,
    .nav-menu-close:active {
        background: #e0e0e0 !important;
    }
    
    /* Simple Menu Items */
    .nav-menu li {
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        list-style: none !important;
        border-bottom: 1px solid #e8e8e8 !important;
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    .nav-menu li:last-child {
        border-bottom: none !important;
    }
    
    .nav-menu a {
        display: block !important;
        padding: 1rem 1.5rem !important;
        width: 100% !important;
        color: #333 !important;
        text-decoration: none !important;
        font-size: 1rem !important;
        font-weight: 500 !important;
        background: #ffffff !important;
        transition: background 0.2s ease !important;
        cursor: pointer !important;
        box-sizing: border-box !important;
        pointer-events: auto !important;
        visibility: visible !important;
        opacity: 1 !important;
        z-index: 10 !important;
        position: relative !important;
    }
    
    .nav-menu a:hover,
    .nav-menu a:active,
    .nav-menu a:focus {
        background: #f5f5f5 !important;
        color: #4CAF50 !important;
    }
    
    /* Active menu item */
    .nav-menu a.active {
        background: #e8f5e9 !important;
        color: #2e7d32 !important;
        font-weight: 600 !important;
    }
    
    /* Menu divider */
    .nav-menu li.divider {
        height: 1px !important;
        background: #e8e8e8 !important;
        margin: 0.5rem 1.5rem !important;
        padding: 0 !important;
        border: none !important;
        list-style: none !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    /* Hero Section */
    .hero {
        padding: 2rem 0;
    }
    
    .hero h1 {
        font-size: 2rem;
    }
    
    .hero p {
        font-size: 1rem;
    }
    
    /* Search Section */
    .search-row {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }
    
    /* Events Grid */
    .events-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* Event Cards */
    .event-card {
        margin-bottom: 1.5rem;
    }
    
    /* Forms */
    .form-section {
        padding: 1.5rem !important;
    }
    
    /* Grid layouts in forms */
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns: 1fr 1fr 1fr"],
    [style*="grid-template-columns: repeat(4, 1fr)"] {
        grid-template-columns: 1fr !important;
    }
    
    /* Buttons */
    .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .btn:last-child {
        margin-bottom: 0;
    }
    
    /* Button groups */
    [style*="display: flex"][style*="gap"] {
        flex-direction: column !important;
    }
    
    /* Tables - make horizontal scroll */
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    
    table thead,
    table tbody,
    table tr {
        display: table;
        width: 100%;
        table-layout: fixed;
    }
    
    /* Alternative: Stack table cells on mobile */
    .responsive-table {
        display: block;
    }
    
    .responsive-table thead {
        display: none;
    }
    
    .responsive-table tbody {
        display: block;
    }
    
    .responsive-table tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        padding: 1rem;
        background: white;
    }
    
    .responsive-table td {
        display: block;
        text-align: right !important;
        padding: 0.5rem 0;
        border: none;
        border-bottom: 1px solid var(--light-color);
    }
    
    .responsive-table td:before {
        content: attr(data-label);
        float: left;
        font-weight: bold;
        text-align: left;
    }
    
    .responsive-table td:last-child {
        border-bottom: none;
    }
    
    /* Event Actions */
    .event-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    /* Ticket Info */
    .ticket-info {
        grid-template-columns: 1fr !important;
    }
    
    /* Admin/Organizer Pages */
    .stats-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* Booking Details */
    .booking-details-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* Images */
    img {
        max-width: 100%;
        height: auto;
    }
    
    /* Modals and Overlays */
    .modal {
        width: 95% !important;
        max-width: 95% !important;
        margin: 1rem auto;
        padding: 1rem;
    }
    
    /* Alerts */
    .alert {
        padding: 1rem;
        font-size: 0.9rem;
    }
    
    /* Container padding */
    .container {
        padding: 0 1rem;
    }
    
    /* Section padding */
    main .container {
        padding: 1rem 0;
    }
    
    /* Form sections */
    [style*="padding: 2rem"] {
        padding: 1.5rem !important;
    }
    
    /* Headings */
    h1 {
        font-size: 1.75rem;
    }
    
    h2 {
        font-size: 1.5rem;
    }
    
    h3 {
        font-size: 1.25rem;
    }
}

/* Small Mobile (480px and below) */
@media (max-width: 480px) {
    /* Hero */
    .hero {
        padding: 1.5rem 0;
    }
    
    .hero h1 {
        font-size: 1.5rem;
    }
    
    .hero p {
        font-size: 0.9rem;
    }
    
    /* Events Section */
    .events-section h2 {
        font-size: 1.5rem;
    }
    
    /* Navigation */
    .nav-brand a {
        font-size: 1.25rem;
    }
    
    /* Forms */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    input[type="date"],
    input[type="datetime-local"],
    select,
    textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        width: 100%;
    }
    
    /* Buttons */
    .btn {
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }
    
    /* Tables */
    table {
        font-size: 0.85rem;
    }
    
    table th,
    table td {
        padding: 0.5rem 0.25rem;
    }
    
    /* Cards */
    .card,
    [style*="background: white"][style*="padding"] {
        padding: 1rem !important;
    }
    
    /* Spacing */
    .container {
        padding: 0 0.75rem;
    }
    
    /* Headings */
    h1 {
        font-size: 1.5rem;
        margin-bottom: 1rem;
    }
    
    h2 {
        font-size: 1.25rem;
    }
    
    /* QR Code */
    .ticket-qr,
    .qr-code-container {
        padding: 1rem 0.5rem !important;
    }
    
    .qr-code-element {
        max-width: 150px !important;
        width: 150px !important;
    }
    
    /* Scanner */
    #scanner-container {
        max-width: 100% !important;
        margin: 1rem 0 !important;
    }
    
    /* Booking Success */
    .ticket {
        padding: 1rem !important;
        margin: 1rem 0 !important;
    }
}

/* Extra Small Mobile (360px and below) */
@media (max-width: 360px) {
    .hero h1 {
        font-size: 1.25rem;
    }
    
    .btn {
        padding: 0.625rem 0.875rem;
        font-size: 0.9rem;
    }
    
    .container {
        padding: 0 0.5rem;
    }
}

/* Landscape Mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .hero {
        padding: 1.5rem 0;
    }
    
    .nav-menu {
        max-height: 70vh;
        overflow-y: auto;
    }
}

/* Print Styles */
@media print {
    .no-print,
    .mobile-menu-toggle,
    .nav-menu,
    header,
    footer,
    .btn {
        display: none !important;
    }
    
    body {
        background: white;
    }
    
    .container {
        max-width: 100%;
        padding: 0;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .btn,
    a,
    button,
    input[type="submit"],
    input[type="button"] {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Better spacing for touch */
    .nav-menu a {
        padding: 1rem;
    }
    
    /* Remove hover effects on touch devices */
    .nav-menu a:hover {
        background: var(--light-color);
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Ensure crisp rendering */
    img,
    .qr-code-element {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}
