/* Shared foundation, split out of the old styles.css: theme tokens, reset,
   app layout, sidebar, main, forms, buttons, lists, badges, tables, modals
   (source, document viewer, chat history), toast, shared chat bubbles and the
   top bar. Loads first; every feature sheet after it relies on these tokens. */

/* Two-tone: a deep navy rail against a white workspace. The navigation is
   permanent furniture, so it carries the colour; the content area stays white
   so the work itself is what you look at. Blue accents are reserved for things
   you can act on. Dark mode is opt-in only. */
:root {
  /* The rail — its own scale, independent of the content surface. */
  --rail: #10233f;
  --rail-2: #1a3357;
  --rail-text: #cdd9ea;
  --rail-text-strong: #ffffff;
  --rail-border: #21395c;
  --rail-accent: #63a4ff;

  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f4f7fb;
  --border: #e1e8f0;
  --text: #10233b;
  --text-muted: #5b6b80;
  --accent: #1857b6;
  --accent-hover: #14488f;
  --accent-soft: #e4edfa;
  --on-accent: #ffffff;
  --danger: #b3261e;
  --success: #16704a;
  --warning: #96591a;
  --radius: 3px;
  --shadow: none;

  /* Design tokens (issue #16 plan item 7). Use these instead of literals.
     Spacing: a 4px scale; --sp-0 (2px) only for hairline chip padding. */
  --sp-0: 2px; --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px;
  --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px; --sp-16: 64px;
  /* Type in rem (11 12 13 14 15 17 20 24px at a 16px root), so a larger
     browser font size scales every box that holds text. */
  --fs-2xs: .6875rem; --fs-xs: .75rem; --fs-sm: .8125rem; --fs-md: .875rem;
  --fs-body: .9375rem; --fs-lg: 1.0625rem; --fs-xl: 1.25rem; --fs-2xl: 1.5rem;
  --lh-tight: 1.25; --lh: 1.5; --lh-loose: 1.6;
  --label-tracking: .06em;
  /* Controls: 40px and 32px at a 16px root; 44px touch target. */
  --control-h: 2.5rem; --control-h-sm: 2rem; --target-touch: 2.75rem;
  --modal-sm: 440px; --modal-md: 560px; --modal-lg: 760px;
  --measure: 72ch;
  /* Page side gutter of .main and .topbar (and anything that lines up with
     them): 34px beside the sidebar, 16px once it becomes the phone strip. */
  --gutter: 34px;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  /* Status pairs shared by badges, calendar events, seats and ratings. */
  --status-bad-bg: #fee2e2; --status-bad-fg: #b91c1c;
  --status-warn-bg: #fef3c7; --status-warn-fg: #b45309;
  --status-ok-bg: #dcfce7; --status-ok-fg: #15803d;
  --status-info-bg: #ede9fe; --status-info-fg: #6d28d9;
  /* The final-exam marker, and text on it and on --danger (issue #16 F-34). */
  --final: #6d28d9; --on-final: #ffffff; --on-danger: #ffffff;
}
@media (pointer: coarse) { :root { --control-h-sm: var(--target-touch); } }
@media (max-width: 760px) { :root { --gutter: 16px; } }

