/**
 * Tour Scheduler Modal Improvements
 * Enhanced styling for better mobile responsiveness and compact desktop layout
 * 
 * @package Hampstead_Academy
 * @since 1.0.0
 */

/* ===== MODAL HEADER IMPROVEMENTS ===== */
/* Fix headline color to white on blue background */
#tour-scheduler-modal .ha-modal-header {
    background: linear-gradient(135deg, var(--wp--preset--color--primary-blue, #07074E) 0%, var(--wp--preset--color--secondary-blue, #3984AD) 100%) !important;
    color: var(--wp--preset--color--white, #ffffff) !important;
    padding: 1rem 2rem 0.75rem !important; /* Further reduced top padding */
    border-bottom: none !important;
    border-radius: 12px 12px 0 0 !important;
}

#tour-scheduler-modal .ha-modal-title {
    color: var(--wp--preset--color--white, #ffffff) !important;
    font-size: 1.5rem !important;
    font-weight: 600 !important;
    margin: 0 !important;
    padding-right: 3rem !important;
}

#tour-scheduler-modal .ha-modal-close {
    color: var(--wp--preset--color--white, #ffffff) !important;
    top: 0.75rem !important; /* Further reduced top position */
    right: 1.5rem !important;
}

#tour-scheduler-modal .ha-modal-close:hover {
    background: rgba(255, 255, 255, 0.2) !important;
    color: var(--wp--preset--color--white, #ffffff) !important;
}

/* ===== COMPACT MODAL LAYOUT ===== */
/* Reduce excessive padding/margin at top of modal */
#tour-scheduler-modal .ha-modal {
    max-width: 1000px !important; /* Increased width for better desktop layout */
    max-height: 95vh !important; /* Increased height utilization */
}

#tour-scheduler-modal .ha-modal-body {
    padding: 1rem 2rem 2rem !important; /* Further reduced top padding */
    max-height: calc(95vh - 100px) !important; /* Adjusted for smaller header */
}

/* ===== IMPROVED DESKTOP LAYOUT ===== */
/* Desktop: Calendar and times side-by-side, form below times */
@media (min-width: 769px) {
    #tour-scheduler-modal .ha-tour-scheduler-container {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 2rem !important;
        margin-bottom: 1.5rem !important;
    }
    
    /* Right column: Times section with form below */
    #tour-scheduler-modal .ha-tour-times-section {
        display: flex !important;
        flex-direction: column !important;
        height: fit-content !important;
    }
    
    /* Form positioned below available times in right column */
    #tour-scheduler-modal .ha-tour-form-section {
        margin-top: 1rem !important;
        margin-bottom: 0 !important;
        background: var(--wp--preset--color--light-gray, #f8f9fa) !important;
        border: 1px solid rgba(57, 132, 173, 0.1) !important;
        border-radius: 8px !important;
        padding: 1.5rem !important;
    }
    
    #tour-scheduler-modal .ha-tour-form-section h3 {
        font-size: 1.125rem !important;
        margin-bottom: 1rem !important;
        text-align: left !important;
    }
    
    /* Compact form layout */
    #tour-scheduler-modal .ha-form-row {
        margin-bottom: 1rem !important;
    }
    
    #tour-scheduler-modal .ha-form-group {
        margin-bottom: 1rem !important;
    }
    
    #tour-scheduler-modal .ha-form-group:last-child {
        margin-bottom: 0 !important;
    }
    
    /* Selected time display - more compact */
    #tour-scheduler-modal .ha-selected-time-display {
        padding: 0.75rem 1rem !important;
        margin-bottom: 1rem !important;
        font-size: 0.9rem !important;
    }
    
    #tour-scheduler-modal .ha-selected-time-display h4 {
        font-size: 1rem !important;
        margin-bottom: 0.25rem !important;
    }
    
    /* Form actions - horizontal layout */
    #tour-scheduler-modal .ha-form-actions {
        display: flex !important;
        gap: 0.75rem !important;
        justify-content: flex-start !important;
        margin-top: 1rem !important;
    }
    
    #tour-scheduler-modal .ha-button {
        padding: 0.75rem 1.5rem !important;
        font-size: 0.9rem !important;
    }
}

