/* =========================================
   Premium Time Selection Popup Styles
   ========================================= */

/* 1. Modal Overlay & Container */
.time-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(30, 30, 30, 0.4);
    /* Darker dim for focus */
    backdrop-filter: blur(5px);
    /* Modern blur effect */
    z-index: 10000;
    /* Super high z-index */
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeInOverlay 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.time-popup-container {
    background: #ffffff;
    width: 90%;
    max-width: 650px;
    /* Optimal reading width */
    max-height: 85vh;
    /* Safe vertical space */
    border-radius: 20px;
    /* Smooth corners */
    box-shadow:
        0 20px 25px -5px rgba(0, 0, 0, 0.1),
        0 10px 10px -5px rgba(0, 0, 0, 0.04),
        0 0 0 1px rgba(0, 0, 0, 0.02);
    /* Subtle outline */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px);
    opacity: 0;
    animation: slideUpModal 0.4s cubic-bezier(0.16, 1, 0.3, 1) 0.1s forwards;
    position: relative;
}

/* 2. Header Section */
.time-popup-header {
    padding: 24px 30px;
    background: #ffffff;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
}

.time-popup-header h3 {
    margin: 0;
    font-size: 1.25rem;
    /* 20px */
    font-weight: 700;
    color: #1e293b;
    font-family: 'Tajawal', sans-serif;
    letter-spacing: -0.01em;
}

/* Elegant Close Button */
.time-popup-close {
    background: #f8fafc;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: #64748b;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.time-popup-close:hover {
    background: #eff6ff;
    color: #ef4444;
    /* Soft red on hover for close action */
    transform: rotate(90deg);
}

/* 3. Modal Body */
.time-popup-body {
    padding: 0;
    overflow-y: auto;
    flex-grow: 1;
    background-color: #ffffff;
}

.calendar-wrapper-compact {
    padding: 20px 30px 40px;
}

/* 4. Calendar Specific Adjustments (Overrides) */
/* Force clean layout regardless of original CSS */
#calendar-container .calendar-header {
    margin-bottom: 25px;
    background: #f8fafc;
    padding: 15px;
    border-radius: 12px;
}

#calendar-container .calendar-month-label {
    font-size: 1.1rem;
    font-weight: 700;
    color: #334155;
}

#calendar-container .calendar-nav-btn {
    width: 32px;
    height: 32px;
    background: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    color: #64748b;
}

/* Hover effects only for devices with mouse/pointer */
@media (hover: hover) {
    #calendar-container .calendar-nav-btn:hover {
        background: #6ba877;
        color: white;
    }

    #calendar-container .calendar-day-available:hover {
        background: #f0fdf4;
        border-color: #6ba877;
        color: #6ba877;
    }

    .time-slot:hover {
        border-color: #6ba877;
        background: #f0fdf4;
        transform: translateY(-2px);
    }

    .time-popup-close:hover {
        background: #eff6ff;
        color: #ef4444;
        transform: rotate(90deg);
    }
}

/* Active states for touch feedback */
.time-slot:active,
#calendar-container .calendar-day-available:active {
    background: #f0fdf4;
    border-color: #6ba877;
    transform: scale(0.98);
}

#calendar-container .calendar-weekdays {
    margin-bottom: 15px;
}

#calendar-container .calendar-weekday {
    font-size: 0.85rem;
    color: #94a3b8;
    font-weight: 500;
}

#calendar-container .calendar-day {
    height: 44px;
    width: 44px;
    margin: 4px auto;
    font-size: 0.95rem;
    border-radius: 10px;
    /* Softer square */
}

/* Active states - purely physical feedback only (no colors) to avoid confusion during scroll */
.time-slot:active,
#calendar-container .calendar-day-available:active {
    transform: scale(0.96);
    /* No color change here to prevent fake selection feeling during scroll */
}

#calendar-container .calendar-day-available {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    color: #334155;
    font-weight: 500;
}

#calendar-container .calendar-day-selected {
    background: #6ba877 !important;
    color: white !important;
    border-color: #6ba877 !important;
    box-shadow: 0 4px 12px rgba(107, 168, 119, 0.3);
}

#calendar-container .calendar-day-unavailable {
    color: #cbd5e1 !important;
    font-weight: 400 !important;
    background: #f8fafc !important;
    border: 1px solid transparent !important;
    cursor: default !important;
    opacity: 0.6;
}

#calendar-container .calendar-day-unavailable.calendar-day-clickable {
    cursor: pointer !important;
    opacity: 0.7 !important;
}