/* Dark: same blue, carried onto navy rather than neutral grey. */
:root[data-theme="dark"] {
  --rail: #08111d;
  --rail-2: #142338;
  --rail-text: #9db0c9;
  --rail-text-strong: #ffffff;
  --rail-border: #1b2c44;
  --rail-accent: #6ba4f0;
  --bg: #0b1421;
  --surface: #111d2e;
  --surface-2: #18273c;
  --border: #24374f;
  --text: #e8eef6;
  --text-muted: #93a5bb;
  --accent: #6ba4f0;
  --accent-hover: #8ab8f5;
  --accent-soft: #16304f;
  --on-accent: #08121e;
  --danger: #e5766c;
  --success: #4bbd8c;
  --warning: #d9a441;
  --shadow: none;
  --status-bad-bg: #451a1a; --status-bad-fg: #f87171;
  --status-warn-bg: #422f06; --status-warn-fg: #fbbf24;
  --status-ok-bg: #14351f; --status-ok-fg: #4ade80;
  --status-info-bg: #322046; --status-info-fg: #c4b5fd;
  /* White on #7c3aed is 5.7:1; the dark --on-accent on it was 3.3:1. The
     dark --danger is light, so its count text is dark (F-34). */
  --final: #7c3aed; --on-final: #ffffff; --on-danger: #08121e;
}
/* No automatic dark mode. The app is a white surface by default and only
   goes dark when someone actually picks Dark from the account menu — matching
   the OS silently made it dark for most people, which is not what this is. */

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

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-body);
  line-height: var(--lh);
  /* A long URL or unbroken word breaks inside its own box instead of pushing
     the page sideways (issue #16 F-02). break-word, not anywhere: it leaves
     min-content sizes alone, so buttons, badges and table cells in tight flex
     rows never start breaking mid-word. Text that must shrink inside a flex
     or grid item sets anywhere on itself. */
  overflow-wrap: break-word;
}

/* Base heading scale for headings with no class of their own (issue #16
   F-79). :where() keeps it at zero specificity, so any rule that styles a
   heading, even a bare `.card h3`, still wins. Size only: weight and line
   height stay as the browser and the body set them, so page titles that a
   descendant rule sizes keep their 700 weight and their height. */
:where(h1:not([class])) { font-size: var(--fs-2xl); }
:where(h2:not([class])) { font-size: var(--fs-xl); }
:where(h3:not([class])) { font-size: var(--fs-lg); }
:where(h4:not([class])) { font-size: var(--fs-body); }

/* One small-caps label look for every section and column label (issue #16
   F-81). It sits early so a later rule can still move or recolour one
   label (the sidebar heads keep their rail colour, see .nav-group-head). */
.eyebrow, th, .nav-group-head, .campus-group-title, .course-section, .assess-label,
.timeline-group-title, .grade-summary-label, .qb2-label, .qbank-label, .landing-section-head,
.calgrid-dow, .fair-stat-l, .fair-sector-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--label-tracking);
  text-transform: uppercase;
  color: var(--text-muted);
}

.app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--rail);
  border-right: 0;
  color: var(--rail-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

/* The brand doubles as the Home button: hover lightens it like a nav item.
   var(--rail-2) is lighter than the rail in both themes. */
.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-4);
  font-weight: 700;
  font-size: var(--fs-lg);
  color: var(--rail-text-strong);
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.12s ease;
}
.brand:hover { background: var(--rail-2); }

.brand-icon { font-size: var(--fs-xl); }
/* The mark is icons/app.svg, the same artwork as the Dock icon, so the app
   looks like itself in the sidebar and on the desktop. It carries its own
   navy plate and rounded corners, so no background or letterform here. */
.brand-mark {
  display: block;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}
.brand-name { font-size: var(--fs-md); font-weight: 600; letter-spacing: -0.01em; color: var(--rail-text-strong); }

/* min-height:0 lets the nav shrink inside the 100vh flex column and scroll,
   so a long class list can't push the footer off-screen. The rail is dark
   in both themes (see "Two-tone shell" below), but this scrollbar sits
   above that rule in the cascade, so it'd otherwise paint the browser's
   default light-mode scrollbar over navy — a pale, chunky bar. */
.nav {
  flex: 1; min-height: 0; overflow-y: auto; padding: var(--sp-2);
  display: flex; flex-direction: column; gap: var(--sp-0);
  color-scheme: dark;
  scrollbar-width: thin;
  scrollbar-color: var(--rail-border) transparent;
}
.nav::-webkit-scrollbar { width: 6px; }
.nav::-webkit-scrollbar-track { background: transparent; }
.nav::-webkit-scrollbar-thumb { background: var(--rail-border); border-radius: 3px; }
.nav::-webkit-scrollbar-thumb:hover { background: var(--rail-accent); }

/* A list taller than the rail fades out at the bottom edge, so a cut-off
   Classes list reads as "more below". The fade is tied to the scroll
   position: it shrinks to nothing at the end of the list and is absent when
   nothing overflows (an inactive scroll timeline leaves --nav-fade at 0). */