/* ===== IMPROVED MOBILE RESPONSIVENESS ===== */
@media (max-width: 768px) {
    /* Mobile: Stack everything vertically - maximize screen usage */
    #tour-scheduler-modal .ha-modal {
        max-width: 98vw !important;
        max-height: 95vh !important;
        margin: 1vw !important;
        width: 98vw !important;
    }
    
    #tour-scheduler-modal .ha-modal-header {
        padding: 0.75rem 1rem 0.5rem !important;
    }
    
    #tour-scheduler-modal .ha-modal-title {
        font-size: 1.25rem !important;
        padding-right: 2.5rem !important;
    }
    
    #tour-scheduler-modal .ha-modal-close {
        top: 0.75rem !important;
        right: 1rem !important;
        width: 35px !important;
        height: 35px !important;
        font-size: 1.25rem !important;
    }
    
    #tour-scheduler-modal .ha-modal-body {
        padding: 0.75rem !important;
        max-height: calc(95vh - 80px) !important;
        overflow-y: auto !important;
        width: 100% !important;
    }
    
    #tour-scheduler-modal .ha-tour-scheduler-container {
        grid-template-columns: 1fr;
        gap: 1.5rem;
        margin-bottom: 1rem;
    }
    
    /* Calendar section improvements for mobile - full width */
    #tour-scheduler-modal .ha-tour-calendar-section,
    #tour-scheduler-modal .ha-tour-times-section {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }
    
    #tour-scheduler-modal .ha-tour-calendar-section h3,
    #tour-scheduler-modal .ha-tour-times-section h3 {
        font-size: 1.125rem;
        padding: 0.75rem 0.5rem;
        margin: 0 0 0.5rem 0;
    }
    
    /* Better mobile calendar display - full width */
    #tour-scheduler-modal .ha-calendar-grid {
        padding: 0.5rem;
        margin: 0;
        width: 100%;
    }
    
    #tour-scheduler-modal .ha-calendar-weekdays {
        gap: 2px;
    }
    
    #tour-scheduler-modal .ha-calendar-days {
        gap: 2px;
    }
    
    #tour-scheduler-modal .ha-calendar-weekday {
        padding: 0.5rem 0.25rem;
        font-size: 0.75rem;
    }
    
    #tour-scheduler-modal .ha-calendar-day {
        padding: 0.5rem 0.25rem;
        min-height: 40px;
        font-size: 0.875rem;
    }
    
    /* Improved mobile calendar navigation - full width */
    #tour-scheduler-modal .ha-calendar-header {
        padding: 0.75rem 0.5rem;
        margin: 0;
        width: 100%;
    }
    
    #tour-scheduler-modal .ha-calendar-nav {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }
    
    #tour-scheduler-modal .ha-calendar-month-year {
        font-size: 1rem;
    }
    
    /* Mobile legend - more compact */
    #tour-scheduler-modal .ha-calendar-legend {
        padding: 0.75rem 1rem;
        gap: 1rem;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    #tour-scheduler-modal .ha-legend-item {
        font-size: 0.8rem;
    }
    
    #tour-scheduler-modal .ha-legend-color {
        width: 14px;
        height: 14px;
    }
    
    /* Mobile time slots - better grid, full width */
    #tour-scheduler-modal .ha-tour-times {
        padding: 0.5rem;
        margin: 0;
        width: 100%;
    }
    
    #tour-scheduler-modal .ha-times-grid {
        grid-template-columns: repeat(3, 1fr); /* Show 3 columns instead of 2 */
        gap: 0.5rem;
    }
    
    #tour-scheduler-modal .ha-time-slot {
        padding: 0.625rem 0.5rem;
        font-size: 0.8rem;
        min-height: 44px; /* Touch-friendly size */
    }
    
    /* Mobile form improvements */
    #tour-scheduler-modal .ha-tour-form-section {
        padding: 1rem;
        margin-top: 1rem;
    }
    
    #tour-scheduler-modal .ha-tour-form-section h3 {
        font-size: 1rem;
        margin-bottom: 1rem;
        padding: 0;
    }
    
    #tour-scheduler-modal .ha-form-row {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    #tour-scheduler-modal .ha-form-actions {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    #tour-scheduler-modal .ha-button {
        width: 100%;
        padding: 0.875rem;
        font-size: 1rem;
    }
}

