*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  :root {
    --primary:   #8b2a3a;
    --primary-h: #6e2030;
    --primary-light: #f5eaec;
    --accent:    #9a9a9a;
    --bg:        #f4f5f7;
    --surface:   #ffffff;
    --border:    #e2e4e9;
    --text:      #1a1d23;
    --muted:     #6b7280;
    --user-bg:   #8b2a3a;
    --bot-bg:    #f0f2f5;
    --radius:    12px;
  }
  body { font-family: "Segoe UI", system-ui, sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }

  .screen { display: none; height: 100vh; }
  .screen.active { display: flex; }

  /* LOGIN */
  #login-screen {
    align-items: center; justify-content: center;
    background: linear-gradient(135deg, #3a1020 0%, #8b2a3a 100%);
  }
  .login-card {
    background: var(--surface); border-radius: 20px;
    padding: 40px 40px 48px; width: 380px;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
    display: flex; flex-direction: column; gap: 20px;
    align-items: center;
  }
  .login-logo { width: 160px; object-fit: contain; margin-bottom: 4px; }
  .login-divider { width: 100%; height: 1px; background: var(--border); }
  .login-card h2 { font-size: 1.1rem; font-weight: 700; color: var(--text); letter-spacing: .02em; }
  .login-card input {
    width: 100%; padding: 12px 16px; border: 1.5px solid var(--border);
    border-radius: var(--radius); font-size: 1rem; outline: none;
    transition: border-color .2s; font-family: inherit;
  }
  .login-card input:focus { border-color: var(--primary); }
  .login-fields { display: flex; flex-direction: column; gap: 12px; width: 100%; }
  .login-card button {
    width: 100%; padding: 13px; background: var(--primary); color: #fff;
    border: none; border-radius: var(--radius); font-size: 1rem;
    font-weight: 600; cursor: pointer; transition: background .2s; font-family: inherit;
  }
  .login-card button:hover { background: var(--primary-h); }
  .login-error { color: #dc2626; font-size: .85rem; text-align: center; display: none; }

  /* APP */
  #app-screen { flex-direction: row; }

  /* SIDEBAR */
  .sidebar {
    width: 280px; min-width: 280px; background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column; height: 100vh;
  }
  .sidebar-logo-wrap {
    padding: 20px 20px 16px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
  }
  .sidebar-logo { width: 130px; object-fit: contain; }

  .section-label {
    font-size: .7rem; font-weight: 700; color: var(--muted);
    text-transform: uppercase; letter-spacing: .08em;
    padding: 16px 20px 8px;
  }

  .agent-btn {
    width: 100%; display: flex; align-items: center; gap: 12px;
    padding: 10px 14px; border: none; background: none;
    cursor: pointer; text-align: left; transition: background .15s;
    margin: 1px 0;
  }
  .agent-btn:hover { background: var(--bg); }
  .agent-btn.active { background: var(--primary-light); }
  .agent-icon {
    width: 38px; height: 38px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.15rem; flex-shrink: 0;
  }
  .agent-info strong { font-size: .9rem; display: block; font-weight: 600; }
  .agent-info span { font-size: .75rem; color: var(--muted); }

  /* Archive */
  .archive-wrap { flex: 1; overflow-y: auto; border-top: 1px solid var(--border); }
  .archive-item {
    width: 100%; display: flex; align-items: flex-start; gap: 10px;
    padding: 9px 14px; border: none; background: none;
    cursor: pointer; text-align: left; transition: background .15s;
  }
  .archive-item:hover { background: var(--bg); }
  .archive-item.active { background: var(--primary-light); }
  .archive-del-btn {
    margin-left: auto; flex-shrink: 0; background: none; border: none;
    cursor: pointer; font-size: .85rem; opacity: 0; padding: 2px 4px;
    border-radius: 4px; transition: opacity .15s, background .15s;
    color: var(--muted);
  }
  .archive-item:hover .archive-del-btn { opacity: 1; }
  .archive-del-btn:hover { background: #fee2e2; color: #dc2626; }
  .archive-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
  .archive-info strong { font-size: .82rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
  .archive-info span { font-size: .72rem; color: var(--muted); }
  .archive-empty { font-size: .82rem; color: var(--muted); padding: 12px 20px; }

  .sidebar-footer {
    padding: 14px 16px; border-top: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
  }
  .sidebar-footer span { font-size: .82rem; color: var(--muted); }
  .logout-btn {
    font-size: .8rem; color: var(--muted); background: none;
    border: 1px solid var(--border); border-radius: 8px;
    padding: 5px 10px; cursor: pointer; transition: all .15s; font-family: inherit;
  }
  .logout-btn:hover { color: var(--primary); border-color: var(--primary); }

  /* MAIN */
  .main { flex: 1; display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

  .welcome-state {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 16px; color: var(--muted);
  }
  .welcome-logo { width: 180px; opacity: .25; }
  .welcome-state h2 { font-size: 1.2rem; font-weight: 700; color: var(--text); }
  .welcome-state p { font-size: .9rem; max-width: 320px; text-align: center; line-height: 1.6; }

  /* Chat header */
  .chat-header {
    padding: 14px 24px; border-bottom: 1px solid var(--border);
    background: var(--surface); display: flex; align-items: center;
    gap: 14px; flex-shrink: 0;
  }
  .chat-header-icon { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; }
  .chat-header-info h3 { font-size: 1.05rem; font-weight: 700; letter-spacing: .01em; }
  .chat-header-info span { font-size: .8rem; color: var(--muted); }
  .new-chat-btn {
    margin-left: auto; padding: 8px 16px; background: var(--primary);
    color: #fff; border: none; border-radius: 8px; font-size: .85rem;
    font-weight: 600; cursor: pointer; transition: background .2s; font-family: inherit;
  }
  .new-chat-btn:hover { background: var(--primary-h); }

  /* Messages */
  .messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
  .msg { display: flex; gap: 10px; max-width: 78%; }
  .msg.user { align-self: flex-end; flex-direction: row-reverse; }
  .msg.bot  { align-self: flex-start; }
  .msg-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: .9rem; flex-shrink: 0; margin-top: 2px;
  }
  .msg.user .msg-avatar { background: var(--primary); color: #fff; }
  .msg.bot  .msg-avatar { background: var(--bot-bg); }
  .msg-bubble {
    padding: 12px 16px; border-radius: 16px;
    font-size: .92rem; line-height: 1.7; white-space: pre-wrap; word-break: break-word;
  }
  .msg.bot .msg-bubble { white-space: normal; }
  .msg.user .msg-bubble { background: var(--user-bg); color: #fff; border-bottom-right-radius: 4px; }
  .msg.bot  .msg-bubble { background: var(--bot-bg); color: var(--text); border-bottom-left-radius: 4px; }
  .msg-bubble a { color: var(--primary); text-decoration: underline; word-break: break-all; }
  .msg.bot .msg-bubble h1,.msg.bot .msg-bubble h2,.msg.bot .msg-bubble h3 { font-weight: 700; margin: 10px 0 4px; line-height: 1.3; }
  .msg.bot .msg-bubble h1 { font-size: 1.1rem; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
  .msg.bot .msg-bubble h2 { font-size: 1rem; }
  .msg.bot .msg-bubble h3 { font-size: .95rem; }
  .msg.bot .msg-bubble p { margin: 0 0 8px; }
  .msg.bot .msg-bubble p:last-child { margin-bottom: 0; }
  .msg.bot .msg-bubble ul,.msg.bot .msg-bubble ol { padding-left: 20px; margin: 4px 0 8px; }
  .msg.bot .msg-bubble li { margin-bottom: 2px; }
  .msg.bot .msg-bubble strong { font-weight: 700; }
  .msg.bot .msg-bubble em { font-style: italic; }
  .msg.bot .msg-bubble code { background: rgba(0,0,0,.07); border-radius: 4px; padding: 1px 5px; font-size: .85em; font-family: monospace; }
  .msg.bot .msg-bubble pre { background: rgba(0,0,0,.07); border-radius: 8px; padding: 10px 12px; overflow-x: auto; margin: 6px 0; }
  .msg.bot .msg-bubble pre code { background: none; padding: 0; }
  .msg.bot .msg-bubble hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }
  .msg-time { font-size: .7rem; color: var(--muted); margin-top: 4px; }
  .msg.user .msg-time { text-align: right; }

  /* Typing */
  .typing { display: flex; gap: 5px; align-items: center; padding: 12px 15px; }
  .typing span { width: 7px; height: 7px; background: var(--muted); border-radius: 50%; animation: bounce .9s infinite; }
  .typing span:nth-child(2) { animation-delay: .15s; }
  .typing span:nth-child(3) { animation-delay: .3s; }
  @keyframes bounce { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-6px)} }

  /* Input */
  .input-area { padding: 16px 24px 20px; border-top: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }

  /* PDF Preview */
  .pdf-preview {
    display: none; align-items: center; gap: 8px;
    background: var(--primary-light); border: 1px solid #d4a0a8;
    border-radius: 8px; padding: 7px 12px; margin-bottom: 8px; font-size: .82rem;
  }
  .pdf-preview.visible { display: flex; }
  .pdf-preview-name { font-weight: 600; color: var(--primary); }
  .pdf-preview-size { color: var(--muted); }
  .pdf-remove {
    margin-left: auto; background: none; border: none; cursor: pointer;
    color: var(--muted); font-size: .9rem; padding: 2px 4px; border-radius: 4px;
    transition: background .15s, color .15s;
  }
  .pdf-remove:hover { background: #fecdd3; color: #dc2626; }

  .input-row {
    display: flex; gap: 10px; align-items: flex-end;
    background: var(--bg); border: 1.5px solid var(--border);
    border-radius: 14px; padding: 10px 14px; transition: border-color .2s;
  }
  .input-row:focus-within { border-color: var(--primary); }

  .pdf-btn {
    background: none; border: none; cursor: pointer; font-size: 1.1rem;
    padding: 4px 6px; border-radius: 8px; transition: background .15s;
    flex-shrink: 0; opacity: 0.6;
  }
  .pdf-btn:hover { background: var(--border); opacity: 1; }
  .pdf-btn.has-file { opacity: 1; }

  #msg-input {
    flex: 1; border: none; background: none; outline: none;
    font-size: .95rem; resize: none; max-height: 120px; font-family: inherit; line-height: 1.5;
  }
  .send-btn {
    width: 36px; height: 36px; background: var(--primary); color: #fff;
    border: none; border-radius: 10px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: background .2s; font-size: 1rem;
  }
  .send-btn:hover { background: var(--primary-h); }
  .send-btn:disabled { background: var(--border); cursor: not-allowed; }
  .input-hint { font-size: .72rem; color: var(--muted); margin-top: 6px; padding-left: 4px; }

  ::-webkit-scrollbar { width: 5px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

/* ===== Ergänzungen Portal v2 (Supabase-Login, Verlauf, Teilen) ===== */
.login-hint { font-size: .78rem; color: var(--muted); text-align: center; line-height: 1.5; }
.login-card button:disabled { background: var(--border); cursor: wait; }

.history-label { display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--border); padding-top: 16px; }
.history-filter {
  font-size: .72rem; color: var(--muted); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 2px 4px; font-family: inherit; text-transform: none; letter-spacing: 0; font-weight: 500;
}
.archive-info { min-width: 0; }
.archive-info span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
.badge {
  display: inline-block; font-size: .66rem; font-weight: 600; padding: 1px 6px; border-radius: 999px;
  background: var(--primary-light); color: var(--primary); margin-top: 3px; vertical-align: middle;
}
.badge.shared-in { background: #eaf0f5; color: #2f5a80; }

.chat-view { display: none; flex-direction: column; height: 100%; }
.chat-view.open { display: flex; }
.chat-header-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.chat-header-actions .new-chat-btn { margin-left: 0; }
.share-btn {
  padding: 8px 14px; background: var(--surface); color: var(--primary);
  border: 1.5px solid var(--primary); border-radius: 8px; font-size: .85rem;
  font-weight: 600; cursor: pointer; transition: all .2s; font-family: inherit;
}
.share-btn:hover { background: var(--primary-light); }
.share-btn[hidden], .new-chat-btn[hidden], .archive-del-btn[hidden], .input-area[hidden] { display: none !important; }

.readonly-banner {
  display: none; padding: 8px 24px; font-size: .8rem; color: #2f5a80; background: #eaf0f5;
  border-bottom: 1px solid #d3dfea; flex-shrink: 0;
}
.readonly-banner.visible { display: block; }

.msg-attachment { font-size: .75rem; opacity: .85; margin-top: 4px; }

.modal-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35);
  align-items: center; justify-content: center; z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border-radius: 16px; width: 420px; max-width: calc(100vw - 32px);
  max-height: 80vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25);
  padding: 22px 22px 16px; gap: 10px;
}
.modal h3 { font-size: 1.05rem; font-weight: 700; }
.modal-sub { font-size: .82rem; color: var(--muted); }
.share-list { overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin: 6px 0; }
.share-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--border);
}
.share-row .share-name { font-size: .9rem; font-weight: 600; display: block; }
.share-row .share-mail { font-size: .75rem; color: var(--muted); display: block; }
.share-row button {
  margin-left: auto; padding: 6px 12px; font-size: .8rem; font-weight: 600; border-radius: 8px;
  border: 1.5px solid var(--primary); background: var(--primary); color: #fff; cursor: pointer; font-family: inherit;
  flex-shrink: 0;
}
.share-row button:disabled { background: var(--bg); color: var(--muted); border-color: var(--border); cursor: default; }
.share-empty { font-size: .85rem; color: var(--muted); padding: 10px 4px; }
.modal-actions { display: flex; justify-content: flex-end; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .85rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: #b91c1c; }

@media (max-width: 720px) {
  #app-screen { flex-direction: column; }
  .sidebar { width: 100%; min-width: 0; height: auto; max-height: 45vh; border-right: none; border-bottom: 1px solid var(--border); }
  .main { height: auto; flex: 1; }
  .msg { max-width: 92%; }
  .messages, .input-area, .chat-header { padding-left: 16px; padding-right: 16px; }
}

/* Quick Replies (Rückfragen als Buttons) */
.quick-replies { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; max-width: 100%; }
.quick-group { display: flex; flex-direction: column; gap: 5px; }
.quick-question { font-size: .8rem; font-weight: 600; color: var(--text); }
.quick-options { display: flex; flex-wrap: wrap; gap: 6px; }
.quick-reply.selected { background: var(--primary); color: #fff; }
.quick-send {
  align-self: flex-start; padding: 8px 14px; background: var(--primary); color: #fff; border: none;
  border-radius: 8px; font-size: .85rem; font-weight: 600; cursor: pointer; font-family: inherit;
}
.quick-send:disabled { background: var(--border); color: var(--muted); cursor: not-allowed; }
.quick-hint { font-size: .72rem; color: var(--muted); }
.quick-reply {
  background: var(--surface); color: var(--primary); border: 1.5px solid var(--primary);
  border-radius: 999px; padding: 6px 12px; font-size: .82rem; font-weight: 600; cursor: pointer;
  font-family: inherit; text-align: left; transition: background .15s, color .15s; max-width: 100%;
}
.quick-reply:hover { background: var(--primary); color: #fff; }

/* Operator-Kurzfassung mit Details-Toggle */
.msg-summary p:last-child { margin-bottom: 0; }
.details-toggle {
  display: inline-block; margin-top: 8px; background: none; border: none; padding: 0;
  color: var(--primary); font-size: .78rem; font-weight: 600; cursor: pointer; font-family: inherit; text-decoration: underline;
}
.msg-details { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); font-size: .85rem; opacity: .9; }
.msg-details[hidden] { display: none; }

/* Inline-Fragen in der Operator-Ansicht + Sammel-Senden */
.msg-summary .quick-group { margin: 6px 0 10px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.msg-summary p:has(> .quick-group) { margin: 0; }
.quick-footer { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.quick-footer .quick-send { align-self: flex-start; }
.quick-reply:disabled { opacity: .45; cursor: default; }
.pref-row { display: flex; align-items: center; gap: 6px; padding: 6px 16px 12px; font-size: .75rem; color: var(--muted); cursor: pointer; }
.pref-row input { accent-color: var(--primary); }

/* Frage-Vertrag: Eingabefeld an der Frage, Mehrfachauswahl, Vorauswahl */
.quick-other { border-style: dashed; }
.quick-other-input {
  margin-top: 6px; width: 100%; max-width: 360px; padding: 7px 10px; border: 1.5px solid var(--primary);
  border-radius: 8px; font-size: .85rem; font-family: inherit; outline: none; background: var(--surface);
}
.quick-other-input[hidden] { display: none; }
