:root {
  --accent: #4F46E5;
  --accent-soft: rgba(79, 70, 229, 0.14);
  --bg: #ffffff;
  --surface: #f2f3f7;
  --surface-2: #e7e9f0;
  --text: #12131a;
  --text-dim: #6b7280;
  --border: rgba(0, 0, 0, 0.08);
  --danger: #dc2626;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #8B87F5;
    --accent-soft: rgba(139, 135, 245, 0.20);
    --bg: #0d0e12;
    --surface: #1b1d24;
    --surface-2: #262933;
    --text: #f3f4f8;
    --text-dim: #9aa0ac;
    --border: rgba(255, 255, 255, 0.10);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Muss die display-Regeln unten schlagen: sonst überschreibt z. B.
   `.sheet { display:flex }` das hidden-Attribut und Menüs wären immer sichtbar. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* Kopfzeile */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: 0.2px; }

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 22px;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  cursor: pointer;
}
.icon-btn:active { background: var(--surface); }

/* Verlauf */
.transcript {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--text-dim);
}
.empty-emoji { font-size: 40px; margin-bottom: 8px; }
.hint { font-size: 14px; }

/* Sprechblasen */
.msg { max-width: 82%; display: flex; flex-direction: column; gap: 6px; }
.msg .bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }
.msg.assistant .bubble { background: var(--surface); border-bottom-left-radius: 6px; }

.msg img.thumb { max-width: 200px; max-height: 200px; border-radius: 12px; }
.transcript-line { font-size: 13px; color: var(--text-dim); }

.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-dim); opacity: 0.5;
  animation: blink 1.2s infinite both;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }

/* Aktions-Karten (Entwurf/Termin/Erinnerung) */
.action {
  background: var(--surface-2);
  border-radius: 14px;
  padding: 10px 12px;
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.action .kind { font-size: 12px; font-weight: 600; color: var(--text-dim); }
.action .preview { font-size: 15px; white-space: pre-wrap; }
.action .row { display: flex; gap: 8px; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); }
.btn:disabled { opacity: 0.5; }

/* Fehlerband */
.error-bar {
  margin: 0 16px;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
  border-radius: 10px;
  font-size: 14px;
}

/* Eingabeleiste */
.composer {
  border-top: 1px solid var(--border);
  padding: 8px 12px calc(var(--safe-bottom) + 8px);
  background: var(--bg);
}
.chips { display: flex; gap: 8px; padding: 4px 4px 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border-radius: 999px;
  padding: 4px 10px; font-size: 13px; color: var(--text-dim);
}
.chip button { border: none; background: transparent; color: var(--text-dim); cursor: pointer; font-size: 14px; }

.composer-row { display: flex; align-items: flex-end; gap: 8px; }
#input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 9px 14px;
  font: inherit;
  background: var(--surface);
  color: var(--text);
  max-height: 120px;
}
#input:focus { outline: none; border-color: var(--accent); }

.send-btn {
  border: none;
  background: var(--accent);
  color: #fff;
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  flex: 0 0 auto;
}
.send-btn:disabled { background: var(--surface-2); color: var(--text-dim); }
.icon-btn.recording { color: var(--danger); }

/* Sheets (Menü / Einstellungen) */
.sheet {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0, 0, 0, 0.4);
  display: flex; align-items: flex-end;
}
.sheet-card {
  width: 100%;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(var(--safe-bottom) + 20px);
  display: flex; flex-direction: column; gap: 12px;
  animation: rise 0.2s ease-out;
}
@keyframes rise { from { transform: translateY(30px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.sheet-card h2 { margin: 0 0 4px; font-size: 18px; }
.sheet-item {
  border: none; background: var(--surface);
  border-radius: 12px; padding: 14px 16px;
  font: inherit; text-align: left; color: var(--text); cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
}
.sheet-item.cancel { color: var(--text-dim); justify-content: center; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 14px; color: var(--text-dim); }
.field input {
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; font: inherit; background: var(--surface); color: var(--text);
}
.field-hint { font-size: 13px; color: var(--text-dim); margin: 0; }
.field-hint code { background: var(--surface); padding: 1px 5px; border-radius: 5px; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; }
