/* ==========================================================================
   Matches Calendar View
   - View toggle (List | Calendar)
   - Day (hourly) / Multi-day (agenda) / Month (grid) layouts
   - Theme-aware, mobile-first
   ========================================================================== */

/* View toggle re-uses .filter-pill styling; just needs icon spacing */
.view-toggle-group .filter-pill i {
    margin-right: 6px;
}

[dir="rtl"] .view-toggle-group .filter-pill i {
    margin-right: 0;
    margin-left: 6px;
}

/* Calendar host */
.calendar-view-wrap {
    margin-top: 0.5rem;
}

.cal2 {
    --cal-accent: #01BE6E;
    --cal-border: rgba(127, 127, 127, 0.22);
    --cal-surface: rgba(127, 127, 127, 0.06);
    --cal-surface-strong: rgba(127, 127, 127, 0.12);
    --cal-muted: rgba(127, 127, 127, 0.85);
    /* The global --text-color stays white even in light theme, so the
       calendar resolves its own theme-aware text color. */
    --cal-text: var(--text-color, #fff);
    width: 100%;
}

[data-theme="dark"] .cal2 {
    --cal-border: rgba(255, 255, 255, 0.12);
    --cal-surface: rgba(255, 255, 255, 0.04);
    --cal-surface-strong: rgba(255, 255, 255, 0.09);
}

[data-theme="light"] .cal2 {
    --cal-border: rgba(0, 0, 0, 0.12);
    --cal-surface: rgba(0, 0, 0, 0.035);
    --cal-surface-strong: rgba(0, 0, 0, 0.07);
    --cal-text: var(--text-primary, #1A1A1A);
    --cal-muted: rgba(60, 60, 60, 0.78);
}

.cal2-empty {
    margin: 0 0 1rem;
    padding: 0.85rem 1rem;
    border: 1px dashed var(--cal-border);
    border-radius: 12px;
    color: var(--cal-text);
    font-size: 0.92rem;
    text-align: center;
    background: var(--cal-surface);
}

/* ---- Shared chip (a single match) ---------------------------------------- */
.cal2-chip {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    width: 100%;
    text-align: left;
    border: 1px solid var(--cal-border);
    border-left: 3px solid var(--cal-accent);
    background: var(--cal-surface);
    color: var(--cal-text);
    border-radius: 10px;
    padding: 6px 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8rem;
    line-height: 1.2;
    transition: background 0.18s ease, transform 0.18s ease, border-color 0.18s ease;
}

[dir="rtl"] .cal2-chip {
    text-align: right;
    border-left: 1px solid var(--cal-border);
    border-right: 3px solid var(--cal-accent);
}

.cal2-chip:hover {
    background: var(--cal-surface-strong);
    transform: translateY(-1px);
    border-color: var(--cal-accent);
}

.cal2-chip.is-live {
    border-left-color: #ff3b3b;
}

[dir="rtl"] .cal2-chip.is-live {
    border-right-color: #ff3b3b;
}

.cal2-chip.is-past {
    opacity: 0.72;
}

.cal2-chip-head,
.cal2-ev-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    min-width: 0;
}

.cal2-chip-time,
.cal2-ev-time {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 700;
    color: var(--cal-accent);
    font-size: 0.72rem;
    white-space: nowrap;
}

.cal2-chip.is-live .cal2-chip-time,
.cal2-ev.is-live .cal2-ev-time {
    color: #ff3b3b;
}

.cal2-chip-game,
.cal2-ev-game {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.cal2-game-logo {
    width: 16px;
    height: 16px;
    object-fit: contain;
}

.cal2-chip-body,
.cal2-ev-body {
    min-width: 0;
}

.cal2-teams-row {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
    flex-wrap: nowrap;
    font-weight: 600;
    font-size: 0.72rem;
}

.cal2-team-unit {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    min-width: 0;
    flex: 0 1 auto;
}

.cal2-team-logo {
    width: 16px;
    height: 16px;
    object-fit: contain;
    flex: 0 0 auto;
}

.cal2-team-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 7.5rem;
}

.cal2-vs {
    opacity: 0.55;
    font-weight: 500;
    padding: 0 2px;
}

.cal2-live-dot {
    flex: 0 0 auto;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ff3b3b;
    box-shadow: 0 0 0 0 rgba(255, 59, 59, 0.6);
    animation: cal2Pulse 1.8s infinite;
}

@keyframes cal2Pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 59, 59, 0.5); }
    70% { box-shadow: 0 0 0 7px rgba(255, 59, 59, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 59, 59, 0); }
}

/* ---- Day (hourly) view --------------------------------------------------- */
.cal2-day-head,
.cal2-section-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--cal-text);
    margin: 0 0 0.85rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.cal2-day-head .cal2-day-sub {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--cal-muted);
}

