/**
 * Calendar Display Fix
 * This file contains CSS fixes for the Events Calendar display
 */

/* Fix for calendar table display */
.tribe-events-calendar-month {
    table-layout: fixed !important;
    width: 100% !important;
    border-collapse: collapse !important;
    display: table !important;
    max-width: 100% !important;
}

/* Force proper table structure */
.tribe-events-calendar-month thead,
.tribe-events-calendar-month tbody {
    display: table-row-group !important;
    width: 100% !important;
}

/* Force each week to be a table row */
.tribe-events-calendar-month__body-row,
.tribe-events-calendar-month__header-row,
.tribe-events-calendar-month tr {
    display: table-row !important;
    width: 100% !important;
    flex-wrap: nowrap !important;
    flex-direction: unset !important;
}

/* Force each day to be a table cell */
.tribe-events-calendar-month__header-column,
.tribe-events-calendar-month__day {
    display: table-cell !important;
    width: 14.285% !important; /* 100% divided by 7 days */
    vertical-align: top !important;
    float: none !important;
    position: relative !important;
}

/* Fix day cell structure */
.tribe-events-calendar-month__day-cell {
    height: 100% !important;
    min-height: 110px !important;
}

/* Fix events container */
.tribe-events-calendar-month__events {
    height: auto !important;
    overflow: visible !important;
}

/* Fix for the day number */
.tribe-events-calendar-month__day-date {
    margin-bottom: 8px !important;
}

/* Override any flex layouts that might be causing issues */
.tribe-common .tribe-common-l-container {
    display: block !important;
}

/* Critical fix for the week structure - force rows to break after every 7 days */
.tribe-events-calendar-month__body {
    display: table-row-group !important;
    flex-direction: unset !important;
    flex-wrap: nowrap !important;
}

/* Force proper week structure */
.tribe-events-calendar-month__week {
    display: table-row !important;
    width: 100% !important;
    flex-direction: unset !important;
    flex-wrap: nowrap !important;
}

/* Target the specific structure of the calendar */
.tribe-events-calendar-month__body > div {
    display: table-row !important;
    width: 100% !important;
}

.tribe-events-calendar-month__body > div > div {
    display: table-cell !important;
    width: 14.285% !important;
}

/* Ensure proper display for the calendar container */
.tribe-events-view--month {
    overflow-x: hidden !important;
    max-width: 100% !important;
}

/* Make sure the calendar doesn't overflow */
.tribe-common--breakpoint-medium.tribe-events .tribe-events-calendar-month {
    width: 100% !important;
    overflow: hidden !important;
}

/* This is the key fix - force the browser to break the row after every 7th day */
.tribe-events-calendar-month__day:nth-child(7n) {
    break-after: always !important;
}

.tribe-events-calendar-month__day:nth-child(7n+1) {
    clear: left !important;
}

/* Mobile fixes */
@media (max-width: 767px) {
    .tribe-events-calendar-month {
        display: table !important;
        width: 100% !important;
    }
    
    .tribe-events-calendar-month__day-cell--mobile {
        height: auto !important;
    }
}

/* Fix for event display within cells */
.tribe-events-calendar-month__calendar-event {
    margin: 0 0 8px !important;
}

.tribe-events-calendar-month__multiday-event-bar {
    margin-top: 0 !important;
}
