* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f4f6f9;
    color: #333;
    line-height: 1.5;
}

.top-bar {
    background-color: #1a252f;
    color: #fff;
    padding: 1.25rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* Both lines scale with the viewport and never wrap. The subtitle is the
   long one — "Department Timetable, AY 2026-27 (Term 1 & Semesters 3, 5, 7)"
   is 62 characters, so at 320px it needs roughly 2.55vw to fit on one line. */
.top-bar h1 {
    font-size: clamp(0.95rem, 4vw, 1.5rem);
    font-weight: 600;
    white-space: nowrap;
}

.top-bar p {
    font-size: clamp(0.5rem, 2.5vw, 0.85rem);
    color: #a0aec0;
    white-space: nowrap;
}

/* Raised from 1400px. At 1400 the five day columns were 232px wide even on a
   1920 monitor — 500px of screen sat unused while course names truncated.
   1600 keeps rows short enough to scan across without losing your place; with
   the rail open the grid gets 1600 minus the rail, with it closed the full
   1600. */
.toolbar,
.workspace {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* ============================================================
   Toolbar — one slim row instead of a 166px filter band
   ============================================================ */

/* Sticks to the top of the viewport so week navigation and Show Filters stay
   reachable however far down the grid you are. Needs an opaque background —
   course cards would otherwise scroll through it. --toolbar-h is measured in
   app.js and is what the day-header row and the rail offset themselves by. */
.toolbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-top: 1rem;
    padding-bottom: 1rem;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 40;
    background: #f4f6f9;
    box-shadow: 0 1px 0 #e2e8f0;
}

.filters-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.9rem;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    background: #fff;
    color: #2d3748;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
}

.filters-toggle:hover {
    background: #edf2f7;
    border-color: #a0aec0;
}

.filters-toggle-icon {
    font-size: 0.95rem;
    color: #718096;
}

/* The grid card has 1.25rem of its own padding, so the table's right edge sits
   that far inside the card. Matching it here lines the button up with the end
   of the Friday header instead of overhanging it. */
#jumpToTodayBtn {
    margin-right: 1.25rem;
}

/* Hamburger and the filter count are phone-only; the arrow + label are the
   desktop shape of the same button. */
.filters-burger,
.filters-count {
    display: none;
}

/* Day tabs and the agenda list are the phone view of the same data. */
.day-tabs,
.agenda-view {
    display: none;
}

.toolbar .week-controls {
    flex: 1;
    justify-content: center;
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

.toolbar .week-controls h2 {
    font-size: 1.05rem;
    font-weight: 600;
    color: #2d3748;
    white-space: nowrap;
}

/* ============================================================
   Filter rail (Titan Eye+ pattern): categories, then that
   category's options, collapsing to give the grid full width
   ============================================================ */

/* Only appears when the current week has nothing to show, pointing at the week
   that does. Breathing room on both sides so it reads as its own line rather
   than as a lid stuck to the toolbar or the grid. */
.week-jump-notice {
    margin: 0.6rem 0 0.9rem;
    padding: 0.5rem 0.75rem;
    border-radius: 5px;
    font-size: 0.82rem;
    font-weight: 600;
    background: #f1f5f9;
    color: #334155;
    border: 1px solid #cbd5e0;
}

.week-jump-notice[hidden] {
    display: none;
}

.workspace {
    display: flex;
    align-items: flex-start;
    gap: 1.25rem;
    padding-bottom: 1.5rem;
}

.workspace-main {
    flex: 1;
    min-width: 0;
}

.filter-rail {
    flex: none;
    width: 310px;
    /* clears the sticky toolbar */
    --rail-top: calc(var(--toolbar-h, 70px) + 1rem);
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    overflow: hidden;
    position: sticky;
    top: var(--rail-top);
}

.workspace.rail-hidden .filter-rail {
    display: none;
}

.rail-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0.9rem;
    border-bottom: 1px solid #edf2f7;
}