@property --nav-fade {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}
@keyframes nav-fade { from { --nav-fade: 40px; } to { --nav-fade: 0px; } }
@supports (animation-timeline: scroll()) {
  .nav {
    -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - var(--nav-fade)), transparent);
    mask-image: linear-gradient(to bottom, #000 calc(100% - var(--nav-fade)), transparent);
    animation: nav-fade linear both;
    animation-timeline: scroll(self block);
  }
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: 4px;
  color: var(--rail-text);
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  font-size: var(--fs-md);
  text-align: left;
  width: 100%;
  position: relative;
}

.nav-item:hover { background: var(--rail-2); color: var(--rail-text-strong); }
.nav-item.active {
  background: var(--rail-2);
  color: var(--rail-text-strong);
  font-weight: 600;
}
/* The active marker: a short accent bar on the left edge that fades in. */
.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 2px;
  border-radius: 2px;
  background: var(--rail-accent);
  animation: fade 0.16s ease both;
}

/* ---------- Classes tree (sidebar) ---------- */
.nav-group {
  margin-top: var(--sp-2);
  padding-top: var(--sp-2);
  border-top: 1px solid var(--rail-border);
}

.nav-group-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
  color: var(--rail-text);
  opacity: 0.72;
}
.nav-group-head:hover { color: var(--rail-text-strong); opacity: 1; }

.nav-caret {
  display: inline-block;
  width: 10px;
  font-size: var(--fs-2xs);
  opacity: 0.8;
}

.nav-count {
  margin-left: auto;
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: 0;
  opacity: 0.7;
}

.nav-group-body[hidden] { display: none; }

.nav-child {
  padding-left: var(--sp-8);
  font-size: var(--fs-sm);
  position: relative;
  /* long course names shouldn't widen the sidebar */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--rail-text);
}
.nav-child:hover { background: var(--rail-2); }
.nav-child .nav-dot { font-size: var(--fs-md); opacity: 0.55; }
.nav-child.active .nav-dot { opacity: 1; }

.nav-empty {
  padding: var(--sp-2) var(--sp-3) var(--sp-2) var(--sp-8);
  font-size: var(--fs-xs);
  color: var(--rail-text);
  opacity: 0.6;
}

/* Footer is just provenance, so it can breathe. */
.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--rail-border);
  color: var(--text-muted);
}
.sidebar-footer small { font-size: var(--fs-2xs); line-height: var(--lh); color: var(--rail-text); opacity: 0.6; }
.app-version { color: var(--rail-text); opacity: 0.6; letter-spacing: 0.04em; }
.sidebar-footer kbd {
  background: var(--rail-2);
  border-color: var(--rail-border);
  color: var(--rail-text);
}

/* ---------- Main ---------- */
/* Workspace stays white and gains a little air. The page column is a size
   container (issue #16 item 4), so grids beside the sidebar (761px and up)
   follow the width they actually get, not the viewport. inline-size only:
   .main still stretches to .content and never sizes to its content;
   position:fixed and sticky children still resolve against the viewport (no
   layout containment). */
.main { flex: 1; padding: var(--sp-1) var(--gutter) var(--sp-10); max-width: 1180px; container: main / inline-size; }

.view-header { margin-bottom: var(--sp-5); }
.view-header h1 { font-size: var(--fs-2xl); margin-bottom: var(--sp-1); }
.view-header p { color: var(--text-muted); }

/* ---------- App page header ---------- */
.page-header { margin-bottom: var(--sp-5); animation: rise 0.18s ease both; }
.back-btn { margin-bottom: var(--sp-3); }
/* Page titles carry the weight now that nothing is coloured. */
.page-header h1 { font-size: var(--fs-2xl); margin-bottom: var(--sp-1); letter-spacing: -0.015em; }
.page-icon { font-size: var(--fs-xl); }
.page-header > p { color: var(--text-muted); max-width: var(--measure); }

