:root {
    --cal-bg: #fff;
    --cal-border: #ddd;
    --cal-text: #333;
    --cal-hover: #f0f0f0;

    --type-mag-public: #AFBFB8;
    --type-mag-private: #e0e0e0;
    --type-mag: darkseagreen;
    --type-boarding: lightseagreen;
    --type-blocked-dog: #986868;
    --type-blocked-nodog: crimson;
    --type-home-visit: #baa;
    --type-mag-blocked: lightgrey;
    --type-waitlist: #c39bd3;

    --user-booking: purple;
    --user-waitlist: CornflowerBlue;

    --status-selected: lightblue;
    --status-available: darkgreen;
    --status-booked: #9F000F;
    --status-warning: orange;
}

#calendar-container {
    display: flex;
    flex-direction: row;
    gap: 20px;
    justify-content: flex-start;
    align-items: flex-start;
    flex-wrap: nowrap;
    /* Prevent wrapping for continuous horizontal scroll */
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    /* Snap perfectly onto each month */
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    /* Smooth iOS scroll */
    padding-bottom: 20px;
    /* Space for scrollbar */
    margin: 20px auto;
    width: 100%;
    max-width: 1200px;
}

.calendar-month {
    flex: 0 0 100%;
    /* Default mobile: 1 per view exactly */
    scroll-snap-align: start;
    min-width: 0;
    max-width: 100%;
    background: var(--cal-bg);
    border: 1px solid var(--cal-border);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

@media (min-width: 768px) {
    #calendar-container {
        scroll-snap-type: none;
        /* Disable scroll-snap to prevent it fighting the raw Javascript mousewheel deltas */
        scroll-behavior: auto;
        /* Instant response to mousewheel scrolling */
    }

    .calendar-month {
        flex: 0 0 calc(50% - 10px);
        /* Desktop: exactly 2 visible months */
    }
}

.calendar-header {
    background: #f8f8f8;
    padding: 10px;
    text-align: center;
    font-weight: bold;
    font-size: 1.2rem;
    border-bottom: 1px solid var(--cal-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.calendar-nav {
    display: none !important;
    /* Hide old calendar arrows, we now scroll! */
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
}

.calendar-day-header {
    padding: 5px 0;
    font-weight: bold;
    background: #eef;
    font-size: 0.9rem;
}

.calendar-day {
    position: relative;
    height: 80px;
    border-right: 1px solid #eee;
    border-bottom: 1px solid #eee;
    display: flex;
    flex-direction: column;
    background: var(--cal-bg);
    transition: background 0.2s;
}

.calendar-day.empty {
    background: #f9f9f9;
}

.calendar-day.today {
    outline: 2px solid #333;
    outline-offset: -2px;
}

.calendar-day.selected {
    background-color: var(--status-selected);
}

.day-number {
    padding: 2px 5px;
    text-align: left;
    font-size: 0.85rem;
    font-weight: bold;
    color: var(--cal-text);
}

.day-slot {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: white;
    cursor: pointer;
    user-select: none;
    padding: 2px;
    text-shadow: 0px 0px 2px rgba(0, 0, 0, 0.5);
    transition: opacity 0.2s;
}

.day-slot:hover {
    opacity: 0.8;
}

.day-slot.past {
    opacity: 0.5;
    cursor: not-allowed;
}

.day-slot.am {
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

/* Status Colors */
.status-available {
    background: var(--status-available);
}

.status-booked {
    background: var(--status-booked);
    cursor: not-allowed;
}

.status-warning {
    background: var(--status-warning);
}

.status-user-booking {
    background: var(--user-booking);
}

.status-user-waitlist {
    background: var(--user-waitlist);
}

.status-blocked {
    background: var(--status-booked);
    cursor: not-allowed;
}

.status-mag {
    background: var(--type-mag);
}

.day-label {
    word-break: break-word;
    line-height: 1.1;
}

/* Loading overlay */
.calendar-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    z-index: 10;
    display: none;
}

#calendar-container.loading .calendar-loading {
    display: flex;
}

@media (max-width: 768px) {
    #calendar-container {
        align-items: flex-start;
        margin: 10px auto;
    }

    .calendar-month {
        flex: 0 0 100%;
        /* Already set but reinforcing */
        width: 100%;
    }

    .calendar-day {
        height: 60px;
    }

    .day-slot {
        font-size: 0.65rem;
        flex-direction: column;
        justify-content: center;
        overflow: hidden;
    }

    .day-label {
        line-height: 1;
        letter-spacing: -0.5px;
        white-space: nowrap;
        text-overflow: clip;
        max-width: 100%;
        font-size: 0.55rem;
    }

    /* Fixed labels like ARRIVE and DEPART should stay standard */
    .day-label.fixed-label {
        font-size: 0.65rem;
    }
}