/* CSS Variables Defaults */
:root {
    --tbec-font-family: inherit;
    --tbec-font-size-date: 16px;
    --tbec-font-size-event: 14px;
    --tbec-font-size-time: 12px;

    --tbec-bg-color: #ffffff;
    --tbec-text-color: #333333;
    --tbec-border-color: #e0e0e0;
    --tbec-today-bg: #e6f7ff;
    --tbec-weekend-bg: #fafbfc;

    --tbec-cell-padding: 10px;
    --tbec-cell-min-height: 100px;
    --tbec-gap: 1px;

    --tbec-border-radius: 4px;
    --tbec-border-width: 1px;

    --tbec-status-green: #52c41a;
    --tbec-status-yellow: #faad14;
    --tbec-status-red: #f5222d;
    --tbec-status-sold-out: #d9d9d9;
}

.tbec-calendar-wrapper {
    font-family: var(--tbec-font-family);
    color: var(--tbec-text-color);
    background: var(--tbec-border-color);
    /* Default background acts as border color for grid */
    border: var(--tbec-border-width) solid var(--tbec-border-color);
    border-radius: var(--tbec-border-radius);
    overflow: hidden;
    position: relative;
    box-sizing: border-box;
}

.tbec-calendar-wrapper * {
    box-sizing: border-box;
}

/* Header */
.tbec-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: var(--tbec-bg-color);
    /* Explicitly white/bg to cover wrapper */
    border-bottom: 1px solid var(--tbec-border-color);
}

.tbec-view-switcher {
    display: flex;
    align-items: center;
    gap: 5px;
}

.tbec-current-date {
    font-size: 1.2em;
    font-weight: bold;
}

.tbec-nav-btn {
    background: none;
    border: 1px solid var(--tbec-border-color);
    padding: 5px 10px;
    cursor: pointer;
    border-radius: 4px;
}

.tbec-nav-btn:hover {
    background: #e6e6e6;
}

/* Grid */
.tbec-calendar-grid {
    display: flex;
    flex-direction: column;
}

.tbec-weekdays {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    border-bottom: 1px solid var(--tbec-border-color);
    background: var(--tbec-bg-color);
    /* Explicitly white/bg */
}

.tbec-weekday {
    padding: 10px;
    text-align: center;
    font-weight: bold;
    font-size: 0.9em;
}

.tbec-weekday-mobile {
    display: none;
}

/* Hidden on Desktop/Tablet by default */
.tbec-view-toggle {
    display: none;
}

@media (max-width: 600px) {
    .tbec-view-toggle {
        display: inline-flex;
        /* or inline-block, matching flex parent */
    }

    .tbec-weekday-desktop {
        display: none;
    }


    .tbec-weekday-mobile {
        display: inline;
    }

    /* Mobile Header Layout */
    .tbec-header {
        flex-wrap: wrap;
        padding-left: 10px;
        padding-right: 10px;
    }

    .tbec-header .tbec-prev {
        order: 1;
        margin-right: 5px;
    }

    .tbec-header .tbec-next {
        order: 2;
        margin-left: 0;
    }

    .tbec-header .tbec-current-date {
        order: 3;
        flex-grow: 1;
        text-align: left;
        padding-left: 10px;
        width: auto;
    }

    .tbec-header .tbec-view-switcher {
        order: 4;
    }

    .tbec-weekday {
        padding: 5px;
        /* Reduce padding on mobile */
        font-size: 0.8em;
    }
}

.tbec-days {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: var(--tbec-gap);
    background: transparent;
    /* Transparent to let wrapper bg show as gap color */
    /* Gap color */
}

/* Day Cell */
.tbec-day {
    background: var(--tbec-bg-color);
    min-height: var(--tbec-cell-min-height);
    padding: var(--tbec-cell-padding);
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
}

.tbec-day:hover {
    background-color: #fce4ec;
    /* Subtle highlight on hover */
}

.tbec-day-empty {
    background: #f9f9f9;
    cursor: default;
}

.tbec-today {
    background-color: var(--tbec-today-bg);
}

