/**
 * Martin CC — Course Schedule Frontend Styles
 *
 * Brand alignment:
 *   - Flat editorial (no shadows, no card outlines)
 *   - Red accents (#cc0000) for sort arrows + delivery pills + focus rings
 *   - Light headline weights (400-500)
 *   - Body font baseline: 18px
 *   - Container queries over media queries (component-level responsive)
 *
 * Uses the existing brand `data-table` + `table-scroll` patterns as a base;
 * this file adds the schedule-specific toolbar, filter UI, sort affordances,
 * and expandable detail rows.
 */

/* ============================================================
   Root container — establishes container query context
   ============================================================ */

.mcc-schedule {
    container-type: inline-size;
    container-name: mcc-schedule;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--color-text, #1a1a1a);
    margin-block: 2rem;

    /* Full-bleed: break out of parent's content-width constraint so the
       table has room to breathe. Page intro/cards stay constrained;
       this section spans near-viewport width with edge gutters. */
    width: 100vw;
    max-width: 100vw;
    margin-inline: calc(50% - 50vw);
    padding-inline: clamp(1rem, 4vw, 2.5rem);
    box-sizing: border-box;
}

.mcc-schedule *,
.mcc-schedule *::before,
.mcc-schedule *::after {
    box-sizing: border-box;
}

/* ============================================================
   Toolbar — search + filters + count
   ============================================================ */

.mcc-schedule__toolbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

@container mcc-schedule (min-width: 640px) {
    .mcc-schedule__toolbar {
        grid-template-columns: minmax(220px, 1fr) auto;
        align-items: start;
    }
}

/* ----- Search ----- */

.mcc-schedule__search-wrap {
    position: relative;
}

.mcc-schedule__search-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.875rem;
    background: #fff;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    transition: border-color 150ms;
}

