/* Schedule 2-column layout: main + sidebar */

.schedule-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 32px;
    align-items: start;
}

.schedule-sidebar {
    position: sticky;
    top: 120px; /* clears sticky header (topbar ~38px + nav ~72px + buffer) */
}

.ad-slot--sidebar {
    padding: 0;
}

.ad-slot__box--sidebar {
    width: 100%;
    min-height: 250px;
    max-width: 320px;
}

@media (max-width: 960px) {
    .schedule-layout {
        grid-template-columns: 1fr;
    }

    .schedule-sidebar {
        position: static;
        /* Move sidebar ad below the schedule on small screens */
    }

    .ad-slot__box--sidebar {
        max-width: 100%;
    }
}

/* Schedule list thumbnail column */

.schedule-list li {
    grid-template-columns: 122px 90px minmax(0, 1fr) auto auto;
}

.schedule-thumb {
    width: 120px;
    height: 72px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.schedule-thumb--empty {
    width: 72px;
    height: 72px;
    background: var(--color-soft);
    border: 1px solid var(--color-line);
    border-radius: var(--radius-sm);
}

.schedule-copy {
    min-width: 0;
}

/* ── Add-to-calendar dropdown ── */

.cal-menu {
    position: relative;
    justify-self: end;
}

.cal-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid var(--color-line);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-muted);
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), box-shadow var(--transition), color var(--transition);
    touch-action: manipulation;
}

.cal-trigger svg {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
}

.cal-trigger:hover {
    border-color: rgb(0 91 187 / 35%);
    background: rgb(0 91 187 / 5%);
    color: var(--color-blue);
    box-shadow: var(--shadow-xs);
}

.cal-menu.is-open .cal-trigger {
    border-color: var(--color-blue);
    color: var(--color-blue);
    background: rgb(0 91 187 / 7%);
    box-shadow: 0 0 0 3px rgb(0 91 187 / 10%);
}


.cal-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 210px;
    background: var(--color-surface);
    border: 1px solid var(--color-line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 6px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-4px);
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 20;
}

.cal-menu.is-open .cal-dropdown {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.cal-option {
    display: flex;
    align-items: center;
    gap: 11px;
    width: 100%;
    min-height: 44px;
    padding: 10px 13px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-ink);
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    text-align: left;
    white-space: nowrap;
    touch-action: manipulation;
}

.cal-option svg {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
}

.cal-option:hover,
.cal-option:focus-visible {
    background: var(--color-soft);
}

/* Divider between options */
.cal-option + .cal-option {
    border-top: 1px solid var(--color-line);
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    margin-top: 2px;
    padding-top: 11px;
}

.cal-option--google svg { color: #4285f4; }
.cal-option--ics svg { color: var(--color-red); }

/* Needed because .cal-option { display: flex } overrides the browser's [hidden] { display: none } */
.cal-option[hidden] { display: none; }

/* iOS: only Apple Calendar shown — remove the divider */
.cal-dropdown--single .cal-option + .cal-option {
    border-top: none;
    padding-top: 10px;
}

@media (max-width: 600px) {
    .schedule-list li {
        grid-template-columns: 90px minmax(0, 1fr) auto;
        grid-template-rows: auto auto auto;
    }

    .schedule-thumb,
    .schedule-thumb--empty {
        width: 90px;
        height: 60px;
        grid-row: 1 / span 2;
    }

    .schedule-list time {
        grid-column: 2;
        grid-row: 1;
    }

    .schedule-copy {
        grid-column: 2;
        grid-row: 2;
    }

    .cal-menu {
        grid-column: 2;
        grid-row: 3;
        justify-self: start;
        margin-top: 6px;
    }

    /* Open upward on mobile so the dropdown isn't clipped by the next row */
    .cal-dropdown {
        top: auto;
        bottom: calc(100% + 8px);
        right: auto;
        left: 0;
    }

    .schedule-list li > .live-pill {
        grid-column: 3;
        grid-row: 1 / span 3;
        align-self: center;
    }
}

/* Tablet: sidebar collapses but row grid is still wide enough — just ensure
   the dropdown doesn't overflow the right edge on narrower viewports */
@media (max-width: 960px) and (min-width: 601px) {
    .cal-trigger {
        width: 42px;
        height: 42px;
    }

    .cal-dropdown {
        /* Flip to left-align when near the right edge */
        right: 0;
        left: auto;
    }
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 26px;
    padding: 6px;
    background: var(--color-soft);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-line);
}

.tabs button {
    flex: 1 1 auto;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    padding: 9px 14px;
    font-weight: 800;
    font-size: 0.88rem;
    color: var(--color-muted);
    cursor: pointer;
    transition: background var(--transition), color var(--transition), border-color var(--transition), box-shadow var(--transition);
    white-space: nowrap;
}

.tabs button:hover:not([aria-selected="true"]) {
    background: rgb(255 255 255 / 80%);
    color: var(--color-ink);
    border-color: var(--color-line);
}

.tabs button[aria-selected="true"] {
    border-color: var(--color-blue);
    background: var(--color-blue);
    color: #fff;
    box-shadow: 0 4px 14px rgb(0 91 187 / 22%);
}

.day-panel {
    display: none;
}

.day-panel.is-active {
    display: block;
    animation: fadeSlideIn 0.2s ease;
}

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.day-panel h2 {
    margin: 0 0 16px;
    font-size: 1.3rem;
    font-weight: 900;
    letter-spacing: -0.01em;
    color: var(--color-ink);
}

/* Currently-airing program highlight */
.schedule-list li.is-now {
    position: relative;
    background: rgb(229 27 43 / 5%);
    border-color: rgb(229 27 43 / 28%);
    box-shadow: 0 0 0 1px rgb(229 27 43 / 14%), var(--shadow-xs);
}

.schedule-list li.is-now time {
    color: var(--color-red);
}

.schedule-list li.is-now::after {
    content: "Now";
    position: absolute;
    top: -1px;
    right: -1px;
    padding: 3px 10px;
    border-radius: 0 var(--radius) 0 8px;
    background: var(--color-red);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 900;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    line-height: 1.6;
}

@media (max-width: 600px) {
    .tabs {
        gap: 6px;
        padding: 5px;
    }

    .tabs button {
        padding: 8px 10px;
        font-size: 0.82rem;
    }
}

/* ── Dark Mode ── */

html.dark .schedule-thumb--empty { background: var(--color-soft); border-color: var(--color-line); }
html.dark .day-panel h2 { color: var(--color-ink); }
html.dark .cal-trigger { background: rgb(28 31 46 / 90%); }
html.dark .cal-trigger:hover { background: rgb(0 91 187 / 12%); }
html.dark .cal-dropdown { background: #1c1f2e; border-color: var(--color-line); }
html.dark .cal-option:hover, html.dark .cal-option:focus-visible { background: var(--color-soft); }
