:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --ink: #22303b;
  --ink-soft: #5c6b76;
  --line: #e2ddd1;
  --accent: #1f6f5c;
  --accent-dark: #164f42;
  --accent-soft: #e3f0eb;
  --user: #eef3f6;
  --danger: #b4472e;
  --shadow: 0 1px 3px rgba(30, 40, 48, 0.08), 0 6px 20px rgba(30, 40, 48, 0.05);
  --radius: 12px;
  font-size: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.55;
  /* App: feste Höhe, nur das Transkript scrollt (Topbar bleibt stehen) */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- Login ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-card {
  background: var(--surface); padding: 40px 36px; border-radius: 16px;
  box-shadow: var(--shadow); width: min(360px, 100%); text-align: center;
  border: 1px solid var(--line);
}
.login-logo { font-size: 40px; }
.login-card h1 { margin: 8px 0 2px; font-size: 24px; }
.login-sub { margin: 0 0 24px; color: var(--ink-soft); font-size: 14px; }
.login-card input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 16px; margin-bottom: 14px; background: var(--surface-2);
}
.login-card input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.login-card button {
  width: 100%; padding: 12px; border: 0; border-radius: 10px; background: var(--accent);
  color: #fff; font-size: 16px; font-weight: 600; cursor: pointer;
}
.login-card button:hover { background: var(--accent-dark); }
.login-err { color: var(--danger); font-size: 14px; margin: 12px 0 0; }

/* ---------- Topbar (kompakt, scrollt nicht) ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px 16px;
  padding: 8px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
  flex-wrap: wrap; /* auf schmalen Screens umbrechen statt überlappen */
}
.brand { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; object-fit: cover;
  border: 2px solid var(--accent-soft); flex: 0 0 auto;
}
.brand-title { font-weight: 700; font-size: 18px; letter-spacing: -0.2px; white-space: nowrap; }
.logo { margin-right: 2px; }
.topbar-controls { display: flex; align-items: center; gap: 12px 14px; min-width: 0; flex: 1 1 auto; justify-content: flex-end; }
/* Label und Eingabe nebeneinander in einer Zeile */
.field { display: flex; flex-direction: row; align-items: center; gap: 8px; min-width: 0; }
.field-label { font-size: 12px; color: var(--ink-soft); white-space: nowrap; }
.field-grow { flex: 1 1 auto; min-width: 0; }
.field-grow input { flex: 1; min-width: 0; }
.field input {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
  background: var(--surface-2); color: var(--ink);
}
.field input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
#day { width: 64px; }
.muted { color: var(--ink-soft); }

/* ---------- Buttons ---------- */
.btn-primary, .btn-ghost, .btn-send {
  font-size: 14px; border-radius: 9px; cursor: pointer; font-weight: 600;
  border: 1px solid transparent; padding: 9px 14px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-send { background: var(--accent); color: #fff; align-self: stretch; padding: 9px 18px; }
.btn-send:hover { background: var(--accent-dark); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px;
  max-width: 1200px; width: 100%; margin: 0 auto; padding: 20px; align-items: start;
  flex: 1 1 auto; min-height: 0; box-sizing: border-box;
}
.chat-col { display: flex; flex-direction: column; height: 100%; min-height: 0; }

/* ---------- Transcript ---------- */
.transcript {
  flex: 1; overflow-y: auto; padding: 4px 4px 12px; display: flex; flex-direction: column; gap: 16px;
}
.empty-hint {
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 24px; color: var(--ink-soft);
}
.empty-hint p { margin: 0 0 10px; }
.empty-hint p:last-child { margin: 0; }

.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 92%; padding: 14px 18px; border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); background: var(--surface); overflow-wrap: anywhere;
}
.msg.user .bubble { background: var(--user); border-color: #d7e0e6; max-width: 78%; white-space: pre-wrap; }
.msg.assistant .bubble { background: var(--surface); }
.bubble .role-tag {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--ink-soft);
  font-weight: 700; margin-bottom: 6px;
}

/* Markdown-Inhalte */
.bubble h1, .bubble h2, .bubble h3 { margin: 14px 0 6px; line-height: 1.3; }
.bubble h1 { font-size: 19px; }
.bubble h2 { font-size: 17px; }
.bubble h3 { font-size: 15px; }
.bubble p { margin: 8px 0; }
.bubble ul, .bubble ol { margin: 8px 0; padding-left: 22px; }
.bubble li { margin: 3px 0; }
.bubble strong { color: var(--accent-dark); }
.bubble code {
  background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 0.9em;
  border: 1px solid var(--line);
}
.bubble hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }

