/* Clean and flat: white surfaces, 1px slate hairlines, one blue accent.
   Grade and status colours are read by app.js, so they stay 6-digit hex. */
:root {
    --bg: #ffffff;
    --surface-2: #f1f5f9;
    --subtle: #f8fafc;
    --text: #0f172a;
    --muted: #5f6f85;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --accent: #2563eb;
    --accent-soft: #eff6ff;
    --accent-border: #bfdbfe;
    --edge: #94a3b8;
    --node: #ffffff;
    --node-border: #8594a9;  /* 3:1 on the canvas: the dashed "not offered" border is the only cue */
    --taken: #15803d;
    --taken-bg: #dcfce7;
    --open: #2563eb;
    --planned-bg: #dbeafe;
    --warn: #dc2626;
    --ok: #15803d;
    --grade-low: #ef4444;
    --grade-mid: #f59e0b;
    --grade-high: #22c55e;
    --shadow: 0 10px 24px -6px rgba(15, 23, 42, 0.14), 0 2px 4px rgba(15, 23, 42, 0.05);
    --radius: 6px;
    --panel-w: 380px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #020817;
        --surface-2: #1e293b;
        --subtle: #0b1222;
        --text: #f1f5f9;
        --muted: #94a3b8;
        --border: #1e293b;
        --border-strong: #334155;
        --accent: #60a5fa;
        --accent-soft: rgba(96, 165, 250, 0.12);
        --accent-border: rgba(96, 165, 250, 0.35);
        --edge: #64748b;
        --node: #0f172a;
        --node-border: #64748b;
        --taken: #4ade80;
        --taken-bg: #14532d;
        --open: #60a5fa;
        --planned-bg: #1e3a8a;
        --warn: #f87171;
        --ok: #4ade80;
        --grade-low: #f87171;
        --grade-mid: #fbbf24;
        --grade-high: #4ade80;
        --shadow: 0 10px 24px -6px rgba(0, 0, 0, 0.6), 0 2px 4px rgba(0, 0, 0, 0.3);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    font-family: 'Heebo', system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}
input, button { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.warn { color: var(--warn); }
.ok { color: var(--ok); }
kbd {
    font-family: inherit;
    font-size: 11px;
    line-height: 18px;
    min-width: 20px;
    text-align: center;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0 5px;
    background: var(--subtle);
    color: var(--muted);
}
.icon {
    width: 16px; height: 16px;
    fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
    flex-shrink: 0;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* inside containers that clip (scrolling chip bars, the zoom group), draw the ring inward */
.toolbar .chip:focus-visible, .segmented button:focus-visible, .zoom button:focus-visible, #cy:focus-visible { outline-offset: -2px; }

/* Floating surfaces: menus, dropdowns, dialogs */
.card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

/* ── Controls ───────────────────────────────────────────────────────────── */
.btn, .picker-btn {
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover, .picker-btn:hover { background: var(--surface-2); }
.btn[aria-pressed="true"], .btn[aria-expanded="true"] { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent); }
.btn-icon { width: 36px; padding: 0; }
.btn-small { height: 28px; min-width: 28px; padding: 0 8px; font-size: 13px; }
.btn-small.btn-icon { width: 28px; padding: 0; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--accent); }
.btn-quiet:hover { background: var(--accent-soft); }
.badge {
    min-width: 18px; height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--accent);
    color: var(--bg);
    font-size: 11px;
    font-weight: 600;
    display: inline-flex; align-items: center; justify-content: center;
}

.segmented {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    border-radius: 8px;
    background: var(--surface-2);
    flex-shrink: 0;
}
.segmented button {
    height: 28px;
    padding: 0 12px;
    border: none;
    border-radius: 5px;
    background: transparent;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--muted);
    cursor: pointer;
    white-space: nowrap;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px rgba(15, 23, 42, 0.1); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    height: 30px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg);
    font-size: 13.5px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent); font-weight: 500; }
.chip .count { color: var(--muted); font-size: 12px; }
.chip[aria-pressed="true"] .count { color: inherit; }