/* ===== EXTRA SMALL MOBILE SCREENS ===== */
@media (max-width: 480px) {
    #tour-scheduler-modal .ha-modal {
        max-width: 98vw;
        margin: 0.5rem;
    }
    
    #tour-scheduler-modal .ha-modal-body {
        padding: 0.75rem;
    }
    
    /* Show all 7 days but smaller */
    #tour-scheduler-modal .ha-calendar-weekday {
        padding: 0.375rem 0.125rem;
        font-size: 0.65rem;
    }
    
    #tour-scheduler-modal .ha-calendar-day {
        padding: 0.375rem 0.125rem;
        min-height: 35px;
        font-size: 0.75rem;
    }
    
    /* Time slots - 2 columns for very small screens */
    #tour-scheduler-modal .ha-times-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    #tour-scheduler-modal .ha-time-slot {
        padding: 0.5rem 0.25rem;
        font-size: 0.75rem;
        min-height: 40px;
    }
    
    /* Compact legend for small screens */
    #tour-scheduler-modal .ha-calendar-legend {
        padding: 0.5rem;
        gap: 0.75rem;
    }
    
    #tour-scheduler-modal .ha-legend-item {
        font-size: 0.7rem;
    }
    
    #tour-scheduler-modal .ha-legend-color {
        width: 12px;
        height: 12px;
    }
}

/* ===== CALENDAR HORIZONTAL SCROLL FIX ===== */
/* Ensure calendar doesn't overflow horizontally on mobile */
#tour-scheduler-modal .ha-calendar-weekdays,
#tour-scheduler-modal .ha-calendar-days {
    min-width: 0; /* Allow grid to shrink */
    overflow: hidden;
}

#tour-scheduler-modal .ha-calendar-grid {
    overflow-x: auto;
    overflow-y: visible;
}

/* ===== DYNAMICALLY GENERATED CALENDAR ELEMENTS ===== */
/* Target the actual calendar elements that get generated by JavaScript */
#tour-scheduler-modal #ha-tour-calendar {
    width: 100% !important;
    overflow: visible !important;
}

#tour-scheduler-modal #ha-tour-calendar * {
    box-sizing: border-box !important;
}

/* Calendar container */
#tour-scheduler-modal #ha-tour-calendar .calendar-container {
    width: 100% !important;
    overflow: visible !important;
}

/* Calendar header with navigation */
#tour-scheduler-modal #ha-tour-calendar .calendar-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 1rem !important;
    background: var(--wp--preset--color--light-gray, #f8f9fa) !important;
}

/* Calendar navigation buttons */
#tour-scheduler-modal #ha-tour-calendar .calendar-nav-btn {
    background: var(--wp--preset--color--secondary-blue, #3984AD) !important;
    color: white !important;
    border: none !important;
    width: 40px !important;
    height: 40px !important;
    border-radius: 50% !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* Current month/year display */
#tour-scheduler-modal #ha-tour-calendar .current-month {
    font-weight: 600 !important;
    color: var(--wp--preset--color--primary-blue, #07074E) !important;
}

/* Calendar grid - ensure proper alignment */
#tour-scheduler-modal #ha-tour-calendar .calendar-grid {
    width: 100% !important;
    display: grid !important;
    grid-template-columns: repeat(7, 1fr) !important;
    gap: 1px !important;
    background: rgba(57, 132, 173, 0.1) !important;
    border-radius: 8px !important;
    overflow: hidden !important;
}

/* Calendar weekdays container */
#tour-scheduler-modal #ha-tour-calendar .calendar-weekdays,
#tour-scheduler-modal .ha-calendar-weekdays {
    display: grid !important;
    grid-template-columns: repeat(7, 1fr) !important;
    gap: 1px !important;
    background: rgba(57, 132, 173, 0.1) !important;
    border-radius: 8px 8px 0 0 !important;
    overflow: hidden !important;
    width: 100% !important;
}

