/* ============================================================================
   MOBILE ENHANCEMENTS - Ma Nox Atlantik Booking System
   Modern mobile UX improvements
   Version: 2025-01-11-v32
   ============================================================================ */

/* ============================================================================
   PERFORMANCE OPTIMIZATIONS
   ============================================================================ */

/* Enable GPU acceleration for animations */
.mobile-overlay,
.modal-content,
.btn,
.nav-item {
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Sidebar uses its own transform for slide animation - don't override */
.sidebar {
    backface-visibility: hidden;
    /* will-change and transform are managed by mobile-optimized.css */
}

/* Smooth scrolling with momentum */
.modal-body,
.table-container,
.sidebar,
.tabs {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* ============================================================================
   ENHANCED TOUCH INTERACTIONS
   ============================================================================ */

/* All interactive elements should be at least 44x44px */
button,
.btn,
a,
.nav-item,
.tab-button {
    min-height: 44px;
    min-width: 44px;
}

/* Checkboxes and radio buttons: ensure touch-friendly without making them huge */
input[type="checkbox"],
input[type="radio"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    /* Touch target will be handled by padding on parent label */
}

/* Better pressed state feedback */
.btn:active,
.nav-item:active,
button:active {
    transform: scale(0.97);
    opacity: 0.9;
    transition: transform 0.1s ease;
}

/* Ripple effect container */
.ripple-container {
    position: relative;
    overflow: hidden;
}

.ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: scale(0);
    animation: ripple-animation 0.6s ease-out;
    pointer-events: none;
}

@keyframes ripple-animation {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* ============================================================================
   LOADING STATES & SKELETONS
   ============================================================================ */

/* Skeleton loader for content */
.skeleton {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 8px;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

.skeleton-text {
    height: 16px;
    margin-bottom: 8px;
    border-radius: 4px;
}

.skeleton-title {
    height: 24px;
    width: 60%;
    margin-bottom: 12px;
    border-radius: 6px;
}

.skeleton-card {
    height: 120px;
    margin-bottom: 16px;
    border-radius: 12px;
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spinner-rotation 0.6s linear infinite;
}

@keyframes spinner-rotation {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================================================
   PULL TO REFRESH INDICATOR
   ============================================================================ */

.pull-to-refresh-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    pointer-events: none;
    opacity: 0;
    transform: translateY(-60px);
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.pull-to-refresh-indicator .ptr-content {
    display: flex;
    align-items: center;
    gap: 10px;
    background: white;
    padding: 10px 20px;
    border-radius: 30px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.pull-to-refresh-indicator .ptr-arrow,
.pull-to-refresh-indicator .ptr-spinner {
    color: #667eea;
    transition: transform 0.2s ease;
}

.pull-to-refresh-indicator .ptr-spinner {
    display: none;
}

.pull-to-refresh-indicator .ptr-text {
    font-size: 13px;
    font-weight: 500;
    color: #555;
    white-space: nowrap;
}

/* Pulling state */
.pull-to-refresh-indicator.ptr-pulling {
    pointer-events: auto;
}

/* Ready to release state */
.pull-to-refresh-indicator.ptr-ready .ptr-arrow {
    color: #10b981;
}

.pull-to-refresh-indicator.ptr-ready .ptr-text {
    color: #10b981;
}

/* Refreshing state */
.pull-to-refresh-indicator.ptr-refreshing .ptr-arrow {
    display: none;
}

.pull-to-refresh-indicator.ptr-refreshing .ptr-spinner {
    display: block;
    animation: ptr-spin 1s linear infinite;
}

.pull-to-refresh-indicator.ptr-refreshing .ptr-text {
    color: #667eea;
}

@keyframes ptr-spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .pull-to-refresh-indicator .ptr-content {
        background: #2d2d2d;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    }

    .pull-to-refresh-indicator .ptr-text {
        color: #ccc;
    }

    .pull-to-refresh-indicator.ptr-ready .ptr-text {
        color: #10b981;
    }

    .pull-to-refresh-indicator.ptr-refreshing .ptr-text {
        color: #667eea;
    }
}

/* Standalone PWA specific - account for notch/safe areas */
@media all and (display-mode: standalone) {
    .pull-to-refresh-indicator {
        top: env(safe-area-inset-top, 0);
    }
}

/* ============================================================================
   SWIPE INDICATORS
   ============================================================================ */

.swipeable {
    position: relative;
    touch-action: pan-y;
}

.swipeable::after {
    content: '';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 40px;
    background: linear-gradient(
        to bottom,
        transparent,
        rgba(102, 126, 234, 0.2) 20%,
        rgba(102, 126, 234, 0.4) 50%,
        rgba(102, 126, 234, 0.2) 80%,
        transparent
    );
    border-radius: 2px;
    opacity: 0;
    animation: swipe-hint 2s ease-in-out infinite;
}

@keyframes swipe-hint {
    0%, 100% {
        opacity: 0;
        transform: translateY(-50%) translateX(0);
    }
    50% {
        opacity: 1;
        transform: translateY(-50%) translateX(-8px);
    }
}

/* ============================================================================
   BOTTOM SHEETS
   ============================================================================ */

.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1001;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
}

.bottom-sheet.active {
    transform: translateY(0);
}

.bottom-sheet-handle {
    width: 40px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    margin: 12px auto 8px;
}

.bottom-sheet-content {
    padding: 0 20px 20px;
    overflow-y: auto;
    max-height: calc(90vh - 40px);
}

/* ============================================================================
   FLOATING ACTION BUTTON (FAB)
   ============================================================================ */

.fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.fab:active {
    transform: scale(0.95);
}

.fab svg {
    width: 24px;
    height: 24px;
}

/* FAB with extended label */
.fab-extended {
    width: auto;
    padding: 0 24px;
    border-radius: 28px;
    gap: 8px;
}

.fab-extended span {
    font-size: 14px;
    font-weight: 600;
}

/* ============================================================================
   TOAST NOTIFICATIONS
   ============================================================================ */

.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #1f2937;
    color: white;
    padding: 14px 20px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 1002;
    min-width: 280px;
    max-width: calc(100% - 48px);
    display: flex;
    align-items: center;
    gap: 12px;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toast.active {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast-success {
    background: #10b981;
}

.toast-error {
    background: #ef4444;
}

.toast-warning {
    background: #f59e0b;
}

.toast-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* ============================================================================
   IMPROVED MODALS
   ============================================================================ */

@media (max-width: 768px) {
    /* Slide up animation for modals */
    .modal-content {
        animation: slide-up 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    @keyframes slide-up {
        from {
            transform: translateY(100%);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }

    /* Backdrop blur effect */
    .modal {
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }

    /* Better modal header with drag handle */
    .modal-header::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 2px;
    }
}

/* ============================================================================
   CARD HOVER EFFECTS (FOR TOUCH)
   ============================================================================ */

.card-interactive {
    transition: all 0.2s ease;
}

.card-interactive:active {
    transform: scale(0.98);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ============================================================================
   SAFE AREA INSETS (FOR NOTCH DEVICES)
   ============================================================================ */

@supports (padding: env(safe-area-inset-bottom)) {
    .main-content {
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }

    .modal-footer,
    .bottom-sheet,
    .fab {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .bulk-actions-bar {
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }
}

/* ============================================================================
   ACCESSIBILITY ENHANCEMENTS
   ============================================================================ */

/* Better focus indicators for keyboard navigation */
*:focus-visible {
    outline: 3px solid #667eea;
    outline-offset: 2px;
    border-radius: 4px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn,
    .card,
    .modal-content {
        border: 2px solid currentColor;
    }
}

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

/* ============================================================================
   IMPROVED FORM INPUTS
   ============================================================================ */

@media (max-width: 768px) {
    /* Better input styling */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="date"],
    input[type="time"],
    select,
    textarea {
        -webkit-appearance: none;
        appearance: none;
        border-radius: 12px;
        font-size: 16px !important; /* Prevents iOS zoom */
    }

    /* Input focus with icon animation */
    .form-group {
        position: relative;
    }

    .form-group input:focus + .input-icon {
        color: #667eea;
        transform: scale(1.1);
        transition: all 0.2s ease;
    }

    /* Floating label effect */
    .form-group.floating-label {
        position: relative;
        margin-top: 24px;
    }

    .form-group.floating-label label {
        position: absolute;
        top: 14px;
        left: 16px;
        background: white;
        padding: 0 4px;
        font-size: 16px;
        color: #6b7280;
        transition: all 0.2s ease;
        pointer-events: none;
    }

    .form-group.floating-label input:focus + label,
    .form-group.floating-label input:not(:placeholder-shown) + label {
        top: -10px;
        font-size: 12px;
        color: #667eea;
        font-weight: 600;
    }
}

/* ============================================================================
   SMOOTH PAGE TRANSITIONS
   ============================================================================ */

.page-transition-enter {
    opacity: 0;
    transform: translateX(20px);
}

.page-transition-enter-active {
    opacity: 1;
    transform: translateX(0);
    transition: all 0.3s ease;
}

.page-transition-exit {
    opacity: 1;
    transform: translateX(0);
}

.page-transition-exit-active {
    opacity: 0;
    transform: translateX(-20px);
    transition: all 0.3s ease;
}

/* ============================================================================
   IMPROVED TABLE CARDS
   ============================================================================ */

@media (max-width: 768px) {
    .data-table.mobile-cards tr {
        position: relative;
        overflow: hidden;
    }

    /* Add subtle gradient background */
    .data-table.mobile-cards tr::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 4px;
        background: linear-gradient(90deg, #667eea, #764ba2);
        opacity: 0;
        transition: opacity 0.2s ease;
    }

    .data-table.mobile-cards tr:active::before {
        opacity: 1;
    }
}

/* ============================================================================
   STATUS BADGES WITH ANIMATIONS
   ============================================================================ */

.badge {
    position: relative;
    overflow: hidden;
}

.badge::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.3s ease, height 0.3s ease;
}

.badge:active::before {
    width: 200px;
    height: 200px;
}

/* Pulsing badge for important statuses */
.badge-pulse {
    animation: badge-pulse 2s ease-in-out infinite;
}

@keyframes badge-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
    }
}

/* ============================================================================
   EMPTY STATES
   ============================================================================ */

.empty-state {
    text-align: center;
    padding: 48px 24px;
}

.empty-state-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 16px;
    opacity: 0.3;
}

.empty-state-title {
    font-size: 20px;
    font-weight: 700;
    color: #1f2937;
    margin-bottom: 8px;
}

.empty-state-description {
    font-size: 14px;
    color: #6b7280;
    margin-bottom: 24px;
    line-height: 1.5;
}

.empty-state .btn {
    margin-top: 8px;
}

/* QR Scanner Page - Action buttons override */
.todays-bookings-section .action-buttons .btn,
.todays-bookings-section .action-buttons .btn-icon,
.todays-bookings-section .action-buttons button {
    min-height: 32px !important;
    min-width: 32px !important;
}

/* ============================================================================
   DARK MODE SUPPORT
   ============================================================================ */

@media (prefers-color-scheme: dark) {
    /* This is prepared for future dark mode implementation */
    .card,
    .modal-content,
    .content-section {
        /* Will be implemented when dark mode is added */
        /* background: #1f2937; */
        /* color: #f9fafb; */
    }
}

/* ============================================================================
   UTILITY CLASSES
   ============================================================================ */

.tap-highlight-none {
    -webkit-tap-highlight-color: transparent;
}

.no-select {
    user-select: none;
    -webkit-user-select: none;
}

.smooth-scroll {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.backdrop-blur {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* ============================================================================
   MFA SECTION - COMPACT LAYOUT (ALL SCREEN SIZES)
   ============================================================================ */

/* MFA Settings Content - add padding to match other sections */
#mfaSettingsContent {
    padding: 0 1.5rem 1.5rem 1.5rem !important;
}

/* Make MFA enabled state more compact */
#mfaEnabledState > div:first-child {
    padding: 1rem !important;
    margin-bottom: 1rem !important;
}

/* Reduce gap in MFA enabled state flex container */
#mfaEnabledState > div:first-child > div[style*="display: flex"] {
    gap: 0.75rem !important;
}

/* Make backup codes section more compact */
#mfaEnabledState div[style*="margin-top: 0.75rem"] {
    margin-top: 0.5rem !important;
    padding: 0.5rem !important;
}

/* Move buttons to the right - target the button container directly */
#mfaEnabledState > div:last-child {
    display: flex !important;
    justify-content: flex-end !important;
    gap: 0.75rem !important;
    margin-bottom: 0 !important;
}