.cursor { display: inline-block; width: 8px; background: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Composer ---------- */
.composer { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 8px; }
.q-banner {
  background: var(--accent-soft); border: 1px solid #cfe3db; border-radius: 9px;
  padding: 8px 12px; margin-bottom: 10px; font-size: 14px; color: var(--ink);
}
.q-banner .q-step {
  display: inline-block; font-weight: 700; color: var(--accent-dark);
  margin-right: 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.3px;
}
.composer-actions { display: flex; gap: 10px; margin-bottom: 10px; }
.composer-input { display: flex; gap: 10px; align-items: stretch; }
.composer-input textarea {
  flex: 1; resize: vertical; min-height: 52px; max-height: 220px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 10px; font: inherit; background: var(--surface);
}
.composer-input textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

/* ---------- Sidebar ---------- */
.side-col {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); position: sticky; top: 20px; max-height: calc(100vh - 102px);
  overflow-y: auto;
}
.side-col h2 { margin: 0 0 14px; font-size: 17px; }

/* ---------- Heute-Karte + Lerntag-Balken ---------- */
.today-card {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; margin-bottom: 18px;
}
.today-card h2 { margin: 0 0 10px; font-size: 15px; }
.today-row { display: flex; justify-content: space-between; gap: 8px; text-align: center; }
.today-stat { display: flex; flex-direction: column; gap: 1px; flex: 1; }
.today-num { font-size: 20px; font-weight: 700; color: var(--accent-dark); }
.today-lbl { font-size: 10px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.3px; }
.lerntag-box { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.lerntag-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.lt-label { font-size: 13px; font-weight: 600; }
.lt-count { font-size: 12px; white-space: nowrap; }
.lerntag-bar { height: 8px; background: #e7e1d4; border-radius: 6px; overflow: hidden; }
.lerntag-fill { height: 100%; width: 0; border-radius: 6px; transition: width 0.4s ease; background: #d98b4a; }
.lerntag-fill.mid { background: #e0b13c; }
.lerntag-fill.high { background: #6ba368; }
.lerntag-fill.complete { background: var(--accent); }
.lt-toggle {
  margin-top: 8px; background: none; border: 0; padding: 2px 0; cursor: pointer;
  font-size: 11px; color: var(--ink-soft); text-decoration: underline;
}
.lt-toggle:hover { color: var(--ink); }
.lt-chapters { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.lt-chapters li { font-size: 12px; display: flex; gap: 6px; align-items: baseline; }
.lt-chapters li .mark { flex: 0 0 auto; width: 12px; }
.lt-chapters li.done { color: var(--ink); }
.lt-chapters li.done .mark { color: var(--accent); }
.lt-chapters li.open { color: var(--ink-soft); }
.lt-chapters li.nonexam { color: #a99; font-style: italic; }
.side-col h3 { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--ink-soft); }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  text-align: center; display: flex; flex-direction: column; gap: 2px;
}
.stat-num { font-size: 22px; font-weight: 700; color: var(--accent-dark); }
.stat-label { font-size: 11px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.4px; }
.topic-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.topic-list li {
  font-size: 13px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; display: flex; justify-content: space-between; gap: 8px;
}
.topic-list li .score { font-weight: 700; color: var(--accent-dark); white-space: nowrap; }
.topic-list li .score.low { color: var(--danger); }
.topic-name { overflow: hidden; text-overflow: ellipsis; }
.side-foot { font-size: 12px; margin-top: 18px; }

/* ---------- Responsive ---------- */
/* Schmaler: Steuerelemente in eine eigene, volle Zeile unter dem Logo (kein Überlappen) */
@media (max-width: 1024px) {
  .topbar { flex-wrap: wrap; }
  .topbar-controls { flex-basis: 100%; justify-content: flex-start; }
}

@media (max-width: 880px) {
  body { overflow: auto; }
  .topbar { position: sticky; top: 0; z-index: 20; }
  /* Smartphone: Steuerelemente untereinander, damit die Eingaben nutzbar breit sind */
  .topbar-controls { flex-direction: column; align-items: stretch; gap: 8px; }
  .field-grow { width: 100%; }
  .layout { grid-template-columns: 1fr; min-height: auto; }
  .side-col { position: static; max-height: none; order: -1; }
  .transcript { max-height: 60vh; }
}