.rail-title {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #4a5568;
}

.rail-body {
    display: flex;
    align-items: stretch;
    min-height: 320px;
}

.rail-cats {
    flex: none;
    width: 124px;
    border-right: 1px solid #edf2f7;
    padding: 0.4rem 0;
    background: #fbfdff;
}

.rail-cat {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    width: 100%;
    padding: 0.55rem 0.7rem;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.8rem;
    color: #4a5568;
    text-align: left;
    cursor: pointer;
    line-height: 1.25;
}

.rail-cat:hover {
    background: #f0f4f8;
}

/* Active category gets the inset bar Titan uses, so the options panel beside
   it is unambiguously "the options for this one". */
.rail-cat.is-active {
    background: #ebf8ff;
    color: #2b6cb0;
    font-weight: 700;
    box-shadow: inset 3px 0 0 #3182ce;
}

.rail-count {
    flex: none;
    min-width: 18px;
    padding: 0 0.3rem;
    border-radius: 999px;
    background: #3182ce;
    color: #fff;
    font-size: 0.66rem;
    font-weight: 700;
    text-align: center;
}

.rail-options {
    flex: 1;
    min-width: 0;
    padding: 0.7rem;
    max-height: 60vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.rail-search {
    width: 100%;
    padding: 0.4rem 0.7rem;
    border: 1px solid #cbd5e0;
    border-radius: 999px;
    font-size: 0.8rem;
    font-family: inherit;
    margin-bottom: 0.5rem;
}

.rail-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    padding-bottom: 0.5rem;
    margin-bottom: 0.4rem;
    border-bottom: 1px solid #edf2f7;
}

.rail-list {
    display: flex;
    flex-direction: column;
}

.rail-option,
.multiselect-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.82rem;
    font-weight: 400;
    color: #2d3748;
    padding: 0.32rem 0.3rem;
    border-radius: 4px;
    cursor: pointer;
    margin-bottom: 0;
    line-height: 1.3;
}

.rail-option:hover,
.multiselect-option:hover {
    background: #f7fafc;
}

.rail-option.is-checked {
    color: #2b6cb0;
    font-weight: 600;
}

.multiselect-group + .multiselect-group {
    margin-top: 0.55rem;
    padding-top: 0.45rem;
    border-top: 1px solid #edf2f7;
}

.multiselect-group-title {
    font-size: 0.66rem;
    font-weight: 700;
    color: #a0aec0;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.25rem;
}

.rail-empty,
.multiselect-empty {
    font-size: 0.8rem;
    color: #a0aec0;
    padding: 0.5rem 0.2rem;
}

/* Kept in the DOM so every existing filter behaviour keeps working; the rail
   is only a view onto these controls. */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

/* The filter panel is sticky so it stays pinned while the grid scrolls
   underneath. Deliberately pure CSS rather than a scroll-linked JS handler:
   an earlier JS version changed element heights on scroll, which shifted the
   layout mid-scroll and re-triggered its own handler — visible as jitter. */
.grid-card {
    background: #ffffff;
    border-radius: 8px;
    padding: 1.25rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    margin-bottom: 1.5rem;
}

.week-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #edf2f7;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.week-info h2 {
    font-size: 1.15rem;
    font-weight: 600;
    color: #2d3748;
}

.btn {
    padding: 0.5rem 1rem;
    border: none;
    background-color: #3182ce;
    color: white;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s;
}

.btn:hover {
    background-color: #2b6cb0;
}

.btn-secondary {
    background-color: #718096;
}

.btn-secondary:hover {
    background-color: #4a5568;
}

.filters-row {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
}

.filters-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.reset-btn {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid #cbd5e0;
    background: #fff;
    color: #4a5568;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.2s, color 0.2s, transform 0.2s;
}

.reset-btn:hover {
    background: #edf2f7;
    color: #2d3748;
    transform: rotate(-45deg);
}

.filter-group {
    display: flex;
    flex-direction: column;
}

