/* ---------------------------------------------------------------- Basis */
:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --border: #e3e0d8;
  --text: #26241f;
  --text-muted: #7a766c;
  --accent: #7c5cff;
  --accent-hover: #6a4be0;
  --accent-soft: #efeaff;
  --green: #2f9e6e;
  --green-soft: #e3f5ec;
  --amber: #b7791f;
  --amber-soft: #fcf0dc;
  --danger: #d64545;
  --danger-soft: #fdeaea;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(30, 25, 15, .06), 0 8px 24px rgba(30, 25, 15, .05);
  --shadow-lg: 0 4px 12px rgba(30, 25, 15, .08), 0 16px 48px rgba(30, 25, 15, .10);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", "Cascadia Code", Consolas, monospace;

  /* Feste Palette zur Farbkennzeichnung von Mitgliedern (Live-Checkliste/Chat).
     Opak-Werte für Punkte/Avatare, kein Text-auf-Hintergrund -> kein Dark-Mode-Override nötig. */
  --user-color-rot: #d6564f;
  --user-color-orange: #d98a3d;
  --user-color-gelb: #c9a92c;
  --user-color-gruen: #3f9e5c;
  --user-color-tuerkis: #3b9aa8;
  --user-color-blau: #4472c4;
  --user-color-violett: #8a63d2;
  --user-color-pink: #c95a94;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --surface: #211f1c;
    --surface-2: #2a2825;
    --border: #37342f;
    --text: #eceae5;
    --text-muted: #98948a;
    --accent: #9d85ff;
    --accent-hover: #b09cff;
    --accent-soft: #2c2545;
    --green: #4cc38a;
    --green-soft: #1d3229;
    --amber: #e2b25c;
    --amber-soft: #3a2f1c;
    --danger: #ef6a6a;
    --danger-soft: #3d2222;
    --shadow: 0 1px 3px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, .4), 0 16px 48px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- Layout */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 17px;
  padding: 6px 10px 22px;
  color: inherit;
}
.brand:hover { text-decoration: none; }
.brand-icon { font-size: 24px; }

.podcast-switch { padding: 0 10px 14px; }
.podcast-switch a { font-size: 12.5px; color: var(--text-muted); }
.podcast-switch-name { font-weight: 700; font-size: 15px; margin-top: 4px; line-height: 1.3; }

.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--text-muted);
  font-weight: 500;
  transition: background .15s, color .15s;
}
.sidebar nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav-icon { width: 18px; text-align: center; font-size: 14px; }
.nav-badge {
  margin-left: auto;
  background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 5px;
}
.sidebar nav a { justify-content: flex-start; }
.sidebar-cta { padding-top: 16px; border-top: 1px solid var(--border); }

.user-box { padding: 14px 10px 4px; border-top: 1px solid var(--border); }
.user-email {
  font-size: 12.5px; font-weight: 600; color: var(--text-muted);
  margin-bottom: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.content {
  flex: 1;
  padding: 36px 44px 80px;
  max-width: 1060px;
  min-width: 0;
}

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 10px 14px; gap: 8px; }
  .brand { padding: 0 6px; }
  .brand-name { display: none; }
  .sidebar nav { flex-direction: row; overflow-x: auto; }
  .sidebar nav a { padding: 8px 12px; white-space: nowrap; }
  .sidebar-cta { border: 0; padding: 0; }
  .content { padding: 20px 16px 60px; }
}

/* ---------------------------------------------------------------- Typo & Karten */
h1 { font-size: 26px; font-weight: 700; margin: 0 0 6px; letter-spacing: -.02em; }
.page-sub { color: var(--text-muted); margin: 0 0 28px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 4px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 26px;
  margin-bottom: 20px;
}
.card-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); margin: 0 0 14px; }

/* ---------------------------------------------------------------- Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-weight: 600; font-size: 14px;
  padding: 9px 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary.glow { box-shadow: 0 0 0 4px var(--accent-soft); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-sm { padding: 5px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------------------------------------------------------------- Formulare */
input[type=text], input[type=number], input[type=date], textarea, select {
  font: inherit;
  width: 100%;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 110px; line-height: 1.55; }
textarea.mono { font-family: var(--mono); font-size: 13px; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); margin: 0 0 5px; }
.field { margin-bottom: 16px; }
.field-row { display: flex; gap: 14px; }
.field-row > .field { flex: 1; }