/* ---------- Cards & layout ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-3);
}
/* Buttons styled as cards (course picker, doc grid, flashcards): buttons
   don't inherit color/font, so set them explicitly or the text renders in
   the browser's default button color — unreadable in dark mode. */
button.card {
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
button.card:hover { border-color: var(--accent); }

.grid { display: grid; gap: var(--sp-4); }
.grid-2 { grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); }

.stat-card .stat-value { font-size: 1.75rem; font-weight: 700; }
.stat-card .stat-label { color: var(--text-muted); font-size: var(--fs-sm); }

.section-title { font-size: var(--fs-xs); font-weight: 700; margin: var(--sp-4) 0 var(--sp-2); color: var(--text-muted); }
/* A section title with its buttons on one row, and the line under it
   (issue #16 F-35): replaces inline negative margins that pulled the line
   up under the buttons. */
.section-head { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2); margin: var(--sp-4) 0 var(--sp-2); }
.section-head > .section-title { flex: 1; margin: 0; }
.section-sub { margin: 0 0 var(--sp-3); }

/* ---------- Forms ---------- */
input, textarea, select {
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

textarea { resize: vertical; min-height: 90px; }

/* One control height (issue #16 F-25): every text-like input and select is
   --control-h tall, so a field, a select and a .btn in one row line up.
   :where() keeps it at zero specificity, so a screen that deliberately
   sizes its own field (the palette search) still can. Textareas grow. */
:where(input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"],
  [type="file"], [type="hidden"], [type="submit"], [type="button"], [type="reset"],
  [type="image"]), select) {
  height: var(--control-h);
}

label { display: block; font-size: var(--fs-sm); font-weight: 600; margin-bottom: var(--sp-1); color: var(--text-muted); }

.form-row { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.form-row > div { flex: 1 1 160px; min-width: 0; }
/* A short select in a table cell (the GPA grade): auto table layout squeezed
   it to 44-52px, and a fixed 72px still cut "B+" to "B" (issue #16 F-06).
   Sized from its text, so two characters and the arrow always fit. */
.select-short { width: auto; min-width: 5.5em; padding-left: var(--sp-2); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  /* Seven of these are <a href> rather than <button> (external links the
     WKWebView shell has to route through Studio.openExternal), and an anchor
     underlines itself by default — so "Open blog" and "Fair page" drew as
     underlined text inside a button box. A button is a button either way. */
  text-decoration: none;
  min-height: var(--control-h);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  font-size: var(--fs-md);
  cursor: pointer;
}

.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger { color: var(--danger); }
/* min-width keeps a one-glyph small button (calendar and lecture arrows) a
   24px target after the side padding snapped from 10 to 8px. */
.btn-sm { min-height: var(--control-h-sm); min-width: var(--sp-6); padding: var(--sp-1) var(--sp-2); font-size: var(--fs-sm); }

/* A button whose whole label is one glyph (attach, mic). Square, centred, and
   a size up so the symbol reads at a glance — a .btn's usual side padding
   around a single character leaves an off-centre mark in a wide box. The
   colour is inherited so the glyph matches the text beside it in both themes.
   Keeps its shape when the label swaps to "…" or "Stop" mid-action. */
.btn-icon {
  justify-content: center;
  min-width: 42px;
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-lg);
  line-height: 1;
}

/* ---------- Lists ---------- */
.item-list { display: flex; flex-direction: column; gap: var(--sp-2); }

.list-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4);
}

.list-item .item-body { flex: 1; min-width: 0; }
.list-item .item-title { font-weight: 600; }
.item-meta { font-size: var(--fs-sm); color: var(--text-muted); }
.list-item.done .item-title { text-decoration: line-through; color: var(--text-muted); }
.list-item .item-title { overflow-wrap: anywhere; }
/* Phones: the title keeps the first line (beside a leading checkbox, 24px
   plus the 12px gap) and the badges and buttons wrap below it. */