/* Calendar days container */
#tour-scheduler-modal #ha-tour-calendar .calendar-days,
#tour-scheduler-modal .ha-calendar-days {
    display: grid !important;
    grid-template-columns: repeat(7, 1fr) !important;
    gap: 1px !important;
    background: rgba(57, 132, 173, 0.1) !important;
    border-radius: 0 0 8px 8px !important;
    overflow: hidden !important;
    width: 100% !important;
}

/* Calendar day headers */
#tour-scheduler-modal #ha-tour-calendar .calendar-day-header,
#tour-scheduler-modal .ha-calendar-weekday {
    background: var(--wp--preset--color--primary-blue, #07074E) !important;
    color: white !important;
    padding: 0.75rem 0.5rem !important;
    text-align: center !important;
    font-size: 0.875rem !important;
    font-weight: 600 !important;
    text-transform: uppercase !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-height: 45px !important;
    box-sizing: border-box !important;
}

/* Calendar days */
#tour-scheduler-modal #ha-tour-calendar .calendar-day,
#tour-scheduler-modal .ha-calendar-day {
    background: white !important;
    padding: 0.75rem 0.5rem !important;
    text-align: center !important;
    cursor: pointer !important;
    min-height: 45px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-weight: 500 !important;
    transition: all 0.2s ease !important;
    box-sizing: border-box !important;
}

#tour-scheduler-modal #ha-tour-calendar .calendar-day:hover {
    background: rgba(57, 132, 173, 0.1) !important;
}

#tour-scheduler-modal #ha-tour-calendar .calendar-day.available:hover {
    background: rgba(57, 132, 173, 0.1) !important;
}

#tour-scheduler-modal #ha-tour-calendar .calendar-day.selected {
    background: var(--wp--preset--color--primary-accent, #50A684) !important;
    color: white !important;
    font-weight: 600 !important;
}

#tour-scheduler-modal #ha-tour-calendar .calendar-day.today {
    background: var(--wp--preset--color--accent-yellow, #F4D03F) !important;
    color: var(--wp--preset--color--primary-blue, #07074E) !important;
    font-weight: 600 !important;
}

#tour-scheduler-modal #ha-tour-calendar .calendar-day.past,
#tour-scheduler-modal #ha-tour-calendar .calendar-day.unavailable {
    color: var(--wp--preset--color--medium-gray, #999) !important;
    cursor: not-allowed !important;
    background: var(--wp--preset--color--light-gray, #f8f9fa) !important;
}

/* Mobile calendar adjustments */
@media (max-width: 768px) {
    #tour-scheduler-modal #ha-tour-calendar .calendar-header {
        padding: 0.75rem !important;
    }
    
    #tour-scheduler-modal #ha-tour-calendar .calendar-nav-btn {
        width: 35px !important;
        height: 35px !important;
        font-size: 0.9rem !important;
    }
    
    #tour-scheduler-modal #ha-tour-calendar .current-month {
        font-size: 1rem !important;
    }
    
    #tour-scheduler-modal #ha-tour-calendar .calendar-day-header {
        padding: 0.5rem 0.25rem !important;
        font-size: 0.75rem !important;
    }
    
    #tour-scheduler-modal #ha-tour-calendar .calendar-day {
        padding: 0.5rem 0.25rem !important;
        min-height: 40px !important;
        font-size: 0.875rem !important;
    }
}

@media (max-width: 480px) {
    #tour-scheduler-modal #ha-tour-calendar .calendar-day-header {
        padding: 0.375rem 0.125rem !important;
        font-size: 0.65rem !important;
    }
    
    #tour-scheduler-modal #ha-tour-calendar .calendar-day {
        padding: 0.375rem 0.125rem !important;
        min-height: 35px !important;
        font-size: 0.75rem !important;
    }
}

/* ===== TIME SLOTS IMPROVEMENTS ===== */
/* Target dynamically generated time slots */
#tour-scheduler-modal #ha-tour-times {
    width: 100% !important;
}