.filter-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #4a5568;
    margin-bottom: 0.35rem;
}

.filter-group select,
.filter-group input[type="date"] {
    padding: 0.5rem;
    border: 1px solid #cbd5e0;
    border-radius: 5px;
    background: white;
    font-size: 0.9rem;
}

.link-btn {
    background: none;
    border: none;
    color: #3182ce;
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
}

.link-btn:hover {
    color: #2b6cb0;
}

/* NOT a scroll container by default. An overflow-x other than visible makes
   this the scrolling ancestor for everything inside it, and a sticky <thead>
   would then anchor to a box that never scrolls vertically — i.e. it would
   silently stop sticking. Horizontal scrolling is re-enabled below 1200px in
   the media query, where the table can genuinely outgrow its column. */
.table-responsive {
    overflow: visible;
}

table {
    width: 100%;
    border-collapse: collapse;
    /* Lowered from 900px: two-line cards stay legible in narrower columns, so
       the grid can fit all five days on a smaller laptop window without
       scrolling sideways. */
    min-width: 820px;
}

th, td {
    border: 1px solid #e2e8f0;
    padding: 0.5rem;
    vertical-align: top;
    width: 18%;
}

/* Fixed layout gives every day column exactly the same width regardless of
   what's inside it, so cards are a uniform width across the whole grid and a
   long course name clips with an ellipsis instead of stretching its column
   and squeezing the other four days. Combined with the widths below it also
   guarantees all five days fit the viewport with no horizontal scroll. */
#timetableGrid {
    table-layout: fixed;
}

th.time-col, td.time-label {
    width: 100px;
    background-color: #f7fafc;
    text-align: center;
    font-weight: 600;
    font-size: 0.85rem;
    color: #4a5568;
}

/* The five day columns split whatever is left, evenly. */
#timetableGrid th:not(.time-col) {
    width: calc((100% - 100px) / 5);
}

/* Rows are much shorter now that cards are two lines, so "14:15 - 15:10" was
   wrapping onto three lines and making the time column the tallest thing in
   the row. Keep it on one line, and give it real breathing room either side —
   at the old 84px width with 3px padding the label sat hard against the first
   day column. */
td.time-label {
    white-space: nowrap;
    font-size: 0.72rem;
    padding: 0.4rem 0.65rem;
    vertical-align: top;
}

/* The day header row pins under the toolbar, so you always know which column
   is which no matter how far down the day you have scrolled. */
thead th {
    position: sticky;
    top: var(--toolbar-h, 70px);
    z-index: 30;
}

th {
    background-color: #2d3748;
    color: white;
    text-align: center;
    padding: 0.75rem 0.5rem;
    font-size: 0.95rem;
}

.th-date {
    font-weight: 400;
    opacity: 0.75;
}

/* ---- Today ------------------------------------------------------------
   Amber, everywhere, and amber ONLY. The grid already spends green on
   semester courses and blue on term courses, so a blue "today" competed with
   the card colours for the same meaning — a tinted column read as "these are
   term classes". Amber is the one hue the legend doesn't use, which leaves
   today unambiguous at a glance.

   Laptop view: today's column reads as one vertical band — an amber bar under
   the header cell, and a warm tint running the column's full height so the day
   stays findable once the header has scrolled under the toolbar. Only ever one
   column, and only when the week on screen is the real current week (see
   todayColumn() in app.js), so paging forward leaves the grid with no
   highlight at all rather than a misleading one. */
#timetableGrid th.is-today {
    /* Header background stays the same dark as the other four days. The bar
       and the pill carry the whole signal, so nothing here can be mistaken
       for a course colour. */
    box-shadow: inset 0 -4px 0 #f6ad55;
}

#timetableGrid th.is-today .th-date {
    opacity: 0.9;
}

/* A word, not just a colour — colour alone isn't readable for everyone, and on
   a projector blue-on-dark can be hard to tell apart. */
