:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f2530;
  --border: #2a313d;
  --text: #e7ebf0;
  --muted: #9aa4b2;
  --accent: #4c8bf5;
  --accent-hover: #3a78e0;
  --user-bubble: #274060;
  --assistant-bubble: #1f2530;
  --error: #ff6b6b;
  --radius: 14px;
}

* { box-sizing: border-box; }

/* Das HTML-hidden-Attribut muss die display-Regeln unten schlagen,
   sonst bleiben Gate/Chat/Bildvorschau immer sichtbar. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
}

/* ---------- Login-Gate ---------- */
.gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.gate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.gate-card h1 { margin: 0; font-size: 1.5rem; }
.subtitle { margin: 0 0 8px; color: var(--muted); font-size: 0.9rem; }
.gate-card label { font-size: 0.85rem; color: var(--muted); }
.gate-card input {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
}
.gate-card button {
  margin-top: 6px;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
.gate-card button:hover { background: var(--accent-hover); }
.notice {
  margin: 8px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.error { color: var(--error); font-size: 0.85rem; margin: 4px 0 0; }

/* ---------- App-Layout ---------- */
.app { display: flex; flex-direction: column; height: 100%; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.brand { font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.remaining { color: var(--muted); font-size: 0.8rem; }
.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.85rem;
}
.ghost:hover { color: var(--text); border-color: var(--accent); }

/* ---------- Nachrichten ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}
.hint { color: var(--muted); text-align: center; font-size: 0.9rem; margin-top: 20px; }
.bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  max-width: 85%;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.bubble.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}
.bubble.assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.bubble.thinking { color: var(--muted); font-style: italic; }
.bubble img.sent-image {
  max-width: 220px;
  border-radius: 10px;
  margin-bottom: 8px;
  display: block;
}

/* ---------- Markdown-Inhalte ---------- */
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3 { margin: 14px 0 8px; line-height: 1.3; }
.bubble h1 { font-size: 1.25rem; }
.bubble h2 { font-size: 1.12rem; }
.bubble h3 { font-size: 1rem; }
.bubble ul, .bubble ol { margin: 0 0 10px; padding-left: 22px; }
.bubble li { margin: 3px 0; }
.bubble code {
  background: rgba(255,255,255,0.08);
  padding: 1px 5px;
  border-radius: 5px;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 0.9em;
}
.bubble pre {
  background: #0c0e12;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  overflow-x: auto;
  margin: 0 0 10px;
}
.bubble pre code { background: none; padding: 0; }
.bubble a { color: var(--accent); }

/* Tabellen – sauber, scrollbar auf schmalen Screens */
.table-wrap { overflow-x: auto; margin: 0 0 10px; }
.bubble table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
}
.bubble th, .bubble td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.bubble th { background: var(--surface-2); font-weight: 600; }

/* ---------- Composer ---------- */
.composer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 12px 16px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.attach {
  cursor: pointer;
  font-size: 1.4rem;
  padding: 6px 8px;
  border-radius: 8px;
  user-select: none;
}
.attach:hover { background: var(--surface-2); }
#input {
  flex: 1;
  resize: none;
  max-height: 180px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.4;
}
#send-btn {
  padding: 12px 18px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
}
#send-btn:hover { background: var(--accent-hover); }
#send-btn:disabled { opacity: 0.5; cursor: default; }

.image-preview { position: relative; display: inline-block; margin-bottom: 10px; }
.image-preview img { max-height: 90px; border-radius: 10px; border: 1px solid var(--border); }
.remove-image {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--error);
  color: white;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

@media (max-width: 600px) {
  .bubble { max-width: 92%; }
}