.tbec-weekend {
    background-color: var(--tbec-weekend-bg);
}

.tbec-day-number {
    display: block;
    margin-bottom: 5px;
    font-size: var(--tbec-font-size-date);
    font-weight: bold;
    color: #888;
}

/* Events */
.tbec-day-events {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tbec-event-marker {
    font-size: var(--tbec-font-size-event);
    padding: 2px 4px;
    border-radius: 3px;
    background: #f0f0f0;
    border-left: 3px solid #ccc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    display: flex;
    /* Changed to flex to align time/title better */
    align-items: center;
}

.tbec-event-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
    flex: 1;
    /* Take remaining space */
}

.tbec-event-time {
    font-size: var(--tbec-font-size-time);
    margin-right: 4px;
    opacity: 0.7;
}

/* Status Colors */
.tbec-status-green {
    border-left-color: var(--tbec-status-green);
}

.tbec-status-yellow {
    border-left-color: var(--tbec-status-yellow);
}

.tbec-status-red {
    border-left-color: var(--tbec-status-red);
}

.tbec-status-sold-out {
    border-left-color: var(--tbec-status-sold-out);
    background: #f5f5f5;
    opacity: 0.7;
}

/* Popover Overlay (Mobile) */
.tbec-popover-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    margin: 0 !important;
    background: rgba(0, 0, 0, 0.5);
    /* Semi-transparent backdrop */
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Popover Inner (Reset relative positioning from marker) */
.tbec-popover-inner {
    position: relative;
    top: auto;
    left: auto;
    background: white;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    padding: 20px;
    width: calc(100% - 20px);
    /* Fill screen with margin */
    max-width: 400px;
    border-radius: 8px;
    margin: 10px;
}

.tbec-popover-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 15px;
    gap: 15px;
}

.tbec-popover-close {
    background: #f0f0f0;
    border: none;
    cursor: pointer;
    font-size: 1.5em;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
    flex-shrink: 0;
    padding: 0;
    line-height: 1;
}

.tbec-popover-close:hover {
    background: #e0e0e0;
}

.tbec-popover-title {
    margin: 0;
    font-size: 1.3em;
    white-space: normal;
    line-height: 1.3;
    flex-grow: 1;
}

.tbec-popover-meta {
    font-size: 1em;
    color: #666;
    margin-bottom: 15px;
}

.tbec-availability-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 5px;
}

.tbec-availability-dot.tbec-status-green {
    background-color: var(--tbec-status-green);
}

.tbec-availability-dot.tbec-status-yellow {
    background-color: var(--tbec-status-yellow);
}

.tbec-availability-dot.tbec-status-red {
    background-color: var(--tbec-status-red);
}

.tbec-availability-dot.tbec-status-sold-out {
    background-color: var(--tbec-status-sold-out);
}

.tbec-button {
    display: block;
    width: 100%;
    padding: 12px 15px;
    background: #0073aa;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    text-align: center;
    font-weight: bold;
    font-size: 1.1em;
    transition: background 0.2s;
}

.tbec-button:hover {
    background: #005177;
    text-decoration: none;
    color: white;
}