.mcc-schedule__search-label:focus-within {
    border-color: var(--color-primary, #cc0000);
    outline: 2px solid var(--color-primary, #cc0000);
    outline-offset: -1px;
}

.mcc-schedule__search-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.125rem;
    height: 1.125rem;
    color: #666;
    flex-shrink: 0;
}

.mcc-schedule__search-icon svg {
    width: 100%;
    height: 100%;
}

.mcc-schedule__search-input {
    flex: 1;
    border: 0;
    outline: 0;
    background: transparent;
    font-size: 1rem;
    font-family: inherit;
    color: inherit;
    min-width: 0;
}

.mcc-schedule__search-input::placeholder {
    color: #888;
}

/* ----- Filters ----- */

.mcc-schedule__filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.mcc-schedule__filter {
    appearance: none;
    -webkit-appearance: none;
    background: #fff;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    font-size: 0.9375rem;
    font-family: inherit;
    color: inherit;
    cursor: pointer;
    min-width: 130px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.625rem center;
    background-size: 12px;
}

.mcc-schedule__filter:focus {
    outline: 2px solid var(--color-primary, #cc0000);
    outline-offset: 1px;
    border-color: var(--color-primary, #cc0000);
}

.mcc-schedule__reset {
    background: transparent;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    padding: 0.5rem 0.875rem;
    font-size: 0.9375rem;
    font-family: inherit;
    color: var(--color-primary, #cc0000);
    cursor: pointer;
    transition: background-color 150ms;
}

.mcc-schedule__reset:hover,
.mcc-schedule__reset:focus {
    background: rgba( 204, 0, 0, 0.06 );
    outline: 0;
}

/* ----- Count display ----- */

.mcc-schedule__count {
    grid-column: 1 / -1;
    font-size: 0.9375rem;
    color: #555;
    padding-top: 0.25rem;
}

.mcc-schedule__count strong {
    color: var(--color-text, #1a1a1a);
    font-weight: 600;
}

/* ============================================================
   Table — extends brand `data-table` pattern
   ============================================================ */

.mcc-schedule__table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9375rem;
    table-layout: auto;
}

.mcc-schedule__table thead th {
    background: #fff;
    border-bottom: 2px solid var(--color-primary, #cc0000);
    padding: 0.75rem 0.75rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.8125rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--color-text, #1a1a1a);
    white-space: nowrap;
    vertical-align: bottom;
}

/* Sort buttons inside <th> inherit the uppercase treatment from their parent. */
.mcc-schedule__table thead th .mcc-schedule__sort-btn {
    text-transform: inherit;
    letter-spacing: inherit;
    font-weight: inherit;
    font-size: inherit;
}

.mcc-schedule__table tbody td {
    padding: 0.75rem;
    border-bottom: 1px solid #eaeaea;
    vertical-align: top;
}

/* Column-specific widths and wrap behavior
   — short/fixed-format columns never wrap (dates, times, days, course code, pill)
   — text columns get sensible min-widths so they don't get squeezed */
.mcc-schedule__table tbody td[data-cell="course"],
.mcc-schedule__table tbody td[data-cell="days"],
.mcc-schedule__table tbody td[data-cell="time"],
.mcc-schedule__table tbody td[data-cell="dates"],
.mcc-schedule__table tbody td[data-cell="delivery"],
.mcc-schedule__table tbody td[data-cell="term"] {
    white-space: nowrap;
}

.mcc-schedule__table tbody td[data-cell="title"] {
    min-width: 220px;
}

.mcc-schedule__table tbody td[data-cell="instructor"] {
    min-width: 140px;
}

.mcc-schedule__table tbody td[data-cell="location"] {
    min-width: 130px;
}

.mcc-schedule__row {
    transition: background-color 100ms;
    cursor: pointer;
}

.mcc-schedule__row:hover {
    background-color: rgba( 0, 0, 0, 0.02 );
}

.mcc-schedule__row.is-filtered-out,
.mcc-schedule__row.is-filtered-out + .mcc-schedule__detail-row {
    display: none;
}

.mcc-schedule__row.is-expanded {
    background-color: rgba( 204, 0, 0, 0.03 );
}

.mcc-schedule__row.is-expanded td {
    border-bottom-color: transparent;
}

.mcc-schedule__course-id {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
}

/* When a course code is linkable to the Kenii catalog, wrap it in a subtle
   dotted-underline anchor. Hover lifts to brand color. Clicking the link
   navigates without expanding the row (row-click handler ignores <a>). */
.mcc-schedule__course-link {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dotted rgba( 204, 0, 0, 0.45 );
    transition: color 100ms ease, border-bottom-color 100ms ease;
}

.mcc-schedule__course-link:hover {
    color: var(--color-primary, #cc0000);
    border-bottom-color: var(--color-primary, #cc0000);
}

.mcc-schedule__course-link:focus-visible {
    outline: 2px solid var(--color-primary, #cc0000);
    outline-offset: 3px;
    border-radius: 2px;
}

/* ----- Sort headers ----- */

.mcc-schedule__sort-btn {
    background: transparent;
    border: 0;
    padding: 0;
    margin: 0;
    font: inherit;
    color: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    text-align: left;
}

.mcc-schedule__sort-btn:hover {
    color: var(--color-primary, #cc0000);
}

.mcc-schedule__sort-btn:focus-visible {
    outline: 2px solid var(--color-primary, #cc0000);
    outline-offset: 2px;
}

.mcc-schedule__sort-arrow {
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: 0.125rem;
    opacity: 0.3;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 5px solid currentColor;
    position: relative;
    top: -1px;
}

th.is-sort-asc .mcc-schedule__sort-arrow {
    opacity: 1;
    color: var(--color-primary, #cc0000);
}

th.is-sort-desc .mcc-schedule__sort-arrow {
    opacity: 1;
    color: var(--color-primary, #cc0000);
    border-bottom: 0;
    border-top: 5px solid currentColor;
}

/* ----- Delivery pills ----- */

.mcc-schedule__delivery-pill {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 500;
    background: #f0f0f0;
    color: #444;
    white-space: nowrap;
}

.mcc-schedule__delivery-pill--in,
.mcc-schedule__delivery-pill--wb {
    background: #e7f1ec;
    color: #1f6b3f;
}

.mcc-schedule__delivery-pill--bl,
.mcc-schedule__delivery-pill--hyflex,
.mcc-schedule__delivery-pill--hy {
    background: #f4ecde;
    color: #7a5d1d;
}

.mcc-schedule__delivery-pill--tr,
.mcc-schedule__delivery-pill--f2f {
    background: #fae6e6;
    color: #963030;
}

/* ----- Expand button ----- */

.mcc-schedule__expand-col {
    width: 2.5rem;
}

.mcc-schedule__expand-cell {
    width: 2.5rem;
    text-align: center;
}

.mcc-schedule__expand-btn {
    background: transparent;
    border: 0;
    padding: 0.375rem;
    cursor: pointer;
    color: #666;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color 150ms, transform 150ms;
}

.mcc-schedule__expand-btn:hover,
.mcc-schedule__expand-btn:focus-visible {
    color: var(--color-primary, #cc0000);
    outline: 0;
}

.mcc-schedule__expand-btn[aria-expanded="true"] .mcc-schedule__expand-icon {
    transform: rotate( 180deg );
}

.mcc-schedule__expand-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    transition: transform 150ms;
}

.mcc-schedule__expand-icon svg {
    width: 100%;
    height: 100%;
}

/* ============================================================
   Detail row — definition list grid
   ============================================================ */

.mcc-schedule__detail-row td {
    padding: 0;
    background: rgba( 204, 0, 0, 0.03 );
    border-bottom: 1px solid #eaeaea;
}

.mcc-schedule__detail-grid {
    padding: 1.25rem 1rem 1.5rem;
}

.mcc-schedule__detail-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
    margin: 0;
}

/* Single-column stacked layout works better on desktop too — each field gets
   a clear label + value, easy to scan. Previously this was 2-col which packed
   too tight and looked busy. */
.mcc-schedule__detail-item--full {
    grid-column: 1 / -1;
}

.mcc-schedule__detail-item dt {
    font-size: 0.8125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #666;
    margin-bottom: 0.25rem;
}

.mcc-schedule__detail-item dd {
    margin: 0;
    font-size: 0.9375rem;
    color: var(--color-text, #1a1a1a);
}

.mcc-schedule__meeting-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.mcc-schedule__meeting {
    padding: 0.375rem 0;
    border-bottom: 1px solid rgba( 0, 0, 0, 0.05 );
}

.mcc-schedule__meeting:last-child {
    border-bottom: 0;
}

.mcc-schedule__meeting-type {
    font-weight: 500;
    color: var(--color-primary, #cc0000);
    margin-right: 0.375rem;
}

/* ============================================================
   Empty state
   ============================================================ */

.mcc-schedule__empty-message {
    padding: 2.5rem 1rem;
    text-align: center;
    color: #666;
    font-size: 1rem;
}

.mcc-schedule__link-btn {
    background: transparent;
    border: 0;
    padding: 0;
    color: var(--color-primary, #cc0000);
    text-decoration: underline;
    cursor: pointer;
    font-size: inherit;
    font-family: inherit;
}

.mcc-schedule__link-btn:hover,
.mcc-schedule__link-btn:focus-visible {
    text-decoration: none;
    outline: 0;
}

.mcc-schedule--empty p {
    padding: 2rem 1rem;
    text-align: center;
    color: #666;
}

/* ============================================================
   Responsive — mobile uses card layout with clear visual separation
   ============================================================

   Switched from container query to media query for reliable mobile
   targeting across browsers + cache layers. Container `.mcc-schedule`
   uses width:100vw so it's effectively viewport-scale anyway.

   Mobile card structure:
   ┌────────────────────────────────────┐
   │  CTI-141-50                    [▾]│  ← course code (small) + chevron
   │  Class Title                       │  ← title (prominent)
   │  [Online Instruction]              │  ← delivery pill
   │  Mon · Wed · Fri                   │  ← days
   └────────────────────────────────────┘
*/

@media (max-width: 720px) {
    /* Tighten container, drop full-bleed shenanigans */
    .mcc-schedule {
        padding-inline: 0;
        margin-inline: 0;
        width: auto;
        max-width: 100%;
    }

    /* Toolbar spacing */
    .mcc-schedule__toolbar {
        gap: 0.75rem;
        margin-bottom: 1rem;
    }

    /* Filters → 2-column grid so dropdowns don't wrap awkwardly */
    .mcc-schedule__filters {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }

    .mcc-schedule__filter {
        min-width: 0;
        width: 100%;
    }

    .mcc-schedule__reset {
        grid-column: 1 / -1;
        text-align: center;
    }

    /* Drop horizontal scroll wrapper on mobile (cards are full-width) */
    .table-scroll {
        overflow: visible;
        margin: 0;
    }

    /* Convert table to block flow */
    .mcc-schedule__table,
    .mcc-schedule__table thead,
    .mcc-schedule__table tbody,
    .mcc-schedule__table tr,
    .mcc-schedule__table td {
        display: block;
    }

    .mcc-schedule__table thead {
        display: none;
    }

    /* Restore hidden behavior on tr (display:block overrides HTML hidden) */
    .mcc-schedule__table tr[hidden],
    .mcc-schedule__detail-row[hidden] {
        display: none !important;
    }

    /* Strip table cell styling */
    .mcc-schedule__table tbody td {
        padding: 0;
        border: 0;
    }

    .mcc-schedule__table tbody td[data-cell]::before {
        content: none;
    }

    /* ===== Card: each row becomes a distinct card ===== */
    .mcc-schedule__row {
        position: relative;
        background: #ffffff;
        border: 1px solid #e6e6e6;
        border-radius: 8px;
        padding: 0.875rem 1rem 1rem;
        margin-bottom: 0.625rem;
        transition: border-color 150ms, background-color 150ms;
    }

    .mcc-schedule__row:hover {
        background: #ffffff;
    }

    .mcc-schedule__row.is-expanded {
        background: #fafafa;
        border-color: var(--color-primary, #cc0000);
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
        border-bottom: 0;
        margin-bottom: 0;
    }

    /* Hide cells we surface only in the expanded panel */
    .mcc-schedule__row td[data-cell="term"],
    .mcc-schedule__row td[data-cell="instructor"],
    .mcc-schedule__row td[data-cell="time"],
    .mcc-schedule__row td[data-cell="location"],
    .mcc-schedule__row td[data-cell="dates"] {
        display: none;
    }

    /* Course code — small monospace label, top of card */
    .mcc-schedule__row td[data-cell="course"] {
        padding-right: 2.5rem;  /* reserve space for chevron */
        line-height: 1;
        margin-bottom: 0.375rem;
    }

    .mcc-schedule__row td[data-cell="course"] .mcc-schedule__course-id {
        display: inline-block;
        font-size: 0.75rem;
        font-weight: 500;
        color: #888;
        letter-spacing: 0.03em;
        text-transform: uppercase;
    }

    /* Title — prominent, leaves room for chevron */
    .mcc-schedule__row td[data-cell="title"] {
        font-size: 1.0625rem;
        font-weight: 500;
        line-height: 1.3;
        color: var(--color-text, #1a1a1a);
        padding-right: 2.5rem;
        margin-bottom: 0.625rem;
    }

    /* Delivery pill row */
    .mcc-schedule__row td[data-cell="delivery"] {
        margin-bottom: 0.5rem;
    }

    .mcc-schedule__row td[data-cell="delivery"] .mcc-schedule__delivery-pill {
        font-size: 0.75rem;
        padding: 0.1875rem 0.625rem;
    }

    /* Days — small muted line, no wrap (it's always short) */
    .mcc-schedule__row td[data-cell="days"] {
        font-size: 0.8125rem;
        color: #777;
        line-height: 1.4;
        font-feature-settings: "tnum";
        letter-spacing: 0.02em;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Chevron — top right of card */
    .mcc-schedule__row .mcc-schedule__expand-cell {
        position: absolute;
        top: 0.5rem;
        right: 0.5rem;
        width: auto;
        text-align: right;
    }

    .mcc-schedule__row .mcc-schedule__expand-btn {
        padding: 0.5rem;
    }

    /* ===== Expanded detail panel — sits flush under the row card ===== */
    .mcc-schedule__detail-row {
        background: #fafafa;
        border: 1px solid var(--color-primary, #cc0000);
        border-top: 0;
        border-radius: 0 0 8px 8px;
        margin-bottom: 0.625rem;
    }

    .mcc-schedule__detail-row td {
        padding: 0;
        border: 0;
        background: transparent;
    }

    .mcc-schedule__detail-grid {
        padding: 0 1rem 1rem;
        background: transparent;
        border-radius: 0;
    }

    .mcc-schedule__detail-list {
        grid-template-columns: 1fr;
        gap: 0.875rem;
    }

    /* Empty state padding */
    .mcc-schedule__empty-message {
        padding: 2rem 0.5rem;
    }
}