@media (max-width: 760px) {
  .list-item { flex-wrap: wrap; }
  .list-item .item-body { flex: 1 1 calc(100% - 36px); }
  .list-item:has(> .checkbox) > .item-body + * { margin-left: calc(24px + var(--sp-3)); }
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  flex-shrink: 0;
  white-space: nowrap;
  /* One 20px chip height shared with .class-chip (issue #16 F-57). */
  padding: 0 var(--sp-2);
  line-height: 1.25rem;
  border-radius: 2px;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--surface-2);
  color: var(--text-muted);
}

.badge-red { background: var(--status-bad-bg); color: var(--status-bad-fg); }
.badge-yellow { background: var(--status-warn-bg); color: var(--status-warn-fg); }
.badge-green { background: var(--status-ok-bg); color: var(--status-ok-fg); }
.badge-blue { background: var(--accent-soft); color: var(--accent); }



/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--border); font-size: var(--fs-md); }
/* The label look comes from the shared eyebrow rule; only the size is
   restated here because th, td above sets 14px after it. */
th { font-size: var(--fs-xs); }
tr:last-child td { border-bottom: none; }
/* Digits line up in columns, badges and key caps (issue #16 F-88). */
td, .badge, kbd { font-variant-numeric: tabular-nums; }
/* The one kbd key cap (issue #16 F-88); palette.css no longer has its own. */
kbd {
  font: inherit;
  font-size: var(--fs-2xs);
  padding: 1px var(--sp-1);
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface-2);
}
/* A table wider than its box scrolls inside it, never the page (F-05). */
.table-wrap { overflow-x: auto; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: var(--sp-6) 0;
}
.empty-state .empty-icon { font-size: 2.125rem; margin-bottom: var(--sp-2); }

.checkbox { width: 24px; height: 24px; flex-shrink: 0; cursor: pointer; }

.toolbar { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-4); align-items: center; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }

/* ---------- Source modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.55);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(16, 24, 40, 0.28);
  padding: var(--sp-5);
  width: 100%;
  max-width: var(--modal-lg);
  max-height: 80vh;
  overflow: auto;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}
.modal-head h3 { font-size: var(--fs-lg); font-weight: 700; word-break: break-word; }

/* Narrower cards for short forms and confirmations. width:100% above keeps
   them inside the backdrop at any viewport. */
.modal-card.modal-sm { max-width: var(--modal-sm); }
.modal-card.modal-md { max-width: var(--modal-md); }

/* A card whose head and action row stay put while only .modal-body scrolls
   (source text, a long syllabus list): the whole card scrolling once put the
   title and close button thousands of px above the card's top edge. The card
   keeps overflow:auto only as the fallback for a viewport too short for even
   the pinned parts. */
.modal-card.modal-fit {
  display: flex;
  flex-direction: column;
}
.modal-fit > .modal-head,
.modal-fit > .modal-sub,
.modal-fit > .modal-actions { flex-shrink: 0; }
.modal-body { flex: 1 1 auto; min-height: 3em; overflow: auto; }
.modal-fit > .modal-actions { padding-top: var(--sp-3); }
.modal-sub { margin: calc(-1 * var(--sp-1)) 0 var(--sp-3); }
.modal-row {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-1) 0;
}

/* Shared action row: wraps instead of pushing a button off a narrow card. */
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--sp-2);
}

/* A close button laid over a bare backdrop (the image lightbox). */
.modal-float-close {
  position: absolute;
  top: var(--sp-3);
  right: var(--sp-3);
}

@media (max-width: 560px) {
  .modal-backdrop { padding: var(--sp-2); }
  .modal-card { padding: var(--sp-3); }
}

.source-text {
  max-width: var(--measure);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: var(--fs-md);
  line-height: var(--lh);
  color: var(--text);
}
.source-empty { color: var(--text-muted); font-size: var(--fs-sm); }
.source-text mark, mark {
  background: var(--accent-soft);
  color: inherit;
  padding: 1px var(--sp-0);
  border-radius: 3px;
}

/* ---- course-document viewer (Studio.openDocument) ----
   The shared .modal-card is sized for prose. A slide deck or a scan needs the
   height, and the body has to be the thing that scrolls (or, for the PDF
   embed, the thing that fills). */
