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

:root {
  --bg:         #f8f7ff;
  --bg2:        #ffffff;
  --primary:    #6c63ff;
  --primary2:   #9b8fff;
  --grad:       linear-gradient(135deg, #6c63ff 0%, #9b8fff 100%);
  --grad-bg:    linear-gradient(160deg, #f0effe 0%, #fafafe 50%, #fff8f8 100%);
  --glass:      rgba(255,255,255,0.72);
  --glass-b:    rgba(255,255,255,0.45);
  --shadow-sm:  0 2px 12px rgba(108,99,255,.08);
  --shadow-md:  0 8px 32px rgba(108,99,255,.12);
  --shadow-lg:  0 20px 60px rgba(108,99,255,.18);
  --text:       #0d0d12;
  --text2:      #4a4760;
  --text3:      #9896ab;
  --border:     rgba(108,99,255,.12);
  --radius-sm:  12px;
  --radius-md:  20px;
  --radius-lg:  28px;
  --radius-xl:  40px;
}

html, body {
  height: 100%;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  background: var(--grad-bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.hidden { display: none !important; }

/* ── App Shell ────────────────────────────────────────────────── */

#app-screen {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Header ───────────────────────────────────────────────────── */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-spacer {
  width: 36px;
}

.header-wordmark {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text2);
  text-transform: lowercase;
}

.header-wordmark span {
  background: var(--grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 700;
}

.logout-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(108,99,255,.1);
  border: 1.5px solid rgba(108,99,255,.2);
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .2s, border-color .2s;
}
.logout-btn:hover {
  background: rgba(108,99,255,.18);
  border-color: rgba(108,99,255,.4);
}
.logout-btn svg { width: 15px; height: 15px; }

/* ── Chat ─────────────────────────────────────────────────────── */

main {
  flex: 1;
  overflow-y: auto;
  padding: 28px 20px 16px;
  scroll-behavior: smooth;
}

main::-webkit-scrollbar { width: 0; }

#chat-container {
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message { display: flex; }
.message.user      { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }

.bubble {
  max-width: 78%;
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  line-height: 1.7;
  font-size: 15.5px;
  white-space: pre-wrap;
  word-break: break-word;
  text-align: left;
}

.message.user .bubble {
  background: var(--grad);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 4px 20px rgba(108,99,255,.35);
}

.message.assistant .bubble {
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--text);
  border-bottom-left-radius: 6px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.message.welcome .bubble {
  background: linear-gradient(135deg,rgba(108,99,255,.06) 0%,rgba(155,143,255,.04) 100%);
  border: 1px solid rgba(108,99,255,.14);
  box-shadow: none;
}

/* Typing dots */
.typing-dots {
  display: flex;
  gap: 6px;
  padding: 18px 22px;
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-sm);
  width: fit-content;
}
.typing-dots span {
  width: 7px; height: 7px;
  background: var(--primary2);
  border-radius: 50%;
  animation: bounce 1.3s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: .18s; }
.typing-dots span:nth-child(3) { animation-delay: .36s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .6; }
  30%            { transform: translateY(-7px); opacity: 1; }
}

/* ── Name Input in Chat ───────────────────────────────────────── */

.name-input-row {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.name-input-row input {
  flex: 1;
  padding: 11px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: rgba(255,255,255,.9);
  color: var(--text);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.name-input-row input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(108,99,255,.1);
}

.name-input-row button {
  padding: 11px 20px;
  background: var(--grad);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: 'Plus Jakarta Sans', sans-serif;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(108,99,255,.3);
  transition: opacity .2s, transform .1s;
}
.name-input-row button:hover  { opacity: .9; }
.name-input-row button:active { transform: scale(.97); }

/* ── Footer ───────────────────────────────────────────────────── */

footer {
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  padding: 14px 20px 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}

.transcript-preview {
  font-size: 13px;
  color: var(--text3);
  font-style: italic;
  padding: 8px 14px;
  background: rgba(108,99,255,.06);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  max-width: 680px;
  margin-left: auto;
  margin-right: auto;
}

.input-row {
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: rgba(255,255,255,.85);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 8px 8px 8px 20px;
  box-shadow: var(--shadow-md);
  transition: border-color .2s, box-shadow .2s;
}

.input-row:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(108,99,255,.1), var(--shadow-md);
}

textarea#text-input {
  flex: 1;
  padding: 8px 0;
  border: none;
  background: transparent;
  font-size: 15.5px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  color: var(--text);
  resize: none;
  outline: none;
  line-height: 1.55;
  max-height: 140px;
  overflow-y: auto;
}

textarea#text-input::placeholder { color: var(--text3); }

/* ── Mic Button ───────────────────────────────────────────────── */