.fragenkatalog { margin-bottom: 16px; }
.fragenkatalog summary {
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text-muted);
  padding: 8px 0;
}
.fragenkatalog summary:hover { color: var(--text); }
.fragenkatalog-body { padding-top: 8px; }
.fragenkatalog textarea.fk-antwort { min-height: 60px; }

/* ---------------------------------------------------------------- Markdown-Inhalt */
.md { line-height: 1.7; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1 { font-size: 22px; margin: 26px 0 10px; }
.md h2 { font-size: 18px; margin: 24px 0 8px; }
.md h3 { font-size: 16px; margin: 20px 0 6px; }
.md p { margin: 10px 0; }
.md ul, .md ol { margin: 10px 0; padding-left: 26px; }
.md li { margin: 3px 0; }
.md blockquote {
  margin: 12px 0; padding: 8px 16px;
  border-left: 3px solid var(--accent);
  background: var(--surface-2);
  border-radius: 0 8px 8px 0;
  color: var(--text-muted);
}
.md code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }
.md pre { background: var(--surface-2); padding: 14px 16px; border-radius: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; margin: 12px 0; width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 7px 12px; text-align: left; }
.md th { background: var(--surface-2); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }

/* ---------------------------------------------------------------- Dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 22px;
}
.stat .num { font-size: 32px; font-weight: 700; letter-spacing: -.03em; }
.stat .lbl { color: var(--text-muted); font-size: 13px; font-weight: 500; }

/* ---------------------------------------------------------------- Listen */
.ep-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 22px;
  margin-bottom: 14px;
  color: inherit;
  transition: transform .12s, box-shadow .15s, border-color .15s;
}
.ep-card:hover { text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow-lg); border-color: var(--accent); }
.ep-card .ep-title { font-weight: 650; font-size: 16px; }
.ep-card .ep-meta { color: var(--text-muted); font-size: 13px; margin-top: 3px; display: flex; gap: 14px; flex-wrap: wrap; }
.ep-nr {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 34px; height: 34px; padding: 0 8px;
  border-radius: 9px;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 14px;
  margin-right: 14px;
  vertical-align: middle;
}

.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.badge-offen { background: var(--amber-soft); color: var(--amber); }
.badge-erledigt { background: var(--green-soft); color: var(--green); }

/* Themenliste */
.topic {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--border);
}
.topic:last-child { border-bottom: 0; }
.topic-check {
  flex-shrink: 0; width: 22px; height: 22px; margin-top: 2px;
  border: 2px solid var(--border); border-radius: 7px;
  background: none; cursor: pointer; font-size: 13px; line-height: 1;
  color: transparent;
  transition: all .15s;
}
.topic-check:hover { border-color: var(--green); }
.topic.done .topic-check { background: var(--green); border-color: var(--green); color: #fff; }
.topic-body { flex: 1; min-width: 0; }
.topic-title { font-weight: 600; }
.topic.done .topic-title { text-decoration: line-through; color: var(--text-muted); }
.topic-desc { color: var(--text-muted); font-size: 13.5px; }
.topic-actions { flex-shrink: 0; display: flex; gap: 6px; opacity: 0; transition: opacity .15s; }
.topic:hover .topic-actions { opacity: 1; }
.icon-btn {
  border: 0; background: none; cursor: pointer;
  color: var(--text-muted); font-size: 14px;
  padding: 4px 7px; border-radius: 7px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------------------------------------------------------------- Chat (Neue Folge) */
.chat-layout { display: grid; grid-template-columns: 240px 1fr; gap: 22px; align-items: start; }
@media (max-width: 900px) { .chat-layout { grid-template-columns: 1fr; } }

.draft-list { display: flex; flex-direction: column; gap: 8px; }
.draft-item {
  display: block;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: inherit;
  font-size: 13.5px;
  transition: border-color .15s, background .15s;
}
.draft-item:hover { text-decoration: none; border-color: var(--accent); }
.draft-item.active { border-color: var(--accent); background: var(--accent-soft); }
.draft-item .d-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.draft-item .d-meta { color: var(--text-muted); font-size: 12px; }

.chat-box { display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 12px; }
.msg-avatar {
  flex-shrink: 0; width: 34px; height: 34px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
  background: var(--surface-2);
}
.msg.user .msg-avatar { background: var(--accent-soft); }
.msg-body {
  flex: 1; min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow);
}
.msg.user .msg-body { background: var(--accent-soft); border-color: transparent; }
.msg-body.streaming::after {
  content: "▋"; color: var(--accent);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.chat-input-bar { position: sticky; bottom: 0; padding: 14px 0 6px; background: linear-gradient(transparent, var(--bg) 30%); }
.chat-input-inner {
  display: flex; gap: 10px; align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 10px;
}
.chat-input-inner textarea { border: 0; box-shadow: none; min-height: 44px; max-height: 220px; }
.chat-input-inner textarea:focus { box-shadow: none; }

.thinking { display: inline-flex; gap: 5px; align-items: center; }
.thinking span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  animation: bounce 1.2s ease-in-out infinite;
}
.thinking span:nth-child(2) { animation-delay: .15s; }
.thinking span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 70%, 100% { transform: translateY(0); opacity: .45; } 35% { transform: translateY(-5px); opacity: 1; } }