/* Make MFA disabled state more compact */
#mfaDisabledState > div {
    padding: 1rem !important;
    gap: 1.5rem !important;
}

/* ============================================================================
   INVOICE MODAL - BUTTON ALIGNMENT (ALL SCREEN SIZES)
   ============================================================================ */

/* Move invoice modal action buttons to the right */
#invoiceModal .modal-actions {
    display: flex !important;
    justify-content: flex-end !important;
    gap: 0.75rem !important;
}


/* ============================================================================
   PAGE-SPECIFIC MOBILE RESPONSIVENESS FIXES
   ============================================================================ */

@media (max-width: 768px) {
    /* ============================================================================
       INVOICES PAGE
       ============================================================================ */

    /* Filter and action rows - stack on mobile */
    #invoices .modern-content-card > div[style*="display: flex"] {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    /* Filter grid - Status and Payment Status side by side, Search full width */
    #invoices div[style*="grid-template-columns: repeat(3"] {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.75rem !important;
    }

    /* Search field takes full width on second row */
    #invoices div[style*="grid-template-columns: repeat(3"] > .form-group:nth-child(3) {
        grid-column: 1 / -1 !important;
    }

    /* Action buttons - side by side on mobile */
    #invoices .form-group[style*="display: flex"] {
        flex-direction: row !important;
        margin-top: 0.75rem !important;
        gap: 0.5rem !important;
    }

    #invoices .form-group[style*="display: flex"] button {
        flex: 1 !important;
        justify-content: center;
        font-size: 0.875rem !important;
        padding: 0.625rem 0.5rem !important;
        white-space: nowrap !important;
    }

    /* Statistics cards - better mobile layout */
    #invoices div[style*="grid-template-columns: repeat(auto-fit"] {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    /* Stat card adjustments */
    #invoices div[style*="border-top: 4px solid"] {
        padding: 1.25rem !important;
    }

    #invoices div[style*="border-top: 4px solid"] > div {
        gap: 0.75rem !important;
    }

    /* Icon size in stat cards */
    #invoices div[style*="width: 64px; height: 64px"] {
        width: 48px !important;
        height: 48px !important;
    }

    #invoices div[style*="width: 64px; height: 64px"] svg {
        width: 24px !important;
        height: 24px !important;
    }

    /* Font sizes in stat cards */
    #invoices div[style*="font-size: 2rem"] {
        font-size: 1.5rem !important;
    }

    /* Pagination - stack on mobile */
    #invoices .email-logs-pagination {
        flex-direction: column !important;
        gap: 0.75rem !important;
        align-items: center !important;
    }

    /* ============================================================================
       SUPPORT TICKETS PAGE
       ============================================================================ */

    /* Filter grid - two columns on mobile */
    #support-tickets div[style*="grid-template-columns: repeat(4"] {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.75rem !important;
    }

    /* Action buttons row */
    #support-tickets div[style*="display: flex"][style*="align-items: end"] {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    /* Action buttons - side by side on mobile */
    #support-tickets .form-group[style*="gap: 0.75rem"] {
        flex-direction: row !important;
        margin-top: 0.75rem !important;
        gap: 0.5rem !important;
    }

    #support-tickets .form-group[style*="gap: 0.75rem"] button {
        flex: 1 !important;
        justify-content: center;
        font-size: 0.875rem !important;
        padding: 0.625rem 0.5rem !important;
        white-space: nowrap !important;
    }

    /* New Ticket Modal improvements */
    #newTicketModal .modal-content {
        width: 95% !important;
        max-width: 95% !important;
        margin: 2rem auto !important;
    }

    /* Two column grid to single column */
    #newTicketModal div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    /* Drop zone - smaller on mobile */
    #newTicketModal #dropZone {
        padding: 1.5rem !important;
    }

    #newTicketModal #dropZone svg {
        width: 36px !important;
        height: 36px !important;
    }

    /* Form actions - full width buttons */
    #newTicketModal .form-actions,
    #ticketDetailModal .form-actions {
        flex-direction: column-reverse !important;
    }

    #newTicketModal .form-actions button,
    #ticketDetailModal .form-actions button {
        width: 100% !important;
    }

    /* Ticket info grid */
    #ticketDetailModal .ticket-info-grid {
        grid-template-columns: 1fr !important;
    }

    /* ============================================================================
       PRICING RULES PAGE
       ============================================================================ */

    /* Pricing card headers */
    #pricing-rules .pricing-card-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }

    #pricing-rules .pricing-card-header button {
        width: 100% !important;
    }

    /* Pricing Rule Modal */
    #pricingRuleModal .modal-content {
        width: 95% !important;
        max-width: 95% !important;
        margin: 2rem auto !important;
    }

    /* Grid layouts to single column */
    #pricingRuleModal div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Tour selection list */
    #pricingRuleModal #pricingRuleToursList {
        max-height: 150px !important;
    }

    /* Modal actions */
    #pricingRuleModal div[style*="justify-content: flex-end"] {
        flex-direction: column-reverse !important;
    }

    #pricingRuleModal div[style*="justify-content: flex-end"] button {
        width: 100% !important;
    }

    /* ============================================================================
       TOUR/SERVICE MODAL (Edit Service)
       ============================================================================ */

    #tourModal .modal-content {
        width: 95% !important;
        max-width: 95% !important;
        margin: 1rem auto !important;
    }

    /* Tour tabs - enable scrolling */
    #tourModal .tour-tabs {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap !important;
    }

    #tourModal .tour-tab {
        padding: 0.75rem 1rem !important;
        font-size: 0.85rem !important;
        white-space: nowrap;
        min-width: auto !important;
    }

    #tourModal .tour-tab svg {
        width: 14px !important;
        height: 14px !important;
    }

    /* Form grids - strategic responsive layout */
    /* Name + Category: single column */
    #tourModal .form-grid[style*="grid-template-columns: 2fr 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }

    /* Duration + Location: single column */
    #tourModal .form-grid[style*="grid-template-columns: 1fr 2fr"] {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }

    /* Prices (Adult, Child, Senior): Adult+Child side by side, Senior full width */
    #tourModal .form-grid[style*="grid-template-columns: repeat(3, 1fr)"] {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.75rem !important;
    }

    #tourModal .form-grid[style*="grid-template-columns: repeat(3, 1fr)"] > .form-group:nth-child(3) {
        grid-column: 1 / -1 !important;
    }

    /* Participants + Difficulty + Status: keep pairs together - MORE SPECIFIC SELECTOR */
    #tourModal .form-grid[style*="1fr 1fr 1fr 1fr"] {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.75rem !important;
    }

    /* Generic 2-column grids - exclude the 4-column grid */
    #tourModal .form-grid[style*="grid-template-columns: 1fr 1fr"]:not([style*="1fr 1fr 1fr 1fr"]) {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }

    /* Keep checkboxes side-by-side on Public Website tab */
    #tourTabWebsite .form-grid[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr 1fr !important;
    }

    /* Remove padding overrides on mobile */
    #tourModal .form-group[style*="padding-right"],
    #tourModal .form-group[style*="padding-left"] {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    /* Map container - smaller on mobile */
    #tourModal #tourMapContainer {
        height: 350px !important;
    }

    #tourModal #mapControls button {
        font-size: 0.8rem !important;
        padding: 0.375rem 0.625rem !important;
    }

    /* Provider assignment section */
    #tourModal div[style*="display: flex; gap: 0.75rem; align-items: flex-end"] {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    #tourModal div[style*="display: flex; gap: 0.75rem; align-items: flex-end"] > div:first-child {
        width: 100% !important;
    }

    #tourModal div[style*="display: flex; gap: 0.75rem; align-items: flex-end"] button {
        width: 100% !important;
    }

    /* Image upload area */
    #tourModal #tourImageUploadArea {
        padding: 1.5rem !important;
    }

    #tourModal #tourImageUploadArea svg {
        width: 36px !important;
        height: 36px !important;
    }

    /* Image gallery - 2 columns on mobile */
    #tourModal #tourImageGallery {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem !important;
    }

    /* Website settings grid in modal */
    #tourModal div[style*="display: grid"][style*="gap: 0"] {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }

    #tourModal div[style*="padding-right: 0.75rem"],
    #tourModal div[style*="padding-left: 0.75rem"] {
        padding: 0 !important;
    }

    /* Form actions - keep Cancel and Save side-by-side */
    #tourModal div[style*="text-align: right"][style*="justify-content: flex-end"] {
        flex-direction: row !important;
        gap: 0.5rem !important;
    }

    #tourModal div[style*="text-align: right"][style*="justify-content: flex-end"] button {
        flex: 1 !important;
        font-size: 0.875rem !important;
        padding: 0.625rem 0.5rem !important;
    }

    /* ============================================================================
       INVOICE MODAL (Add Invoice)
       ============================================================================ */

    #invoiceModal .modal-content {
        width: 95% !important;
        max-width: 95% !important;
        margin: 1rem auto !important;
    }

    /* All form grids to single column EXCEPT Invoice Information section */
    #invoiceModal .form-grid:not(.form-grid-2) {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }

    /* Invoice Information section - stack all fields vertically on mobile */
    #invoiceModal .invoice-mobile-stack {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.6rem !important;
    }

    /* First stack - no top margin */
    #invoiceModal .invoice-mobile-stack:first-of-type {
        margin-top: 0 !important;
    }

    /* Second stack - reduce margin significantly */
    #invoiceModal .invoice-mobile-stack[style*="margin-top"] {
        margin-top: 0.35rem !important;
    }

    /* Reset grid items to full width for proper stacking */
    #invoiceModal .invoice-mobile-stack > .form-group {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
    }

    /* Specifically target the customer field to add negative bottom margin */
    #invoiceModal .invoice-mobile-stack:first-of-type > .invoice-customer-field {
        margin-bottom: -0.65rem !important;
    }

    /* Line items - stack vertically */
    #invoiceModal .form-grid[style*="grid-template-columns: 2fr 1fr 1fr 1fr auto"] {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }

    /* Line item fields */
    #invoiceModal .line-item-row .form-group {
        margin-bottom: 0.75rem !important;
    }

    /* Remove button in line items */
    #invoiceModal .line-item-row > div > div:last-child {
        padding-top: 0 !important;
    }

    #invoiceModal .line-item-row button {
        width: 100% !important;
        margin-top: 0.5rem;
    }

    /* Form sections - adjust padding */
    #invoiceModal .form-section {
        padding: 1.25rem !important;
        margin-bottom: 1rem !important;
    }

    /* Dates section - uniform padding all around */
    #invoiceModal .form-section:nth-of-type(2) {
        padding: 1.25rem 1.25rem !important;
    }

    /* Title row - no extra padding needed */
    #invoiceModal .form-section:nth-of-type(2) > div:first-child {
        margin-bottom: 1rem !important;
    }

    /* Dates grid - perfectly centered */
    #invoiceModal .form-section:nth-of-type(2) > div:last-child {
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Customer field - arrange as: Label on top, Button + Dropdown side-by-side */
    #invoiceModal .invoice-customer-field {
        display: grid !important;
        grid-template-columns: 70px 1fr !important;
        grid-template-rows: auto auto !important;
        gap: 0.5rem 0.5rem !important;
        row-gap: 0.1rem !important;
        position: relative !important;
        margin-bottom: 0 !important;
        padding-bottom: 0 !important;
    }

    #invoiceModal .invoice-customer-field label {
        display: block !important;
        position: static !important;
        grid-column: 1 / -1 !important;
        grid-row: 1 !important;
        margin-bottom: 0 !important;
        padding-bottom: 0 !important;
        width: 100% !important;
        line-height: 1 !important;
        font-size: 0.8rem !important;
    }

    /* New button - make it smaller */
    #invoiceModal .invoice-customer-field button {
        position: static !important;
        top: auto !important;
        right: auto !important;
        grid-column: 1 !important;
        grid-row: 2 !important;
        width: 100% !important;
        height: 34px !important;
        padding: 0.375rem 0.25rem !important;
        font-size: 0.7rem !important;
        margin: 0 !important;
    }

    /* Customer dropdown */
    #invoiceModal .invoice-customer-field select {
        grid-column: 2 !important;
        grid-row: 2 !important;
        width: 100% !important;
        margin: 0 !important;
        padding-top: 0.375rem !important;
        padding-bottom: 0.375rem !important;
        height: 34px !important;
        font-size: 0.875rem !important;
    }

    /* Invoice Date and Due Date - keep side-by-side on mobile */
    #invoiceModal .invoice-dates-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 0.5rem !important;
        width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        box-sizing: border-box !important;
    }

    #invoiceModal .invoice-dates-grid > .form-group {
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        box-sizing: border-box !important;
    }

    #invoiceModal .invoice-dates-grid input {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    #invoiceModal .invoice-dates-grid label {
        display: block !important;
        margin-bottom: 0.5rem !important;
    }

    /* Summary section - more compact */
    #invoiceModal div[style*="background: rgba(255, 255, 255, 0.15)"] {
        padding: 1.25rem !important;
    }

    /* Modal actions - keep Cancel and Create Invoice side-by-side */
    #invoiceModal .modal-actions {
        flex-direction: row !important;
        gap: 0.5rem !important;
    }

    #invoiceModal .modal-actions button {
        flex: 1 !important;
        font-size: 0.875rem !important;
        padding: 0.625rem 0.5rem !important;
    }

    /* Icons in section headers - slightly smaller */
    #invoiceModal .form-section svg {
        width: 20px !important;
        height: 20px !important;
    }

    /* Section headings */
    #invoiceModal .form-section h4 {
        font-size: 1rem !important;
    }

    /* Line Items "Add Item" button - make it more compact on mobile */
    #invoiceModal button[onclick*="addLineItem"] {
        padding: 0.4rem 0.5rem !important;
        font-size: 0.7rem !important;
        gap: 0.2rem !important;
        white-space: nowrap !important;
        min-width: auto !important;
        max-width: 90px !important;
        height: auto !important;
        line-height: 1.2 !important;
    }

    #invoiceModal button[onclick*="addLineItem"] svg {
        width: 11px !important;
        height: 11px !important;
        flex-shrink: 0 !important;
    }

    #invoiceModal button[onclick*="addLineItem"] span {
        font-size: 0.7rem !important;
        line-height: 1.2 !important;
    }

    /* Ensure the header container allows button to shrink */
    #invoiceModal div[style*="justify-content: space-between"] button {
        flex-shrink: 1 !important;
    }

    /* ============================================================================
       WAYPOINT MODAL
       ============================================================================ */

    #waypointModal .modal-content {
        width: 95% !important;
        max-width: 95% !important;
    }

    #waypointModal div[style*="justify-content: flex-end"] {
        flex-direction: column-reverse !important;
        align-items: stretch !important;
    }

    #waypointModal div[style*="justify-content: flex-end"] button {
        width: 100% !important;
        margin: 0 !important;
    }

    #waypointModal button[style*="margin-right: auto"] {
        order: 3 !important;
        margin-top: 0.5rem !important;
    }

    /* ============================================================================
       MFA SECTION - COMPACT LAYOUT
       ============================================================================ */

    /* Make MFA enabled state more compact */
    #mfaEnabledState > div:first-child {
        padding: 1rem !important;
        margin-bottom: 1rem !important;
    }

    /* Reduce gap in MFA enabled state flex container */
    #mfaEnabledState > div:first-child > div[style*="display: flex"] {
        gap: 0.75rem !important;
    }

    /* Make backup codes section more compact */
    #mfaEnabledState div[style*="margin-top: 0.75rem"] {
        margin-top: 0.5rem !important;
        padding: 0.5rem !important;
    }

    /* Move buttons to the right - target the button container directly */
    #mfaEnabledState > div:last-child {
        justify-content: flex-end !important;
    }

    /* Make MFA disabled state more compact */
    #mfaDisabledState > div {
        padding: 1rem !important;
        gap: 1.5rem !important;
    }
}