/* Mobile Responsive */
@media (max-width: 600px) {
    .tbec-day {
        padding: 2px;
        min-height: 60px;
    }

    .tbec-event-marker {
        padding: 0;
        width: 8px;
        height: 8px;
        border-radius: 50%;
        text-indent: -9999px;
        /* Hide text, show dot */
        display: inline-block;
        border: none;
        margin: 1px;
    }

    .tbec-status-green {
        background-color: var(--tbec-status-green);
    }

    .tbec-status-yellow {
        background-color: var(--tbec-status-yellow);
    }

    .tbec-status-red {
        background-color: var(--tbec-status-red);
    }

    .tbec-day-events {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    /* If list view enabled */
    .tbec-view-list .tbec-calendar-grid {
        display: none;
    }

    .tbec-view-list .tbec-mobile-list-view {
        display: block !important;
    }

    /* Hide close button in list view (it's not a popover there) */
    .tbec-view-list .tbec-popover-close,
    .tbec-mobile-list-view .tbec-popover-close {
        display: none !important;
    }
}

/* Popover Link Styles */
.tbec-popover-event-link.tbec-btn-style {
    display: block;
    width: 100%;
    padding: 12px 15px;
    background: #0073aa;
    /* Fallback if Elementor inactive */
    color: white;
    /* Fallback */
    text-decoration: none;
    border-radius: 4px;
    text-align: center;
    font-weight: bold;
    font-size: 1.1em;
    transition: background 0.2s;
}

.tbec-popover-event-link.tbec-btn-style:hover {
    background: #005177;
    text-decoration: none;
    color: white;
}

.tbec-popover-event-link.tbec-link-style {
    display: inline-block;
    color: #0073aa;
    text-decoration: underline;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    font-size: 1em;
}


/* More Events Indicator */
.tbec-more-events-indicator {
    text-align: center;
    color: #666;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    padding: 2px 0;
    font-size: 1.2em;
    border-radius: 3px;
    background: transparent;
    transition: background-color 0.2s, color 0.2s;
}

.tbec-more-events-indicator:hover {
    background-color: #f0f0f0;
    color: #333;
}

.tbec-events-hidden {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 4px;
}

/* Ensure hidden events show correctly when container is toggled visible */
.tbec-events-hidden[style*="block"],
.tbec-events-hidden[style*="display: block"] {
    display: flex !important;
}


/* Mobile adjustments for More Indicator */
@media (max-width: 600px) {
    .tbec-more-events-indicator {
        display: inline-block;
        width: 10px;
        height: 10px;
        font-size: 14px;
        /* Ensure 3 dots are visible/consistent or just use text */
        /* Actually on mobile we want it to look like another dot potentially, OR an ellipsis text */
        /* Let's keep it as ellipsis text but ensure it fits */
        width: auto;
        height: auto;
        margin: 1px;
        padding: 0 2px;
        vertical-align: middle;
    }
}

/* Card Stack Styles */
.tbec-popover-stack {
    position: relative;
    width: 100%;
    /* Remove height 100% to allow flex centering of the block */
    height: auto;
    /* Ensure it fills overlay */
    max-width: 400px;
    /* Match popover width */
    margin: 0 auto;
    perspective: 1000px;
    z-index: 10000;
}

.tbec-popover-card {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    background: white;
    border-radius: 12px;
    /* Slightly rounder */
    padding: 20px;
    box-shadow: 0 8px 6px rgba(0, 0, 0, 0.2);
    /* Requested shadow */
    transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1), top 0.4s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.3s;
    /* Smooth stack movement */
    overflow-y: auto;
    max-height: 80vh;
    /* Limit height to allow scrolling */
    overscroll-behavior: contain;
    /* Prevents scroll chaining to body */
    touch-action: pan-y;
    /* Explicitly allow vertical panning, we handle boundaries in JS */
}

/* Stack Offsets - handled via JS usually, but defaults here */
.tbec-popover-card.tbec-card-active {
    z-index: 10;
}

.tbec-popover-card.tbec-card-next {
    z-index: 9;
    /* Will be offset by JS */
}

/* Animation Classes */
.tbec-slide-out-top {
    transform: translateY(-120%);
    opacity: 0.5;
}

.tbec-slide-in-top {
    /* Reset is default, class removed to slide in */
}

/* Stack wrapper in overlay */
.tbec-popover-overlay .tbec-popover-stack-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
}

@media (max-width: 600px) {
    .tbec-popover-card {
        border-radius: 16px;
    }
}

body.tbec-no-scroll {
    overflow: hidden !important;
    touch-action: none;
    /* Disable touch interactions on body to further prevent scroll */
}

/* Lazy Loading State */
.tbec-avail-loading {
    color: #888;
    font-size: 0.9em;
    font-style: italic;
    animation: tbec-pulse 1.5s infinite;
}

@keyframes tbec-pulse {
    0% {
        opacity: 0.6;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.6;
    }
}