.today-pill {
    display: inline-block;
    margin-left: 0.35rem;
    padding: 1px 6px;
    border-radius: 999px;
    background: #f6ad55;
    color: #2a2a2a;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    vertical-align: 1px;
}

/* Chip beside the week label whenever the displayed week contains today, so
   "no highlight in the grid" is never ambiguous. Amber like the rest of the
   today treatment, not blue — blue is the term-course colour. */
.week-controls.is-current-week #currentWeekDisplay::after {
    content: "This week";
    margin-left: 0.45rem;
    padding: 2px 7px;
    border-radius: 999px;
    background: #fffaf0;
    border: 1px solid #fbd38d;
    color: #b7791f;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    white-space: nowrap;
    vertical-align: 2px;
}

.day-cell {
    min-height: 80px;
    background-color: #ffffff;
}

/* No column tint. It was tried in two colours and both lost: a pale blue
   column read as "these are term classes", and even a neutral cream put a
   second background behind cards whose own backgrounds are the legend. The
   header bar alone is enough — nothing in the cells competes with the cards,
   and the header row is sticky, so the marker stays on screen the whole way
   down the day anyway. */

/* Course Cards in Grid
   Two lines: course name (+ section letter), then faculty · room. Tight
   geometry on purpose — Monday 14:15 stacks 11 sections, so every pixel of
   card height is multiplied by 11 in the tallest row. Anything that doesn't
   fit here is one click away in .detail-panel. */
.course-card {
    padding: 4px 6px;
    border-radius: 4px;
    margin-bottom: 4px;
    font-size: 0.8rem;
    line-height: 1.2;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    border-left: 3px solid #cbd5e0;
    cursor: pointer;
}

/* A meeting of a filtered-in course that happens in a DIFFERENT room. Shown so
   the course reads as one thing across the week, faded and inert so it cannot
   be mistaken for something happening in the room you filtered by. */
.course-card.is-ghost {
    opacity: 0.45;
    background-image: repeating-linear-gradient(
        45deg,
        rgba(0, 0, 0, 0.035),
        rgba(0, 0, 0, 0.035) 5px,
        transparent 5px,
        transparent 10px
    );
    box-shadow: none;
}

/* Still clickable, so it still responds to a pointer. */
.course-card.is-ghost:hover {
    opacity: 0.75;
    box-shadow: 0 2px 6px rgba(0,0,0,0.14);
}

.course-card:not(.is-ghost):hover {
    box-shadow: 0 2px 6px rgba(0,0,0,0.16);
}

.course-card:focus-visible {
    outline: 2px solid #2b6cb0;
    outline-offset: 1px;
}

/* Semester Course Style (Green) */
.course-card.semester {
    background-color: #f0fff4;
    border-left-color: #38a169;
    color: #22543d;
}

/* Term / Block Course Style (Blue) */
.course-card.term {
    background-color: #ebf8ff;
    border-left-color: #3182ce;
    color: #1a4971;
}

/* Line 1 — the course name, plus the section letter.

   A flex row, not a single clipped block. The clipping lives on .course-name
   alone so an ellipsis can only ever mean "this name was cut"; the badge is
   flex:none and sits outside the clipped box, so it is never truncated and
   never triggers a misleading ellipsis of its own. */
.course-card .title {
    display: flex;
    align-items: baseline;
    font-weight: 700;
    font-size: 0.72rem;
}