.cal2-hours {
    border: 1px solid var(--cal-border);
    border-radius: 14px;
    overflow: hidden;
}

.cal2-hour {
    display: grid;
    grid-template-columns: 72px 1fr;
    border-bottom: 1px solid var(--cal-border);
    min-height: 46px;
}

.cal2-hour:last-child {
    border-bottom: none;
}

.cal2-hour.is-now {
    background: rgba(1, 190, 110, 0.07);
}

.cal2-hour-label {
    padding: 8px 10px;
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--cal-muted);
    border-right: 1px solid var(--cal-border);
    background: var(--cal-surface);
    text-align: right;
}

[dir="rtl"] .cal2-hour-label {
    border-right: none;
    border-left: 1px solid var(--cal-border);
    text-align: left;
}

.cal2-hour.is-now .cal2-hour-label {
    color: var(--cal-accent);
}

.cal2-hour-slot {
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* ---- Multi-day agenda (3 / 7 days) --------------------------------------- */
.cal2-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.cal2-daycard {
    border: 1px solid var(--cal-border);
    border-radius: 14px;
    background: var(--cal-surface);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 110px;
}

.cal2-daycard.is-today {
    border-color: var(--cal-accent);
    box-shadow: inset 0 0 0 1px rgba(1, 190, 110, 0.35);
}

.cal2-daycard-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--cal-border);
}

.cal2-daycard-weekday {
    font-weight: 700;
    color: var(--cal-text);
    font-size: 0.92rem;
}

.cal2-daycard.is-today .cal2-daycard-weekday {
    color: var(--cal-accent);
}

.cal2-daycard-date {
    font-size: 0.78rem;
    color: var(--cal-muted);
}

.cal2-daycard-count {
    font-size: 0.72rem;
    color: var(--cal-muted);
}

.cal2-daycard-empty {
    font-size: 0.8rem;
    color: var(--cal-muted);
    padding: 6px 2px;
}

/* ---- Time grid (Google-Calendar style: day columns x hour rows) ---------- */
.cal2-tg {
    --tg-gutter: 56px;
    --tg-cols: 7;
    --tg-col-min: 150px;
    border: 1px solid var(--cal-border);
    border-radius: 14px;
    overflow-x: auto;
    overflow-y: visible;
    background: var(--cal-surface);
}

.cal2-tg-body {
    overflow: visible;
    position: relative;
}

.cal2-tg-inner {
    min-width: 100%;
}

.cal2-tg-head,
.cal2-tg-grid {
    display: grid;
    grid-template-columns: var(--tg-gutter) repeat(var(--tg-cols), minmax(var(--tg-col-min, 140px), 1fr));
}

.cal2-tg-head {
    background: var(--card-bg, #16161a);
    border-bottom: 1px solid var(--cal-border);
}

[data-theme="light"] .cal2-tg-head {
    background: var(--card-bg, #fff);
}

.matches-tz-badge {
    margin: 0.25rem 0 0;
}

.cal2-tg-corner {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 4px 6px;
    font-size: 0.58rem;
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
    color: var(--cal-muted);
    border-right: 1px solid var(--cal-border);
    word-break: break-word;
}

[dir="rtl"] .cal2-tg-corner {
    border-right: none;
    border-left: 1px solid var(--cal-border);
}

.cal2-tg-dayhead {
    text-align: center;
    padding: 8px 2px;
    border-left: 1px solid var(--cal-border);
}

.cal2-tg-dayname {
    display: block;
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--cal-muted);
}

.cal2-tg-daynum {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    height: 30px;
    margin-top: 2px;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--cal-text);
    border-radius: 50%;
}

.cal2-tg-dayhead.is-today .cal2-tg-dayname {
    color: var(--cal-accent);
}

.cal2-tg-dayhead.is-today .cal2-tg-daynum {
    background: var(--cal-accent);
    color: #fff;
}

.cal2-tg-gutter {
    border-right: 1px solid var(--cal-border);
}

[dir="rtl"] .cal2-tg-gutter {
    border-right: none;
    border-left: 1px solid var(--cal-border);
}

.cal2-tg-hourlabel {
    position: relative;
    text-align: right;
    padding-right: 6px;
    font-size: 0.66rem;
    font-weight: 600;
    color: var(--cal-muted);
    transform: translateY(-0.55em);
}

[dir="rtl"] .cal2-tg-hourlabel {
    text-align: left;
    padding-right: 0;
    padding-left: 6px;
}