.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.check.external { display: inline-flex; gap: 6px; }
fieldset { border: none; display: flex; flex-direction: column; }
fieldset > legend, .field > span { font-size: 12.5px; font-weight: 500; color: var(--muted); margin-bottom: 6px; }
.field { display: flex; flex-direction: column; }

/* Picker: dropdowns drawn by the page, so they follow its direction */
.picker { position: relative; min-width: 0; }
.picker-btn { display: flex; align-items: center; justify-content: space-between; gap: 10px; max-width: 100%; text-align: start; }
.picker-btn::after {
    content: "";
    width: 6px; height: 6px;
    border: solid var(--muted);
    border-width: 0 1.5px 1.5px 0;
    transform: translateY(-2px) rotate(45deg);
    flex-shrink: 0;
}
.picker-btn[aria-expanded="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.picker-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-pop {
    position: fixed;
    z-index: 80;
    display: flex;
    flex-direction: column;
    width: max-content;
    max-width: min(560px, calc(100vw - 16px));
    padding: 4px;
}
.picker-search {
    flex-shrink: 0;
    height: 34px;
    margin: 0 0 4px;
    padding: 0 10px;
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    background: transparent;
}
.picker-search:focus { outline: none; }
.picker-list { list-style: none; overflow-y: auto; min-height: 0; outline: none; }
.picker-list [role="option"] { padding: 6px 10px; border-radius: 4px; cursor: pointer; line-height: 1.45; }
.picker-list .active { background: var(--surface-2); }
.picker-list [aria-selected="true"] { color: var(--accent); font-weight: 500; }
.picker-group { padding: 10px 10px 4px; font-size: 12px; font-weight: 500; color: var(--muted); }
.picker-empty { padding: 10px; color: var(--muted); }