.course-card .course-name {
    flex: 0 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Line 2 — "Ketan Kulkarni · ARB002". */
.course-card .meta {
    font-size: 0.66rem;
    opacity: 0.78;
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 600;
    margin-top: 0.25rem;
}

.badge-visiting {
    background: #feebc8;
    color: #7b341e;
}

.badge-full-time {
    background: #e2e8f0;
    color: #2d3748;
}

.badge-adjunct {
    background: #e9d8fd;
    color: #553c9a;
}

.badge-venue {
    background: #edf2f7;
    color: #4a5568;
    margin-left: 0.25rem;
}

/* Section letter rides on the title line: 16 courses run more than one
   section and some share a teacher, so without it "Service Design / Avani
   Chaturvedi" appears twice with nothing to tell B from C.

   Outlined rather than filled. A filled chip has to out-contrast the card it
   sits on, and the old pale-blue fill (#ebf4ff) scored 1.03:1 against the
   pale-blue Term card — invisible. A border only has to read as a line, and
   taking its colour from currentColor means it inherits each card type's own
   ink: blue-grey on Term cards, green-grey on Semester ones, ~3:1 against the
   card either way, from one rule that keeps working if a third card type is
   ever added.

   flex:none keeps it out of the name's clipping — see .course-name above. */
.badge-section {
    flex: none;
    background: transparent;
    color: inherit;
    border: 1px solid currentColor;
    opacity: 0.62;
    margin-left: 0.3rem;
    margin-top: 0;
    padding: 0 0.26rem;
    font-size: 0.62rem;
    line-height: 1.35;
}

.badge-semester {
    background: #e6fffa;
    color: #22543d;
}

.badge-term {
    background: #ebf8ff;
    color: #1a4971;
}

/* ============================================================
   Course detail panel — everything the two-line card can't show.
   ============================================================ */

.detail-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(26, 32, 44, 0.35);
    z-index: 90;
}

.detail-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 340px;
    max-width: 92vw;
    background: #fff;
    box-shadow: -10px 0 30px rgba(0,0,0,0.18);
    padding: 1.5rem 1.4rem;
    overflow-y: auto;
    z-index: 100;
    transform: translateX(12px);
    opacity: 0;
    transition: transform 0.16s ease, opacity 0.16s ease;
}

.detail-panel.open {
    transform: translateX(0);
    opacity: 1;
}

.detail-close {
    float: right;
    border: none;
    background: transparent;
    font-size: 1.4rem;
    line-height: 1;
    color: #a0aec0;
    cursor: pointer;
    padding: 0 0.2rem;
}

.detail-close:hover { color: #2d3748; }

.detail-code {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #2b6cb0;
    text-transform: uppercase;
}

.detail-title {
    font-size: 1.15rem;
    line-height: 1.25;
    margin: 0.3rem 0 0.7rem;
    color: #1a202c;
}

.detail-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-bottom: 0.9rem;
}

/* No text-transform: labels arrive correctly cased from FACULTY_TYPES.
   `capitalize` was rendering "Full-time" as "Full-Time". */
.detail-badges .badge { margin-top: 0; }

.detail-row {
    display: flex;
    gap: 0.75rem;
    font-size: 0.82rem;
    padding: 0.5rem 0;
    border-top: 1px solid #edf2f7;
}

.detail-key {
    flex: none;
    width: 92px;
    color: #a0aec0;
}

.detail-val {
    color: #2d3748;
    font-weight: 500;
    line-height: 1.45;
}

