/* ==========================================================================
   AI Weekly Podcast — light "studio" theme (self-contained, no CDN/fonts)
   ========================================================================== */

:root {
  /* TNG corporate palette (Confluence: "TNG-Farben"). Primary blue #0563A5,
     primary grey #A1A6AE, secondary red #93272C, plus the documented shade
     steps. Per the CI guidance only these colors are used — other hues are
     discouraged, so functional colors (ok/warn/danger) reuse the palette. */
  --tng-blue: #0563a5;
  --tng-grey: #a1a6ae;
  --tng-red: #93272c;

  --bg: #111315;
  /* Surfaces are translucent on purpose: the page sits on the constellation
     artwork, so the panels let it through (backdrop-filter keeps text crisp). */
  --surface: rgba(54, 56, 61, 0.42);
  --surface-2: rgba(111, 115, 121, 0.18);
  /* Only the history chips are glass; the chrome around them is clear. */
  --aside-surface: rgba(54, 56, 61, 0.06);
  --border: #6f7379;
  --border-strong: #a1a6ae;
  --text: #f8f8fa;
  --muted: #d1d4db;
  --primary: #6090c0;
  --primary-strong: #b5dffd;
  --primary-soft: rgba(96, 144, 192, 0.22);
  --accent: #db7073;
  --ok: #b5dffd;
  --ok-bg: rgba(96, 144, 192, 0.24);
  --warn: #db7073;
  --warn-bg: rgba(147, 39, 44, 0.35);
  --danger: #db7073;
  --danger-bg: rgba(147, 39, 44, 0.35);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 10px 32px rgba(0, 0, 0, 0.55);
  --ring: 0 0 0 3px rgba(96, 144, 192, 0.4);
  --radius: 12px;
  --radius-sm: 8px;
  /* Page backdrop: constellation artwork. Swap this one line (e.g. point it at
     /static/bg.jpg) to change the picture; the scrim below keeps text legible. */
  --bg-image: url("/static/bg-network.svg");
  --bg-scrim: linear-gradient(180deg, rgba(10, 12, 18, 0.58), rgba(10, 12, 18, 0.74));
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* Dark is the only theme (it is built for the artwork), so native controls
     (selects, inputs, scrollbars) render dark too. */
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  /* The shell fills the viewport and never scrolls: the history and the
     episode pane scroll inside it. */
  overflow: hidden;
  /* The scrim is the first layer (painted on top); the artwork sits behind it,
     so panels keep their contrast while the page gets depth. */
  background-color: var(--bg);
  background-image: var(--bg-scrim), var(--bg-image);
  background-size: cover, cover;
  background-position: center, center;
  background-repeat: no-repeat, no-repeat;
  background-attachment: fixed, fixed;
  -webkit-font-smoothing: antialiased;
}

/* Dark theme: let the artwork through much more, with a darker scrim. */

/* Frosted chrome: the large panels are translucent (see --surface), so blur
   keeps their content legible over the artwork. */
.modal {
  -webkit-backdrop-filter: blur(18px) saturate(130%);
  backdrop-filter: blur(18px) saturate(130%);
}

button, input, select { font: inherit; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: var(--radius-sm);
}

.muted { color: var(--muted); }

.hidden { display: none !important; }

/* Reduced motion: keep transitions instant (they are feedback, not
   decoration), but do NOT freeze animations wholesale — an `!important`
   duration on `*` silently stopped the wave, the job spinner and toasts for
   every OS with "reduce motion" on. Animated elements opt out individually. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
  }
}

/* --- buttons ------------------------------------------------------------- */

button {
  padding: 7px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease,
              box-shadow 0.15s ease, color 0.15s ease, transform 0.05s ease;
}
button:hover { background: var(--surface-2); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary {
  background: linear-gradient(180deg, var(--primary), var(--primary-strong));
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(5, 99, 165, 0.35);
}
button.primary:hover { background: var(--primary-strong); }

button.ghost { background: transparent; border-color: var(--border-strong); }
button.ghost:hover { background: var(--surface-2); }

.nav-link {
  display: inline-flex; align-items: center; padding: 8px 12px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  color: var(--text); text-decoration: none; font-size: 0.9rem;
}
.nav-link:hover { background: var(--surface-2); }

button.danger { color: var(--danger); border-color: var(--danger-border); background: var(--danger-bg); }
button.danger:hover { background: var(--danger-bg); }

button.link {
  border: none; background: none; color: var(--primary);
  padding: 2px; box-shadow: none;
}
button.link:hover { background: none; text-decoration: underline; }
button.link.danger { color: var(--danger); }
button.link.danger:hover { color: var(--danger); }

/* --- header --------------------------------------------------------------- */

.app-header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 22px;
  /* Fully transparent: the artwork runs behind the top row and the left
     column alike, so the page reads as one surface. Only the history chips
     and the dialogs are glass. */
  background: none;
  border-bottom: 0;
  box-shadow: none;
  overflow: hidden;
  isolation: isolate;
}