/* ── Header: the same bar on every tab; the map adds its own bar under it ── */
.topbar, .toolbar {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    padding: 0 16px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.topbar { height: 56px; gap: 24px; z-index: 30; }
.toolbar { min-height: 52px; gap: 12px; z-index: 25; overflow-x: auto; scrollbar-width: none; }
.toolbar::-webkit-scrollbar { display: none; }
.toolbar .chips { flex-wrap: nowrap; }
/* a faculty may have dozens of units: their chips scroll, the picker next to them keeps its size */
.toolbar > .picker { flex-shrink: 0; }
#deptBar { min-width: 0; overflow-x: auto; scrollbar-width: thin; }
.spacer { flex: 1; }
.count-label { font-size: 13px; color: var(--muted); white-space: nowrap; }
#searchOpen { display: none; }

/* Tabs: text with an underline in the header; a bar at the bottom on phones */
.tabs { display: flex; align-self: stretch; gap: 4px; }
.tabs button {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 10px;
    border: none;
    border-bottom: 2px solid transparent;
    background: none;
    font-size: 14.5px;
    font-weight: 500;
    color: var(--muted);
    cursor: pointer;
    white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-current] { color: var(--text); border-bottom-color: var(--accent); }
.tabs .icon { display: none; }
.tabs button:focus-visible { outline-offset: -4px; }

.brand { display: flex; align-items: center; gap: 10px; color: inherit; flex-shrink: 0; }
.brand:hover { text-decoration: none; }
.logo { width: 28px; height: 28px; }
.logo rect { fill: var(--accent); }
.logo circle { fill: var(--bg); }
.logo path { stroke: var(--bg); stroke-width: 2; fill: none; }
.brand-name { font-size: 17px; font-weight: 700; }

.search { position: relative; flex: 1; max-width: 440px; margin-inline: auto; }
.search input {
    width: 100%;
    height: 36px;
    padding: 0 36px 0 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-icon { position: absolute; top: 50%; inset-inline-start: 12px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-kbd { position: absolute; top: 50%; inset-inline-end: 10px; transform: translateY(-50%); pointer-events: none; }
.search input:focus ~ .search-kbd, .search input:not(:placeholder-shown) ~ .search-kbd { display: none; }
.search-results {
    position: absolute;
    top: calc(100% + 4px);
    inset-inline: 0;
    max-height: min(420px, 70vh);
    overflow-y: auto;
    list-style: none;
    padding: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    z-index: 60;
}
.search-results li { padding: 7px 10px; border-radius: 4px; cursor: pointer; }
.search-results li[aria-selected="true"], .search-results li:hover { background: var(--surface-2); }
.search-results .sub { font-size: 12.5px; color: var(--muted); }

.actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.account { position: relative; }
#accountBtn { padding-inline: 8px 12px; }
.avatar {
    width: 22px; height: 22px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--accent); color: var(--bg); font-size: 12px; font-weight: 600; object-fit: cover;
}
.icon.google { width: 16px; height: 16px; stroke: none; }
.account-menu {
    position: absolute;
    top: calc(100% + 6px);
    inset-inline-end: 0;
    width: 260px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    z-index: 70;
}
.account-menu p { color: var(--muted); margin: 4px 0 6px; }
.account-menu .btn { justify-content: flex-start; }
.account-menu .btn.warn { color: var(--warn); }

/* ── Canvas ─────────────────────────────────────────────────────────────── */
.layout { flex: 1; position: relative; overflow: hidden; background: var(--bg); }
#cy { position: absolute; inset: 0; }
#bands, #margin { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
#margin { z-index: 5; }
.band { position: absolute; left: 0; right: 0; border-top: 1px solid var(--border); }
.band:first-child, .band-label:first-child { border-top-color: transparent; }

/* Band labels sit in a quiet column at the start (right) edge, above the graph */
#margin::before {
    content: "";
    position: absolute;
    top: 0; bottom: 0;
    inset-inline-start: 0;
    width: var(--gutter);
    background: color-mix(in srgb, var(--subtle) 90%, transparent);
    border-inline-end: 1px solid var(--border);
}
#margin:empty::before { display: none; }
.band-label {
    position: absolute;
    inset-inline-start: 0;
    width: var(--gutter);
    max-width: 16rem;
    padding: 10px 16px 10px 12px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
    border: none;
    border-top: 1px solid var(--border);
    background: none;
    color: var(--text);
    text-align: start;
    font: inherit;
}
.band-title { font-size: 14px; font-weight: 600; line-height: 1.35; }
.band-sub { font-size: 12px; color: var(--muted); line-height: 1.45; }
button.band-label { pointer-events: auto; cursor: pointer; }
button.band-label:hover .band-title { color: var(--accent); }

.empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--muted);
    pointer-events: none;
}
.empty .btn { pointer-events: auto; }

.hint {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: calc(100% - 32px);
    display: flex;
    align-items: center;
    gap: 8px;
    padding-block: 5px;
    padding-inline: 14px 5px;
    font-size: 13.5px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    z-index: 12;
}
body.panel-open .hint { left: calc(50% + var(--panel-w) / 2); max-width: calc(100% - var(--panel-w) - 32px); }

/* Filters: a dropdown under their button */
.filters {
    position: absolute;
    top: 8px;
    inset-inline-end: 16px;
    width: 300px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    z-index: 40;
}
.filters .btn-quiet { align-self: flex-start; margin: -4px -8px -6px; }