.doc-view-card {
  display: flex;
  flex-direction: column;
  max-width: 1000px;
  max-height: 88vh;
  overflow: hidden;
}
.doc-view-card > .modal-head { flex-shrink: 0; }
.doc-view-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.doc-view-text { flex: 1; min-height: 0; overflow: auto; }
.doc-view-msg { font-size: var(--fs-sm); color: var(--text-muted); margin-bottom: var(--sp-2); }

/* The child is centred with margin:auto, not align-items:center — a centred
   flex item inside an overflow:auto box has its overflowing top clipped
   unreachably above the scroll origin. */
.doc-view-frame {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.doc-view-frame > * { margin: auto; }

/* <embed> has no intrinsic size — without an explicit height it collapses. */
.doc-view-pdf {
  width: 100%;
  height: 72vh;
  min-height: 320px;
  border: 0;
  background: var(--surface-2);
}

.doc-view-img {
  max-width: 100%;
  object-fit: contain;
  display: block;
}

/* ---- chat-history modal (Studio.openChatHistory) ---- */
.hist-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.hist-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.hist-item:hover { border-color: var(--accent); background: var(--surface-2); }
.hist-body { flex: 1; min-width: 0; }
.hist-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: var(--sp-6);
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--text);
  color: var(--bg);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius);
  /* Sized to its text, not to the half viewport left of the 50% anchor. */
  width: max-content;
  max-width: min(560px, calc(100vw - 32px));
  font-size: var(--fs-md);
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(16, 24, 40, 0.3);
  z-index: 1100;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-action {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  min-height: 24px;
  white-space: nowrap;
  margin-left: var(--sp-3);
  text-decoration: underline;
  cursor: pointer;
  pointer-events: auto;
}

/* ---------- Theme toggle (js/theme.js) ---------- */

/* ---- shared chat bubbles (Studio.chatBubble) ---- */
.chat-thread { display: flex; flex-direction: column; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.chat-user {
  align-self: flex-end;
  max-width: 82%;
  background: var(--accent);
  color: var(--on-accent);
  padding: var(--sp-2) var(--sp-3);
  border-radius: 14px 14px 2px 14px;
}
.chat-error { border-color: var(--danger); color: var(--danger); max-width: 92%; }
.chat-error-partial { color: var(--text); }
.chat-error-line { color: var(--danger); margin-top: var(--sp-2); overflow-wrap: anywhere; }
.chat-assistant { max-width: min(92%, var(--measure)); align-self: flex-start; }
.chat-sources { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-2); }
/* A source chip never grows past the bubble: its label ellipsises and the
   full name stays in the button's title.
   The chip keeps its short height under the shared .btn min-height (F-25);
   --control-h-sm is still 44px on a coarse pointer. */
.chat-sources .btn { max-width: 100%; min-width: 0; min-height: var(--control-h-sm); overflow: hidden; padding: var(--sp-0) var(--sp-2); }
.chat-source-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-reasoning-box { margin-bottom: var(--sp-2); }
.chat-reasoning-box > summary { cursor: pointer; }
.chat-reasoning {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 160px;
  overflow: auto;
  margin-top: var(--sp-1);
  opacity: 0.75;
}
/* Suggested prompts: left-aligned rows, so a label that wraps on a phone
   reads as text rather than a centred, ragged block (issue #16 F-92). */