.cal2-tg-col {
    position: relative;
    border-left: 1px solid var(--cal-border);
    /* hour gridlines (matches JS ROW_H) */
    background-image: repeating-linear-gradient(
        to bottom,
        var(--cal-border) 0,
        var(--cal-border) 1px,
        transparent 1px,
        transparent 64px
    );
}

.cal2-tg-col.is-today {
    background-color: rgba(1, 190, 110, 0.045);
}

/* now indicator */
.cal2-now {
    position: absolute;
    left: 0;
    right: 0;
    height: 0;
    border-top: 2px solid #ff3b3b;
    z-index: 4;
    pointer-events: none;
}

.cal2-now::before {
    content: "";
    position: absolute;
    left: -4px;
    top: -5px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #ff3b3b;
}

/* event block */
.cal2-ev {
    position: absolute;
    z-index: 2;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 2px;
    text-align: left;
    overflow: hidden;
    border: 1px solid var(--cal-border);
    border-left: 3px solid var(--cal-accent);
    background: var(--card-bg, #1d1f24);
    color: var(--cal-text);
    border-radius: 7px;
    padding: 4px 5px;
    cursor: pointer;
    font-family: inherit;
    line-height: 1.15;
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

[data-theme="light"] .cal2-ev {
    background: #fff;
}

[dir="rtl"] .cal2-ev {
    text-align: right;
    border-left: 1px solid var(--cal-border);
    border-right: 3px solid var(--cal-accent);
}

.cal2-ev:hover {
    transform: scale(1.02);
    border-color: var(--cal-accent);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    z-index: 5;
}

.cal2-ev.is-live {
    border-left-color: #ff3b3b;
}

[dir="rtl"] .cal2-ev.is-live {
    border-right-color: #ff3b3b;
}

.cal2-ev.is-past {
    opacity: 0.66;
}

.cal2-ev .cal2-team-name {
    max-width: 6.5rem;
}

.cal2-ev .cal2-teams-row {
    overflow: hidden;
}

/* ---- Month grid ---------------------------------------------------------- */
.cal2-month-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
    margin-bottom: 6px;
}

.cal2-month-weekdays > span {
    text-align: center;
    font-size: 0.74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--cal-muted);
    padding: 4px 0;
}

.cal2-month-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}

.cal2-cell {
    border: 1px solid var(--cal-border);
    border-radius: 10px;
    background: var(--cal-surface);
    min-height: 104px;
    max-height: 168px;
    overflow-y: auto;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.cal2-cell.is-other {
    opacity: 0.42;
}

.cal2-cell.is-today {
    border-color: var(--cal-accent);
    box-shadow: inset 0 0 0 1px rgba(1, 190, 110, 0.35);
}

.cal2-cell-num {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--cal-text);
    margin-bottom: 2px;
}

.cal2-cell.is-today .cal2-cell-num {
    color: var(--cal-accent);
}

/* Compact chip variant inside dense month cells */
.cal2-cell .cal2-chip {
    padding: 4px 6px;
    font-size: 0.72rem;
    gap: 3px;
}

.cal2--month .cal2-cell .cal2-team-name {
    max-width: none;
    white-space: normal;
}

/* ---- Mobile -------------------------------------------------------------- */
@media (max-width: 768px) {
    .cal2-tg {
        --tg-gutter: 44px;
        --tg-col-min: 108px;
    }

    /* Time-grid on mobile: logos only (names hidden). Month view keeps full names. */
    .cal2--grid .cal2-tg .cal2-team-name,
    .cal2--grid .cal2-ev .cal2-team-name {
        display: none;
    }

    .cal2--grid .cal2-tg .cal2-team-logo,
    .cal2--grid .cal2-ev .cal2-team-logo {
        width: 18px;
        height: 18px;
    }

    .cal2--month .cal2-team-name {
        display: inline;
        max-width: none;
        white-space: normal;
    }

    /* Let multi-day grids scroll horizontally with room for logo-only teams row */
    .cal2-tg-inner {
        min-width: calc(var(--tg-gutter) + (var(--tg-cols) * 120px));
    }

    .cal2-tg-daynum {
        min-width: 26px;
        height: 26px;
        font-size: 0.95rem;
    }

    .cal2-tg-hourlabel {
        font-size: 0.6rem;
    }

    /* Month grid becomes a stacked agenda for readability on phones */
    .cal2-month-weekdays {
        display: none;
    }

    .cal2-month-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .cal2-cell {
        min-height: 0;
        max-height: none;
        overflow: visible;
    }

    .cal2-cell.is-other:empty,
    .cal2-cell.is-other.cal2-cell--noevents {
        display: none;
    }

    .cal2-cell-num {
        font-size: 0.82rem;
    }

    .cal2-chip-time {
        min-width: 50px;
    }
}