.detail-dim { color: #a0aec0; font-weight: 400; }

/* Sits under the dates: says how much of the term the section actually runs,
   in weeks, instead of a label the reader has to decode. */
.detail-note {
    display: block;
    font-weight: 400;
    font-size: 0.76rem;
    color: #a0aec0;
    margin-top: 1px;
}

/* Sessions list — each meeting carries its own room, because a section can
   sit in a different room on different days. */
.session-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.session-item {
    padding: 0.3rem 0 0.3rem 0.6rem;
    border-left: 2px solid #e2e8f0;
    margin-bottom: 0.3rem;
}

.session-item:last-child { margin-bottom: 0; }

.session-when {
    display: block;
    font-weight: 600;
    color: #2d3748;
}

.session-where {
    display: block;
    font-weight: 400;
    font-size: 0.78rem;
    color: #718096;
    margin-top: 1px;
}


.day-cell.holiday-cell {
    background-color: #f7f7f7;
    background-image: repeating-linear-gradient(
        45deg,
        rgba(0, 0, 0, 0.03),
        rgba(0, 0, 0, 0.03) 8px,
        transparent 8px,
        transparent 16px
    );
}

.holiday-note {
    font-size: 0.75rem;
    font-weight: 600;
    color: #975a16;
    background: #fefcbf;
    border-radius: 4px;
    padding: 0.25rem 0.4rem;
    text-align: center;
}

.swipe-hint {
    display: none;
    font-size: 0.75rem;
    color: #718096;
    text-align: center;
    margin-bottom: 0.5rem;
}

/* Mobile: keep the day-by-day grid (rather than switching to a list view),
   but make the horizontal scroll snap one day at a time, pin the time
   column so it stays visible while swiping, and shrink everything to fit. */
@media (max-width: 640px) {
    .top-bar {
        padding: 1rem 1.25rem;
    }

    .top-bar h1 {
        font-size: 1.15rem;
    }

    .top-bar p {
        font-size: 0.75rem;
    }

    .toolbar,
    .workspace {
        padding: 0 0.5rem;
    }

    .toolbar {
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
        gap: 0.6rem;
    }

    /* One row: hamburger, week arrows, week label, jump. The arrows lose
       their words (font-size:0 on the button, glyph via ::after) so the week
       label keeps the space instead of wrapping onto a third line. */
    .toolbar {
        flex-wrap: nowrap;
        gap: 0.4rem;
    }

    .toolbar .week-controls {
        flex: 1;
        min-width: 0;
        gap: 0.3rem;
    }

    .toolbar .week-controls h2 {
        font-size: 0.78rem;
        text-align: center;
        flex: 1;
        min-width: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #prevWeekBtn,
    #nextWeekBtn {
        font-size: 0;
        padding: 0.4rem 0.6rem;
        flex: none;
    }

    #prevWeekBtn::after { content: "\2039"; font-size: 1.15rem; line-height: 1; }
    #nextWeekBtn::after { content: "\203A"; font-size: 1.15rem; line-height: 1; }

    /* Short words beat an icon here: a circular arrow gave no clue that it
       jumps to the current week. Full wording stays in title/aria-label. */
    #jumpToTodayBtn {
        font-size: 0;
        padding: 0.3rem 0.45rem;
        margin-right: 0;
        flex: none;
        align-self: center;
        border-radius: 6px;
    }

    /* Two short lines rather than one long one, so the button stays narrow
       next to the week label. pre-line renders the \n in data-short. */
    #jumpToTodayBtn::after {
        content: attr(data-short);
        display: block;
        font-size: 0.62rem;
        font-weight: 600;
        line-height: 1.1;
        white-space: pre-line;
        text-align: center;
    }

    /* Fixed square rather than stretching to the toolbar's full height. */
    .filters-toggle {
        flex: none;
        align-self: center;
        width: 38px;
        height: 38px;
        padding: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0.25rem;
    }

    .filters-burger {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 1.05rem;
        line-height: 1;
    }

    /* With a count badge the button needs a little more room. */
    .filters-toggle:has(.filters-count:not([hidden])) {
        width: auto;
        padding: 0 0.5rem;
    }

    .grid-card {
        padding: 0.85rem;
    }


    /* ============================================================
       Phone: one day at a time, filters behind the hamburger
       ============================================================ */

    /* The week grid is what a 390px screen cannot do well, so it goes away
       entirely and the agenda takes over — no horizontal scrolling at all. */
    .table-responsive,
    .swipe-hint {
        display: none;
    }

    /* Pins under the sticky toolbar, so the week and the day you are looking
       at stay on screen however far down the day you scroll. */
    .day-tabs {
        display: flex;
        background: #fff;
        border: 1px solid #e2e8f0;
        border-radius: 8px;
        overflow: hidden;
        margin-bottom: 0.85rem;
        position: sticky;
        top: var(--toolbar-h, 56px);
        z-index: 35;
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    }

    .day-tab {
        flex: 1;
        padding: 0.5rem 0.15rem;
        border: none;
        border-bottom: 2px solid transparent;
        background: transparent;
        font-family: inherit;
        font-size: 0.78rem;
        font-weight: 600;
        color: #718096;
        cursor: pointer;
        line-height: 1.25;
    }

    .day-tab span {
        display: block;
        font-size: 0.66rem;
        font-weight: 400;
        color: #a0aec0;
    }

    .day-tab.is-active {
        color: #2b6cb0;
        border-bottom-color: #3182ce;
        background: #f7fbff;
    }

    /* Two states, two languages. The tab you TAPPED is the blue-underlined
       one; TODAY is the amber one. They are usually the same tab (the phone
       view opens on today) but must stay tellable apart the moment you tap
       another day, or swipe to another week where nothing is today. */
    /* Text and the cap bar only — no fill, matching the desktop header where
       the bar alone marks today. */
    .day-tab.is-today {
        color: #b7791f;
    }

    .day-tab.is-today span {
        color: #b7791f;
        font-weight: 700;
    }

    /* Amber cap along the top edge — doesn't compete with the blue active
       underline along the bottom, so a tab can wear both at once. */
    .day-tab.is-today::before {
        content: "";
        display: block;
        height: 3px;
        margin: -0.5rem -0.15rem 0.35rem;
        background: #f6ad55;
    }

    /* Phone toolbar is tight and the "Today" tab already says it. */
    .week-controls.is-current-week #currentWeekDisplay::after {
        display: none;
    }

    .agenda-view {
        display: block;
    }

    .agenda-slot {
        display: flex;
        gap: 0.7rem;
        padding: 0.5rem 0;
        border-top: 1px solid #edf2f7;
    }

    .agenda-slot:first-child {
        border-top: none;
        padding-top: 0;
    }

    .agenda-time {
        flex: none;
        width: 52px;
        font-size: 0.7rem;
        font-weight: 700;
        color: #4a5568;
        padding-top: 0.2rem;
        line-height: 1.3;
    }

    .agenda-time em {
        display: block;
        font-style: normal;
        font-weight: 400;
        color: #a0aec0;
    }

    /* Full width for the card, which is the whole point of dropping the grid:
       nothing truncates. */
    .agenda-body {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        gap: 0.35rem;
    }

    .agenda-body .course-card {
        margin-bottom: 0;
        padding: 0.45rem 0.55rem;
    }

    .agenda-body .course-card .title {
        font-size: 0.8rem;
    }

    .agenda-body .course-card .meta {
        font-size: 0.72rem;
    }

    /* Names have room here, so let a long one wrap rather than clip. */
    .agenda-body .course-name {
        white-space: normal;
        overflow: visible;
    }

    .agenda-empty {
        font-size: 0.82rem;
        color: #a0aec0;
        padding: 1rem 0.2rem;
        text-align: center;
    }

    /* ---- the toggle becomes a hamburger ---- */
    .filters-burger {
        display: inline;
        font-size: 1.05rem;
        line-height: 1;
    }

    .filters-toggle-icon,
    #toggleFiltersLabel {
        display: none;
    }

    .filters-count {
        display: inline-block;
        min-width: 16px;
        padding: 0 0.28rem;
        border-radius: 999px;
        background: #3182ce;
        color: #fff;
        font-size: 0.64rem;
        font-weight: 700;
        text-align: center;
    }

    .filters-count[hidden] {
        display: none;
    }

    /* ---- the rail becomes a left drawer ---- */
    .rail-scrim {
        position: fixed;
        inset: 0;
        background: rgba(26, 32, 44, 0.45);
        z-index: 70;
    }

    .rail-scrim[hidden] {
        display: none;
    }

    .filter-rail {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 86%;
        max-width: 330px;
        border-radius: 0;
        box-shadow: 6px 0 24px rgba(0, 0, 0, 0.2);
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        z-index: 80;
        display: flex;
        flex-direction: column;
    }

    body.drawer-open .filter-rail {
        transform: translateX(0);
    }

    /* The desktop "collapsed" state must not hide the drawer on a phone —
       there it is simply off-canvas until the hamburger opens it. */
    .workspace.rail-hidden .filter-rail {
        display: flex;
    }

    .rail-body {
        flex: 1;
        min-height: 0;
    }

    .rail-options {
        max-height: none;
    }

    .swipe-hint {
        display: block;
    }

    .table-responsive {
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 640px;
    }

    th,
    td {
        padding: 0.35rem;
        font-size: 0.8rem;
    }

    /* Below 1200px the table can outgrow its column, so the wrapper becomes a
       horizontal scroller again. That also means the sticky day headers stop
       sticking here — a scroll container can only host one sticky context —
       which is the accepted trade at this size. */
    th.time-col,
    td.time-label {
        position: sticky;
        left: 0;
        z-index: 31;
        width: 62px;
        min-width: 62px;
    }

    /* Phones deliberately opt out of "all five days fit": 130px columns would
       be unreadable, so the grid scrolls horizontally one day at a time and
       the fixed desktop column width is released. */
    #timetableGrid {
        table-layout: auto;
    }

    td.day-cell,
    #timetableGrid th:not(.time-col) {
        scroll-snap-align: start;
        min-width: 130px;
        width: auto;
    }

    .course-card {
        padding: 0.35rem;
        font-size: 0.72rem;
    }

    /* The card is already down to two lines on desktop, so mobile keeps both
       — hiding either would leave a course with no name or no owner. Only the
       type scale comes down. */
    .course-card .title {
        font-size: 0.7rem;
    }

    .course-card .meta {
        font-size: 0.64rem;
    }

    /* A centred dialog rather than a near-fullscreen sheet: it sizes to its
       own content (a two-session course is a short box), so the grid stays
       visible around it and the popup reads as "more about this card" instead
       of a new screen. Dismissed by the X or by tapping outside. */
    .detail-panel {
        top: 50%;
        left: 50%;
        right: auto;
        bottom: auto;
        width: min(92vw, 420px);
        max-width: none;
        height: auto;
        max-height: 78vh;
        border-radius: 12px;
        padding: 1.1rem 1.05rem;
        box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
        transform: translate(-50%, -50%) scale(0.97);
    }

    .detail-panel.open {
        transform: translate(-50%, -50%) scale(1);
    }

    .detail-title {
        font-size: 1.05rem;
    }

    .detail-row {
        font-size: 0.8rem;
        padding: 0.45rem 0;
    }

    .detail-key {
        width: 82px;
    }
}

