/* the surrounding theme forces very low-contrast text; re-assert readable colours here */
#kli-calendar-widget, #kli-calendar-widget * { color: #1f2937; }
#kli-calendar-widget .fc { background: #fff; }
#kli-calendar-widget .fc-toolbar-title { color: #111827 !important; font-weight: 700; }
#kli-calendar-widget .fc-col-header-cell { background: #f3f4f6; }
#kli-calendar-widget .fc-daygrid-day.fc-day-today { background: #fef9c3 !important; }
#kli-calendar-widget .fc-button {
    background: #1f2937 !important;
    border-color: #1f2937 !important;
    color: #fff !important;
    text-transform: none !important;
}
#kli-calendar-widget .fc-button:hover { background: #374151 !important; }
#kli-calendar-widget .fc-prev-button,
#kli-calendar-widget .fc-next-button {
    min-width: 110px;
    text-align: center;
    white-space: nowrap;
}
#kli-calendar-widget .fc-toolbar-chunk { position: relative; } /* anchors the filter dropdown panel */
#kli-calendar-widget .fc-kliFilter-button {
    min-width: 190px;
    text-align: center;
    white-space: nowrap;
}
#kli-calendar-widget .fc-kliFilter-button.has-filters { background: #2563eb !important; border-color: #2563eb !important; }
#kli-calendar-widget .fc-event {
    border: none !important;
    border-radius: 4px;
    padding: 1px 4px;
    font-size: 12px;
    cursor: pointer;
}
#kli-calendar-widget .fc-event, #kli-calendar-widget .fc-event * { color: #fff !important; }
#kli-calendar-widget .fc-event-main-frame { display: flex; align-items: center; gap: 6px; }
#kli-calendar-widget .fc-event-time { margin-right: 4px; flex-shrink: 0; }
#kli-calendar-widget, #kli-calendar-widget .fc { max-width: 100%; overflow-x: hidden; }

/* ---------------------------------------------------------------------
 * Phones: stacked layout - title / today+filter / grid / prev,next - matching
 * the headerToolbar+footerToolbar split calendar.js picks below 782px.
 * ------------------------------------------------------------------- */
@media (max-width: 782px) {
    #kli-calendar-widget .fc-toolbar-title { font-size: 1.15rem; }
    #kli-calendar-widget .fc-header-toolbar { flex-wrap: wrap; row-gap: 10px; }
    #kli-calendar-widget .fc-header-toolbar .fc-toolbar-chunk:nth-child(1) {
        flex: 1 1 100%;
        text-align: center;
    }
    #kli-calendar-widget .fc-today-button {
        flex: 0 0 auto;
        min-width: 0;
        padding: 6px 10px;
        font-size: 11px;
    }
    #kli-calendar-widget .fc-kliFilter-button { min-width: 0; }
    #kli-calendar-widget .fc-footer-toolbar {
        display: flex;
        justify-content: center;
        gap: 16px;
        margin-top: 12px;
    }
    /* narrow day cells can't fit a full title - truncate with an ellipsis instead of wrapping,
     * which would otherwise break long words onto their own line one letter at a time */
    #kli-calendar-widget .fc-event-title {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        min-width: 0;
    }
    #kli-calendar-widget .fc-event-main-frame { min-width: 0; }
    #kli-calendar-widget .fc-daygrid-event-harness { max-width: 100%; }
}

.kli-cal-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.kli-cal-modal-overlay.is-open { display: flex; }
.kli-cal-modal {
    background: #fff;
    color: #1f2937;
    width: 100%;
    max-width: 480px;
    max-height: 80vh;
    overflow: auto;
    border-radius: 8px;
    padding: 24px;
    position: relative;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}
.kli-cal-modal * { color: #1f2937; }
.kli-cal-modal h3 { margin: 0 0 14px; font-size: 18px; }
/* never require horizontal scrolling to read the modal, even with long unbroken text */
.kli-cal-modal, .kli-cal-modal-event { overflow-wrap: break-word; word-break: break-word; }
@media (max-width: 480px) {
    .kli-cal-modal-overlay { padding: 12px; }
    .kli-cal-modal { padding: 16px; }
}
.kli-cal-modal-close {
    position: absolute;
    top: 8px;
    right: 12px;
    font-size: 24px;
    line-height: 1;
    background: none;
    border: none;
    cursor: pointer;
    color: #6b7280;
}
.kli-cal-modal-event {
    border-left: 4px solid #2563eb; /* overridden inline per-event to match its calendar color */
    padding: 8px 12px;
    margin-bottom: 10px;
    background: #f8f9fa;
    border-radius: 4px;
}
.kli-cal-modal-event .kli-cal-time { font-weight: 600; }
.kli-cal-modal-event .kli-cal-competition { font-size: 12px; color: #6b7280; margin-top: 2px; }
.kli-cal-modal-event .kli-cal-location { font-size: 13px; color: #4b5563; margin-top: 2px; }
.kli-cal-modal-event .kli-cal-desc { font-size: 13px; margin-top: 4px; white-space: pre-line; }
.kli-cal-modal-event a { color: #2563eb; }

.kli-cal-filter-panel {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    /* !important needed: FullCalendar's own stylesheet adds spacing between a toolbar chunk's
       children with higher specificity, and this panel is appended as a second child of the
       button's chunk, so it otherwise inherits an unwanted margin-left there too */
    margin: 4px 0 0 0 !important;
    width: 280px;
    max-height: 320px;
    overflow: auto;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
    z-index: 20;
    padding: 10px;
    text-align: left;
}
.kli-cal-filter-panel.is-open { display: block; }
.kli-cal-filter-panel * { color: #1f2937; }
.kli-cal-filter-search-wrap {
    display: flex;
    align-items: stretch;
    gap: 6px;
    margin-bottom: 8px;
}
.kli-cal-filter-search {
    flex: 0 0 80%;
    width: 80%;
    box-sizing: border-box;
    padding: 6px 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 13px;
}
.kli-cal-filter-clear-all {
    flex: 1 1 auto;
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    color: #1f2937 !important;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}
.kli-cal-filter-clear-all.is-empty { opacity: .4; cursor: default; }
.kli-cal-filter-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 2px;
    font-size: 13px;
    cursor: pointer;
}
.kli-cal-filter-item input { margin: 0; }
.kli-cal-filter-empty { font-size: 13px; color: #6b7280 !important; padding: 6px 2px; }