/* ---------------------------------------------------------------- Tabs & Toasts */
.tabs { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; margin-bottom: 16px; }
.tab {
  border: 0; background: none; font: inherit; font-weight: 600; font-size: 13.5px;
  padding: 6px 16px; border-radius: 8px; cursor: pointer; color: var(--text-muted);
}
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

#toast-container { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast {
  background: var(--text); color: var(--bg);
  padding: 11px 18px; border-radius: 10px;
  font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in .25s ease;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.empty {
  text-align: center; color: var(--text-muted);
  padding: 48px 20px;
  border: 2px dashed var(--border); border-radius: var(--radius);
}
.empty .big { font-size: 36px; margin-bottom: 8px; }

/* ---------------------------------------------------------------- Auth-Seiten */
.auth-body { display: flex; flex-direction: column; min-height: 100vh; }
.auth-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px;
}
.auth-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 32px 30px;
  text-align: center;
}
.auth-card h1 { font-size: 22px; margin-bottom: 4px; }
.auth-card .page-sub { margin-bottom: 22px; }
.auth-card form { text-align: left; }
.auth-card .field-row { text-align: left; }
.auth-switch { margin-top: 20px; font-size: 13.5px; color: var(--text-muted); }
.alert { padding: 10px 14px; border-radius: 10px; font-size: 13.5px; margin-bottom: 16px; text-align: left; }
.alert-error { background: var(--danger-soft); color: var(--danger); }

/* ---------------------------------------------------------------- Podcast-Auswahl */
.podcast-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 20px; }
.podcast-tile {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  color: inherit;
  transition: transform .12s, box-shadow .15s, border-color .15s;
}
.podcast-tile:hover { text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow-lg); border-color: var(--accent); }
.pt-title { font-weight: 700; font-size: 16px; }
.pt-slug { color: var(--text-muted); font-size: 13px; margin-top: 3px; }

/* ---------------------------------------------------------------- Mitglieder */
.member-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}
.member-row:last-child { border-bottom: 0; }
.member-name { font-weight: 600; }

.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.mt { margin-top: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------------------------------------------------------------- Farbauswahl */
.color-swatch {
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; padding: 0;
}
.color-swatch.selected { border-color: var(--text); }
.color-swatch-sm {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 6px; cursor: default; vertical-align: middle;
}

/* ---------------------------------------------------------------- Live-Checkliste */
.live-layout { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .live-layout { grid-template-columns: 1fr; } }

.checklist-section-title {
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .06em; margin: 18px 0 6px;
}
.checklist-section:first-of-type .checklist-section-title { margin-top: 0; }
/* Checkbox wird bei Abhaken direkt mit der Farbe des jeweiligen Users gefüllt
   (background/border per Inline-Style aus JS) -- hier nur der Haken-Kontrast. */
.checklist-item.checked .topic-check { color: #fff; }

.pacing-banner { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.badge-pace-on_track, .badge-pace-ahead { background: var(--green-soft); color: var(--green); }
.badge-pace-behind { background: var(--amber-soft); color: var(--amber); }
.badge-pace-far_behind { background: var(--danger-soft); color: var(--danger); }

#chat-card #live-chat { max-height: 480px; overflow-y: auto; }
