/**
 * Comprehensive Responsive Styles for Evento
 * 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) {
    /* 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 - Modern Design */
    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        order: 2;
        background: var(--light-color);
        border: none;
        width: 44px;
        height: 44px;
        border-radius: 12px;
        cursor: pointer;
        padding: 0;
        transition: all 0.2s ease;
        -webkit-tap-highlight-color: transparent;
        position: relative;
    }
    
    .mobile-menu-toggle span {
        font-size: 1.5rem;
        color: var(--text-color);
        transition: transform 0.3s ease;
        display: block;
    }
    
    .mobile-menu-toggle.active span {
        transform: rotate(90deg);
    }
    
    .mobile-menu-toggle:hover,
    .mobile-menu-toggle:active {
        background: var(--primary-color);
    }
    
    .mobile-menu-toggle:hover span,
    .mobile-menu-toggle:active span {
        color: white;
    }
    
    /* Mobile Menu Overlay */
    .nav-menu-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.75);
        backdrop-filter: blur(3px);
        -webkit-backdrop-filter: blur(3px);
        z-index: 9998;
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    
    .nav-menu-overlay.active {
        display: block;
        opacity: 1;
    }
    
    /* Mobile Menu Drawer - Modern Design */
    .nav-menu {
        display: flex !important;
        flex-direction: column;
        position: fixed;
        top: 0;
        right: -100%;
        width: 320px;
        max-width: 90vw;
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile */
        background: #ffffff;
        box-shadow: -4px 0 40px rgba(0,0,0,0.3);
        z-index: 9999;
        margin: 0;
        padding: 0;
        gap: 0;
        transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        border-left: 2px solid rgba(0,0,0,0.08);
        visibility: hidden;
    }
    
    .nav-menu.active {
        right: 0;
        visibility: visible;
    }
    
    /* Menu Header - Modern Design */
    .nav-menu > li:first-child {
        background: linear-gradient(135deg, #4CAF50 0%, #45a049 50%, #388e3c 100%);
        margin: 0;
        padding: 0;
        position: relative;
        min-height: 160px;
        display: flex;
        align-items: flex-end;
        padding-bottom: 1.5rem;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        border-bottom: 3px solid rgba(255,255,255,0.25);
        flex-shrink: 0;
    }
    
    .nav-menu > li:first-child::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="20" cy="20" r="2" fill="rgba(255,255,255,0.15)"/><circle cx="80" cy="40" r="1.5" fill="rgba(255,255,255,0.15)"/><circle cx="40" cy="60" r="1" fill="rgba(255,255,255,0.15)"/><circle cx="60" cy="80" r="1.5" fill="rgba(255,255,255,0.1)"/></svg>');
        opacity: 0.4;
    }
    
    .nav-menu > li:first-child a {
        color: #ffffff !important;
        font-weight: 700;
        font-size: 1.4rem;
        padding: 0 1.5rem;
        pointer-events: none;
        cursor: default;
        position: relative;
        z-index: 1;
        text-shadow: 0 2px 6px rgba(0,0,0,0.3);
        letter-spacing: 0.5px;
        width: 100%;
    }
    
    .nav-menu > li:first-child a::before,
    .nav-menu > li:first-child a::after {
        display: none !important;
    }
    
    .nav-menu li {
        width: 100%;
        margin: 0;
        list-style: none;
    }
    
    .nav-menu li:not(:first-child) {
        border-bottom: 1px solid #e0e0e0;
        background: #ffffff;
        margin: 0;
        width: 100%;
        display: block;
    }
    
    .nav-menu li:last-child {
        border-bottom: none;
        margin-bottom: 0;
    }
    
    .nav-menu a {
        display: flex !important;
        align-items: center;
        padding: 1.4rem 1.5rem;
        width: 100%;
        color: #1a1a1a !important;
        text-decoration: none;
        transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        font-size: 1.1rem;
        font-weight: 500;
        position: relative;
        background: #ffffff !important;
        border-left: 3px solid transparent;
        line-height: 1.5;
        min-height: 56px;
        box-sizing: border-box;
    }
    
    .nav-menu a:hover,
    .nav-menu a:active,
    .nav-menu a:focus {
        background: linear-gradient(90deg, #f5f5f5 0%, rgba(76, 175, 80, 0.08) 100%) !important;
        color: #2e7d32 !important;
        padding-left: 2rem;
        transform: translateX(4px);
        border-left-color: #4CAF50 !important;
    }
    
    /* Menu item icons - Modern Design */
    .nav-menu a::before {
        content: '';
        width: 8px;
        height: 8px;
        background: #4CAF50;
        border-radius: 50%;
        margin-right: 1rem;
        opacity: 0;
        transition: all 0.25s ease;
        flex-shrink: 0;
        transform: scale(0);
    }
    
    .nav-menu a:hover::before,
    .nav-menu a:active::before,
    .nav-menu a.active::before {
        opacity: 1;
        transform: scale(1);
        background: #4CAF50;
    }
    
    /* Active menu item indicator */
    .nav-menu a.active {
        background: linear-gradient(90deg, rgba(76, 175, 80, 0.2) 0%, rgba(76, 175, 80, 0.1) 100%);
        color: #2e7d32;
        border-left: 4px solid #4CAF50;
        padding-left: calc(1.5rem - 4px);
        font-weight: 600;
    }
    
    .nav-menu a.active::before {
        opacity: 1;
        transform: scale(1);
        background: #4CAF50;
    }
    
    /* Close button in menu - Modern Design */
    .nav-menu-close {
        position: absolute;
        top: 1rem;
        right: 1rem;
        background: rgba(255, 255, 255, 0.35);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border: 2px solid rgba(255, 255, 255, 0.5);
        font-size: 1.4rem;
        color: #ffffff;
        cursor: pointer;
        padding: 0;
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 10000;
        border-radius: 50%;
        transition: all 0.2s ease;
        -webkit-tap-highlight-color: transparent;
        box-shadow: 0 3px 12px rgba(0,0,0,0.25);
        font-weight: bold;
        line-height: 1;
    }
    
    .nav-menu-close:hover,
    .nav-menu-close:active {
        background: rgba(255, 255, 255, 0.55);
        transform: scale(1.1) rotate(90deg);
        box-shadow: 0 5px 18px rgba(0,0,0,0.35);
        border-color: rgba(255, 255, 255, 0.7);
    }
    
    /* Menu divider for logout/login */
    .nav-menu li.divider {
        height: 1px;
        background: var(--light-color);
        margin: 0.5rem 0;
        padding: 0;
        border: none;
    }
    
    /* Special styling for logout/login items */
    .nav-menu li:last-child a,
    .nav-menu li.logout-item a {
        color: #d32f2f;
        font-weight: 600;
    }
    
    .nav-menu li:last-child a:hover,
    .nav-menu li.logout-item a:hover {
        background: linear-gradient(90deg, rgba(244, 67, 54, 0.15) 0%, rgba(244, 67, 54, 0.08) 100%);
        color: #c62828;
        border-left-color: #d32f2f;
    }
    
    /* Divider styling */
    .nav-menu li.divider {
        height: 1px;
        background: #e0e0e0;
        margin: 0.75rem 1.5rem;
        padding: 0;
        border: none;
        list-style: none;
    }
    
    /* 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;
    }
}