.mic-btn {
  flex-shrink: 0;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(108,99,255,.08);
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s, transform .1s, box-shadow .2s;
  touch-action: none;
  user-select: none;
}
.mic-btn svg { width: 20px; height: 20px; }
.mic-btn:hover { background: rgba(108,99,255,.14); }

.mic-btn.recording {
  background: var(--grad);
  color: #fff;
  animation: pulse-mic 1.1s infinite;
  box-shadow: 0 0 0 0 rgba(108,99,255,.5);
}

@keyframes pulse-mic {
  0%   { box-shadow: 0 0 0 0 rgba(108,99,255,.4); }
  70%  { box-shadow: 0 0 0 12px rgba(108,99,255,0); }
  100% { box-shadow: 0 0 0 0 rgba(108,99,255,0); }
}

/* ── Send Button ──────────────────────────────────────────────── */

.send-btn {
  flex-shrink: 0;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--grad);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(108,99,255,.4);
  transition: opacity .2s, transform .1s, box-shadow .2s;
}
.send-btn svg { width: 18px; height: 18px; }
.send-btn:hover  { opacity: .9; box-shadow: 0 6px 20px rgba(108,99,255,.5); }
.send-btn:active { transform: scale(.95); }
.send-btn:disabled {
  background: rgba(108,99,255,.2);
  box-shadow: none;
  cursor: not-allowed;
  color: rgba(108,99,255,.4);
}

.footer-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 10px;
  max-width: 680px;
  margin-left: auto;
  margin-right: auto;
}

.mic-hint {
  font-size: 12px;
  color: var(--text3);
  letter-spacing: 0.01em;
}

.msg-counter {
  font-size: 11px;
  color: rgba(0,0,0,0.35);
  display: none;
  white-space: nowrap;
}

/* ── Bild-Upload Button ───────────────────────────────────────── */

.img-btn {
  flex-shrink: 0;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(108,99,255,.08);
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s;
  position: relative;
}
.img-btn svg { width: 19px; height: 19px; }
.img-btn:hover { background: rgba(108,99,255,.16); }

.img-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--grad);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(108,99,255,.4);
  pointer-events: none;
}

/* ── Bild-Vorschau Strip ─────────────────────────────────────── */

.image-preview-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 0 10px;
  max-width: 680px;
  margin: 0 auto 4px;
  scrollbar-width: none;
}
.image-preview-strip::-webkit-scrollbar { display: none; }

.img-thumb-wrap {
  position: relative;
  flex-shrink: 0;
}

.img-thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 12px;
  border: 2px solid rgba(108,99,255,.3);
  display: block;
}

.img-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #ff6b6b;
  color: #fff;
  border: none;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}

/* ── Bild-Notiz in User-Bubble ───────────────────────────────── */

.img-attach-note {
  font-size: 12px;
  opacity: 0.8;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* ── Responsive: Tablet ───────────────────────────────────────── */

@media (max-width: 768px) {
  .bubble { max-width: 86%; }
  main    { padding: 20px 16px 12px; }

  .input-row { border-radius: 24px; padding: 7px 7px 7px 18px; }

  .mic-btn, .send-btn { width: 44px; height: 44px; }
}

/* ── Responsive: Mobile ───────────────────────────────────────── */

@media (max-width: 480px) {
  :root { font-size: 15px; }

  header { padding: 14px 20px; }
  .header-wordmark { font-size: 14px; }

  main { padding: 16px 12px 10px; }

  .bubble {
    max-width: 92%;
    padding: 13px 16px;
    font-size: 15px;
    border-radius: 20px;
  }
  .message.user .bubble      { border-bottom-right-radius: 5px; }
  .message.assistant .bubble { border-bottom-left-radius: 5px; }

  #chat-container { gap: 10px; }

  footer { padding: 10px 12px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }

  .input-row {
    border-radius: 22px;
    padding: 6px 6px 6px 16px;
    gap: 8px;
  }

  textarea#text-input { font-size: 16px; } /* verhindert iOS-Zoom */

  .mic-btn, .send-btn { width: 42px; height: 42px; }
  .mic-btn svg, .send-btn svg { width: 18px; height: 18px; }

  .mic-hint { font-size: 11px; margin-top: 7px; }

  .name-input-row { flex-direction: column; gap: 8px; }
  .name-input-row input  { width: 100%; }
  .name-input-row button { width: 100%; padding: 13px; }
}

/* ── Responsive: Große Screens ────────────────────────────────── */

@media (min-width: 1024px) {
  .bubble { font-size: 16px; line-height: 1.75; }
  main    { padding: 36px 24px 16px; }
  #chat-container { gap: 16px; }
}