#calendar-container .calendar-day-unavailable.calendar-day-clickable:hover {
    opacity: 0.9 !important;
    border-color: #e2e8f0 !important;
    color: #94a3b8 !important;
}

/* 5. Custom Scrollbar (Sleek) */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background-color: #e2e8f0;
    border-radius: 20px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background-color: #cbd5e1;
}

/* 6. Animations */
@keyframes fadeInOverlay {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUpModal {
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* 7. Loading State */
.calendar-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 0;
    color: #64748b;
    gap: 15px;
}

.calendar-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e2e8f0;
    border-top-color: #6ba877;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* 8. Fix for time slots if they appear */
.time-slots-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
    padding: 20px 30px;
    border-top: 1px solid #f1f5f9;
    margin-top: 10px;
}

.time-slot {
    padding: 10px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: white;
}

/* Correct class name matching JS (time-slot-selected) */
.time-slot.selected,
.time-slot-selected,
.time-slot.time-slot-selected {
    background: #6ba877 !important;
    color: white !important;
    border-color: #6ba877 !important;
    box-shadow: 0 4px 10px rgba(107, 168, 119, 0.4);
    transform: translateY(-2px);
}

.time-slot-time {
    font-weight: 700;
    font-size: 1.1rem;
    display: block;
    margin-bottom: 4px;
}

.time-slot-duration {
    font-size: 0.8rem;
    color: #94a3b8;
}

/* Fix text color in selected state */
.time-slot.selected .time-slot-duration,
.time-slot-selected .time-slot-duration {
    color: rgba(255, 255, 255, 0.9);
}

/* Prevent default tap highlight on mobile */
* {
    -webkit-tap-highlight-color: transparent;
}

/* =========================================
   Mobile Responsiveness (Bottom Sheet Design)
   ========================================= */
@media (max-width: 768px) {
    .time-popup-overlay {
        align-items: flex-end;
        /* Align to bottom */
        padding: 0;
        background: rgba(0, 0, 0, 0.5);
        /* Slightly darker */
    }

    .time-popup-container {
        width: 100%;
        max-width: 100%;
        max-height: 85vh;
        /* Cover 85% of screen height */
        border-radius: 24px 24px 0 0;
        /* Rounded top corners only */
        margin: 0;
        padding-bottom: env(safe-area-inset-bottom);
        /* Support for iPhone Home Indicator */
        opacity: 1;
        /* Force visible */
        animation: slideUpMobile 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    }

    @keyframes slideUpMobile {
        from {
            transform: translateY(100%);
            opacity: 1;
        }

        to {
            transform: translateY(0);
            opacity: 1;
        }
    }

    /* Add a "Handle" visual indicator for bottom sheet feel */
    .time-popup-header::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: #e2e8f0;
        border-radius: 2px;
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
    }

    .time-popup-header {
        padding: 20px 20px 15px;
        /* More padding top for handle */
        border-bottom: 1px solid #f1f5f9;
    }

    .time-popup-header h3 {
        font-size: 1.1rem;
    }

    .calendar-wrapper-compact {
        padding: 15px 15px 40px;
        /* Reduced side padding */
    }

    /* Make touch targets bigger */
    #calendar-container .calendar-day {
        height: 48px;
        /* Taller for fingers */
        width: 100%;
        /* Stretch to fill grid */
        font-size: 1rem;
        margin: 2px 0;
    }

    #calendar-container .calendar-nav-btn {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }

    .time-slots-list {
        grid-template-columns: repeat(3, 1fr);
        /* 3 columns on mobile usually fits well */
        gap: 10px;
        padding: 15px;
    }

    .time-slot {
        padding: 12px 5px;
        font-size: 0.9rem;
    }

    .time-slot-time {
        font-weight: 700;
        font-size: 1rem;
    }

    /* FORCE DISABLE HOVER ON MOBILE TO FIX STICKY HOVER ISSUES */
    .time-slot:hover {
        background-color: white;
        border-color: #e2e8f0;
        transform: none;
        box-shadow: none;
    }

    /* Ensure selected state overrides the hover reset */
    .time-slot.selected,
    .time-slot.time-slot-selected,
    .time-slot.selected:hover,
    .time-slot.time-slot-selected:hover {
        background-color: #6ba877 !important;
        border-color: #6ba877 !important;
        color: white !important;
        transform: translateY(-2px);
        box-shadow: 0 4px 10px rgba(107, 168, 119, 0.4);
    }
}

/* Extra small screens check */
@media (max-width: 380px) {
    .time-slots-list {
        grid-template-columns: repeat(2, 1fr);
        /* 2 columns for very small screens */
    }
}