/* The wave lives in the *empty* middle of the banner, never behind the
   wordmark or the buttons: it is a flex item with the remaining space, capped
   so it stays a mark rather than a band. */
.header-wave-slot {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 660px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 20px;
  pointer-events: none;
}

/* The two hosts: outline only, one stroke, no fill. */
.wave-figure {
  flex: 0 0 auto;
  width: 54px;
  height: 54px;
  color: #ffffff;
  opacity: 0.8;
  /* The glyphs carry ~25 % padding inside their 32-unit viewBox, so a small
     flex gap already reads as a comfortable one. */
  filter: drop-shadow(0 0 10px rgba(60, 110, 200, 0.55));
}

/* The ribbon itself is what fades at the edges, not the figures. */
.header-wave-clip {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  /* A tight fade only: the travelling pattern has real amplitude at both clip
     edges, so without it the ribbon is cut with a hard vertical edge. the window is ~520 px, so 6 % ≈ 31 px of dissolve — smooth, and it
     reads as the wave arriving from off-screen. */
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
}
/* The wave stays put and breathes in amplitude: each of the five layers
   swells and settles on its own period, so the ribbon looks like it is being
   modulated rather than sliding past. */
.header-wave {
  display: block;
  width: 1120px;                /* two periods of 560 units */
  height: 64px;
  filter: drop-shadow(0 0 16px rgba(60, 110, 200, 0.5));
}

/* Travelling wave: the SVG holds two identical periods and the track slides
   exactly one of them per cycle, so the crests propagate left → right inside a
   fixed window — cos(ωt − x) rather than a graphic sliding past. */
.header-wave-track {
  width: 1120px;
  height: 64px;
  animation: wave-travel 7s linear infinite;
}

@keyframes wave-travel {
  from { transform: translateX(-50%); }
  to   { transform: translateX(0); }
}

.wave-layer {
  transform-box: fill-box;
  transform-origin: center;
  will-change: transform;
  /* Sine-ish oscillation: the timing function approximates sin() between the
     keys, so each layer swells and settles smoothly instead of stepping. */
  animation: wave-oscillate var(--dur, 3s) cubic-bezier(0.45, 0, 0.55, 1) infinite;
  animation-delay: var(--delay, 0s);
}

@keyframes wave-oscillate {
  0%   { transform: scaleY(0.78) scaleX(1); }
  18%  { transform: scaleY(1.00) scaleX(1.008); }
  32%  { transform: scaleY(0.80) scaleX(1); }
  50%  { transform: scaleY(1.09) scaleX(1.012); }
  68%  { transform: scaleY(0.84) scaleX(1); }
  82%  { transform: scaleY(1.03) scaleX(1.006); }
  100% { transform: scaleY(0.78) scaleX(1); }
}

@media (prefers-reduced-motion: reduce) {
  /* slower travel, no per-layer breathing */
  .wave-layer { animation: none; }
  .header-wave-track { animation-duration: 24s; }
}


.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  flex: 0 0 auto;
  width: 40px; height: 40px; border-radius: 12px;
  display: block;
  box-shadow: 0 4px 14px rgba(47, 111, 208, 0.35);
}

.brand-text h1 { margin: 0; font-size: 16px; letter-spacing: -0.01em; }

.tagline { font-size: 12px; color: var(--muted); }

/* Listener (non-admin) badge next to the tagline. */
.listener-note {
  display: inline-block; margin-left: 8px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: #36383d;
  background: #d1d4db; border: 1px solid #b8bcc3; border-radius: 999px;
  padding: 1px 8px;
}

.header-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* --- layout --------------------------------------------------------------- */

/* the app shell: one viewport tall, panes scroll inside */
.shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

