:root {
  --accent: #ec7f36;
  --accent-ink: #ffffff;
  --bg: #faf9f7;
  --surface: #ffffff;
  --neutral: #f0eee9;
  --text: #1c1b19;
  --muted: #8a857c;
  --border: #ece9e3;
  --shadow: 0 1px 3px rgba(0,0,0,.05), 0 6px 20px rgba(0,0,0,.04);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent: #f0873a;
    --accent-ink: #1a120b;
    --bg: #161519;
    --surface: #1f1e24;
    --neutral: #2a2831;
    --text: #eceae6;
    --muted: #98938c;
    --border: #2c2a32;
    --shadow: 0 1px 3px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* --- Login --- */
.login {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--bg);
}
.login-card { width: 100%; max-width: 320px; text-align: center; }
.login-card h1 { margin: 18px 0 2px; font-size: 26px; font-weight: 650; }
.login-card p { margin: 0 0 24px; }
#loginForm { display: flex; flex-direction: column; gap: 12px; }
#loginForm input {
  padding: 15px 16px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--text); font-size: 16px; outline: none;
}
#loginForm input:focus { border-color: var(--accent); }
#loginForm button, .login-card button {
  padding: 15px 16px; border: none; border-radius: 14px;
  background: var(--accent); color: var(--accent-ink); font-size: 16px; font-weight: 600;
}
.login-error { color: #d9534f; min-height: 18px; font-size: 14px; margin-top: 12px; }

/* --- App shell --- */
.app { display: flex; flex-direction: column; height: 100%; }
.view { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
.topbar-text { flex: 1; min-width: 0; }
.topbar-name { font-weight: 650; font-size: 17px; }
.topbar-status { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.topbar-status .dot { width: 7px; height: 7px; border-radius: 50%; background: #4caf72; display: inline-block; }
.topbar-status.off .dot { background: var(--muted); }
.icon-btn {
  border: none; background: transparent; color: var(--muted);
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center;
}
.icon-btn:active { background: var(--neutral); }

/* --- Avatar --- */
.avatar { width: 40px; height: 40px; border-radius: 50%; flex: none; overflow: hidden; background: var(--neutral); }
.avatar-lg { width: 76px; height: 76px; margin: 0 auto; }
.avatar svg { width: 100%; height: 100%; display: block; }

/* --- Messages --- */
.messages {
  flex: 1; overflow-y: auto; padding: 16px 14px 8px;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.bubble {
  max-width: 82%; padding: 10px 14px; border-radius: 20px; font-size: 15.5px;
  line-height: 1.42; white-space: pre-wrap; word-wrap: break-word; box-shadow: var(--shadow);
}
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 7px; }
.bubble.sam { align-self: flex-start; background: var(--surface); color: var(--text); border-bottom-left-radius: 7px; }
.bubble.typing { color: var(--muted); font-style: italic; }

/* Sprach-Blase */
.voice { display: flex; align-items: center; gap: 10px; }
.voice .play { width: 34px; height: 34px; border-radius: 50%; border: none; background: rgba(255,255,255,.25); color: inherit; display: grid; place-items: center; flex: none; }
.bubble.sam .voice .play { background: var(--neutral); }
.voice .wave { display: flex; align-items: center; gap: 2.5px; height: 22px; flex: 1; }
.voice .wave span { width: 3px; border-radius: 3px; background: currentColor; opacity: .55; }
.voice .dur { font-size: 12px; opacity: .8; flex: none; }
.voice-text { font-size: 13px; opacity: .85; margin-top: 6px; }

/* --- Composer --- */
.composer {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px calc(var(--safe-bottom) + 8px);
  border-top: 1px solid var(--border); background: var(--bg);
}
.composer input {
  flex: 1; padding: 12px 16px; border: 1px solid var(--border); border-radius: 22px;
  background: var(--surface); color: var(--text); font-size: 16px; outline: none;
}
.composer input:focus { border-color: var(--accent); }
.mic-btn, .send-btn {
  width: 44px; height: 44px; border-radius: 50%; border: none; flex: none;
  display: grid; place-items: center;
}
.mic-btn { background: var(--neutral); color: var(--text); }
.mic-btn.recording { background: var(--accent); color: var(--accent-ink); animation: pulse 1.2s infinite; }
.send-btn { background: var(--accent); color: var(--accent-ink); }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }

/* --- Aufnehmen --- */
.record-area { display: flex; flex-direction: column; align-items: center; padding: 34px 24px 10px; }
.rec-btn { position: relative; width: 132px; height: 132px; border: none; background: transparent; }
.rec-ring { position: absolute; inset: 0; border-radius: 50%; border: 3px solid var(--accent); opacity: .35; }
.rec-core {
  position: absolute; inset: 18px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 8px 24px rgba(236,127,54,.35); transition: all .2s;
}
.rec-btn.recording .rec-core { inset: 40px; border-radius: 16px; }
.rec-btn.recording .rec-ring { animation: ring 1.4s infinite; }
@keyframes ring { 0% { transform: scale(1); opacity: .5; } 100% { transform: scale(1.25); opacity: 0; } }
.rec-label { margin-top: 20px; font-size: 16px; font-weight: 550; }
.rec-hint { margin-top: 10px; max-width: 300px; text-align: center; font-size: 13.5px; color: var(--muted); line-height: 1.5; }
.upload-link { display: inline-block; margin-top: 8px; color: var(--accent); font-weight: 600; }

.rec-list-head { padding: 18px 18px 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.rec-list { flex: 1; overflow-y: auto; padding: 0 14px calc(var(--safe-bottom) + 14px); display: flex; flex-direction: column; gap: 10px; }
.rec-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); }
.rec-card .r-title { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.rec-card .r-meta { font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.badge { background: rgba(76,175,114,.15); color: #3c9e63; font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600; }
.rec-card .r-actions { margin-top: 10px; display: flex; gap: 8px; }
.rec-card .r-actions button { border: 1px solid var(--border); background: var(--bg); color: var(--text); padding: 8px 12px; border-radius: 10px; font-size: 13px; }
.rec-card .r-transcript { margin-top: 10px; font-size: 13.5px; color: var(--muted); line-height: 1.45; max-height: 0; overflow: hidden; transition: max-height .25s; }
.rec-card.open .r-transcript { max-height: 400px; overflow-y: auto; }

/* --- Tabs --- */
.tabs {
  display: flex; border-top: 1px solid var(--border); background: var(--bg);
  padding-bottom: var(--safe-bottom);
}
.tab {
  flex: 1; border: none; background: transparent; color: var(--muted);
  padding: 8px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px;
}
.tab.active { color: var(--accent); }

/* --- Toast --- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 80px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; box-shadow: var(--shadow); z-index: 50; max-width: 88%;
}
