:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface2: #1f242e;
  --text: #e6e9ef;
  --muted: #8b93a3;
  --accent: #4f8cff;
  --accent2: #7aa8ff;
  --user-bubble: #22345c;
  --bot-bubble: #1f242e;
  --border: #2a3140;
  --danger: #ff6b6b;
  --drawer-w: 280px;
}

[data-theme="light"] {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface2: #eef1f6;
  --text: #1a1f2b;
  --muted: #5a6375;
  --accent: #2f6bff;
  --accent2: #1a4fd8;
  --user-bubble: #dbe7ff;
  --bot-bubble: #ffffff;
  --border: #d8dee9;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* ---------- Login ---------- */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 24px;
}
#login-form {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#login-form h1 { font-size: 22px; margin-bottom: 4px; }
#login-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
#login-form input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 16px; /* >=16px verhindert iOS-Zoom */
}
#login-form button, .primary {
  padding: 11px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.error { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------- Main-Layout ---------- */
#main-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}
#topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#topbar button {
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  padding: 6px 8px;
  cursor: pointer;
}
#session-title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--drawer-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform 0.18s ease;
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding: 10px;
  gap: 8px;
}
#drawer.open { transform: translateX(0); }
#drawer-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 25;
  display: none;
}
#drawer-scrim.open { display: block; }
#session-list { list-style: none; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 2px; }
#session-list li {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#session-list li.active { background: var(--accent); color: #fff; }
#session-list li:not(.active):hover { background: var(--surface2); }

#chat-area { flex: 1; overflow-y: auto; position: relative; }
#messages { display: flex; flex-direction: column; gap: 8px; padding: 14px; }
#empty-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 24px;
}
.msg {
  max-width: 85%;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user { align-self: flex-end; background: var(--user-bubble); }
.msg.bot { align-self: flex-start; background: var(--bot-bubble); border: 1px solid var(--border); }
.msg.streaming::after { content: "▌"; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0; } }
.msg.error { color: var(--danger); border: 1px solid var(--danger); }

#composer {
  display: flex;
  gap: 8px;
  padding: 10px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
#input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  color: var(--text);
  padding: 10px 12px;
  font-size: 16px;
  max-height: 120px;
}
#send {
  width: 44px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}
#send:disabled { opacity: 0.5; }