/* Canvas tools: zoom in the corner, the legend on one line beside it */
.canvas-tools {
    position: absolute;
    bottom: 16px;
    inset-inline-end: 16px;
    max-width: calc(100% - 32px);
    display: flex;
    flex-direction: row-reverse;
    align-items: flex-end;
    gap: 8px;
    z-index: 6;
}
body.panel-open .canvas-tools { inset-inline-end: calc(var(--panel-w) + 16px); max-width: calc(100% - var(--panel-w) - 32px); }
.zoom {
    display: flex;
    flex-shrink: 0;
    overflow: hidden;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.zoom button {
    width: 32px; height: 32px;
    border: none;
    background: transparent;
    font-size: 17px;
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
}
.zoom button + button { border-inline-start: 1px solid var(--border); }
.zoom button:hover { background: var(--surface-2); }
.legend {
    min-height: 34px;
    display: flex;
    align-items: center;
    padding: 6px 12px;
    font-size: 12px;
    color: var(--muted);
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.legend-toggle {
    display: none;
    border: none; background: none; cursor: pointer;
    font-size: 12.5px; font-weight: 500; color: var(--muted);
    gap: 6px; align-items: center;
}
.legend-toggle::after { content: "▾"; transition: transform 0.15s; }
.legend-toggle[aria-expanded="false"]::after { transform: rotate(90deg); }
.legend-body { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.legend-row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.swatch-line { width: 20px; border-top: 1.5px solid var(--edge); }
.swatch-line.alt { border-top-style: dotted; border-top-width: 2px; }
.swatch-line.coreq { border-top-style: dashed; }
.swatch-box { width: 14px; height: 11px; border: 1px solid var(--node-border); border-radius: 3px; background: var(--node); }
.swatch-box.dashed { border-style: dashed; }
.swatch-box.taken { background: var(--surface-2); }
.swatch-box.planned { background: var(--planned-bg); border-color: var(--open); }
.swatch-box.invalid { border: 2px solid var(--warn); }
.swatch-box.taken, .swatch-box.invalid { width: 16px; height: 14px; display: inline-flex; align-items: center; justify-content: center; font-size: 9px; line-height: 1; color: var(--muted); }
.progress-only { display: none !important; }
body.has-progress .progress-only { display: flex !important; }

/* ── Side panel: course, program and planner details, docked to the left edge ── */
.panel {
    position: absolute;
    top: 0;
    bottom: 0;
    inset-inline-end: 0;
    width: var(--panel-w);
    overflow-y: auto;
    padding: 20px 20px 28px;
    background: var(--bg);
    border-inline-start: 1px solid var(--border);
    z-index: 16;
}
.panel .close { position: absolute; top: 16px; inset-inline-end: 16px; }
.panel h2 { font-size: 18px; font-weight: 600; line-height: 1.35; padding-inline-end: 36px; }
.panel h2:focus { outline: none; }  /* focused by script, to start reading a new card from its title */
.panel h3 { font-size: 12.5px; font-weight: 500; color: var(--muted); margin: 22px 0 8px; }
.panel p { line-height: 1.6; }
.card-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { font-size: 12px; padding: 1px 8px; border-radius: 4px; background: var(--surface-2); color: var(--muted); }

.stats {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    margin-top: 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.stat { padding: 10px 12px; min-width: 0; }
.stat + .stat { border-inline-start: 1px solid var(--border); }
.stat b { display: flex; align-items: center; gap: 6px; font-size: 18px; font-weight: 600; line-height: 1.3; font-variant-numeric: tabular-nums; }
.stat > span { font-size: 12px; color: var(--muted); }
.stat .swatch { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.req { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.req .req { padding-inline-start: 12px; border-inline-start: 2px solid var(--border); margin-top: 2px; }
.req-head { font-size: 12.5px; color: var(--muted); }
.course-link { background: none; border: none; padding: 0; cursor: pointer; text-align: start; color: var(--accent); }
.course-link:hover { text-decoration: underline; }
.course-link.done::after { content: " ✓"; color: var(--taken); }
.course-link.planned::after { content: " ◷"; color: var(--open); }
.course-id { color: var(--muted); font-size: 12px; direction: ltr; unicode-bidi: isolate; }
details.more summary, details.about summary { cursor: pointer; font-size: 13px; color: var(--accent); margin-top: 6px; }
details.more[open] summary { margin-bottom: 4px; }
details.about summary { margin-top: 14px; }

.plan-box { margin-top: 18px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--subtle); }
.plan-box p.warn, .plan-box p.ok { font-size: 13px; margin-bottom: 8px; }
.plan-box p.warn:last-child { margin: 8px 0 0; }
.plan-row { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; }
.plan-row .picker-btn { height: 30px; }

.links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.links a {
    height: 32px;
    display: inline-flex;
    align-items: center;
    padding: 0 12px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.links a:hover { background: var(--surface-2); text-decoration: none; }

.hist { display: flex; align-items: flex-end; gap: 3px; height: 100px; direction: ltr; padding-top: 14px; }
.hist .bar { flex: 1; border-radius: 2px 2px 0 0; position: relative; min-height: 1px; }
.hist .bar span { position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--muted); }
.hist-axis { display: flex; gap: 3px; direction: ltr; border-top: 1px solid var(--border); padding-top: 2px; }
.hist-axis span { flex: 1; font-size: 10px; white-space: nowrap; color: var(--muted); text-align: center; }
.trend { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 4px; margin-top: 8px; }
.trend li { font-size: 12.5px; color: var(--muted); }
.trend b { color: var(--text); font-weight: 600; }
dl.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin-top: 22px; line-height: 1.5; }
dl.facts dt { color: var(--muted); }

.note {
    white-space: pre-line;
    font-size: 13px;
    line-height: 1.6;
    background: var(--subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-top: 8px;
}
.section-list { list-style: none; }
.section-list > li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.section-list .row { display: flex; justify-content: space-between; gap: 10px; }
.section-list button.course-link { font-weight: 500; }

/* Planner */
.plan-controls { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.plan-controls .picker-btn { width: 100%; }
.plan-controls .segmented { align-self: flex-start; }
.plan-list { list-style: none; display: flex; flex-direction: column; }
.plan-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 7px 0;
    border-bottom: 1px solid var(--border);
}
.plan-item:last-child { border-bottom: none; }
.plan-item .sub, .progress .sub { font-size: 12px; color: var(--muted); }
.plan-item .sub.warn { color: var(--warn); }
.plan-sem { margin-top: 10px; }
.plan-sem-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); padding: 4px 0; border-bottom: 1px solid var(--border); }
.plan-sem-head b { color: var(--text); font-weight: 600; }
.progress { display: flex; flex-direction: column; gap: 4px; padding: 6px 0; }
.progress-top { display: flex; justify-content: space-between; gap: 10px; }
.progress .sub.ok { color: var(--ok); font-weight: 600; }
.meter { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; display: flex; }
.meter i { display: block; height: 100%; }
.meter .done { background: var(--taken); }
.meter .planned { background: var(--open); opacity: 0.5; }

/* ── My degree: checklist, semesters and program chooser ───────────────── */
.sheet {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    background: var(--bg);
    z-index: 14;
}
body.panel-open .sheet { inset-inline-end: var(--panel-w); }
.sheet-inner { max-width: 880px; margin: 0 auto; padding: 0 24px 64px; }
.sheet-inner.wide { max-width: 1120px; }

/* The page's title: the program (switches it), then the start year and its details */
.page-head { padding-top: 24px; }
.page-head h1 { font-size: 22px; font-weight: 700; line-height: 1.3; }
.program-switch {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    max-width: 100%;
    margin-inline-start: -8px;
    padding: 2px 8px;
    border: none;
    border-radius: var(--radius);
    background: none;
    font: inherit;
    text-align: start;
    cursor: pointer;
}
.program-switch:hover { background: var(--surface-2); }
.program-switch::after {
    content: "";
    width: 8px; height: 8px;
    border: solid var(--muted);
    border-width: 0 2px 2px 0;
    transform: translateY(-3px) rotate(45deg);
    flex-shrink: 0;
}
.page-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; margin-top: 4px; font-size: 13.5px; }
.page-meta .btn-link { font-size: 13.5px; }
.page-meta .picker { margin-inline-start: -10px; }
.page-meta .picker-btn { height: 30px; padding: 0 10px; border-color: transparent; background: none; font-size: 13.5px; font-weight: 400; color: var(--muted); }
.page-meta .picker-btn:hover, .page-meta .picker-btn[aria-expanded="true"] { border-color: var(--border); }
.btn-link { border: none; background: none; padding: 0; cursor: pointer; font-size: 13px; color: var(--accent); }
.btn-link.warn { color: var(--warn); }
.btn-link:hover { text-decoration: underline; }

.summary {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 20px 0 14px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.summary-top { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.summary-total { font-size: 15px; color: var(--muted); }
.summary-total b { font-size: 28px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.summary-side { display: flex; align-items: baseline; gap: 16px; font-size: 13.5px; color: var(--muted); }
.summary-side b { font-size: 18px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.summary .meter { height: 8px; border-radius: 4px; }
.summary-sections { display: flex; flex-wrap: wrap; gap: 6px; }
.section-chip {
    display: inline-flex;
    gap: 6px;
    align-items: baseline;
    padding: 2px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12.5px;
    color: var(--muted);
}
.section-chip:hover { background: var(--surface-2); text-decoration: none; }
.section-chip b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.section-chip.complete { background: var(--taken-bg); border-color: transparent; }
.section-chip.complete b { color: var(--taken); }

.degree-section { margin-top: 26px; scroll-margin-top: 150px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.section-head h2 { font-size: 17px; font-weight: 600; }
.section-head .muted { font-size: 13px; font-variant-numeric: tabular-nums; }

.cat { border: 1px solid var(--border); border-radius: 8px; margin-top: 10px; overflow: hidden; }
.cat-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 9px 14px;
    background: var(--subtle);
}
/* the part's name opens and closes it */
.cat-toggle {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 12px;
    min-width: 0;
    margin: -9px -14px;
    padding: 9px 14px;
    border: none;
    background: none;
    font: inherit;
    text-align: start;
    cursor: pointer;
}
.cat-toggle::before {
    content: "";
    align-self: center;
    width: 6px; height: 6px;
    border: solid var(--muted);
    border-width: 0 1.5px 1.5px 0;
    transform: rotate(135deg);
    transition: transform 0.15s;
}
.cat-toggle[aria-expanded="true"]::before { transform: rotate(45deg); }
.cat-toggle:focus-visible { outline-offset: -2px; }
.cat-title { font-weight: 600; }
.cat-status { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cat.complete .cat-status { color: var(--taken); font-weight: 500; }
.cat > .meter { height: 3px; border-radius: 0; }
.cat > details.about, .cat > details.more { padding: 0 14px 10px; }
.cat:has(.cat-toggle[aria-expanded="false"]) .cat-head { background: var(--bg); }
.cat-body { padding: 12px 14px; }
.cat-body.manual { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }

.rows { list-style: none; }
.row {
    display: grid;
    grid-template-columns: auto 1fr auto 104px;
    align-items: center;
    gap: 12px;
    padding: 7px 14px;
    border-top: 1px solid var(--border);
}
/* the whole cell around the checkbox takes the click */
.row-check { display: flex; align-items: center; justify-content: center; align-self: stretch; margin-block: -7px; margin-inline: -14px -6px; padding-inline: 14px 6px; cursor: pointer; }
.row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--taken); cursor: pointer; }
.row-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; min-width: 0; }
.row.done .course-link { color: var(--text); }
.row-credits { font-size: 12.5px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-status { display: flex; justify-content: flex-end; }
.row-status .picker-btn { height: 28px; padding: 0 8px; font-size: 12.5px; font-weight: 400; color: var(--muted); border-color: transparent; background: none; }
.row-status .picker-btn:hover, .row-status .picker-btn[aria-expanded="true"] { border-color: var(--border); background: var(--bg); }
.row.planned .row-status .picker-btn { color: var(--accent); background: var(--accent-soft); }
.pills { display: flex; flex-wrap: wrap; gap: 4px; flex-basis: 100%; min-width: 0; }
.pill {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;  /* long warnings wrap: phones have no tooltips */
    font-size: 11.5px;
    line-height: 16px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--muted);
}
.pill.warn { background: color-mix(in srgb, var(--warn) 10%, transparent); color: var(--warn); }
input.grade {
    width: 72px;
    height: 28px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    font-variant-numeric: tabular-nums;
}
input.grade:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.row input.grade:placeholder-shown:not(:focus) { background: var(--subtle); border-color: transparent; }
input.grade:invalid { border-color: var(--warn); }
.clear-all { margin-top: 28px; }

/* Semesters: passed courses at the start, then a year per row with semesters א׳ and ב׳ side by side */
.timeline {
    display: grid;
    grid-template-columns: minmax(200px, 1fr) minmax(0, 1.5fr);
    gap: 12px;
    padding-top: 16px;
    align-items: start;
}
.terms { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: start; }
.terms .term { grid-column: var(--col); }
.term { border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.term.passed { background: var(--subtle); }
.term-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.term-head .muted { font-size: 12.5px; font-variant-numeric: tabular-nums; }
.term-list { list-style: none; }
.term-item { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 7px 12px; border-bottom: 1px solid var(--border); }
.term-item.invalid { box-shadow: inset 3px 0 0 var(--warn); }
.term-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; width: 100%; }
.term-empty { padding: 10px 12px; }
.term-add { padding: 8px; }
.term-add .picker-btn { width: 100%; height: 30px; justify-content: center; color: var(--accent); border-style: dashed; }
.term-add .picker-btn::after { display: none; }

/* Program chooser: the page before a program is chosen, and the dialog that switches it */
.chooser-page { padding-top: 28px; }
.chooser-page h1 { font-size: 22px; font-weight: 700; margin-bottom: 14px; }
.chooser-tools { display: flex; flex-direction: column; gap: 10px; }
.degree-split { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.degree-split button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--muted);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
}
.degree-split button:hover { background: var(--surface-2); color: var(--text); }
.degree-split button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent); font-weight: 600; }
.degree-split .count { font-size: 12.5px; font-weight: 400; opacity: 0.8; }
.chooser-search {
    width: 100%;
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
}
.chooser-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chooser-empty { grid-column: 1 / -1; padding: 8px 0; }
.chooser-browse { margin-top: 24px; font-size: 13.5px; }
.chooser-list { list-style: none; margin-top: 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px; }
.chooser-group { grid-column: 1 / -1; margin-top: 14px; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.chooser-item {
    width: 100%;
    min-height: 40px;
    padding: 8px 12px;
    text-align: start;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    cursor: pointer;
}
.chooser-item:hover { border-color: var(--accent-border); background: var(--accent-soft); }
.chooser-item.current { border-color: var(--accent); color: var(--accent); font-weight: 500; }
.program-dialog { width: min(880px, calc(100% - 32px)); max-height: min(720px, calc(100% - 32px)); overflow-y: auto; }
.program-dialog .chooser-list { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

/* Undo messages */
.toast {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 16px;
    font-size: 13.5px;
    white-space: nowrap;
    z-index: 45;
}
.toast .btn-link { font-size: 13.5px; font-weight: 600; }

/* ── Loading ────────────────────────────────────────────────────────────── */
.status {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: var(--bg);
    color: var(--muted);
    z-index: 50;
    transition: opacity 0.3s;
}
.status.done { opacity: 0; pointer-events: none; }
.spinner {
    width: 28px; height: 28px;
    border: 2.5px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Help dialog ────────────────────────────────────────────────────────── */
dialog {
    margin: auto;
    width: min(520px, calc(100% - 32px));
    padding: 20px 22px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(15, 23, 42, 0.4); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.dialog-head h2 { font-size: 17px; font-weight: 600; }
dialog ul { padding-inline-start: 18px; display: flex; flex-direction: column; gap: 6px; line-height: 1.6; }
dialog p { margin-top: 14px; font-size: 12.5px; line-height: 1.6; }

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation-duration: 0.01ms !important; }
}

/* ── Narrow screens (keep in sync with MOBILE in app.js) ────────────────── */
@media (max-width: 760px) {
    /* Header: one row, search behind an icon that opens it over the row */
    .topbar { height: 52px; gap: 8px; padding: 0 12px; }
    .search { display: none; max-width: none; }
    body.searching .search { display: block; }
    body.searching .brand, body.searching .actions { display: none; }
    .search-kbd { display: none; }
    #searchOpen { display: inline-flex; }
    .actions { margin-inline-start: auto; gap: 6px; }
    .account-name { display: none; }

    /* Tabs: a bar at the bottom, within thumb reach */
    body { padding-bottom: calc(56px + env(safe-area-inset-bottom)); }
    .tabs {
        position: fixed;
        inset-inline: 0;
        bottom: 0;
        z-index: 30;
        height: calc(56px + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
        gap: 0;
        background: var(--bg);
        border-top: 1px solid var(--border);
    }
    .tabs button { flex: 1; flex-direction: column; justify-content: center; gap: 2px; border-bottom: none; font-size: 11.5px; }
    .tabs button[aria-current] { color: var(--accent); }
    .tabs .icon { display: block; width: 22px; height: 22px; }

    /* The map's bar: scope and faculty on the first row, the units on the second */
    .toolbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; overflow: visible; }
    .toolbar > *, .toolbar .picker-btn { min-width: 0; }
    .toolbar .spacer, .count-label { display: none; }
    .toolbar > .picker { flex: 1 1 0; }  /* the faculty takes what's left of the first row */
    #faculty { width: 100%; }
    #filtersBtn { position: relative; margin-inline-start: auto; width: 36px; padding: 0; }
    #filtersBtn .btn-text { display: none; }
    #filtersBtn .badge { position: absolute; top: -6px; inset-inline-end: -6px; }
    #electivesBtn { margin-inline-start: auto; }
    #deptBar { order: 1; flex-basis: 100%; overflow-x: auto; scrollbar-width: none; }
    .filters { inset-inline: 8px; width: auto; }

    #margin::before { display: none; }
    .band-label { width: auto; max-width: calc(100% - 16px); flex-direction: row; align-items: baseline; gap: 8px; padding: 6px 12px; border-top: none; }

    .panel {
        top: auto;
        inset-inline: 0;
        width: auto;
        max-height: 62%;
        border-inline-start: none;
        border-top: 1px solid var(--border);
        border-radius: 12px 12px 0 0;
        box-shadow: 0 -8px 24px -8px rgba(15, 23, 42, 0.18);
    }
    body.panel-open .canvas-tools { display: none; }
    .canvas-tools { flex-direction: column; align-items: flex-end; }
    .legend { flex-direction: column; align-items: flex-start; }
    .legend-toggle { display: flex; }
    .legend-toggle[aria-expanded="false"] + .legend-body { display: none; }
    .legend-body { flex-direction: column; margin-top: 6px; }
    .hint, body.panel-open .hint { top: 8px; left: 50%; max-width: calc(100% - 32px); }
    body.panel-open .sheet { inset-inline-end: 0; }
    .sheet-inner { padding-inline: 12px; padding-bottom: 48px; }
    .summary { position: static; padding-top: 14px; }
    .page-head { padding-top: 16px; }
    .page-head h1, .chooser-page h1 { font-size: 19px; }
    .chooser-page { padding-top: 18px; }
    .chooser-list { grid-template-columns: minmax(0, 1fr); }
    .program-dialog { width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; border: none; border-radius: 0; }
    .summary-total b { font-size: 24px; }
    .degree-section { scroll-margin-top: 12px; }
    .row { grid-template-columns: auto 1fr auto; }
    .row-credits { display: none; }
    /* touch-sized controls in the checklist */
    .row-check { min-width: 44px; }
    .row input[type="checkbox"] { width: 20px; height: 20px; }
    .row-status .picker-btn, .row input.grade, .plan-row .picker-btn, .term-add .picker-btn { height: 38px; }
    .timeline, .terms { grid-template-columns: minmax(0, 1fr); }
    .terms .term { grid-column: auto; }
    .term.passed { order: 1; }
    .toast { bottom: 12px; }
}