main {
  display: flex;
  /* Take the rest of the viewport (no magic header height), and let the two
     panes, not the page, be the scroll containers. */
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* --- history sidebar ------------------------------------------------------ */

aside#episode-list {
  width: clamp(230px, 26vw, 360px); flex: 0 0 clamp(230px, 26vw, 360px);
  /* Transparent like the episode pane: the artwork runs behind the whole
     content area; only the rows themselves are glass. */
  background: none;
  border-right: 0;
  overflow-y: auto;
  padding: 14px 12px 16px;
}

.list-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 6px 10px;
}
.list-head h2 {
  margin: 0; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted);
}
.count-chip {
  font-size: 11px; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 9px;
}

aside ul { list-style: none; margin: 0; padding: 0; }
aside li {
  position: relative;
  padding: 10px 12px 10px 14px;
  margin-bottom: 6px;
  /* The chips are the only glass in the sidebar: rows read as objects sitting
     on the artwork, the column around them stays clear. */
  background: var(--aside-surface);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  backdrop-filter: blur(10px) saturate(120%);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
aside li::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px;
  border-radius: 3px; background: transparent;
}
aside li:hover { background: var(--surface-2); border-color: var(--border); }
/* The pinned featured episode: light TNG-blue tint + blue edge marker. */
aside li.featured {
  background: var(--primary-soft);
  border-color: rgba(5, 99, 165, 0.35);
}
aside li.featured::before { background: var(--primary); }
aside li.featured .ep-date { color: var(--primary); }
/* The currently selected episode: solid TNG blue, clearly distinct from the
   featured tint above (and wins when an item is both). */
