:root {
  --bg: oklch(97% 0.008 80);
  --surface: oklch(99% 0.006 80);
  --surface-alt: oklch(95% 0.012 82);
  --line: oklch(82% 0.025 78);
  --ink: oklch(25% 0.018 68);
  --muted: oklch(48% 0.02 70);
  --accent: oklch(48% 0.12 42);
  --accent-dark: oklch(34% 0.09 42);
  --accent-soft: oklch(90% 0.045 55);
  --good: oklch(45% 0.09 150);
  --shadow: 0 18px 42px oklch(35% 0.025 70 / 0.12);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

a {
  color: var(--accent-dark);
}

.app-shell {
  width: min(1380px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 36px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 10px 0 18px;
}

.topbar-actions,
.search-row,
.admin-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 3.5vw, 3.6rem);
  line-height: 0.96;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 5px;
  font-size: 1.05rem;
}

h3 {
  font-size: 1rem;
}

.search-surface,
.panel {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.search-surface {
  padding: 18px;
  border-radius: 8px;
}

.search-form label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.search-row {
  align-items: stretch;
}

.search-row input,
.search-row select,
.admin-actions input {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

.search-row input {
  flex: 1 1 34rem;
  min-width: 0;
  padding: 0 14px;
  font-size: 1.05rem;
}

.search-row select {
  flex: 0 0 190px;
  padding: 0 12px;
}

.admin-actions input {
  width: 100%;
  min-width: 0;
  padding: 0 12px;
}

.status-line {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 0.48fr);
  gap: 18px;
  margin-top: 18px;
  align-items: start;
}

.side-stack {
  display: grid;
  gap: 18px;
}

.panel {
  min-width: 0;
  padding: 18px;
  border-radius: 8px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.panel-header.compact {
  margin-bottom: 12px;
}

.muted,
.empty-state {
  color: var(--muted);
}

.muted {
  margin-bottom: 0;
  font-size: 0.9rem;
}

.empty-state {
  margin: 0;
  line-height: 1.55;
}

button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 14px;
  font-weight: 700;
}

.primary-button {
  background: var(--accent);
  color: var(--surface);
}

.secondary-button {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.ghost-button {
  border-color: var(--line);
  background: transparent;
  color: var(--accent-dark);
}

.link-button {
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  text-align: left;
}

.results-list,
.episode-list {
  display: grid;
  gap: 10px;
}

.results-list {
  max-height: 70vh;
  overflow: auto;
}

.result-row {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-alt);
}

.result-heading,
.result-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.result-heading span,
.result-meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.result-row p {
  margin: 10px 0;
  line-height: 1.55;
}

.result-meta {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.result-meta span {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface);
}

.episode-list {
  max-height: 310px;
  overflow: auto;
}

.episode-row {
  display: flex;
  width: 100%;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  min-height: 0;
  padding: 12px;
  border-color: var(--line);
  background: var(--surface-alt);
  color: var(--ink);
  text-align: left;
}

.episode-row strong,
.episode-row small {
  display: block;
}

.episode-row small,
.episode-word-count {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
}

.detail-panel {
  min-height: 340px;
}

.episode-detail h3 {
  margin-bottom: 4px;
}

.detail-source {
  margin-bottom: 12px;
  font-size: 0.88rem;
}

.episode-detail pre,
.activity-log {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}

.episode-detail pre {
  max-height: 420px;
  overflow: auto;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
}

.activity-log {
  min-height: 96px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: oklch(28% 0.018 68);
  color: oklch(95% 0.01 78);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.82rem;
}

@media (max-width: 980px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }

  .results-list {
    max-height: none;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 18px, 1380px);
    padding-top: 12px;
  }

  .topbar,
  .search-row,
  .topbar-actions,
  .admin-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .search-row select,
  .search-row input {
    flex-basis: auto;
    width: 100%;
  }

  .panel-header,
  .result-heading {
    flex-direction: column;
    align-items: flex-start;
  }
}