/* Below this the table (min-width 820px) can no longer fit beside an open
   rail: viewport - 32 page padding - 310 rail - 20 gap - 40 card padding.
   That works out at ~1222px, so 1240 leaves a margin. Under it the wrapper
   scrolls horizontally again, which costs the sticky day headers — a scroll
   container can only anchor one sticky context. */
@media (max-width: 1240px) {
    .table-responsive {
        overflow-x: auto;
    }
}

/* ============================================================
   Jump button: shown only when you have paged away from the current week.
   On the desktop it keeps its space (visibility) so the week controls stay
   centred; on a phone it collapses so the week label gets the room.
   ============================================================ */
#jumpToTodayBtn.is-hidden {
    visibility: hidden;
    pointer-events: none;
}

@media (max-width: 640px) {
    #jumpToTodayBtn.is-hidden {
        display: none;
    }
}

/* Notice when the sheet can't be reached (cached copy) or can't be read. */
.data-notice {
    margin: 0 0 0.75rem;
    padding: 0.6rem 0.9rem;
    border-radius: 6px;
    background: #fffaf0;
    border: 1px solid #fbd38d;
    color: #744210;
    font-size: 0.85rem;
}

.data-notice.is-error {
    background: #fff5f5;
    border-color: #feb2b2;
    color: #742a2a;
}