aside li.active {
  background: var(--primary);
  border-color: var(--primary);
}
aside li.active::before { background: #b5dffd; }
aside li.active .ep-date { color: #fff; }
aside li.active .ep-meta { color: #b5dffd; }
aside li.active .ep-star { color: #fff; }
aside li.featured.active { border-color: var(--primary-strong); }
aside li.empty-hint { cursor: default; color: var(--muted); border: 0; }
aside li.empty-hint:hover { background: transparent; }
/* Every episode/version row gets a compact vN marker in its upper-left corner. */
aside li.versioned { padding-left: 48px; }
.version-badge {
  position: absolute; top: 8px; left: 8px;
  min-width: 25px; padding: 1px 5px; text-align: center;
  font-family: var(--mono); font-size: 10px; font-weight: 700;
  color: var(--primary-strong); background: var(--primary-soft);
  border: 1px solid rgba(37, 99, 235, 0.24); border-radius: 4px;
}

.ep-date { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.ep-star { color: var(--accent); font-size: 13px; }
.ep-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

.badge {
  font-size: 10px; font-weight: 600; padding: 1px 7px;
  border-radius: 999px; text-transform: capitalize;
}
.badge-ready { background: var(--ok-bg); color: var(--ok); }
.badge-draft { background: var(--warn-bg); color: var(--warn); }
.badge-empty { background: var(--surface-2); color: var(--muted); }
.badge-debug { background: var(--warn-bg); color: var(--accent); }

/* --- detail --------------------------------------------------------------- */

section#detail { flex: 1; overflow-y: auto; padding: 22px 28px 40px; }

.empty-state {
  height: 100%; min-height: 320px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 6px; color: var(--muted);
}
.empty-state h2 { margin: 10px 0 0; color: var(--text); font-size: 18px; }
.empty-state .muted { max-width: 340px; }
.empty-orb {
  width: 64px; height: 64px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-soft), #d1d4db);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
}
.empty-orb::after {
  content: ""; width: 0; height: 0; margin-left: 4px;
  border-left: 18px solid var(--primary);
  border-top: 11px solid transparent;
  border-bottom: 11px solid transparent;
}

.hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px 16px;
  margin-bottom: 18px;
}

.detail-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.detail-head h2 { margin: 0; font-size: 20px; letter-spacing: -0.01em; }

.chip {
  font-size: 12px; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 2px 10px;
}
.chip-customized { color: var(--accent); background: #faebeb; border-color: #f0c2c3; }
.chip-debug { color: var(--accent); background: #faebeb; border-color: #f0c2c3; }
.chip-topic { color: var(--primary-strong); background: var(--primary-soft); border-color: rgba(5, 99, 165, 0.25); }

/* --- custom audio player (rounded seek bar) ------------------------------- */
/* Native <audio controls> cannot be styled, so the player is a button + range
   input. Track 8px high, thumb 14px, both vertically centered by the flex row
   (the thumb overflows the track symmetrically — no clipping). */
.player {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0 14px;
}
.player-toggle {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.player-toggle:hover {
  background: var(--primary-strong);
  border-color: var(--primary-strong);
}
.player-seek {
  flex: 1 1 auto;
  display: block;
  height: 8px;
  margin: 0;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    var(--primary) var(--fill, 0%),
    var(--border) var(--fill, 0%)
  );
  cursor: pointer;
}
.player-seek::-moz-range-track {
  height: 8px;
  border: 0;
  border-radius: 999px;
  background: transparent;
}
.player-seek::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--primary);
  box-shadow: var(--shadow-sm);
}
.player-seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--primary);
  box-shadow: var(--shadow-sm);
}
.player-time {
  flex: 0 0 auto;
  min-width: 92px;
  text-align: right;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.player-audio { display: none; }

.hero-actions { display: flex; gap: 10px; margin-top: 4px; }

/* Featured episode: the detail hero gets a TNG-blue backdrop so the pinned
   episode reads as the official one. Text/chips use the colors cleared for
   TNG blue (#FFFFFF, #E6F4FE, #B5DFFD, #F0C2C3). */
.featured-detail .hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%);
  border-color: var(--primary-strong);
  color: #fff;
  box-shadow: var(--shadow-md);
}
.featured-detail .hero .detail-head h2 { color: #fff; }
.featured-detail .hero .chip {
  color: #e6f4fe;
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(181, 223, 253, 0.6);
}
.featured-detail .hero .chip-featured { color: #fff; background: rgba(255, 255, 255, 0.22); }
.featured-detail .hero .chip-customized {
  color: #f0c2c3; background: rgba(147, 39, 44, 0.55); border-color: #db7073;
}
.featured-detail .hero .nav-link {
  color: #e6f4fe; border-color: rgba(181, 223, 253, 0.6);
}
.featured-detail .hero .nav-link:hover { background: rgba(255, 255, 255, 0.12); }
.featured-detail .hero button.ghost {
  color: #e6f4fe; background: transparent; border-color: rgba(181, 223, 253, 0.6);
}
.featured-detail .hero button.ghost:hover { background: rgba(255, 255, 255, 0.12); }
.featured-detail .hero button.danger {
  color: #f0c2c3; background: transparent; border-color: #db7073;
}
.featured-detail .hero button.danger:hover { background: rgba(147, 39, 44, 0.35); }
/* Player on the blue backdrop: light track fill, white thumb, light times. */
.featured-detail .hero .player-toggle {
  background: #fff; border-color: #fff; color: var(--primary);
}
.featured-detail .hero .player-toggle:hover { background: #e6f4fe; border-color: #e6f4fe; }
.featured-detail .hero .player-seek {
  background: linear-gradient(
    to right,
    #b5dffd var(--fill, 0%),
    rgba(255, 255, 255, 0.28) var(--fill, 0%)
  );
}
.featured-detail .hero .player-seek::-moz-range-thumb {
  background: #fff; border-color: rgba(5, 99, 165, 0.7);
}
.featured-detail .hero .player-seek::-webkit-slider-thumb {
  background: #fff; border-color: rgba(5, 99, 165, 0.7);
}
.featured-detail .hero .player-time { color: #e6f4fe; }

/* action row pinned to the top of a tab body */
.tab-toolbar {
  display: flex; justify-content: flex-end; align-items: center;
  gap: 10px; margin: 0 0 14px;
}

/* segmented tabs */
.tabs {
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  margin-bottom: 14px;
}
.tabs button {
  border: 0; background: transparent; color: var(--muted);
  padding: 6px 16px; border-radius: 999px;
}
.tabs button.active {
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm);
}

.tab-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px 20px;
}

.tab-body.markdown { font-family: inherit; white-space: normal; }
.tab-body.markdown h2 {
  margin: 26px 0 12px; font-size: 12.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted);
  display: flex; align-items: center; gap: 10px;
}
.tab-body.markdown h2::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}
.tab-body.markdown h2:first-child { margin-top: 0; }