.chat-suggestions { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.chat-suggestions .btn { text-align: left; }
/* One chat input row for every chat (issue #16 F-69): one gap, one input
   that shrinks, an Ask button that keeps its width when its label turns into
   an ellipsis. It stays in the flow: on Career and Employer the chat is one
   section of a long page, and a sticky row covered the section heading above
   it while the page scrolled. The class page, where the chat is the page,
   keeps its own sticky .ctab-composer. */
.chat-composer {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
}
.chat-composer > input { flex: 1; min-width: 0; }
.chat-composer > .btn-primary { min-width: 60px; justify-content: center; }
.chat-hist-del { flex-shrink: 0; min-height: 24px; }
@media (pointer: coarse) { .chat-hist-del { min-height: 44px; } }

/* ---- model-output prose (Studio.fmt): chat bubbles and every other
   container that renders fmt() output (.prose) ---- */
.prose, .chat-assistant { overflow-wrap: anywhere; }
/* About 72 characters a line (issue #16 F-33). */
.prose { max-width: var(--measure); }
.prose ul, .prose ol, .chat-assistant ul, .chat-assistant ol { margin: var(--sp-2) 0; padding-left: var(--sp-6); }
.prose li, .chat-assistant li { margin: var(--sp-1) 0; line-height: var(--lh); }
.prose p, .chat-assistant p { margin: 0 0 var(--sp-2); line-height: var(--lh); }
.prose p:last-child, .prose li:last-child,
.chat-assistant p:last-child, .chat-assistant li:last-child { margin-bottom: 0; }
.prose .chat-h, .chat-assistant .chat-h { font-size: var(--fs-lg); font-weight: 700; margin: var(--sp-3) 0 var(--sp-1); line-height: var(--lh-tight); }
.prose .chat-h:first-child, .chat-assistant .chat-h:first-child { margin-top: 0; }
.prose .badge, .chat-assistant .badge { white-space: normal; overflow-wrap: anywhere; max-width: 100%; }
.prose code, .chat-assistant code {
  font-family: Menlo, Monaco, "Courier New", monospace;
  font-size: 0.9em;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 1px var(--sp-1);
}
.chat-code {
  margin: var(--sp-2) 0;
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface-2);
  border-radius: var(--radius);
  overflow-x: auto;
  white-space: pre;
  overflow-wrap: normal;
  font-size: var(--fs-sm);
  line-height: var(--lh);
}
.chat-code code { padding: 0; background: none; font-size: inherit; border-radius: 0; }
.chat-table-wrap { max-width: 100%; overflow-x: auto; margin: var(--sp-2) 0; }
.chat-table { width: auto; min-width: 100%; }
.chat-table th, .chat-table td { padding: var(--sp-1) var(--sp-2); vertical-align: top; overflow-wrap: normal; }

/* ---- chat image attachments (paste a screenshot into the chat) ---- */
.chat-attach-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-2); }
.chat-attach {
  position: relative;
  width: 58px;
  height: 58px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  flex-shrink: 0;
  box-shadow: var(--shadow);
}
.chat-attach img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-attach-x {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(16, 24, 40, 0.65);
  color: var(--on-accent);
  font-size: var(--fs-2xs);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.chat-attach-x:hover { background: rgba(16, 24, 40, 0.9); }

/* Thumbnails inside a sent user bubble */
.chat-img-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.chat-img-row:not(:last-child) { margin-bottom: var(--sp-2); }
.chat-img {
  max-width: 220px;
  max-height: 220px;
  border-radius: 10px;
  display: block;
  cursor: zoom-in;
}
.lightbox-img {
  max-width: 92vw;
  max-height: 88vh;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  cursor: zoom-out;
}

/* ---------- Top bar (Canvas status + resync) ---------- */
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }

/* Same cap as .main, so the account chip lines up with the content edge. */
.topbar {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: safe flex-end;
  gap: var(--sp-2);
  row-gap: var(--sp-2);
  padding: var(--sp-3) var(--gutter) var(--sp-0);
  max-width: 1180px;
  min-height: 46px;
}

.sync-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
}
.sync-btn:hover { border-color: var(--accent); color: var(--text); }
.sync-btn[disabled] { opacity: 0.6; cursor: default; }
.sync-btn .sync-icon { font-size: var(--fs-sm); display: inline-block; }
.sync-btn.busy .sync-icon { animation: sync-spin 0.9s linear infinite; }
@keyframes sync-spin { to { transform: rotate(360deg); } }
.sync-when { font-weight: 400; opacity: 0.75; }
/* Top bar controls: one line, one height, whatever the label (issue #16 F-01). */
.sync-btn, .canvas-alert, .canvas-offline { white-space: nowrap; height: 36px; }
@media (max-width: 560px) { .sync-when { display: none; } }

