:root {
  color-scheme: light dark;
  --bg: #f7f6f3;
  --panel: #ffffff;
  --text: #1d1b19;
  --muted: #6b665f;
  --line: #e4e0d8;
  --accent: #6d28d9;
  --accent-soft: #ede7fb;
  --ok: #1f7a4d;
  --ok-soft: #e3f3ea;
  --warn: #9a5b00;
  --warn-soft: #fbf0dc;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151413;
    --panel: #1e1d1b;
    --text: #f1eee9;
    --muted: #a39d94;
    --line: #34312d;
    --accent: #a78bfa;
    --accent-soft: #2c2440;
    --ok: #5fd39a;
    --ok-soft: #1a3027;
    --warn: #f2b65a;
    --warn-soft: #3a2c15;
    --bad: #ff8a7f;
    --bad-soft: #3d1f1c;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }
p { margin: 0.4rem 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small-text { font-size: 0.85rem; }
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.85em; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.75rem 1.25rem; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 2;
}
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 650; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), #db2777);
}
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: flex-end; }
.chip {
  display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.2rem 0.6rem;
  border-radius: 999px; font-size: 0.82rem; background: var(--bg); border: 1px solid var(--line);
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.chip.ok::before { background: var(--ok); }
.chip.warn::before { background: var(--warn); }
.chip.bad::before { background: var(--bad); }

/* Layout */
.layout { display: grid; grid-template-columns: 260px 1fr; min-height: calc(100vh - 53px); }
.sidebar { border-right: 1px solid var(--line); padding: 1rem; display: flex; flex-direction: column; gap: 1rem; }
.sidebar-head { display: flex; justify-content: space-between; align-items: center; }
.show-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.show-list button {
  width: 100%; display: flex; align-items: center; gap: 0.6rem; padding: 0.45rem; border: 0;
  background: none; color: inherit; font: inherit; text-align: left; border-radius: 8px; cursor: pointer;
}
.show-list button:hover { background: var(--panel); }
.show-list button[aria-current="true"] { background: var(--accent-soft); }
.show-list img, .art-placeholder { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; flex: none; background: var(--line); }
.show-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.budget { margin-top: auto; border-top: 1px solid var(--line); padding-top: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
main { padding: 1.5rem; max-width: 1100px; width: 100%; outline: none; }

/* Panels and forms */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.grid-2 > *, .field { min-width: 0; }
.field select, .field input, .field textarea { width: 100%; }
.row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.field { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.88rem; }
.field > span { color: var(--muted); }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0.75rem; }
input, select, textarea {
  font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 0.45rem 0.6rem; min-width: 0;
}
textarea { resize: vertical; min-height: 3.5rem; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.button {
  font: inherit; font-weight: 600; border: 0; border-radius: 8px; padding: 0.5rem 0.95rem;
  background: var(--accent); color: white; cursor: pointer;
}
.button.secondary { background: var(--bg); color: var(--text); border: 1px solid var(--line); }
.button.danger { background: var(--bad-soft); color: var(--bad); }
.button.small { padding: 0.3rem 0.65rem; font-size: 0.85rem; }
.button:disabled { opacity: 0.5; cursor: default; }
.link-button { border: 0; background: none; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }

/* Show header */
.show-head { display: flex; gap: 1rem; align-items: center; }
.show-head img { width: 84px; height: 84px; border-radius: 10px; object-fit: cover; }
.show-head .actions { margin-left: auto; }

/* Banners */
.banner { border-radius: var(--radius); padding: 0.8rem 1rem; display: flex; gap: 0.75rem; align-items: flex-start; }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner.info { background: var(--accent-soft); }
.banner strong { display: block; }
.banner p { color: var(--text); }

/* Phone card */
.phone { display: grid; grid-template-columns: 148px 1fr; gap: 1rem; align-items: center; }
.phone img { width: 148px; height: 148px; background: white; border-radius: 8px; padding: 4px; }
.feed-url { font-family: ui-monospace, Menlo, monospace; font-size: 0.78rem; word-break: break-all; color: var(--muted); }

/* Episodes */
.episodes-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 0.6rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.5rem 0.4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
td.label { font-variant-numeric: tabular-nums; color: var(--muted); width: 4.5rem; }
td.date { color: var(--muted); white-space: nowrap; width: 7rem; font-size: 0.88rem; }
td.status { width: 15rem; }
td.actions { width: 1%; white-space: nowrap; text-align: right; }
.badge { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.busy { background: var(--accent-soft); color: var(--accent); }
.progress { display: block; font-size: 0.8rem; color: var(--muted); margin-top: 0.15rem; }
.preview { background: var(--bg); border-radius: 8px; padding: 0.8rem; white-space: pre-wrap; font-size: 0.9rem; }
.preview audio { width: 100%; margin-top: 0.6rem; }

/* Search results */
.results { list-style: none; padding: 0; margin: 0.5rem 0 0; display: flex; flex-direction: column; gap: 0.25rem; }
.results li { display: flex; align-items: center; gap: 0.7rem; padding: 0.4rem; border-radius: 8px; }
.results li:hover { background: var(--bg); }
.results img { width: 44px; height: 44px; border-radius: 6px; }
.results .grow { flex: 1; min-width: 0; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 0.6rem 1rem; border-radius: 10px; font-size: 0.9rem; max-width: 90vw; z-index: 5;
}

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .grid-2, .phone { grid-template-columns: 1fr; }
  td.date, th.date { display: none; }
}