/* the episode summary: a lead paragraph above the source list */
.tab-body.markdown .brief-summary {
  margin: 0 0 6px; padding: 13px 16px;
  font-size: 14.5px; line-height: 1.6; color: var(--text);
  background: var(--surface-2);
  border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.tab-body.markdown ul.brief-items { list-style: none; padding-left: 0; margin: 8px 0 18px; }
.tab-body.markdown ul.brief-items li {
  padding: 10px 13px; border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  margin-bottom: 8px; background: var(--surface);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.tab-body.markdown ul.brief-items li:hover {
  background: var(--primary-soft); border-color: var(--primary);
}
.tab-body.markdown ul.brief-items li > a { font-weight: 600; line-height: 1.45; }
.tab-body.markdown a { color: var(--primary); text-decoration: none; }
.tab-body.markdown a:hover { text-decoration: underline; }
.tab-body.markdown a.pdf { color: var(--muted); font-size: 0.9em; }
.tab-body.markdown .score { color: var(--ok); font-weight: 600; }
.tab-body.markdown .label {
  display: block; width: fit-content;
  margin-top: 3px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.015em;
  color: #36383d;
  background: #d1d4db; border: 1px solid #b8bcc3; border-radius: 999px;
  padding: 1px 9px;
}
.tab-body.markdown blockquote {
  margin: 6px 0 10px; padding: 6px 14px; border-left: 3px solid var(--border-strong);
  color: var(--muted); font-size: 13px; background: var(--surface-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* cross-episode memory tab */
.tab-body.markdown .mem-list { display: flex; flex-direction: column; gap: 10px; }
.tab-body.markdown .mem-topic {
  padding: 9px 12px; background: var(--bg); border-left: 3px solid var(--border-strong);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.tab-body.markdown .mem-topic p { margin: 6px 0 0; font-size: 13.5px; color: var(--text); }
.tab-body.markdown .mem-topic .chip-topic { font-size: 11.5px; }

/* transcript dialogue */
.tab-body.markdown .trn.turn {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 9px 0; border-bottom: 1px dashed var(--border);
}.tab-body.markdown .trn.turn:last-child { border-bottom: none; }
.trn-speaker {
  flex: 0 0 30px; width: 30px; height: 30px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff; margin-top: 1px;
}
.trn-Person1 { background: var(--primary); }
.trn-Person2 { background: var(--accent); }
.trn-text { flex: 1; line-height: 1.55; }
.trn-name { display: block; font-size: 11px; font-weight: 700; color: var(--muted); margin-bottom: 1px; }

/* transcript editor (per-turn textareas) — same white card as the view */
.trn-edit-list {
  max-width: 820px; margin-top: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 20px;
}
.trn-edit {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 10px 0; border-bottom: 1px dashed var(--border);
}
.trn-edit:last-child { border-bottom: none; }
.trn-edit-raw { color: var(--muted); font-size: 12px; padding: 6px 0; white-space: pre-wrap; }
.trn-edit-body { flex: 1; min-width: 0; }
.trn-edit-text {
  width: 100%; box-sizing: border-box; resize: vertical;
  font: inherit; line-height: 1.55; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px 8px;
}
.trn-edit-text:hover { border-color: var(--border-strong); }
.trn-edit-text:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}

/* concepts tab */
.concept-list { max-width: 820px; margin-top: 12px; }
.concept-item {
  display: flex; gap: 10px; align-items: flex-start; cursor: pointer;
  padding: 9px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 8px; background: var(--surface);
}
.concept-item input { margin-top: 3px; }
.concept-body { display: flex; flex-direction: column; gap: 2px; }
.concept-term { font-weight: 600; }
.concept-context { font-size: 12.5px; color: var(--muted); }

/* concept background: deep-search results shown at the end of the brief tab */
.tab-body.markdown .concept-bg-list { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 18px; }
.tab-body.markdown .concept-bg {
  padding: 12px 15px; background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.tab-body.markdown .concept-bg-term { font-weight: 700; margin-bottom: 4px; }
.tab-body.markdown .concept-bg p { margin: 0; font-size: 14px; line-height: 1.6; }
.tab-body.markdown .concept-bg-sources {
  margin-top: 7px; font-size: 12.5px; color: var(--muted);
}
.tab-body.markdown .concept-bg-sources a { color: var(--primary); }

/* --- edit brief ----------------------------------------------------------- */

.perso-head { margin-bottom: 4px; }
.perso-list { max-width: 820px; margin-top: 12px; }
.perso-item {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 8px; background: var(--surface);
  transition: opacity 0.15s ease, background 0.15s ease;
}
.perso-item.removed { opacity: 0.5; background: var(--surface-2); }
.perso-item .main { flex: 1; min-width: 0; }
.perso-item .title { font-weight: 600; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.perso-item .title a { color: var(--primary); text-decoration: none; }
.perso-item .title a:hover { text-decoration: underline; }
.perso-item .reason {
  font-size: 12px; color: var(--muted); margin-top: 5px; font-style: italic;
  border-left: 2px solid var(--border-strong); padding-left: 10px;
}
.perso-actions { display: flex; flex-direction: column; gap: 4px; }
.perso-actions-row { margin-top: 14px; display: flex; gap: 10px; }

.tag {
  font-size: 10px; font-weight: 700; padding: 1px 7px; border-radius: 999px;
  letter-spacing: 0.02em;
}
.tag-src { background: var(--primary-soft); color: var(--primary-strong); }
.tag-score { background: var(--ok-bg); color: var(--ok); font-family: var(--mono); font-weight: 600; }
.tag-label { background: var(--accent-bg, #faebeb); color: var(--accent); }
.tag-removed { background: var(--surface-2); color: var(--muted); }

/* --- topic selector (settings) -------------------------------------------- */

.topic-fieldset {
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 8px 10px 10px; margin: 4px 0 2px;
  grid-column: 1 / -1;   /* span the full settings grid width */
}
.topic-fieldset legend {
  font-size: 12px; font-weight: 600; padding: 0 6px; color: var(--muted);
}
.topic-checks {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 4px 12px;
}
.topic-check {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px; padding: 3px 4px; border-radius: 6px;
}
.topic-check:hover { background: var(--surface-2); }
.topic-check input { accent-color: var(--primary); }

/* --- modals --------------------------------------------------------------- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(17, 19, 21, 0.45);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: min(760px, 94vw); max-width: 100%;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 18px 22px 20px;
}
.modal-sm { width: 420px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-close {
  border: 0; background: transparent; color: var(--muted);
  font-size: 14px; padding: 4px 8px; border-radius: 50%;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal .muted { margin: 6px 0 0; }
.modal-section { margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--border); }
.modal-section h4 { margin: 0 0 10px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

.cfg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px 16px;
}
.cfg-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 600; }
.cfg-grid input, .cfg-grid select {
  padding: 7px 9px; font-size: 13px; color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface);
}
.cfg-grid input:focus, .cfg-grid select:focus { border-color: var(--primary); }

.debug-toggle {
  display: flex; align-items: center; gap: 8px;
  margin: 12px 0 0; padding: 9px 11px;
  font-size: 13px; font-weight: 600; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer;
}
.debug-toggle input { width: 16px; height: 16px; accent-color: var(--accent); }
.debug-note { margin: 7px 1px 0; max-width: 620px; }

.stat-pill {
  margin: 13px 0 0; display: inline-block;
  font-size: 12px; font-weight: 700; color: var(--primary-strong);
  background: var(--primary-soft); border: 1px solid rgba(5, 99, 165, 0.3);
  border-radius: 999px; padding: 4px 14px;
}
.confirm-message { color: var(--text); margin: 8px 0 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* --- jobs panel (floating list of queued + running jobs) -------------------- */

#run-panel {
  position: fixed; bottom: 0; right: 22px; width: 640px; max-width: calc(100vw - 44px);
  background: var(--surface); border: 1px solid var(--border);
  border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -8px 30px rgba(17, 19, 21, 0.18); z-index: 100;
}

.run-panel-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
}
.run-panel-head h3 { margin: 0; font-size: 13px; }

.jobs-list { display: flex; flex-direction: column; gap: 10px; padding: 12px 16px 16px; }

.job-row {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 12px; background: var(--bg);
}
.job-row-queued { opacity: 0.85; }

.job-row-head { display: flex; align-items: center; gap: 8px; }
.job-row-name {
  flex: 1; min-width: 0; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.job-row-cancel,
.job-row-dismiss { padding: 0 4px; }

.job-row-meta {
  margin-top: 6px; font-size: 12px; color: var(--muted);
  display: flex; justify-content: space-between; gap: 8px;
  flex-wrap: wrap;
}
.job-row-stage { display: inline-flex; align-items: center; gap: 6px; }
.job-row-time { white-space: nowrap; }
.job-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--primary); display: inline-block;
  animation: job-pulse 1.1s ease-in-out infinite;
}
@keyframes job-pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.1); }
}
.job-row-failed { border-color: rgba(147, 39, 44, 0.5); }
.job-row-error {
  flex-basis: 100%; color: var(--danger); font-family: var(--mono);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* job-status badges */
.badge-queued { background: var(--surface-2); color: var(--muted); }
.badge-running { background: var(--primary-soft); color: var(--primary-strong); }
.badge-done { background: var(--ok-bg); color: var(--ok); }
.badge-failed { background: var(--danger-bg); color: var(--danger); }
.badge-cancelled { background: var(--warn-bg); color: var(--warn); }

.error-message {
  margin: 0; padding: 10px 12px; max-height: 240px; overflow-y: auto;
  font-family: var(--mono); font-size: 12px; line-height: 1.45;
  white-space: pre-wrap; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--danger);
}

/* --- toasts --------------------------------------------------------------- */

.toasts {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  background: #111315; color: #f8f8fa;
  border-radius: 999px; padding: 8px 18px; font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.2s ease;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast-error { background: var(--danger); color: #fff; }
.toast-info { background: var(--primary); color: #fff; }
.toast-out { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* --- responsive ----------------------------------------------------------- */

@media (max-width: 1100px) {
  aside#episode-list { width: clamp(230px, 24vw, 300px); flex-basis: clamp(230px, 24vw, 300px); }
  section#detail { padding: 18px 20px 36px; }
}

@media (max-width: 900px) {
  .app-header { flex-wrap: wrap; }
  .header-wave-slot { display: none; }
  /* Stacked panes: the page itself may scroll here. */
  body { overflow: auto; }
  main { flex-direction: column; height: auto; overflow: visible; }
  aside#episode-list {
    width: 100%; flex: none; border-right: 0; border-bottom: 1px solid var(--border);
    max-height: 40vh; min-height: 180px;
  }
  section#detail { padding: 16px; }
  #run-panel { right: 0; left: 0; width: auto; max-width: none; border-radius: 0; }
}

@media (max-width: 700px) {
  .tagline { display: none; }
  .hero { padding: 14px 16px 12px; }
  .detail-head h2 { font-size: 18px; }
  section#detail { padding: 14px 12px 28px; }
  .perso-item { flex-direction: column; }
  .perso-actions { flex-direction: row; align-items: center; }
  .modal-actions, .hero-actions { flex-wrap: wrap; }
  .modal { padding: 16px 16px 20px; }
}

@media (max-width: 480px) {
  .brand-text h1 { font-size: 15px; }
  .modal { padding: 14px 12px 18px; }
  .cfg-grid { gap: 10px; }
}

/* --- dark theme components ----------------------------------------------- */
/* The palette is dark everywhere (see :root); these are the few components
   that need an explicit colour rather than a variable. */
/* Primary buttons stay TNG blue with white text (both cleared for blue). */
button.primary {
  background: var(--tng-blue);
  border-color: var(--tng-blue);
}
button.primary:hover { background: #2d567d; }

/* Selected history row: the deep TNG blue keeps white text readable. */
aside li.active { background: #0563a5; border-color: #0563a5; }
.toast { background: #f8f8fa; color: #111315; }
.tab-body.markdown blockquote { background: rgba(111, 115, 121, 0.2); }
.error-message { background: rgba(147, 39, 44, 0.25); }
.chip-customized {
  color: #f0c2c3; background: rgba(147, 39, 44, 0.35); border-color: #93272c;
}
/* The featured detail hero keeps the TNG-blue backdrop. */
.featured-detail .hero {
  background: linear-gradient(135deg, #0563a5 0%, #2d567d 100%);
}
.featured-detail .hero .chip { background: rgba(255, 255, 255, 0.14); }

/* Session-expired overlay: shown before re-login when the Cognito token dies. */
.session-expired {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(17, 19, 21, 0.55);
}
.session-expired-card {
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: 12px; padding: 26px 30px; max-width: 420px; text-align: center;
  box-shadow: 0 12px 32px rgba(17, 19, 21, 0.3);
}
.session-expired-card h2 { margin: 0 0 8px; font-size: 18px; }
.session-expired-card p { margin: 0 0 18px; color: var(--muted); }
