/* ============================================================================
   Classroom Chatbot — Design System
   Responsive-first, dark/light theming, custom accent (blue), smooth motion.
   Mirrors the visual language Rishvanth prefers (Horizon-tab / laundry-tracker):
   glassmorphism surfaces, soft shadows, spring-y transitions, and layouts that
   adapt to any screen (mobile / tablet / laptop / desktop).
   ============================================================================ */

:root {
  /* ---------------------------------------------------------------------
     Translucent surfaces over a soft ambient ground, one accent only. The
     old scheme ran five accents at once; a single hue at several lightnesses
     is what reads as considered rather than assembled.
     --------------------------------------------------------------------- */

  /* Accent — Penn State blue.
     Beaver Blue #1E407C over Nittany Navy #001E44. A true navy, deliberately
     not the indigo-violet that reads as generic AI; the depth is what makes
     it look expensive rather than default. */
  --accent: #1E407C;              /* text and icons: 9.1:1 on white */
  --accent-bright: #2F63B8;       /* fills and gradients */
  --accent-soft: rgba(30, 64, 124, 0.09);
  --accent-hover: #16305E;
  --navy: #001E44;
  --accent-grad: linear-gradient(160deg, #2F63B8, #10275A);

  /* A SELECTED chip or tab — an accent block with text on top of it. This has
     to be its own token because --accent is tuned as a text colour and gets
     LIGHTER after dark so it stays legible on a dark ground; a white label on
     that pale blue lands around 2:1. --accent-fill stays in the mid-blue in
     both themes, where white holds 4.6:1 or better. */
  --accent-fill: #1E407C;
  --accent-on: #ffffff;

  /* Ground — three low-saturation washes. Glass needs something behind it;
     blur over flat grey just looks like flat grey. */
  --bg: #E8EBF1;
  --bg-gradient: radial-gradient(900px 520px at 12% -8%, #CBD9EE 0%, transparent 62%),
                 radial-gradient(760px 480px at 88% 4%, #DCE2EC 0%, transparent 58%),
                 radial-gradient(640px 520px at 50% 108%, #D2DAE8 0%, transparent 60%),
                 var(--bg);

  /* Glass */
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #ffffff;
  --surface-2: rgba(255, 255, 255, 0.55);
  --surface-3: rgba(0, 30, 68, 0.055);
  --border: rgba(255, 255, 255, 0.85);      /* the lit edge of the glass */
  --border-hair: rgba(0, 30, 68, 0.09);     /* dividers inside a panel */
  --glass-blur: blur(24px) saturate(180%);
  --glass-inset: inset 0 1px 0 rgba(255, 255, 255, 0.9);

  --text: #10141B;
  --text-muted: #5B6676;

  /* Layered and tinted toward the navy, never one flat black drop */
  --shadow: 0 1px 2px rgba(0, 30, 68, 0.05), 0 14px 38px rgba(0, 30, 68, 0.09);
  --shadow-sm: 0 1px 2px rgba(0, 30, 68, 0.04), 0 8px 22px rgba(0, 30, 68, 0.07);

  --user-bubble: linear-gradient(160deg, #2F63B8, #10275A);
  --user-bubble-text: #ffffff;
  --bot-bubble: rgba(255, 255, 255, 0.6);
  --bot-bubble-text: #1A1F28;

  /* The primary button is the one surface that must NOT follow --accent.
     --accent flips to a pale blue after dark so it stays legible as text on a
     dark ground, which is the opposite of what a white-labelled fill needs.
     Pinning the fill to the mid-blue keeps white text at 4.6:1 at the top of
     the gradient and 9.1:1 at the bottom, in both themes, and keeps the brand
     mark identical rather than letting it drift lighter at night. */
  --btn-top: #2F63B8;
  --btn-bottom: #1E407C;
  --btn-top-hover: #3A72C8;
  --btn-bottom-hover: #16305E;
  --btn-text: #ffffff;
  --btn-glow: rgba(0, 30, 68, 0.26);
  --btn-glow-hover: rgba(0, 30, 68, 0.34);

  /* Radii step down as you nest: outer soft, inner tighter */
  --r-lg: 28px;
  --r-md: 18px;
  --r-sm: 12px;
  --r-pill: 999px;
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  /* A softer overshoot than --ease-spring: things that GROW out of
     something else (a panel unfolding, a rail widening) read as liquid
     rather than bouncy. --ease-spring stays for taps and pops. */
  --ease-liquid: cubic-bezier(0.22, 1.12, 0.36, 1);
  /* One set of durations for the whole app, so a tap, a popover and a
     panel move at related speeds instead of each picking its own. */
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --dur-1: 0.14s;   /* hover, press, colour */
  --dur-2: 0.24s;   /* popovers, menus, list rows */
  --dur-3: 0.34s;   /* panels and layout */

  /* Control heights. Every small control in a panel (tabs, segmented
     switches, toolbar buttons, the search box) is the same height, so rows
     line up instead of stepping by a few pixels each. */
  --ctl-sm: 30px;
  --ctl: 36px;
  --head-h: 52px;   /* the head row of every side panel */

  /* Floating things (selection bar, menus, the note box) sit over text, so
     they are opaque: even 97% white let the lines underneath show through
     the note box as smudged lettering (Chrome, phone width). */
  --popover-bg: #ffffff;
  /* A field inside a popover: a faint well with a visible edge. The page's
     --border is the white "lit edge" of the glass, which vanishes on a white
     popover and left the note's text box with no outline at all. */
  --field-bg: rgba(0, 30, 68, 0.04);
  --field-border: rgba(0, 30, 68, 0.18);
  /* Regions inside a panel (the library, the highlights column) sit on a
     faint inset instead of being boxed in with rules; cards inside them
     lift a little off it. */
  --inset-bg: rgba(0, 30, 68, 0.035);
  --inset-card: rgba(255, 255, 255, 0.82);
  --inset-card-border: rgba(0, 30, 68, 0.07);
  --popover-border: rgba(0, 30, 68, 0.12);
  --shadow-pop: 0 14px 38px rgba(0, 20, 50, 0.18), 0 2px 8px rgba(0, 20, 50, 0.08);

  /* One scrollbar everywhere. The thumb floats over the content's right
     edge with a transparent track, so no rectangular strip ever appears
     against a rounded card border. */
  --scroll-thumb: rgba(18, 24, 32, 0.25);
  --scroll-thumb-hover: rgba(18, 24, 32, 0.38);

  color-scheme: light;
}

[data-theme="dark"] {
  /* The same scheme after dark: smoked glass, the blue lifted for contrast. */

  --accent: #86AEEC;              /* lifted so it reads on a dark ground */
  --accent-bright: #9DC2F5;
  --accent-soft: rgba(134, 174, 236, 0.15);
  --accent-hover: #A6C6F7;
  --navy: #001E44;
  --accent-grad: linear-gradient(160deg, #3A72C8, #10275A);

  /* Not --accent (#86AEEC): white on that is unreadable. */
  --accent-fill: #2F63B8;
  --popover-bg: #181e2c;
  --field-bg: rgba(255, 255, 255, 0.05);
  --field-border: rgba(255, 255, 255, 0.16);
  --inset-bg: rgba(255, 255, 255, 0.035);
  --inset-card: rgba(255, 255, 255, 0.045);
  --inset-card-border: rgba(255, 255, 255, 0.07);
  --popover-border: rgba(255, 255, 255, 0.12);
  --shadow-pop: 0 16px 42px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
  --accent-on: #ffffff;

  --scroll-thumb: rgba(190, 210, 240, 0.22);
  --scroll-thumb-hover: rgba(190, 210, 240, 0.36);

  --bg: #080C14;
  --bg-gradient: radial-gradient(900px 520px at 12% -8%, rgba(47, 99, 184, 0.20), transparent 62%),
                 radial-gradient(760px 480px at 88% 4%, rgba(120, 140, 175, 0.10), transparent 58%),
                 radial-gradient(640px 520px at 50% 108%, rgba(0, 30, 68, 0.55), transparent 60%),
                 var(--bg);

  --surface: rgba(20, 28, 44, 0.72);
  --surface-solid: #141C2C;
  --surface-2: rgba(255, 255, 255, 0.05);
  --surface-3: rgba(255, 255, 255, 0.09);
  --border: rgba(255, 255, 255, 0.10);
  --border-hair: rgba(255, 255, 255, 0.07);
  --glass-blur: blur(24px) saturate(160%);
  --glass-inset: inset 0 1px 0 rgba(255, 255, 255, 0.07);

  --text: #E9EDF5;
  --text-muted: #96A2B8;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.45), 0 16px 42px rgba(0, 8, 24, 0.5);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 8, 24, 0.42);

  --user-bubble: linear-gradient(160deg, #3A72C8, #10275A);
  --user-bubble-text: #ffffff;
  --bot-bubble: rgba(255, 255, 255, 0.055);
  --bot-bubble-text: #DEE4EF;

  /* Same fill, deeper glow: a navy-tinted drop reads as a cast shadow on a
     dark ground, where the light theme's softer one disappears. */
  --btn-glow: rgba(0, 0, 0, 0.5);
  --btn-glow-hover: rgba(0, 0, 0, 0.6);

  color-scheme: dark;
}

/* A translucent surface over a busy ground is unreadable without the blur.
   Where the browser cannot do it, fall back to opaque. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :root { --surface: #ffffff; --surface-2: #F1F4F9; --border: rgba(0,30,68,0.11); }
  [data-theme="dark"] { --surface: #141C2C; --surface-2: #1C2538; --border: rgba(255,255,255,0.12); }
}

/* ---------------- Reset / base ---------------- */
* { box-sizing: border-box; }

html {
  margin: 0;
  padding: 0;
  background: var(--bg);
}

body {
  margin: 0;
  padding: 0;
  /* Plus Jakarta Sans, not Inter: Inter is the default AI choice and reads
     as a grid rather than a voice. Weights 400-800 let hierarchy come from
     weight instead of size alone, which is most of what reads as considered. */
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  background: var(--bg-gradient);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  transition: background 0.4s ease, color 0.3s ease;
  overflow-x: hidden;
}

/* Themed scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; }
*::-webkit-scrollbar-track { background: transparent; }

a { color: var(--accent); text-decoration: none; }

/* ---------------- Shared components ---------------- */
.btn {
  font: inherit;
  /* A variant-less .btn used to fall through to the browser's own button
     chrome — a grey slab that looked like a different app. The base now IS
     the secondary style, so every call site is deliberate by default and
     .btn-primary / .btn-ghost / .btn-icon override it below. */
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-hair);
  border-radius: var(--r-md);
  padding: 0.7rem 1.15rem;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.14s var(--ease-spring), background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(0.96); }
.btn:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; }

/* Flat, not bubbly.
   The old version was a vertical gradient under a 20px drop glow and a
   white inset highlight — three effects doing the work of one. Inside a
   scrolling list the glow was also CLIPPED by the scroll container, which
   is the "weird shade cut off inside a rectangle" on the New note button:
   a shadow cannot escape an `overflow: hidden` ancestor, so it rendered as
   a hard-edged smudge. A flat fill has no shadow to clip. */
.btn-primary {
  background: var(--btn-bottom);
  color: var(--btn-text);
  border-color: transparent;
  box-shadow: none;
}
.btn-primary:hover {
  background: var(--btn-top);
  transform: none;
  box-shadow: none;
}
.btn-primary:active { background: var(--btn-bottom-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
}
.btn-ghost:hover { background: var(--surface-3); }

.btn-icon {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
  width: 40px; height: 40px;
  padding: 0; border-radius: var(--r-sm);
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }

/* Inputs */
.input {
  font: inherit;
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: var(--r-md);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.input::placeholder { color: var(--text-muted); }

/* Card surface */
.surface {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}

/* The hidden attribute always wins. Without this, any rule that sets display
   (a .btn, a flex row) silently overrides [hidden] — a bug this app hit more
   than once (the zones, the reader bar, the rail buttons). */
[hidden] { display: none !important; }

/* ---------------- Floating app header (shared across pages) ---------------- */
.app-header {
  display: flex;
  align-items: center;
  gap: 1.15rem;
  padding: 0.9rem 1.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.app-header .logo { width: 42px; height: 42px; border-radius: var(--r-sm); object-fit: cover; flex-shrink: 0; }
.app-header .titles { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.2rem; }
.app-header .titles h1 { font-size: 1.08rem; margin: 0; line-height: 1.2; letter-spacing: -0.015em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-header .titles .sub { font-size: 0.78rem; color: var(--text-muted); display: flex; align-items: center;
  gap: 0.45rem; margin: 0; line-height: 1.2; min-width: 0; flex-wrap: wrap; }
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; display: inline-block; flex-shrink: 0; }
.header-actions { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.head-group { display: flex; align-items: center; gap: 0.5rem; }
.head-divider { width: 1px; height: 24px; background: var(--border); margin: 0 0.35rem; }
.head-btn { display: inline-flex; align-items: center; gap: 0.45rem; white-space: nowrap; padding: 0.5rem 0.8rem; }
.head-btn svg { flex-shrink: 0; }
.head-btn-label { line-height: 1; }
.head-btn.active { background: var(--surface-3); color: var(--text); border-color: var(--border); }
.head-btn .cnt { margin-left: 0.1rem; }
.head-btn.danger:hover { color: #ef4444; border-color: rgba(239, 68, 68, 0.4); background: rgba(239, 68, 68, 0.08); }
.head-btn.icon-only { padding: 0.5rem 0.6rem; }
.theme-toggle-btn .ico-light { display: none; }
html[data-theme="dark"] .theme-toggle-btn .ico-dark { display: none; }
html[data-theme="dark"] .theme-toggle-btn .ico-light { display: block; }
@media (max-width: 640px) { .head-btn-label { display: none; } }

/* ---------------- Page shell + floating panels (shared) ---------------- */
/* Staff pages (dashboard, records, transcript) share the chat page's header
   size and grow with the screen the way the chat page does, instead of
   sitting as a 1160px island on a 1440p or ultrawide monitor. The header
   sticks a little below the top edge, so its rounded corners are never cut
   off by the window while a long transcript scrolls under it. */
.page {
  max-width: 1160px;
  margin: 0 auto;
  padding: clamp(0.75rem, 2vw, 1.4rem);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
@media (min-width: 1800px) { .page { max-width: 1480px; } }
@media (min-width: 2400px) { .page { max-width: 1760px; } }
.page > .app-header { position: sticky; top: clamp(0.5rem, 1.2vw, 0.9rem); z-index: 40; }
/* The header can never be wider than the page it sits in, whatever its
   title or its row of buttons asks for: the title gives way (ellipsis), the
   buttons drop their labels below 980px, and nothing pushes past the right
   edge. A staff page whose header sits straight in <body> rather than in
   .page gets the same inset, width and stickiness instead of running edge
   to edge. */
.page { width: 100%; min-width: 0; box-sizing: border-box; }
.page > * { min-width: 0; max-width: 100%; }
.app-header { box-sizing: border-box; max-width: 100%; min-width: 0; }
.app-header .header-actions { flex: 0 1 auto; min-width: 0; flex-wrap: nowrap; }
body > .app-header {
  position: sticky; top: clamp(0.5rem, 1.2vw, 0.9rem); z-index: 40;
  width: auto; max-width: min(1160px, calc(100% - 2 * clamp(0.75rem, 2vw, 1.4rem)));
  margin: clamp(0.75rem, 2vw, 1.4rem) auto 0;
}
@media (min-width: 1800px) { body > .app-header { max-width: 1480px; } }
@media (min-width: 2400px) { body > .app-header { max-width: 1760px; } }
@media (max-width: 980px) { .app-header .head-btn-label { display: none; } .app-header .head-btn { padding: 0.5rem 0.6rem; } }
/* On a phone the sticky header stays one compact row: the subtitle is cut
   with an ellipsis instead of wrapping into three lines over the content. */
@media (max-width: 640px) {
  .app-header { gap: 0.7rem; padding: 0.6rem 0.75rem; }
  .app-header .logo { width: 34px; height: 34px; }
  .app-header .titles h1 { font-size: 0.98rem; }
  .app-header .titles .sub { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .app-header .titles .sub .online-dot { vertical-align: middle; margin-right: 0.3rem; }
  .app-header .header-actions { gap: 0.3rem; flex-wrap: nowrap; }
}
.page-main { display: flex; flex-direction: column; gap: 1rem; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 0.88rem; font-weight: 700; letter-spacing: 0.02em; }
.panel-head .panel-sub { font-size: 0.72rem; color: var(--text-muted); font-weight: 400; }
.panel-body { padding: 1.3rem 1.4rem; }
.panel-body.flat { padding: 0; }

/* ---------------- Tabs (course + view, shared) ---------------- */
.tab-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.tab {
  padding: 0.5rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.15s var(--ease-spring);
}
.tab:hover { border-color: var(--accent); transform: translateY(-1px); }
.tab.active { background: var(--accent-fill); color: var(--accent-on); border-color: var(--accent-fill); }
.tab .cnt { font-size: 0.72rem; font-weight: 700; background: rgba(255,255,255,0.25); color: inherit; border-radius: 999px; padding: 0.08rem 0.42rem; margin-left: 0.35rem; }

/* ---------------- Expandable terms (accordion) ---------------- */
.terms-list { max-height: 46dvh; overflow-y: auto; padding-right: 0.2rem; }
.terms-intro { margin: 0 0 0.7rem; font-size: 0.92rem; color: var(--text-muted); }
.terms-sec {
  border: 1px solid var(--border-strong, var(--border));
  border-radius: var(--r-md);
  background: var(--surface);
  margin: 0 0 0.55rem;
  overflow: hidden;
}
.terms-sec summary {
  list-style: none;
  cursor: pointer;
  padding: 0.7rem 0.9rem;
  font-weight: 600;
  font-size: 0.86rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  user-select: none;
}
.terms-sec summary::-webkit-details-marker { display: none; }
.terms-sec summary::after { content: "+"; font-size: 1.05rem; color: var(--accent); font-weight: 600; line-height: 1; transition: transform 0.15s ease; }
.terms-sec[open] summary::after { content: "\2212"; }
.terms-sec .terms-body { padding: 0 0.9rem 0.8rem; font-size: 0.84rem; line-height: 1.55; color: var(--text-muted); }
.terms-sec .terms-body p { margin: 0 0 0.5rem; }
.terms-sec .terms-body p:last-child { margin-bottom: 0; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.8rem 1.2rem;
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  font-size: 0.95rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  z-index: 200;
  transition: transform 0.3s var(--ease-spring), opacity 0.3s ease;
  max-width: min(90vw, 420px);
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { border-left: 4px solid #22c55e; }
.toast.error { border-left: 4px solid #ef4444; }

/* ---------------- Keyframe helpers ---------------- */
/* These animate `translate` and `scale`, never `transform`. An animation
   that ends on `transform: scale(1)` replaces whatever transform the element
   uses to sit where it sits: that is how the note box lost its
   translateX(-50%) and slid half out of the panel. The individual
   properties compose with `transform` instead of overwriting it. */
@keyframes fadeUp {
  from { opacity: 0; translate: 0 14px; }
  to { opacity: 1; translate: 0 0; }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
  0% { opacity: 0; scale: 0.92; }
  100% { opacity: 1; scale: 1; }
}
/* Popovers grow from where they point (transform-origin set per element). */
@keyframes popoverIn {
  from { opacity: 0; scale: 0.94; translate: 0 4px; }
  to { opacity: 1; scale: 1; translate: 0 0; }
}
@keyframes slideFromRight {
  from { opacity: 0; translate: 18px 0; }
  to { opacity: 1; translate: 0 0; }
}
@keyframes slideFromLeft {
  from { opacity: 0; translate: -18px 0; }
  to { opacity: 1; translate: 0 0; }
}
.anim-fade-up { animation: fadeUp 0.4s var(--ease-spring) both; }
.anim-pop { animation: popIn 0.3s var(--ease-spring) both; }

/* ---------------- Modal / consent (shared by auth + chat pages) ---------------- */
/* The scrim's background and blur live in the glass block at the end of this
   file, with the other scrims, so there is one place to tune the material. */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: none;
  align-items: center; justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal-overlay.open .modal-panel { animation: popIn 0.28s var(--ease-spring) both; }
.modal-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  width: 100%;
  max-height: min(86dvh, 720px);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { display: flex; align-items: center; gap: 0.5rem; margin: 0; font-size: 1.15rem; letter-spacing: -0.01em; }
.modal-body { padding: 1.4rem; overflow-y: auto; }

/* Consent gate (terms of service) */
.consent-gate { z-index: 200; }
.consent-gate .modal-panel { animation: popIn 0.3s var(--ease-spring) both; }
.consent-body { padding: 1.2rem 1.4rem 1.4rem; }
.consent-lead { margin: 0 0 0.8rem; font-size: 0.92rem; }
.consent-scroll {
  max-height: 40dvh; overflow-y: auto; padding: 0.9rem 1rem;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-2); font-size: 0.88rem; line-height: 1.55;
}
.consent-scroll p { margin: 0 0 0.7rem; }
.consent-scroll p:last-child { margin-bottom: 0; }
.consent-check {
  display: flex; gap: 0.6rem; align-items: flex-start;
  margin: 1rem 0 1.1rem; font-size: 0.88rem; line-height: 1.45; cursor: pointer;
}
.consent-check input { margin-top: 0.15rem; accent-color: var(--accent); width: 17px; height: 17px; flex-shrink: 0; }
.consent-course-pill {
  font-size: 0.75rem; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); border-radius: 999px; padding: 0.3rem 0.7rem;
}
.btn-block { width: 100%; }

/* ---------------- Responsive utility ---------------- */
.hide-mobile { }
.show-mobile { display: none !important; }

@media (max-width: 640px) {
  .hide-mobile { display: none !important; }
  .show-mobile { display: flex !important; }
}

/* ---------------- Code blocks (Prism) ---------------- */
/* Always-dark code surface (the ChatGPT / Slack / GitHub pattern) with a
   token palette tuned for that surface. Scoped to chat bubbles so it never
   leaks into other pages. */
.msg-bubble pre[class*="language-"],
.msg-bubble pre {
  background: #0d1424;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  padding: 0.9rem 1.05rem;
  margin: 0.6rem 0;
  overflow-x: auto;
  color: #e6edf3;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.8rem;
  line-height: 1.6;
}
.msg-bubble pre code[class*="language-"] {
  color: #e6edf3;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-shadow: none;
}
.msg-bubble :not(pre) > code {
  background: rgba(29, 95, 208, 0.14);
  color: inherit;
  padding: 0.14em 0.42em;
  border-radius: 6px;
  font-size: 0.85em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Token palette (dark surface) */
.msg-bubble .token.comment, .msg-bubble .token.prolog, .msg-bubble .token.doctype, .msg-bubble .token.cdata { color: #6b7a90; }
.msg-bubble .token.punctuation { color: #9aa8bd; }
.msg-bubble .token.tag, .msg-bubble .token.boolean, .msg-bubble .token.number, .msg-bubble .token.constant, .msg-bubble .token.symbol, .msg-bubble .token.deleted { color: #7dd3fc; }
.msg-bubble .token.selector, .msg-bubble .token.attr-name, .msg-bubble .token.string, .msg-bubble .token.char, .msg-bubble .token.builtin, .msg-bubble .token.inserted { color: #86efac; }
.msg-bubble .token.operator, .msg-bubble .token.entity, .msg-bubble .token.url { color: #d3dce8; }
.msg-bubble .token.atrule, .msg-bubble .token.attr-value, .msg-bubble .token.keyword { color: #c4b5fd; }
.msg-bubble .token.function, .msg-bubble .token.class-name { color: #93c5fd; }
.msg-bubble .token.regex, .msg-bubble .token.important, .msg-bubble .token.variable { color: #f9a8d4; }

/* The in-app feedback form and its star picker were removed: feedback now
   goes through the anonymous Qualtrics survey, so there is no form to style.
   The dashboard's star display is read-only inline text, not a control. */

/* ---------------- Data primitives (teacher pages) ---------------- */
/* dashboard.html, sensitive.html and student.html each used to redefine
   these, which is how they drifted apart. They live here now so a change
   lands on all three. */

.data-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.data-table th,
.data-table td {
  text-align: left;
  padding: 0.68rem 0.75rem;
  border-bottom: 1px solid var(--border-hair);
  vertical-align: middle;
}
.data-table th {
  color: var(--text-muted); font-weight: 600; font-size: 0.72rem;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.data-table tbody tr:last-child td { border-bottom: none; }
/* A translucent white band would brighten the glass; a navy tint recedes. */
.data-table tbody tr { transition: background 0.14s ease; }
.data-table tbody tr:hover { background: var(--surface-3); }

/* KPI tile — the recessed inner surface, one step tighter than its panel. */
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 1rem 1.15rem;
}
.kpi .v { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15;
          font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }
.kpi .l { font-size: 0.74rem; color: var(--text-muted); text-transform: uppercase;
          letter-spacing: 0.04em; margin-top: 0.15rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; }

/* Badges. Status is semantic (a disabled account really is a red state);
   mastery is NOT — see the tier note below. */
.badge {
  display: inline-block; padding: 0.14rem 0.55rem; border-radius: var(--r-pill);
  font-size: 0.72rem; font-weight: 700; white-space: nowrap;
}
.badge.ok   { background: rgba(22, 163, 74, 0.14); color: #15803d; }
.badge.warn { background: rgba(245, 158, 11, 0.16); color: #b45309; }
.badge.bad  { background: rgba(239, 68, 68, 0.14); color: #dc2626; }
.badge.neutral { background: var(--surface-3); color: var(--text-muted); }
[data-theme="dark"] .badge.ok   { color: #5ee9a0; }
[data-theme="dark"] .badge.warn { color: #fcd34d; }
[data-theme="dark"] .badge.bad  { color: #fca5a5; }

/* Mastery tiers: one hue at three lightnesses, matching .bar-fill. Not
   red-to-green — that ramp fails colourblind readers, and it tells a beginner
   they are failing, which is the opposite of what the scoring engine means by
   "starting". Depth carries the ordering instead. */
.tier {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 0.4rem; vertical-align: middle;
  box-shadow: inset 0 0 0 1px rgba(0, 30, 68, 0.12);
}
.tier.starting  { background: color-mix(in srgb, var(--accent-bright) 30%, transparent); }
.tier.growing   { background: color-mix(in srgb, var(--accent-bright) 65%, transparent); }
.tier.exceeding { background: var(--accent-bright); }

/* After dark, mixing toward transparent drags the low steps into the panel
   and the three tiers collapse into one blue. Mixing toward white instead
   keeps them separable, and the ring has to lighten for the same reason. */
[data-theme="dark"] .tier { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16); }
[data-theme="dark"] .tier.starting  { background: color-mix(in srgb, var(--accent-bright) 50%, #0B1222); }
[data-theme="dark"] .tier.growing   { background: var(--accent-bright); }
[data-theme="dark"] .tier.exceeding { background: #9DC2F5; }

.heat-row {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.55rem 0; border-bottom: 1px solid var(--border-hair);
}
.heat-row:last-child { border-bottom: none; }
.heat-name { flex: 0 0 210px; font-weight: 600; font-size: 0.86rem;
             overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.heat-bar { flex: 1; height: 10px; border-radius: var(--r-pill);
            background: var(--surface-3); overflow: hidden; }
.heat-fill { height: 100%; border-radius: var(--r-pill); transition: width 0.4s var(--ease-spring); }
.heat-fill.starting  { background: color-mix(in srgb, var(--accent-bright) 38%, transparent); }
.heat-fill.growing   { background: color-mix(in srgb, var(--accent-bright) 70%, transparent); }
.heat-fill.exceeding { background: var(--accent-grad); }
[data-theme="dark"] .heat-fill.starting  { background: color-mix(in srgb, var(--accent-bright) 60%, #0B1222); }
[data-theme="dark"] .heat-fill.growing   { background: var(--accent-bright); }
[data-theme="dark"] .heat-fill.exceeding { background: linear-gradient(90deg, var(--accent-bright), #9DC2F5); }
.heat-val { flex: 0 0 90px; font-size: 0.8rem; color: var(--text-muted); text-align: right;
            font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }

.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.78rem;
          color: var(--text-muted); margin-bottom: 0.6rem; }
.legend span { display: inline-flex; align-items: center; gap: 0.35rem; }

/* Seven-day activity sparkline (class totals, no identity in it). */
.activity-row { display: flex; gap: 0.7rem; align-items: flex-end; height: 110px; padding-top: 0.4rem; }
.activity-day { flex: 1; display: flex; flex-direction: column; align-items: center;
                justify-content: flex-end; gap: 0.3rem; height: 100%; }
.activity-count { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
                  font-size: 0.72rem; color: var(--text-muted); }
.activity-bar {
  width: 60%; max-width: 42px; min-height: 2px;
  /* 7px, not --r-sm: the radius is fixed while the height is data, so a 12px
     cap turns the shortest day into a dome rather than a bar. */
  border-radius: 7px 7px 3px 3px;
  background: var(--accent-grad);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22);
}
.activity-label { font-size: 0.68rem; color: var(--text-muted); }

.btn-sm { min-height: var(--ctl-sm); padding: 0 0.75rem; font-size: 0.78rem; border-radius: var(--r-pill); }
.btn-sm.icon-only { width: var(--ctl-sm); padding: 0; }
.btn-sm.icon-only svg { width: 16px; height: 16px; }
.muted { color: var(--text-muted); }

/* ---------------- Glass surfaces ---------------- */

/* Everything that floats above the ground gets the same treatment, so the
   layering reads as one material rather than a set of unrelated cards.
   --surface is translucent, so a card WITHOUT the blur does not look like
   glass — it looks like a washed-out solid. Every shared card belongs in this
   list; the five chat-only selectors at the end are the voice canvas. */
.surface,
.panel,
.app-header,
.modal-panel,
.kpi,
.zone,
.chat-header,
.composer,
.holo-panel,
.vpanel {
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--shadow), var(--glass-inset);
}

/* The header and the small tiles sit lower in the stack than a page card, so
   they take the shallower drop — same material, less lift. */
.app-header,
.kpi { box-shadow: var(--shadow-sm), var(--glass-inset); }

/* Controls that sit ON glass get a lighter blur: a full 24px blur inside an
   already-blurred parent compounds into a milky patch. */
.tab,
.input,
.toast,
.terms-sec,
.consent-scroll {
  backdrop-filter: blur(8px) saturate(140%);
  -webkit-backdrop-filter: blur(8px) saturate(140%);
}

/* A scrim is glass too — blurring what is behind the dialog is what makes a
   modal read as a layer rather than a rectangle with a grey wash over it. */
.modal-overlay,
.scrim {
  background: rgba(8, 14, 28, 0.42);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
}

/* The side panels and the chat column must finish level. The grid already
   stretches them; this stops any inner scroll area from pushing one taller. */
.zones { align-items: stretch; }
.zone { min-height: 0; }

/* Controls are pills, panels are soft rectangles — the iOS distinction. */
.composer { border-radius: var(--r-pill); }
.send-btn,
.head-btn,
.topic-chip,
.follow-chip { border-radius: var(--r-pill); }

/* Data reads in mono with tabular figures so scores line up in a column.
   (.bar-val / .bar-track / .bar-fill used to be listed here with a
   [data-level] ramp. No markup ever carried those names — the progress bars
   are .pbar-* and set .low/.mid/.high, which is why that ramp never appeared
   on screen. The live rules now live with the bars in index.html.) */
.pbar-val,
.debug-delta,
.msg-time { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }

/* States. The audit's point: an interface with no feedback feels unfinished
   however good the palette is. */
.head-btn,
.topic-chip,
.follow-chip,
.send-btn { transition: transform 0.18s var(--ease-spring), background 0.2s ease, box-shadow 0.2s ease; }

.head-btn:hover,
.topic-chip:hover,
.follow-chip:hover { transform: translateY(-1px); }

.head-btn:active,
.topic-chip:active,
.follow-chip:active,
.send-btn:active { transform: scale(0.97); }

:where(a, button, input, textarea, [tabindex]):focus-visible {
  outline: 2.5px solid var(--text);
  outline-offset: 3px;
  border-radius: var(--r-sm);
}

@media (prefers-reduced-motion: reduce) {
  .head-btn, .topic-chip, .follow-chip, .send-btn { transition: none; }
  .head-btn:hover, .topic-chip:hover, .follow-chip:hover { transform: none; }
}


/* ===================================================================
   WORKSPACE PANEL
   Docks to the left of the chat, or fills the window. Three states, set
   on <body> so the grid and the panel move together:
     (none)    chat + progress rail
     .ws-open  panel | chat | progress
     .ws-max   panel only
   =================================================================== */

:root { --ws-w: 380px; }

/* The workspace tabs used to live up here in the header, beside About,
   Privacy, Feedback, the theme toggle and the rest — eleven controls in a
   row, with the course title squeezed to "IS...". They are in the rail now
   and the header is down to five. */

@media (max-width: 1180px) { .chat-header .titles .sub { display: none; } }

/* ---- the rail ---- */

:root { --rail-w: 54px; --side-w: 340px; }
body.rail-open { --rail-w: 190px; }

.rail {
  grid-row: 1; grid-column: 1;
  display: flex; flex-direction: column; justify-content: space-between;
  gap: 0.5rem; padding: 0.5rem;
  min-height: 0; overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow), var(--glass-inset);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  /* The width is the animation. Everything inside is laid out for the
     expanded size and clipped, so growing the rail slides the labels out
     from under the icons rather than popping them into place. */
  transition: width 0.34s var(--ease-liquid);
}
.rail-group { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.rail-btn {
  display: flex; align-items: center; gap: 0.7rem;
  width: 100%; padding: 0.55rem; min-height: 38px;
  border: none; background: transparent; color: var(--text-muted);
  font: inherit; font-size: 0.84rem; font-weight: 600;
  border-radius: var(--r-md); cursor: pointer; text-align: left;
  white-space: nowrap; overflow: hidden;
  transition: background 0.18s ease, color 0.18s ease;
}
.rail-btn[hidden] { display: none !important; }
.rail-btn svg { width: 19px; height: 19px; flex-shrink: 0; }
.rail-btn:hover { background: var(--surface-3); color: var(--text); }
.rail-btn[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.rail-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Collapsed, the label is still in the DOM and still laid out — it is
   clipped by the rail's width and faded, so expanding reveals a label
   that is already in place instead of reflowing the row. */
.rail-label {
  opacity: 0; transform: translateX(-4px);
  transition: opacity 0.2s ease 0.04s, transform 0.28s var(--ease-liquid) 0.04s;
}
body.rail-open .rail-label { opacity: 1; transform: none; }

.rail-sep { height: 1px; background: var(--border-hair); margin: 0.35rem 0.4rem; }
.rail-expand svg { transition: transform 0.34s var(--ease-liquid); }
body:not(.rail-open) .rail-expand svg { transform: rotate(0deg); }
body.rail-open .rail-expand svg { transform: rotate(180deg); }

/* The theme button swaps its own glyph; only one is ever shown. */
.theme-toggle-btn .ico-light { display: none; }
[data-theme="dark"] .theme-toggle-btn .ico-dark { display: none; }
[data-theme="dark"] .theme-toggle-btn .ico-light { display: block; }

/* ---- the grid, with the rail in column 1 ---- */

.zones { grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--side-w); }
#chatZone  { grid-column: 2; }
#sidePanel { grid-column: 3; }

/* Every docked rule says :not(.ws-max). A maximised panel is also open, so
   a later "docked, on a smaller screen" rule used to win over the maximise
   rule below 1340px — the panel stayed 380px wide, the chat vanished, and
   the reader was squeezed into a column one letter wide. */
body.ws-open:not(.ws-max) .zones { grid-template-columns: var(--rail-w) var(--ws-w) minmax(0, 1fr) var(--side-w); }
body.ws-open #wsPanel  { grid-column: 2; }
body.ws-open:not(.ws-max) #chatZone { grid-column: 3; }
body.ws-open:not(.ws-max) #sidePanel { grid-column: 4; }

/* Maximised: the panel takes everything but the rail, which is how you
   get back. */
body.ws-max .zones { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
body.ws-max #wsPanel { grid-column: 2; }
body.ws-max #chatZone,
body.ws-max #sidePanel { display: none; }

/* ---- step up on large displays ----
   The margins used to stop at 1440px and the rest of a wide monitor went
   to waste. Widening the side columns shows more at once; the chat column
   takes the remainder, and the bubble cap below keeps lines readable. */
@media (min-width: 1800px) {
  :root { --side-w: 400px; --ws-w-default: 460px; }
  body:not(.ws-resizing) { --ws-w: var(--ws-w-default, 380px); }
}
@media (min-width: 2400px) {
  :root { --side-w: 460px; --ws-w-default: 560px; }
}
/* The chat/voice toggle switches a mode of something that is not on
   screen, so it goes with it. #wsChatBtn is the way back. */
body.ws-max .hl-toggle,
body.ws-max .chat-header .head-divider { display: none !important; }

/* Nothing selected yet. Without this the right two thirds of a maximised
   panel are a blank rectangle, which reads as broken rather than ready. */
.ws-detail-body:empty::before {
  content: 'Pick something on the left to open it.';
  display: flex; align-items: center; justify-content: center;
  flex: 1; color: var(--text-muted); font-size: 0.86rem; padding: 2rem;
}

/* Docked, three columns do not fit a laptop once the panel is real. The
   progress rail is the one that can wait — it is a summary, not a surface
   you work in. */
/* Docked, four columns do not fit a laptop. The progress rail is the one
   that can wait — it is a summary, not a surface you work in. */
@media (max-width: 1340px) {
  body.ws-open:not(.ws-max) .zones { grid-template-columns: var(--rail-w) var(--ws-w) minmax(0, 1fr); }
  body.ws-open #sidePanel { display: none; }
  /* An expanded rail beside a docked panel leaves nothing for the chat. */
  body.ws-open.rail-open { --rail-w: 54px; }
  body.ws-open.rail-open .rail-label { opacity: 0; }
}
/* Below this there is no room to dock beside anything, so the panel takes
   the chat's place and the rail stays as the way back. */
/* Tablets and phones (980px and below — an iPad, a half-screen window):
   the page header's rules turn .zones into a single column, so the rail
   cannot be a column beside the chat. It used to render as a full-width
   block stacked ON TOP of the chat. It becomes the bottom bar here, as it
   already was on phones, and the workspace takes the chat's place rather
   than splitting the height with it. */
@media (max-width: 980px) {
  :root { --rail-w: 0px; }
  .app { padding-bottom: 0; }
  .rail {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 60;
    flex-direction: row; justify-content: space-around; align-items: center;
    gap: 0; padding: 0.3rem 0.6rem calc(0.3rem + env(safe-area-inset-bottom));
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    border-bottom: none;
    transition: none;
  }
  .rail-group { flex-direction: row; gap: 2px; }
  .rail-btn { flex-direction: column; gap: 2px; padding: 0.4rem 0.55rem; min-height: 46px; width: auto; }
  .rail-label { display: none; }
  .rail-sep, .rail-expand { display: none; }
  .rail-btn.rail-progress { display: flex !important; }
  .zones { grid-template-columns: minmax(0, 1fr) !important;
    padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
  #chatZone, #wsPanel, #sidePanel { grid-column: 1 !important; }
  body.ws-open #chatZone, #sidePanel { display: none !important; }
  /* The panel fills the column (it is a flex item there, not a grid cell). */
  #wsPanel { flex: 1 1 auto; min-height: 0; }
  .ws-grip { display: none; }
  /* Each view is one at a time on a screen this size, so maximise has
     nothing to add. */
  #wsMaxBtn { display: none; }
}
/* The progress button exists for the bottom bar only; on a desktop the
   progress column is always on screen. */
.rail-btn.rail-progress { display: none; }
/* A tablet has the room for a label under each icon, which a bar of nine
   bare glyphs needs: the shield, the checkbox and the speech bubble are
   not self-explanatory. */
@media (min-width: 700px) and (max-width: 980px) {
  .rail-btn { min-width: 62px; padding: 0.32rem 0.45rem; gap: 3px; min-height: 50px; }
  .rail-label { display: block; opacity: 1; transform: none;
    font-size: 0.64rem; font-weight: 600; letter-spacing: 0.01em; }
}
@media (max-width: 640px) {
  .rail { padding: 0.3rem 0.4rem calc(0.3rem + env(safe-area-inset-bottom)); }
  .rail-btn { padding: 0.4rem 0.42rem; }
}

/* Lines stay readable while the card grows: the cap rises with the screen
   rather than letting a bubble run the full width of an ultrawide. */
/* A table in a reply scrolls inside its bubble instead of spilling out
   over the chat's edge, and its cells wrap at spaces rather than between
   every letter (the bubble's break-word was splitting "column" into
   c/o/l/u/m/n down the cell). Same in the staff transcript. */
.msg-bubble table, .tx-html table {
  display: block; max-width: 100%; overflow-x: auto;
  border-collapse: collapse; margin: 0.55rem 0; font-size: 0.86em;
}
.msg-bubble th, .msg-bubble td, .tx-html th, .tx-html td {
  word-break: normal; overflow-wrap: normal;
  padding: 0.35rem 0.6rem; border: 1px solid var(--border-hair);
  text-align: left; vertical-align: top;
}
.msg-bubble th, .tx-html th { background: var(--surface-3); font-weight: 650; }
@media (min-width: 1800px) { .msg-bubble { max-width: min(74%, 780px); } }
@media (min-width: 2400px) { .msg-bubble { max-width: min(70%, 920px); } }

/* While dragging the grip, kill the column transition or the panel lags
   the pointer by the length of the animation. */
body.ws-resizing .zones { transition: none; }
body.ws-resizing { cursor: col-resize; user-select: none; }

/* ---- the panel ---- */

.ws-panel {
  position: relative;
  grid-row: 1;
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow), var(--glass-inset);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  /* clip, not hidden: a hidden overflow is still a scroll container, and a
     focus() or a menu opening could scroll the whole panel up under its
     own edge (which also shut the "more" menu the moment it opened). */
  overflow: hidden;   /* for browsers without clip */
  overflow: clip;
  animation: wsIn 0.26s var(--ease-spring) both;
}
.ws-panel[hidden] { display: none !important; }

/* The panel grows out of the rail rather than appearing beside it: the
   origin is pinned to the left edge so it reads as unfolding from the
   button that was clicked, and --ease-liquid overshoots just enough to
   settle rather than snap. */
.ws-panel { transform-origin: left center; }
@keyframes wsIn {
  from { opacity: 0; translate: -14px 0; scale: 0.97 1; }
  60%  { opacity: 1; }
  to   { opacity: 1; translate: 0 0; scale: 1; }
}

/* Switching tabs inside the panel. Without this the content is simply
   replaced between frames, which is the "it just turns into whatever the
   next thing is" problem — the eye gets no hint that anything moved. */
@keyframes viewIn {
  from { opacity: 0; translate: 0 6px; }
  to   { opacity: 1; translate: 0 0; }
}
.ws-list > *,
.ws-detail-body > :not(.doc-selbar, .doc-comment, .pop-menu) { animation: viewIn var(--dur-2) var(--ease-out) both; }
/* Opening a row moves the content in from the right, going back moves the
   list in from the left — the direction says where you are in the
   hierarchy, the way iOS navigation does. Tabs keep the gentle rise. */
/* Popovers that live in the detail view (the selection bar, the note box)
   keep their own pop-in: given the view's slide instead, the note box flew
   in sideways from the right like a new page. */
.ws-panel[data-nav="forward"] .ws-detail-body > :not(.doc-selbar, .doc-comment, .pop-menu) { animation-name: slideFromRight; }
.ws-panel[data-nav="back"] .ws-list > * { animation-name: slideFromLeft; }
/* Rows arrive in sequence rather than all at once — a short stagger is
   what makes a list feel poured rather than pasted. Capped at six, after
   which the delay would be longer than anyone waits. */
.ws-list > *:nth-child(2) { animation-delay: 0.02s; }
.ws-list > *:nth-child(3) { animation-delay: 0.04s; }
.ws-list > *:nth-child(4) { animation-delay: 0.06s; }
.ws-list > *:nth-child(5) { animation-delay: 0.08s; }
.ws-list > *:nth-child(n+6) { animation-delay: 0.1s; }


@media (prefers-reduced-motion: reduce) {
  .ws-panel { animation: none; }
  /* !important: the entrance and slide rules above are more specific. */
  .ws-list > *, .ws-detail-body > *, .doc-selbar, .doc-comment, .pop-menu { animation: none !important; }
  .rail, .zones { transition: none; }
}

/* Layout changes morph instead of jumping (wsshell.js wraps them in
   document.startViewTransition). Each region is named so the browser moves
   it from its old box to its new one. The snapshots are shown at their own
   size and clipped by the moving box — "revealed", not stretched — so text
   never squashes mid-animation. */
#wsPanel { view-transition-name: ws-panel; }
#chatZone { view-transition-name: chat-zone; }
#sidePanel { view-transition-name: side-panel; }
.rail { view-transition-name: rail; }
::view-transition-group(*) {
  animation-duration: var(--dur-3);
  animation-timing-function: var(--ease-out);
}
::view-transition-old(ws-panel), ::view-transition-new(ws-panel),
::view-transition-old(chat-zone), ::view-transition-new(chat-zone),
::view-transition-old(side-panel), ::view-transition-new(side-panel) {
  width: 100%; height: 100%;
  object-fit: none; object-position: left top;
}
::view-transition-image-pair(ws-panel),
::view-transition-image-pair(chat-zone),
::view-transition-image-pair(side-panel) { border-radius: var(--r-lg); overflow: hidden; }
/* A panel that appears or disappears slides with the rail edge rather than
   fading in place. */
::view-transition-new(ws-panel):only-child { animation: vtPanelIn var(--dur-3) var(--ease-out) both; }
::view-transition-old(ws-panel):only-child { animation: vtPanelOut var(--dur-2) ease-in both; }
::view-transition-new(side-panel):only-child { animation: vtFadeIn var(--dur-3) var(--ease-out) both; }
::view-transition-old(side-panel):only-child { animation: vtFadeOut var(--dur-2) ease-in both; }
@keyframes vtPanelIn { from { opacity: 0; translate: -18px 0; } to { opacity: 1; translate: 0 0; } }
@keyframes vtPanelOut { from { opacity: 1; translate: 0 0; } to { opacity: 0; translate: -18px 0; } }
@keyframes vtFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes vtFadeOut { from { opacity: 1; } to { opacity: 0; } }
/* Shown by a view transition, the panel skips its own entrance (wsshell.js
   sets .no-enter), so it does not fade in a second time afterwards. */
.ws-panel.no-enter { animation: none; }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

.ws-head {
  display: flex; align-items: center; gap: 0.4rem;
  min-height: var(--head-h); box-sizing: border-box;
  padding: 0 0.6rem 0 0.7rem;
  border-bottom: 1px solid var(--border-hair);
}
/* The workspace's views switch on the same segmented track as Progress /
   Course in the right-hand panel and Chat / Voice in the header: one
   control, one look, wherever a panel changes what it shows. */
.ws-itabs {
  display: flex; gap: 2px; flex: 0 1 340px; min-width: 0; margin-right: auto;
  padding: 2px; border-radius: var(--r-pill); background: var(--surface-3);
  overflow-x: auto; scrollbar-width: none;
}
.ws-itabs::-webkit-scrollbar { display: none; }
.ws-itab {
  flex: 1 1 0; min-width: 0; height: 30px; padding: 0 0.55rem;
  border: none; background: transparent; color: var(--text-muted);
  font: inherit; font-size: 0.78rem; font-weight: 650; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
  border-radius: var(--r-pill); cursor: pointer;
  transition: background var(--dur-1) ease, color var(--dur-1) ease;
}
.ws-itab:hover:not(.is-on) { color: var(--text); }
.ws-itab.is-on { background: var(--accent-fill); color: var(--accent-on); box-shadow: 0 1px 3px rgba(0, 30, 68, 0.12); }
.ws-icon { width: 30px; height: 30px; flex-shrink: 0; }

.ws-searchbar { padding: 0.5rem 0.65rem; border-bottom: 1px solid var(--border-hair); }
.ws-search { width: 100%; height: var(--ctl); padding: 0 0.85rem; font-size: 0.82rem; border-radius: var(--r-pill); }

.ws-body { flex: 1; min-height: 0; display: flex; }
.ws-rail {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  flex: 1; padding: 0.6rem;
}
.ws-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 0.3rem; }
.ws-listbar { display: flex; gap: 0.4rem; margin-bottom: 0.5rem; }
.ws-foot { margin: 0.5rem 0 0; font-size: 0.7rem; color: var(--text-muted); text-align: center; }
.ws-scope { margin: 0 0 0.4rem; font-size: 0.72rem; color: var(--text-muted); }
.ws-empty { color: var(--text-muted); font-size: 0.84rem; line-height: 1.55; padding: 0.9rem 0.3rem; margin: 0; }

.ws-detail { display: none; flex-direction: column; min-height: 0; min-width: 0; flex: 1; }
.ws-detail-body { display: flex; flex-direction: column; flex: 1; min-height: 0; min-width: 0;
  /* The reader's selection bar and note box position against this box. */
  position: relative; }
.ws-back {
  display: none; align-self: flex-start; flex-shrink: 0;
  margin: 0.5rem 0 0 0.55rem; height: 28px; padding: 0 0.7rem 0 0.45rem; gap: 0.2rem;
  font-size: 0.76rem; color: var(--text-muted);
}
.ws-back:hover { color: var(--accent); }

/* Narrow (docked): list OR detail, with a back button. A list beside a
   document does not fit in 380px, and pretending otherwise gives two
   unusable columns instead of one good one. */
.ws-panel.showing-detail .ws-rail { display: none; }
.ws-panel.showing-detail .ws-detail { display: flex; }
.ws-panel.showing-detail .ws-back { display: inline-flex; }

/* Maximised: the list and the open item side by side, as calm regions
   rather than boxes drawn with rules. The list sits on a soft inset, the
   open item on the panel itself, and the search moves up into the head
   row instead of spending a full-width row of its own. */
.ws-panel.is-max {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: var(--head-h) minmax(0, 1fr);
}
.ws-panel.is-max .ws-head { grid-row: 1; grid-column: 1; border-bottom: 0; }
.ws-panel.is-max .ws-searchbar {
  grid-row: 1; grid-column: 1; z-index: 1;
  align-self: center; justify-self: end;
  width: min(420px, calc(100% - 340px - 8rem));
  margin-right: 5.6rem; padding: 0; border: 0;
}
.ws-panel.is-max .ws-body {
  grid-row: 2; grid-column: 1; min-height: 0;
  display: grid; grid-template-columns: 256px minmax(0, 1fr);
  gap: 0.75rem; padding: 0.25rem 0.75rem 0.75rem;
}
.ws-panel.is-max .ws-rail {
  display: flex; padding: 0.6rem;
  background: var(--inset-bg); border-radius: var(--r-md);
}
.ws-panel.is-max .ws-detail { display: flex; }
.ws-panel.is-max .ws-back { display: none; }
/* Nothing open yet: say what the space is for, in the view's own words. */
.ws-panel[data-view="docs"] .ws-detail-body:empty::before { content: 'Open a document from your library, or add one.'; }
.ws-panel[data-view="notes"] .ws-detail-body:empty::before { content: 'Open a note, or start a new one.'; }
.ws-panel[data-view="highlights"] .ws-detail-body:empty::before { content: 'Pick a highlight to open it in its document.'; }

.ws-grip {
  position: absolute; top: 0; right: -3px; bottom: 0; width: 7px;
  cursor: col-resize; z-index: 5;
}
.ws-grip::after {
  content: ''; position: absolute; top: 50%; left: 2px;
  width: 3px; height: 38px; margin-top: -19px; border-radius: 2px;
  background: var(--border); opacity: 0; transition: opacity 0.18s ease;
}
.ws-grip:hover::after, body.ws-resizing .ws-grip::after { opacity: 1; }
body.ws-max .ws-grip { display: none; }

/* ---- rows ---- */

.ws-row {
  display: grid; grid-template-columns: 1fr auto; gap: 0.1rem;
  width: 100%; text-align: left;
  padding: 0.55rem 0.65rem; border-radius: var(--r-md);
  background: transparent; border: 1px solid transparent;
  color: var(--text); font: inherit; cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.ws-row:hover { background: var(--surface-3); }
.ws-row.is-on { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 22%, transparent); }
.ws-row-title {
  font-weight: 600; font-size: 0.84rem; display: flex; align-items: center; gap: 0.35rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ws-row-kind {
  font-size: 0.68rem; color: var(--text-muted); white-space: nowrap;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}
.ws-row-sub {
  grid-column: 1 / -1; font-size: 0.76rem; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.ws-drop {
  /* --border is the glass's white edge: a dashed line in it vanished on a
     light panel. Outlines drawn inside a panel use the field edge. */
  border: 1.5px dashed var(--field-border); border-radius: var(--r-md);
  padding: 0.7rem; text-align: center; font-size: 0.74rem; color: var(--text-muted);
  margin-bottom: 0.5rem; transition: border-color 0.18s ease, background 0.18s ease;
}
.ws-drop.is-over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* ---- notes editor ---- */

.note-bar {
  display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap;
  padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border-hair);
}
.note-title {
  flex: 1; min-width: 7rem; border: none; background: transparent; color: var(--text);
  font: inherit; font-size: 0.98rem; font-weight: 650; letter-spacing: -0.01em; padding: 0.2rem 0;
}
.note-title:focus { outline: none; }
.note-state { font-size: 0.7rem; color: var(--text-muted); min-width: 3.8rem; text-align: right; }
.note-state.is-error { color: #dc2626; font-weight: 600; }
[data-theme="dark"] .note-state.is-error { color: #fca5a5; }

.note-tools {
  display: flex; align-items: center; gap: 0.15rem; flex-wrap: wrap;
  padding: 0.35rem 0.75rem; border-bottom: 1px solid var(--border-hair);
  background: var(--surface-3);
}
.note-tools button {
  min-width: 28px; height: 26px; padding: 0 0.4rem;
  border: none; background: transparent; color: var(--text-muted);
  font: inherit; font-size: 0.82rem; border-radius: var(--r-sm); cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.note-tools button:hover { background: var(--surface); color: var(--accent); }
.note-hint { margin-left: auto; font-size: 0.7rem; color: var(--text-muted); }
.note-hint code {
  background: var(--surface); padding: 0.05rem 0.28rem; border-radius: 4px;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em;
}
@media (max-width: 1400px) { .note-hint { display: none; } }

.note-body {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 1rem 1.15rem 3rem; line-height: 1.7; font-size: 0.9rem; color: var(--text);
}
.note-body:focus { outline: none; }
.note-body:empty::before {
  content: 'Start writing. Markdown shortcuts work as you type.'; color: var(--text-muted);
}
.note-body h1 { font-size: 1.3rem; margin: 1rem 0 0.45rem; letter-spacing: -0.02em; }
.note-body h2 { font-size: 1.1rem; margin: 0.9rem 0 0.4rem; letter-spacing: -0.015em; }
.note-body h3 { font-size: 0.98rem; margin: 0.85rem 0 0.35rem; }
.note-body p { margin: 0 0 0.65rem; }
.note-body ul, .note-body ol { margin: 0 0 0.65rem; padding-left: 1.35rem; }
.note-body li { margin-bottom: 0.22rem; }
.note-body blockquote {
  margin: 0 0 0.75rem; padding: 0.5rem 0.9rem;
  border-left: 3px solid var(--accent-bright); background: var(--surface-3);
  border-radius: 0 var(--r-sm) var(--r-sm) 0; color: var(--text);
}
.note-body pre {
  margin: 0 0 0.75rem; padding: 0.75rem 0.95rem; overflow-x: auto;
  background: var(--surface-3); border: 1px solid var(--border-hair);
  border-radius: var(--r-md);
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem; line-height: 1.55;
}
.note-body code {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88em; background: var(--surface-3); padding: 0.08rem 0.28rem; border-radius: 4px;
}
.note-body pre code { background: none; padding: 0; }

/* ---- the document library ---- */

.doc-lib { position: relative; display: flex; flex-direction: column; gap: 0.25rem; min-height: 100%; }
.doc-lib-head { display: flex; align-items: center; gap: 0.6rem; margin: 0 0 0.4rem; }
.doc-add { display: inline-flex; align-items: center; gap: 0.35rem; }
.doc-add svg { width: 12px; height: 12px; }
.doc-lib-hint { font-size: 0.7rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Files dragged over the library: the whole column is the target. */
.doc-lib.is-over::after {
  content: 'Drop to add'; position: absolute; inset: 0; z-index: 2;
  display: flex; align-items: center; justify-content: center;
  border: 2px dashed var(--accent); border-radius: var(--r-md);
  background: color-mix(in srgb, var(--accent-soft) 70%, var(--popover-bg));
  color: var(--accent); font-size: 0.86rem; font-weight: 650;
}
.doc-lib.is-empty { justify-content: center; }
.doc-empty {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 0.4rem;
  margin: auto 0; padding: 1.6rem 1rem 1.4rem;
  border: 1.5px dashed var(--field-border); border-radius: var(--r-md);
}
.doc-empty-icon {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); margin-bottom: 0.2rem;
}
.doc-empty-icon svg { width: 20px; height: 20px; }
.doc-empty-title { margin: 0; font-weight: 650; font-size: 0.9rem; }
.doc-empty-sub { margin: 0 0 0.45rem; font-size: 0.76rem; color: var(--text-muted); line-height: 1.5; max-width: 26ch; }
.doc-lib.is-over .doc-empty { visibility: hidden; }

.doc-row { grid-template-columns: auto minmax(0, 1fr); align-items: center; column-gap: 0.65rem; padding: 0.5rem 0.55rem; }
.doc-row-text { display: flex; flex-direction: column; gap: 0.12rem; min-width: 0; }
.doc-row .ws-row-sub { grid-column: auto; }

/* The file-type tag: one shape, a colour per family. */
.doc-type {
  --t: #64748b;
  flex-shrink: 0; display: inline-grid; place-items: center;
  width: 30px; height: 34px; border-radius: 7px;
  background: color-mix(in srgb, var(--t) 13%, transparent);
  color: color-mix(in srgb, var(--t) 80%, var(--text));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--t) 24%, transparent);
  font: 750 0.54rem/1 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.02em;
}
.doc-type:empty { display: none; }
.doc-type.t-pdf  { --t: #e5484d; }
.doc-type.t-doc  { --t: #3b82f6; }
.doc-type.t-ppt  { --t: #f97316; }
.doc-type.t-code { --t: #8b5cf6; }
.doc-type.t-img  { --t: #16a34a; }
[data-theme="dark"] .doc-type { color: color-mix(in srgb, var(--t) 62%, #fff); }

/* ---- document reader ---- */

.doc-reader { position: relative; display: flex; flex-direction: column; flex: 1; min-height: 0; min-width: 0; }
.doc-ident { flex: 1; min-width: 0; display: flex; align-items: center; gap: 0.6rem; }
.doc-ident .doc-type { width: 28px; height: 32px; font-size: 0.5rem; }
.doc-ident-text { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.doc-name { font-weight: 650; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { font-size: 0.68rem; color: var(--text-muted);
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }

.doc-split { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
.doc-pages { overflow-y: auto; padding: 1rem 1.15rem 3rem; }
/* The highlights column only earns its width once the panel is
   maximised; docked, each highlight opens its own bar instead. */
.doc-rail { display: none; }
.doc-rail-head { display: flex; align-items: center; gap: 0.5rem; padding: 0.85rem 0.95rem 0.6rem; }
.doc-rail-head h4 { margin: 0; font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--text-muted); }
.doc-rail-count:not(:empty) {
  display: inline-grid; place-items: center; min-width: 20px; height: 18px; padding: 0 0.4rem;
  border-radius: var(--r-pill); background: var(--accent-soft); color: var(--accent);
  font-size: 0.66rem; font-weight: 700;
}
.doc-rail-list {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 0.5rem; padding: 0 0.6rem 0.8rem;
}

/* Maximised: the document in the middle and its highlights in a full-height
   column beside it; the toolbar runs over the document only. */
.ws-panel.is-max .doc-reader {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "bar rail" "pages rail";
  column-gap: 0.75rem;
}
.ws-panel.is-max .doc-split { display: contents; }
.ws-panel.is-max .doc-pages { grid-area: pages; padding: 0.5rem 0.75rem 4rem; }
.ws-panel.is-max .doc-rail {
  grid-area: rail; display: flex; flex-direction: column; min-height: 0;
  background: var(--inset-bg); border-radius: var(--r-md);
}
/* A reading measure: at the full width of a maximised panel a line runs
   to 150 characters, which is too long to follow back to the next line. */
.ws-panel.is-max .doc-page,
.ws-panel.is-max .doc-pages > .doc-note { max-width: 46rem; margin-left: auto; margin-right: auto; }
.ws-panel.is-max .doc-page-text { font-size: 0.95rem; line-height: 1.8; }
.ws-panel.is-max .doc-canvas-page { max-width: 860px; margin-left: auto; margin-right: auto; }
/* The note editor, maximised, reads the same way: no rules between its
   parts, the format bar as a soft strip, the text on the same measure. */
.ws-panel.is-max .note-bar {
  border-bottom: 0; padding: 0.4rem 0.6rem 0.65rem;
  width: 100%; max-width: calc(46rem + 1.2rem); margin: 0 auto;
}
.ws-panel.is-max .note-tools {
  border: 0; border-radius: 10px; background: var(--inset-bg);
  width: calc(100% - 0.7rem); max-width: calc(46rem + 1.5rem); margin: 0 auto;
}
.ws-panel.is-max .note-body {
  padding-top: 1.25rem; padding-bottom: 4rem;
  padding-left: max(1.15rem, calc((100% - 46rem) / 2));
  padding-right: max(1.15rem, calc((100% - 46rem) / 2));
}
.ws-foot { text-wrap: balance; }

.doc-page { margin-bottom: 2rem; }
.doc-page-no {
  font-size: 0.64rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); margin-bottom: 0.55rem;
}
.doc-page-text { line-height: 1.75; font-size: 0.89rem; white-space: pre-wrap; word-break: break-word; }

/* Tinted, not saturated — the text under a highlight has to stay the most
   legible thing on the page. */
.hl { padding: 0.05em 0.1em; border-radius: 3px; background: none; color: inherit; }
.hl-yellow { background: rgba(250, 204, 21, 0.38); }
.hl-green  { background: rgba(34, 197, 94, 0.28); }
.hl-blue   { background: rgba(56, 189, 248, 0.3); }
.hl-pink   { background: rgba(236, 72, 153, 0.26); }
[data-theme="dark"] .hl-yellow { background: rgba(250, 204, 21, 0.3); }
[data-theme="dark"] .hl-green  { background: rgba(34, 197, 94, 0.3); }
[data-theme="dark"] .hl-blue   { background: rgba(56, 189, 248, 0.28); }
[data-theme="dark"] .hl-pink   { background: rgba(236, 72, 153, 0.32); }

/* The selection bar: colours first, then what to do with the passage.
   Its controls carry their own classes rather than styling every <button>
   in the bar: a blanket `.doc-selbar button { background: transparent }`
   outranked `.sw-yellow` and turned all four colour dots invisible. */
.doc-selbar {
  position: absolute; z-index: 20;
  display: flex; align-items: center; gap: 0.15rem;
  max-width: calc(100% - 1rem);
  padding: 0.28rem;
  background: var(--popover-bg); border: 1px solid var(--popover-border);
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-pop);
  transform-origin: 50% 100%;
  animation: popoverIn var(--dur-2) var(--ease-out) both;
}
.doc-selbar.is-below { transform-origin: 50% 0; }
.sel-swatches { display: flex; align-items: center; gap: 0.2rem; padding: 0 0.15rem; }
.doc-selbar .sel-swatch {
  width: 22px; height: 22px; padding: 0; flex-shrink: 0; cursor: pointer;
  border-radius: 50%; border: 2px solid var(--popover-bg);
  background: var(--sw);
  box-shadow: 0 0 0 1px rgba(0, 30, 68, 0.18);
  transition: scale var(--dur-1) var(--ease-spring), box-shadow var(--dur-1) ease;
}
[data-theme="dark"] .doc-selbar .sel-swatch { box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.22); }
.doc-selbar .sel-swatch:hover { scale: 1.14; }
.doc-selbar .sel-swatch:active { scale: 0.92; }
.doc-selbar .sel-swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sel-swatch[data-colour="yellow"] { --sw: #facc15; }
.sel-swatch[data-colour="green"]  { --sw: #22c55e; }
.sel-swatch[data-colour="blue"]   { --sw: #38bdf8; }
.sel-swatch[data-colour="pink"]   { --sw: #ec4899; }
.sel-div { width: 1px; height: 18px; background: var(--border); margin: 0 0.2rem; flex-shrink: 0; }
.doc-selbar .sel-act {
  display: inline-flex; align-items: center; gap: 0.32rem;
  height: 30px; padding: 0 0.6rem; flex-shrink: 0;
  border: none; background: transparent; color: var(--text); cursor: pointer;
  font: inherit; font-size: 0.76rem; font-weight: 600; white-space: nowrap;
  border-radius: var(--r-pill);
  transition: background var(--dur-1) ease, color var(--dur-1) ease;
}
.doc-selbar .sel-act svg { width: 15px; height: 15px; flex-shrink: 0; }
.doc-selbar .sel-act:hover { background: var(--accent-soft); color: var(--accent); }
/* In a narrow docked panel the actions keep their icons and drop their
   words, so the bar stays one line instead of wrapping over the text. */
.ws-detail-body { container-type: inline-size; container-name: detail; }
@container detail (max-width: 430px) {
  .doc-selbar .sel-act .sel-lbl { display: none; }
  .doc-selbar .sel-act { width: 32px; padding: 0; justify-content: center; }
  .doc-selbar .sel-act.is-confirm { width: auto; padding: 0 0.6rem; }
  .doc-selbar .sel-act.is-confirm .sel-lbl { display: inline; }
}
/* A marked area has no words to ask about or copy. */
.doc-selbar.is-area [data-act="ask"], .doc-selbar.is-area [data-act="note"] { display: none; }

/* The bar for a highlight that already exists: its note (if it has one)
   above the same colours and actions, plus Remove. */
.doc-hlbar { flex-direction: column; align-items: stretch; gap: 0.2rem; border-radius: 18px; }
.hl-pop-row { display: flex; align-items: center; gap: 0.15rem; }
.hl-pop-note {
  /* As wide as the bar's row of buttons, never wider: a long note wraps. */
  contain: inline-size; width: 100%; margin: 0.1rem 0 0; padding: 0.4rem 0.6rem;
  border: 0; border-radius: 12px; background: var(--inset-bg); color: var(--text);
  font: inherit; font-size: 0.78rem; line-height: 1.45; text-align: left; cursor: pointer;
  white-space: pre-wrap; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
}
.hl-pop-note:hover { background: var(--accent-soft); }
.doc-hlbar .sel-swatch.is-current { box-shadow: 0 0 0 2px var(--popover-bg), 0 0 0 3.5px var(--sw); }
.doc-selbar .sel-act.is-danger { color: #dc2626; }
.doc-selbar .sel-act.is-danger:hover,
.doc-selbar .sel-act.is-confirm { background: rgba(220, 38, 38, 0.1); color: #dc2626; }
[data-theme="dark"] .doc-selbar .sel-act.is-danger,
[data-theme="dark"] .doc-selbar .sel-act.is-confirm { color: #fca5a5; }

/* A highlight in the column: a card with its colour down the edge, the
   passage, the note, and actions that appear when you reach for it. */
.anno {
  --a: #eab308;
  position: relative; display: flex; flex-direction: column; gap: 0.3rem;
  padding: 0.65rem 0.75rem 0.7rem 0.95rem;
  background: var(--inset-card); border-radius: 10px;
  box-shadow: 0 0 0 1px var(--inset-card-border);
}
.anno::before {
  content: ''; position: absolute; left: 0.4rem; top: 0.7rem; bottom: 0.7rem;
  width: 3px; border-radius: 3px; background: var(--a);
}
.anno-yellow { --a: #eab308; }
.anno-green  { --a: #22c55e; }
.anno-blue   { --a: #0ea5e9; }
.anno-pink   { --a: #ec4899; }
.anno-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; display: inline-block; }
/* Dots are solid: the translucent highlight tints read as grey at 8px. */
.anno-dot.hl-yellow { background: #eab308; }
.anno-dot.hl-green  { background: #22c55e; }
.anno-dot.hl-blue   { background: #0ea5e9; }
.anno-dot.hl-pink   { background: #ec4899; }
.anno-go {
  display: flex; flex-direction: column; gap: 0.3rem; width: 100%;
  border: 0; background: none; padding: 0; margin: 0; text-align: left;
  color: var(--text); font: inherit; cursor: pointer;
}
.anno-meta {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.64rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted);
}
.anno-quote {
  font-size: 0.8rem; line-height: 1.5; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.anno-go:hover .anno-quote { color: var(--accent); }
.anno-comment {
  font-size: 0.78rem; line-height: 1.5; color: var(--text); white-space: pre-wrap;
  padding: 0.4rem 0.55rem; border-radius: 7px; background: var(--inset-bg);
}
.anno-comment.is-empty { color: var(--text-muted); font-style: italic; background: none; padding: 0; }
/* On the page label's row, never over the passage; they show when the
   card is pointed at or focused (always, on a touch screen). */
.anno-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; min-height: 18px; }
.anno-actions {
  display: flex; gap: 0.05rem; margin: -0.3rem -0.4rem -0.3rem 0;
  opacity: 0; transition: opacity var(--dur-1) ease;
}
.anno:hover .anno-actions, .anno:focus-within .anno-actions { opacity: 1; }
@media (hover: none) { .anno-actions { opacity: 1; } }
.anno-act {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.3rem;
  height: 26px; min-width: 26px; padding: 0 0.3rem;
  border: 0; border-radius: 7px; background: transparent; color: var(--text-muted); cursor: pointer;
  font: inherit; font-size: 0.7rem; font-weight: 650; white-space: nowrap;
  transition: background var(--dur-1) ease, color var(--dur-1) ease;
}
.anno-act svg { width: 14px; height: 14px; }
.anno-act:hover { background: var(--accent-soft); color: var(--accent); }
.anno-act.is-danger:hover, .anno-act.is-confirm { background: rgba(220, 38, 38, 0.1); color: #dc2626; }
[data-theme="dark"] .anno-act.is-danger:hover, [data-theme="dark"] .anno-act.is-confirm { color: #fca5a5; }
.anno-act-lbl:empty { display: none; }
.anno-empty {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.6rem;
  padding: 0.2rem 0.35rem; color: var(--text-muted); font-size: 0.8rem; line-height: 1.55;
}
.anno-empty p { margin: 0; }
.anno-empty-icon {
  width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center;
  background: var(--inset-card); box-shadow: 0 0 0 1px var(--inset-card-border);
}
.anno-empty-icon svg { width: 16px; height: 16px; }
.hl-row-note { font-style: italic; }
.hl-row .ws-row-sub:not(.hl-row-note) {
  white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.link-btn { border: none; background: none; padding: 0; cursor: pointer;
  font: inherit; font-size: 0.72rem; font-weight: 600; color: var(--accent); }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: #dc2626; }
[data-theme="dark"] .link-btn.danger { color: #fca5a5; }

/* The note box opens beside the passage it is about, positioned and
   clamped inside the panel by docs.js — never centred with a transform, so
   no animation can push it off the edge. */
.doc-comment {
  position: absolute; z-index: 22;
  width: min(360px, calc(100% - 1.5rem));
  display: flex; flex-direction: column; gap: 0.55rem;
  padding: 0.8rem;
  background: var(--popover-bg); border: 1px solid var(--popover-border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-pop);
  transform-origin: 50% 0;
  animation: popoverIn var(--dur-2) var(--ease-out) both;
}
.doc-comment.is-above { transform-origin: 50% 100%; }
.doc-comment-quote {
  margin: 0; font-size: 0.76rem; color: var(--text-muted); line-height: 1.45;
  border-left: 3px solid var(--accent-bright); padding-left: 0.55rem;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.doc-comment textarea {
  min-height: 74px; max-height: 40vh; resize: vertical;
  padding: 0.6rem 0.7rem; font-size: 0.84rem; line-height: 1.5; border-radius: var(--r-sm);
  background: var(--field-bg); border: 1px solid var(--field-border);
}
.doc-comment textarea:focus {
  background: var(--popover-bg); border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.doc-comment .btn-row { display: flex; gap: 0.4rem; justify-content: flex-end; align-items: center; }
.doc-comment .btn-row .hint { margin-right: auto; font-size: 0.68rem; color: var(--text-muted); }

/* The reader's bar: the document's name gets a whole line, so it is never
   cut to three letters in the docked panel; the actions sit beneath it.
   Maximised there is room for one row, and no rule under it. */
.doc-bar {
  display: flex; flex-direction: column; gap: 0.5rem;
  padding: 0.65rem 0.75rem; border-bottom: 1px solid var(--border-hair);
}
.doc-bar .doc-ident { flex: none; }
.doc-actions { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.doc-actions-gap { flex: 1; }
.doc-icon-btn { width: 32px; height: 30px; padding: 0 !important; display: inline-flex;
  align-items: center; justify-content: center; }
.ws-panel.is-max .doc-bar {
  grid-area: bar; flex-direction: row; align-items: center; gap: 0.75rem;
  padding: 0.4rem 0.25rem 0.8rem 0.35rem; border-bottom: 0;
}
.ws-panel.is-max .doc-bar .doc-ident { flex: 1; min-width: 0; }
.ws-panel.is-max .doc-actions { flex: none; }
.doc-tool { display: inline-flex; align-items: center; gap: 0.35rem; }
.doc-tool svg { width: 15px; height: 15px; flex-shrink: 0; }
.doc-tool[aria-pressed="true"] {
  background: var(--accent-soft); color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 32%, transparent);
}
@container detail (max-width: 520px) {
  .doc-tool .doc-tool-lbl { display: none; }
  .doc-tool { padding: 0 0.5rem; }
}
/* Docked, Seal and its receipt move into the "more" menu (docs.js) so
   the toolbar keeps to one line. */
@container detail (max-width: 430px) {
  .doc-actions .doc-seal { display: none !important; }
}
.doc-sealed { color: #15803d; font-weight: 600; }
[data-theme="dark"] .doc-sealed { color: #5ee9a0; }
@container detail (min-width: 431px) { .doc-sealed { display: none; } }

/* ---- shared panel pieces: segmented switch, toolbar row, menu ---- */

/* The segmented switch, one look everywhere (Text/Pages in the reader;
   the same pill as Chat/Voice in the header, scaled to panel size). */
.seg {
  display: inline-flex; align-items: center; gap: 2px; flex-shrink: 0;
  height: var(--ctl-sm); padding: 2px;
  border: 1px solid var(--border-hair); border-radius: var(--r-pill);
  background: var(--surface-3);
}
.seg[hidden] { display: none !important; }
.doc-actions > .seg { flex: 0 0 auto; }
.seg button {
  height: 100%; padding: 0 0.7rem; border: none; border-radius: var(--r-pill);
  background: transparent; color: var(--text-muted); cursor: pointer;
  font: inherit; font-size: 0.74rem; font-weight: 650;
  transition: background var(--dur-1) ease, color var(--dur-1) ease;
}
.seg button.is-on { background: var(--accent-fill); color: var(--accent-on); }
.seg button:not(.is-on):hover { color: var(--text); }

/* The editor/reader header: the title line, then one row of actions. */
.note-bar { display: flex; flex-direction: column; align-items: stretch; gap: 0.5rem; }
.note-head { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }

/* The "more" menu (wsshell.js popMenu). */
.pop-menu {
  position: absolute; z-index: 40; min-width: 200px;
  display: flex; flex-direction: column; padding: 0.3rem;
  background: var(--popover-bg); border: 1px solid var(--popover-border);
  border-radius: var(--r-sm); box-shadow: var(--shadow-pop);
  transform-origin: 100% 0;
  animation: popoverIn var(--dur-2) var(--ease-out) both;
}
.pop-menu.is-above { transform-origin: 100% 100%; }
.pop-item {
  display: flex; align-items: center; gap: 0.6rem;
  height: 34px; padding: 0 0.7rem; border: none; border-radius: 8px;
  background: transparent; color: var(--text); cursor: pointer; text-align: left;
  font: inherit; font-size: 0.8rem; font-weight: 550; white-space: nowrap;
}
.pop-item svg { width: 15px; height: 15px; flex-shrink: 0; color: var(--text-muted); }
.pop-item:hover, .pop-item:focus-visible { background: var(--accent-soft); color: var(--accent); outline: none; }
.pop-item:hover svg, .pop-item:focus-visible svg { color: currentColor; }
.pop-item.is-danger { color: #dc2626; }
.pop-item.is-danger svg { color: currentColor; }
.pop-item.is-danger:hover, .pop-item.is-danger:focus-visible { background: rgba(220, 38, 38, 0.1); color: #dc2626; }
[data-theme="dark"] .pop-item.is-danger,
[data-theme="dark"] .pop-item.is-danger:hover { color: #fca5a5; }

/* A sealed note or document: green while unchanged, amber once edited. */
.seal-chip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  border: 1px solid rgba(22, 163, 74, 0.32); background: rgba(22, 163, 74, 0.1); color: #15803d;
  border-radius: var(--r-pill); padding: 0.2rem 0.6rem; cursor: pointer;
  font: inherit; font-size: 0.7rem; font-weight: 650; white-space: nowrap;
}
.seal-chip::before { content: '✓'; font-weight: 800; }
.seal-chip.is-changed { border-color: rgba(217, 119, 6, 0.35); background: rgba(245, 158, 11, 0.12); color: #b45309; }
.seal-chip.is-changed::before { content: '!'; }
[data-theme="dark"] .seal-chip { color: #5ee9a0; }
[data-theme="dark"] .seal-chip.is-changed { color: #fcd34d; }


/* A status beside a document's page count: reading, scanned, locked. */
.doc-flag { font-weight: 600; }
.doc-flag.is-busy { color: var(--accent); animation: docPulse 1.2s ease-in-out infinite; }
@keyframes docPulse { 50% { opacity: 0.45; } }

.doc-note {
  margin: 0.5rem 0 1rem; padding: 0.85rem 1rem;
  border: 1px solid var(--border-hair); border-radius: var(--r-md);
  background: var(--surface-3); font-size: 0.84rem; line-height: 1.55; color: var(--text);
}
.doc-note p { margin: 0 0 0.55rem; }
.doc-note p:last-child { margin-bottom: 0; }
.doc-note .btn { margin-top: 0.15rem; }
.doc-note-inline { margin-top: 0; }
.doc-empty-page { color: var(--text-muted); font-style: italic; font-size: 0.8rem; }

/* Code keeps its shape: monospace, tabs, no reflow. */
.doc-page-text.is-code {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem; line-height: 1.6; tab-size: 4; word-break: normal; overflow-wrap: anywhere;
}

/* The Pages view: the real page images, drawn as they scroll near. */
.doc-canvas-page {
  position: relative; width: 100%; margin: 0 0 1rem;
  background: #fff; border-radius: 6px; overflow: hidden;
  box-shadow: 0 0 0 1px var(--border-hair), var(--shadow-sm);
}
.doc-canvas-page canvas { display: block; width: 100%; height: 100%; }
.doc-canvas-no {
  position: absolute; right: 0.5rem; bottom: 0.4rem;
  font-size: 0.62rem; font-weight: 650; color: rgba(0, 30, 68, 0.45);
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}
.doc-canvas-page:not(.is-drawn)::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(0, 30, 68, 0.05) 50%, transparent 70%);
  background-size: 220% 100%; animation: docShimmer 1.4s linear infinite;
}
.doc-canvas-page.is-failed::after { animation: none; background: rgba(220, 38, 38, 0.06); }
@keyframes docShimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }

.doc-image { margin: 0; }
.doc-image img { display: block; max-width: 100%; height: auto; margin: 0 auto;
  border-radius: var(--r-sm); box-shadow: 0 0 0 1px var(--border-hair); }

/* ---- Pages view: canvas, then highlight boxes, then pdf.js's text layer ---- */
.doc-canvas-page { --scale-round-x: 1px; --scale-round-y: 1px; }
/* Zoomed, a page is wider than the reader and the reader scrolls sideways. */
.doc-pages .doc-canvas-page { width: calc(100% * var(--zoom, 1)); }
.doc-pages.is-zoomed { overflow-x: auto; }
.ws-panel.is-max .doc-pages .doc-canvas-page { max-width: calc(860px * var(--zoom, 1)); }
.doc-zoom {
  position: absolute; right: 1rem; bottom: 1rem; z-index: 15;
  display: flex; align-items: center; gap: 0.1rem; padding: 0.2rem;
  background: var(--popover-bg); border: 1px solid var(--popover-border);
  border-radius: var(--r-pill); box-shadow: var(--shadow-pop);
}
.ws-panel.is-max .doc-zoom { right: calc(290px + 0.75rem + 1rem); }
.doc-zoom button {
  display: inline-grid; place-items: center; height: 28px; min-width: 28px; padding: 0 0.4rem;
  border: 0; border-radius: var(--r-pill); background: transparent; color: var(--text); cursor: pointer;
  font: inherit; font-size: 0.72rem; font-weight: 650; font-variant-numeric: tabular-nums;
}
.doc-zoom button svg { width: 13px; height: 13px; }
.doc-zoom button:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent); }
.doc-zoom button:disabled { opacity: 0.35; cursor: default; }
.doc-zoom-val { min-width: 46px !important; }
.doc-canvas-no { z-index: 3; pointer-events: none; }
/* Multiplied onto the page like a real highlighter: the ink stays black. */
.pg-hl-layer { position: absolute; inset: 0; z-index: 1; pointer-events: none; mix-blend-mode: multiply; }
.pg-hl, .pg-area { position: absolute; }
.pg-hl { border-radius: 2px; }
.doc-canvas-page .pg-hl-layer .hl-yellow.pg-hl { background: rgba(250, 204, 21, 0.55); }
.doc-canvas-page .pg-hl-layer .hl-green.pg-hl  { background: rgba(34, 197, 94, 0.42); }
.doc-canvas-page .pg-hl-layer .hl-blue.pg-hl   { background: rgba(56, 189, 248, 0.45); }
.doc-canvas-page .pg-hl-layer .hl-pink.pg-hl   { background: rgba(236, 72, 153, 0.38); }
.pg-hl.has-note::after, .pg-area.has-note::after {
  content: ''; position: absolute; top: -4px; right: -4px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--pc);
}
.pg-hl, .pg-area { --pc: #ca8a04; }
.pg-hl.hl-green, .pg-area.hl-green { --pc: #16a34a; }
.pg-hl.hl-blue, .pg-area.hl-blue { --pc: #0284c7; }
.pg-hl.hl-pink, .pg-area.hl-pink { --pc: #db2777; }
.doc-canvas-page .pg-hl-layer .pg-area {
  border: 2px solid var(--pc); border-radius: 6px;
  background: color-mix(in srgb, var(--pc) 9%, transparent);
}
.doc-canvas-page .pg-hl-layer .pg-area.is-draft { --pc: #2563eb; border-style: dashed; }
.pg-hl.is-flash, .pg-area.is-flash { animation: pgFlash 1.1s var(--ease-liquid); }
@keyframes pgFlash {
  0%, 100% { outline: 0 solid transparent; outline-offset: 2px; }
  25% { outline: 3px solid rgba(37, 99, 235, 0.55); outline-offset: 2px; }
}

/* pdf.js's text layer (after its text_layer_builder.css): the page's words
   as invisible text over the printed ones, positioned and sized by pdf.js,
   scaled by --total-scale-factor. Selecting it selects the page. */
.doc-canvas-page .textLayer {
  position: absolute; inset: 0; z-index: 2;
  overflow: clip; opacity: 1; line-height: 1; text-align: initial;
  -webkit-text-size-adjust: none; text-size-adjust: none; forced-color-adjust: none;
  transform-origin: 0 0; caret-color: CanvasText;
  --min-font-size: 1;
  --text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size));
  --min-font-size-inv: calc(1 / var(--min-font-size));
}
.doc-canvas-page .textLayer :is(span, br) {
  color: transparent; position: absolute; white-space: pre; cursor: text; transform-origin: 0% 0%;
}
.doc-canvas-page .textLayer > :not(.markedContent),
.doc-canvas-page .textLayer .markedContent span:not(.markedContent) {
  z-index: 1;
  --font-height: 0;
  font-size: calc(var(--text-scale-factor) * var(--font-height));
  --scale-x: 1;
  --rotate: 0deg;
  transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv));
}
.doc-canvas-page .textLayer .markedContent { top: 0; height: 0; }
.doc-canvas-page .textLayer ::selection { background: rgba(37, 99, 235, 0.3); }
.doc-canvas-page .textLayer br::selection { background: transparent; }
.doc-canvas-page .textLayer .endOfContent {
  display: block; position: absolute; inset: 100% 0 0; z-index: 0;
  cursor: default; user-select: none; -webkit-user-select: none;
}
.doc-canvas-page .textLayer.selecting .endOfContent { top: 0; }
.doc-canvas-page .textLayer[data-main-rotation="90"] { transform: rotate(90deg) translateY(-100%); }
.doc-canvas-page .textLayer[data-main-rotation="180"] { transform: rotate(180deg) translate(-100%, -100%); }
.doc-canvas-page .textLayer[data-main-rotation="270"] { transform: rotate(270deg) translateX(-100%); }
/* Over a highlight, the page says it can be opened. */
.doc-canvas-page.over-hl .textLayer span { cursor: pointer; }
/* Mark area: the pointer draws instead of selecting. */
.doc-pages.is-area .textLayer { pointer-events: none; }
.doc-pages.is-area .doc-canvas-page.is-drawn { cursor: crosshair; touch-action: none; user-select: none; -webkit-user-select: none; }

mark.hl { cursor: pointer; }
mark.hl:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
mark.hl.has-note { text-decoration: underline dotted; text-decoration-thickness: 1px; text-underline-offset: 3px; }
mark.hl.is-flash, .anno.is-flash { animation: hlFlash 1.1s var(--ease-liquid); }
@keyframes hlFlash {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  25% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 30%, transparent); }
}
.anno.is-flash { border-radius: var(--r-sm); }

@media (prefers-reduced-motion: reduce) {
  .doc-flag.is-busy, .doc-canvas-page::after, mark.hl.is-flash, .anno.is-flash,
  .pg-hl.is-flash, .pg-area.is-flash { animation: none; }
}

/* The attached-document chip above the composer. */
.doc-chip {
  display: inline-flex; align-items: center; gap: 0.4rem;
  align-self: flex-start; margin: 0 0 0.4rem 0.2rem;
  padding: 0.25rem 0.5rem 0.25rem 0.6rem;
  background: var(--accent-soft); color: var(--accent);
  border-radius: var(--r-pill); font-size: 0.76rem; font-weight: 600;
  max-width: 100%;
}
.doc-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-chip button {
  border: none; background: none; color: inherit; cursor: pointer;
  font-size: 1rem; line-height: 1; padding: 0 0.1rem; opacity: 0.7;
}
.doc-chip button:hover { opacity: 1; }

/* The one action on a finished answer. Quiet until the message is hovered,
   because most answers are read and not kept. */
.msg-save {
  display: block; margin-top: 0.5rem;
  border: none; background: none; padding: 0; cursor: pointer;
  font: inherit; font-size: 0.72rem; font-weight: 600;
  color: var(--text-muted); opacity: 0; transition: opacity 0.18s ease, color 0.18s ease;
}
.msg-row:hover .msg-save, .msg-save:focus-visible { opacity: 1; }
.msg-save:hover { color: var(--accent); }
.msg-save:disabled { color: var(--accent); opacity: 1; cursor: default; }
@media (hover: none) { .msg-save { opacity: 1; } }


/* ===================================================================
   SCROLLBARS — one treatment, everywhere
   Lifted from .messages, which was the only place that got it right:
   a transparent track and a slim fully-rounded thumb floating over the
   content's right edge. No rectangular strip butting against a rounded
   card border, which is what every other scroll area was doing.
   =================================================================== */

.messages,
.ws-list,
.ws-detail-body,
.note-body,
.doc-pages,
.doc-rail,
.ws-itabs,
.panel-scroll,
.consent-scroll,
.modal-body,
.terms-body,
.scroll-y {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) transparent;
}
.messages::-webkit-scrollbar,
.ws-list::-webkit-scrollbar,
.ws-detail-body::-webkit-scrollbar,
.note-body::-webkit-scrollbar,
.doc-pages::-webkit-scrollbar,
.doc-rail::-webkit-scrollbar,
.panel-scroll::-webkit-scrollbar,
.consent-scroll::-webkit-scrollbar,
.modal-body::-webkit-scrollbar,
.terms-body::-webkit-scrollbar,
.scroll-y::-webkit-scrollbar { width: 6px; height: 6px; }

.messages::-webkit-scrollbar-track,
.ws-list::-webkit-scrollbar-track,
.ws-detail-body::-webkit-scrollbar-track,
.note-body::-webkit-scrollbar-track,
.doc-pages::-webkit-scrollbar-track,
.doc-rail::-webkit-scrollbar-track,
.panel-scroll::-webkit-scrollbar-track,
.consent-scroll::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track,
.terms-body::-webkit-scrollbar-track,
.scroll-y::-webkit-scrollbar-track { background: transparent; }

.messages::-webkit-scrollbar-thumb,
.ws-list::-webkit-scrollbar-thumb,
.ws-detail-body::-webkit-scrollbar-thumb,
.note-body::-webkit-scrollbar-thumb,
.doc-pages::-webkit-scrollbar-thumb,
.doc-rail::-webkit-scrollbar-thumb,
.panel-scroll::-webkit-scrollbar-thumb,
.consent-scroll::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb,
.terms-body::-webkit-scrollbar-thumb,
.scroll-y::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: var(--r-pill);
  min-height: 42px;
}
.messages::-webkit-scrollbar-thumb:hover,
.ws-list::-webkit-scrollbar-thumb:hover,
.ws-detail-body::-webkit-scrollbar-thumb:hover,
.note-body::-webkit-scrollbar-thumb:hover,
.doc-pages::-webkit-scrollbar-thumb:hover,
.doc-rail::-webkit-scrollbar-thumb:hover,
.panel-scroll::-webkit-scrollbar-thumb:hover,
.consent-scroll::-webkit-scrollbar-thumb:hover,
.modal-body::-webkit-scrollbar-thumb:hover,
.terms-body::-webkit-scrollbar-thumb:hover,
.scroll-y::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); }

/* The platform's own stepper buttons are the other half of the look the
   chat window has: arrow, pill, arrow. They are left alone deliberately —
   styling them away is what produced the bare rectangular strip. */


/* ================= Conversation history (chat page + staff transcript) ===== */

.day-sep {
  display: flex; align-items: center; gap: 0.75rem;
  margin: 0.9rem 0 0.2rem; color: var(--text-muted);
  font-size: 0.68rem; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase;
}
.day-sep::before, .day-sep::after { content: ''; flex: 1; height: 1px; background: var(--border-hair); }
.history-note {
  align-self: center; width: fit-content; max-width: min(34rem, 100%);
  margin: 0 auto; padding: 0.4rem 0.9rem; border-radius: var(--r-pill);
  background: var(--surface-3); color: var(--text-muted);
  font-size: 0.74rem; line-height: 1.45; text-align: center;
}
.msg-redacted, .tx-tag { text-decoration: underline dotted; text-underline-offset: 2px; cursor: help; }

.transcript {
  display: flex; flex-direction: column; gap: 0.8rem;
  max-width: 920px; margin: 0 auto;
}
@media (min-width: 1800px) { .transcript { max-width: 1080px; } }
.tx-row { display: flex; }
.tx-row.user { justify-content: flex-end; }
.tx-bubble {
  max-width: min(80%, 660px); min-width: 0;
  padding: 0.65rem 0.95rem; border-radius: var(--r-md);
  font-size: 0.9rem; line-height: 1.55; word-break: break-word;
}
.tx-row.user .tx-bubble {
  background: var(--user-bubble); color: var(--user-bubble-text);
  border-bottom-right-radius: 4px;
}
.tx-row.bot .tx-bubble {
  background: var(--bot-bubble); color: var(--bot-bubble-text);
  border: 1px solid var(--border); border-bottom-left-radius: 4px;
}
.tx-text { white-space: pre-wrap; font-feature-settings: "liga" 0, "calt" 0; }
.tx-meta {
  margin-top: 0.3rem; font-size: 0.68rem; opacity: 0.8;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}
.tx-html > :first-child { margin-top: 0; }
.tx-html > :last-child { margin-bottom: 0; }
.tx-html p { margin: 0.4rem 0; }
.tx-html ul, .tx-html ol { margin: 0.4rem 0; padding-left: 1.3rem; }
.tx-html pre {
  margin: 0.55rem 0; padding: 0.75rem 0.9rem; overflow-x: auto;
  background: #0f172a; color: #e2e8f0; border-radius: var(--r-sm);
  font-size: 0.8rem; line-height: 1.55;
}
.tx-html code {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.86em;
}
.tx-html :not(pre) > code { background: var(--surface-3); padding: 0.08rem 0.3rem; border-radius: 4px; }
.tx-gap {
  align-self: center; width: fit-content; max-width: 100%;
  padding: 0.45rem 0.95rem; border-radius: var(--r-pill);
  border: 1px dashed var(--field-border); color: var(--text-muted);
  font-size: 0.74rem; text-align: center; line-height: 1.45;
}
@media (max-width: 640px) {
  .tx-bubble { max-width: 92%; }
}