#tour-scheduler-modal #ha-tour-times .times-grid,
#tour-scheduler-modal #ha-tour-times .ha-times-grid {
    display: grid !important;
    gap: 0.75rem !important;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)) !important;
}

#tour-scheduler-modal #ha-tour-times .time-slot,
#tour-scheduler-modal #ha-tour-times .ha-time-slot {
    background: white !important;
    border: 2px solid rgba(57, 132, 173, 0.2) !important;
    border-radius: 8px !important;
    padding: 0.75rem 1rem !important;
    text-align: center !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    font-weight: 500 !important;
    color: var(--wp--preset--color--primary-blue, #07074E) !important;
}

#tour-scheduler-modal #ha-tour-times .time-slot:hover,
#tour-scheduler-modal #ha-tour-times .ha-time-slot:hover {
    border-color: var(--wp--preset--color--secondary-blue, #3984AD) !important;
    background: rgba(57, 132, 173, 0.05) !important;
    transform: translateY(-2px) !important;
}

#tour-scheduler-modal #ha-tour-times .time-slot.selected,
#tour-scheduler-modal #ha-tour-times .ha-time-slot.selected {
    background: var(--wp--preset--color--primary-accent, #50A684) !important;
    border-color: var(--wp--preset--color--primary-accent, #50A684) !important;
    color: white !important;
}

/* Mobile time slots */
@media (max-width: 768px) {
    #tour-scheduler-modal #ha-tour-times .times-grid,
    #tour-scheduler-modal #ha-tour-times .ha-times-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 0.5rem !important;
    }
    
    #tour-scheduler-modal #ha-tour-times .time-slot,
    #tour-scheduler-modal #ha-tour-times .ha-time-slot {
        padding: 0.625rem 0.5rem !important;
        font-size: 0.8rem !important;
        min-height: 44px !important;
    }
}

@media (max-width: 480px) {
    #tour-scheduler-modal #ha-tour-times .times-grid,
    #tour-scheduler-modal #ha-tour-times .ha-times-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    #tour-scheduler-modal #ha-tour-times .time-slot,
    #tour-scheduler-modal #ha-tour-times .ha-time-slot {
        padding: 0.5rem 0.25rem !important;
        font-size: 0.75rem !important;
        min-height: 40px !important;
    }
}

/* ===== IMPROVED LOADING STATES ===== */
#tour-scheduler-modal .ha-loading,
#tour-scheduler-modal .loading {
    padding: 1.5rem;
}

#tour-scheduler-modal .ha-loading-spinner,
#tour-scheduler-modal .loading-spinner {
    width: 20px;
    height: 20px;
    border-width: 2px;
    margin-right: 0.5rem;
}

/* ===== MESSAGE IMPROVEMENTS ===== */
#tour-scheduler-modal .ha-tour-messages {
    margin-bottom: 1rem;
}

#tour-scheduler-modal .ha-message {
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */
#tour-scheduler-modal .ha-calendar-day:focus,
#tour-scheduler-modal .ha-time-slot:focus {
    outline: 2px solid var(--wp--preset--color--primary-accent, #50A684);
    outline-offset: 2px;
    z-index: 1;
    position: relative;
}

/* ===== ANIMATION IMPROVEMENTS ===== */
#tour-scheduler-modal .ha-time-slot,
#tour-scheduler-modal .ha-calendar-day {
    transition: all 0.2s ease; /* Faster transitions for better mobile experience */
}

/* ===== HIGH CONTRAST MODE ===== */
@media (prefers-contrast: high) {
    #tour-scheduler-modal .ha-modal-header {
        border-bottom: 2px solid var(--wp--preset--color--white, #ffffff);
    }
    
    #tour-scheduler-modal .ha-calendar-day,
    #tour-scheduler-modal .ha-time-slot {
        border-width: 2px;
    }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
    #tour-scheduler-modal .ha-time-slot,
    #tour-scheduler-modal .ha-calendar-day,
    #tour-scheduler-modal .ha-button {
        transition: none;
    }
    
    #tour-scheduler-modal .ha-loading-spinner,
    #tour-scheduler-modal .loading-spinner {
        animation: none;
    }
}