/* Canvas is disconnected: loud enough to act on, quiet enough to ignore. */
.canvas-alert {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  border: 1px solid var(--danger);
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 700;
  cursor: pointer;
}
.canvas-alert:hover { background: color-mix(in srgb, var(--danger) 22%, transparent); }

/* Canvas is up but we couldn't reach it — a fact, not an alarm. Red is
   reserved for "your token is broken", which this is not: the same shape as
   the alert so the bar doesn't reflow, in muted colour so it doesn't shout. */
.canvas-offline {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
}
.canvas-offline:hover { color: var(--text); border-color: var(--text-muted); }

/* ---------- Account menu (top bar) ---------- */
.account { position: relative; }
.account-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-2) var(--sp-1) var(--sp-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-sm);
  white-space: nowrap;
  height: 36px;
  max-width: 100%;
  cursor: pointer;
}
.account-btn:hover { border-color: var(--accent); }
.account-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  border-radius: 2px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: var(--fs-2xs);
  font-weight: 700;
}
/* A long name is cut with an ellipsis; the button's title and the menu head
   keep it whole (issue #16 F-12). */
.account-name {
  font-weight: 500;
  min-width: 0;
  max-width: 16ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Phones: the avatar alone. The name stays in the button's accessible name. */
@media (max-width: 560px) {
  .account-name {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
  }
}
.account-caret { font-size: var(--fs-2xs); color: var(--text-muted); }

.account-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 5px);
  z-index: 30;
  min-width: 230px;
  max-width: min(320px, calc(100vw - 32px));
  max-height: calc(100dvh - 72px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(16, 35, 59, 0.14);
  overflow-x: hidden;
  overflow-y: auto;
  animation: rise 0.13s ease both;
}
.account-head {
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.account-head-name { font-weight: 600; font-size: var(--fs-sm); overflow-wrap: anywhere; }
.account-head-mail {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-role {
  display: inline-block;
  margin-top: var(--sp-1);
  padding: 1px var(--sp-1);
  border-radius: 2px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: var(--label-tracking);
  text-transform: uppercase;
}
.account-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: var(--fs-sm);
  text-align: left;
  cursor: pointer;
}
.account-item:hover { background: var(--surface-2); }
.account-note { color: var(--text-muted); font-size: var(--fs-xs); }
.account-sep { height: 1px; background: var(--border); }

/* Layout fixes (issue #16 item 9): touch targets on coarse pointers.
   A finger needs about 44px; a mouse keeps the desktop control heights. A
   native checkbox stays at its 24px box (base rule above) rather than
   drawing a 44px tick. .btn-sm already gets 44px from --control-h-sm under
   a coarse pointer; it stays listed here so the rule reads whole. */
@media (pointer: coarse) {
  .btn, .btn-sm, .nav-item, .nav-group-head, .account-item { min-height: 44px; }
}

/* ---------- Shell geometry and motion ----------
   Emoji-free flat geometry: collapse what held the emoji, labels read as
   labels. */
.page-icon:empty,
.app-icon:empty,
.brand-icon:empty,
.nav-item > span:empty,
.today-title > span:empty { display: none; }

/* Section headers read as labels now that nothing colourful leads them. */
.today-title,
.section-title,
.course-section,
.campus-group-title {
  text-transform: uppercase;
  letter-spacing: var(--label-tracking);
}

/* Motion: small, fast, and only on entrance or hover. Anything slower than
   ~180ms starts to feel like waiting, which defeats the instant view swaps. */
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.page-view { animation: fade 0.14s ease both; }
.today-strip, .launcher, .campus-groups, .card, .doc-grid, .assess-list,
.material-list, .news-list { animation: rise 0.2s ease both; }

.btn, .nav-item, .app-card, .today-card, .fair-card, .doc-card, .material-row,
.assess-row, .campus-link, .news-row, .course-picker-item {
  transition: background 0.13s ease, color 0.13s ease, border-color 0.13s ease;
}

.assess-details { animation: rise 0.16s ease both; }
.school-options, .modal-card { animation: rise 0.14s ease both; }

/* Someone who asked the OS for less motion gets none of it. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
