:root {
  --page: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #eef3f8;
  --ink: #17202f;
  --muted: #657186;
  --line: #dce3ed;
  --blue: #1764e8;
  --green: #1c8d62;
  --amber: #b96c12;
  --rose: #c44964;
  --cyan: #0f7f98;
  --radius: 8px;
  --shadow: 0 14px 34px rgba(23, 32, 47, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--page);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button, input { font: inherit; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 320px minmax(0, 1fr); align-items: start; }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
  background: #fbfcfe;
  border-right: 1px solid var(--line);
}

.brand { display: grid; gap: 6px; }

.eyebrow { margin: 0; color: var(--blue); font-size: 12px; font-weight: 700; text-transform: uppercase; }

h1, h2, h3, p { margin: 0; }
h1 { font-size: 22px; line-height: 1.2; }
h2 { font-size: 24px; line-height: 1.25; overflow-wrap: anywhere; }
h3 { font-size: 15px; line-height: 1.3; }

.subtitle, .panel-heading p, .metric span, .small, .detail-state { color: var(--muted); font-size: 12px; line-height: 1.5; }

.search-input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}

.search-input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23, 100, 232, 0.12); }
.search-input:disabled { cursor: wait; color: var(--muted); background: var(--surface-soft); }

.episode-list { display: grid; flex: 1; min-height: 0; gap: 8px; overflow: auto; padding-right: 2px; }

.episode-button {
  width: 100%;
  min-width: 0;
  padding: 10px;
  cursor: pointer;
  text-align: left;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
}

.episode-button:hover { background: var(--surface-soft); }
.episode-button.active { background: #e9f1ff; border-color: #bdd4ff; }

.episode-title { display: block; overflow-wrap: anywhere; font-size: 13px; font-weight: 700; line-height: 1.4; }
.episode-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 7px; color: var(--muted); font-size: 12px; }

.main-content { min-width: 0; padding: 22px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 18px; }
.topbar > div { min-width: 0; display: grid; gap: 8px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  white-space: nowrap;
  color: var(--green);
  background: #eef9f3;
  border: 1px solid #b9dbc9;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.metric { display: grid; align-content: start; gap: 8px; min-height: 86px; padding: 14px; }
.metric p { color: var(--muted); font-size: 12px; }
.metric strong { font-size: 24px; line-height: 1; overflow-wrap: anywhere; }

.content-grid { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.4fr); gap: 16px; align-items: start; }
.structure-stack { display: grid; gap: 16px; }
.panel { min-width: 0; padding: 16px; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; }
.panel-heading > div { display: grid; gap: 4px; }

.local-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.local-metrics .metric { box-shadow: none; }

.speaker-bars { display: grid; gap: 10px; }
.speaker-row { display: grid; grid-template-columns: 86px minmax(0, 1fr) 52px; align-items: center; gap: 10px; font-size: 12px; }
.speaker-row strong { overflow-wrap: anywhere; }
.bar-track { height: 9px; overflow: hidden; background: var(--surface-soft); border-radius: 999px; }
.bar-fill { height: 100%; min-width: 4px; border-radius: inherit; }

.timeline { min-height: 110px; padding: 12px; overflow: hidden; background: #fbfcfe; border: 1px solid var(--line); border-radius: var(--radius); }
.timeline-track { position: relative; height: 22px; margin-bottom: 8px; overflow: hidden; background: var(--surface-soft); border-radius: 999px; }
.timeline-bar { position: absolute; top: 0; height: 100%; min-width: 2px; border-radius: 999px; }
.timeline-labels { display: flex; justify-content: space-between; margin-top: 4px; color: var(--muted); font-size: 11px; }

.reader { min-height: 680px; }
.reader-tools { display: grid; gap: 12px; margin-bottom: 14px; }
.speaker-filter { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 30px; padding: 5px 10px; cursor: pointer; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; font-size: 12px; font-weight: 700; }
.chip.active { color: #ffffff; background: var(--ink); border-color: var(--ink); }

.transcript-list { display: grid; gap: 8px; max-height: 640px; overflow: auto; padding-right: 4px; }
.transcript-row { display: grid; grid-template-columns: 66px 92px minmax(0, 1fr) 54px; gap: 10px; align-items: start; padding: 10px; background: #fbfcfe; border: 1px solid var(--line); border-radius: var(--radius); }
.time { color: var(--blue); font-size: 12px; font-weight: 800; white-space: nowrap; }
.speaker-badge { display: inline-flex; justify-content: center; min-width: 78px; padding: 4px 8px; color: #ffffff; border-radius: 999px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.sentence { font-size: 14px; line-height: 1.65; overflow-wrap: anywhere; }
.speed { color: var(--muted); font-size: 12px; text-align: right; white-space: nowrap; }
.empty { padding: 28px; color: var(--muted); text-align: center; background: #fbfcfe; border: 1px dashed var(--line); border-radius: var(--radius); }
mark { padding: 0 2px; color: inherit; background: #fff0b8; border-radius: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 280px minmax(0, 1fr); }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content-grid { grid-template-columns: 1fr; }
  .reader { min-height: 520px; }
}

@media (max-width: 760px) {
  .app-shell { display: block; max-width: 100vw; overflow-x: hidden; }
  .sidebar { position: static; height: auto; min-height: auto; max-width: 100vw; border-right: 0; border-bottom: 1px solid var(--line); }
  .episode-list { max-height: 260px; }
  .main-content { max-width: 100vw; padding: 16px; overflow-x: hidden; }
  .topbar { flex-direction: column; }
  .metrics, .local-metrics { grid-template-columns: 1fr; }
  .transcript-row { grid-template-columns: 58px minmax(0, 1fr); }
  .speaker-badge { justify-self: start; }
  .sentence, .speed { grid-column: 1 / -1; }
  .speed { text-align: left; }
}
