:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #d9dde3;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-contrast: #ffffff;
  --bubble-user: #2563eb;
  --bubble-user-text: #ffffff;
  --bubble-assistant: #eef1f5;
  --bubble-assistant-text: #1f2430;
  --danger: #b91c1c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

header h1 {
  margin: 0 0 4px;
  font-size: 1.25rem;
}

#layout {
  /* Nutzervorgabe 2026-10-02: Chatfenster breiter (vorher 1040px gesamt, ~680px Chat). */
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  align-items: flex-start;
}

main {
  flex: 1 1 720px;
  min-width: 0;
  margin: 24px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

#feedback-panel {
  flex: 0 1 300px;
  min-width: 260px;
  margin: 24px 0;
}

#feedback-panel form {
  gap: 10px;
}

#feedback-panel textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  resize: vertical;
}

.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

.feedback-status {
  margin: 0;
  font-size: 0.82rem;
}

.feedback-status.success {
  color: #16a34a;
}

.feedback-status.error {
  color: var(--danger);
}

@media (max-width: 800px) {
  #layout {
    flex-direction: column;
  }

  #feedback-panel {
    flex-basis: auto;
    width: 100%;
  }
}

section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

h2 {
  margin-top: 0;
  font-size: 1rem;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-header h2 {
  margin: 0;
}

#end-chat-btn {
  font-size: 0.8rem;
  padding: 6px 10px;
}

form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

input[type="text"],
input[type="password"] {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
}

button {
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 0.95rem;
  cursor: pointer;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

button.secondary {
  background: var(--bubble-assistant);
  color: var(--text);
}

#chat-log {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 200px;
  max-height: 50vh;
  overflow-y: auto;
  padding: 8px 0;
}

.bubble {
  /* auf breiten Fenstern die Zeilenlänge begrenzen, damit lange Antworten lesbar bleiben */
  max-width: min(85%, 960px);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.92rem;
  line-height: 1.4;
}

.bubble ul {
  margin: 4px 0;
  padding-left: 20px;
}

.bubble li {
  margin: 2px 0;
}

.bubble.user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  white-space: pre-wrap;
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--bubble-assistant);
  color: var(--bubble-assistant-text);
}

.bubble.system {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-style: italic;
  font-size: 0.82rem;
  white-space: pre-wrap;
}

.bubble.pending {
  align-self: flex-start;
  background: var(--bubble-assistant);
  color: var(--muted);
  font-style: italic;
}

.bubble.pending .hourglass {
  display: inline-block;
  animation: pending-flip 2s ease-in-out infinite;
}

.bubble.pending .pending-dots i {
  display: inline-block;
  width: 4px;
  height: 4px;
  margin-left: 3px;
  border-radius: 50%;
  background: currentColor;
  animation: pending-blink 1.2s infinite ease-in-out;
}

.bubble.pending .pending-dots i:nth-child(2) { animation-delay: 0.2s; }
.bubble.pending .pending-dots i:nth-child(3) { animation-delay: 0.4s; }

@keyframes pending-flip {
  0%, 40% { transform: rotate(0deg); }
  60%, 100% { transform: rotate(180deg); }
}

@keyframes pending-blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

/* Barrierefreiheit: Nutzer mit "reduzierte Bewegung" bekommen die Anzeige ohne Animation. */
@media (prefers-reduced-motion: reduce) {
  .bubble.pending .hourglass,
  .bubble.pending .pending-dots i {
    animation: none;
    opacity: 1;
  }
}

#plan-actions {
  display: flex;
  gap: 8px;
  margin: 8px 0;
}

/* WICHTIG: ohne diese Regel überschreibt "display: flex" oben die Browser-Standardregel
   "[hidden]{display:none}" vollständig (Autor-CSS gewinnt immer gegen User-Agent-Stile,
   unabhängig von Selektor-Spezifität) — das "hidden"-Attribut wurde dadurch von JS zwar
   korrekt gesetzt, aber optisch komplett ignoriert: die Buttons waren dauerhaft sichtbar.
   Nutzer-Feedback 2026-09-21. */
#plan-actions[hidden] {
  display: none;
}

#message-form {
  flex-direction: row;
  margin-top: 12px;
}

#message-form input {
  flex: 1;
}

#voice-controls {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 8px;
}

#voice-controls label {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

#attach-btn,
#mic-btn {
  background: var(--bubble-assistant);
  color: var(--text);
  font-size: 1.1rem;
  padding: 8px 12px;
}

#mic-btn.listening {
  background: var(--danger);
  color: #ffffff;
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* --- Excel-/CSV-Import (Nutzerliste hochladen) --- */
#import-panel {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

#import-upload-label {
  display: inline-flex;
  cursor: pointer;
  color: var(--accent);
  font-size: 0.9rem;
}

#import-preview,
#import-phone-form {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

#import-preview[hidden],
#import-phone-form[hidden] {
  display: none;
}

#import-preview-summary {
  margin: 0 0 6px;
  font-weight: 600;
}

#import-warnings {
  margin: 0 0 8px;
  padding-left: 18px;
  color: var(--danger);
  font-size: 0.82rem;
}

#import-warnings:empty {
  display: none;
}

#import-preview-table-wrap {
  max-height: 260px;
  overflow: auto;
  margin-bottom: 10px;
}

#import-preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

#import-preview-table th,
#import-preview-table td {
  text-align: left;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
}

.button-row {
  display: flex;
  gap: 8px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #14161b;
    --panel: #1c1f26;
    --border: #333844;
    --text: #e6e8eb;
    --muted: #9099a8;
    --accent: #3b82f6;
    --accent-contrast: #ffffff;
    --bubble-user: #3b82f6;
    --bubble-user-text: #ffffff;
    --bubble-assistant: #262b34;
    --bubble-assistant-text: #e6e8eb;
    --danger: #f87171;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14161b;
  --panel: #1c1f26;
  --border: #333844;
  --text: #e6e8eb;
  --muted: #9099a8;
  --accent: #3b82f6;
  --accent-contrast: #ffffff;
  --bubble-user: #3b82f6;
  --bubble-user-text: #ffffff;
  --bubble-assistant: #262b34;
  --bubble-assistant-text: #e6e8eb;
  --danger: #f87171;
}

/* PBX-Adresse: kurzes Namensfeld (typisch 5-20 Zeichen) + Endung als einzeiliges Dropdown rechts daneben, darunter die zusammengesetzte Adresse als Vorschau */
.domain-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: flex-start;
  margin-top: 4px;
}

.domain-row input[type="text"] {
  flex: 0 1 22ch;
  width: 22ch;
  min-width: 8ch;
  margin-top: 0;
}

.domain-radios {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 14px;
}

/* überschreibt die globale label-Regel (Spalte, kleine graue Schrift) für die Radio-Optionen */
.radio-opt {
  flex-direction: row;
  align-items: center;
  gap: 5px;
  font-size: 0.95rem;
  color: var(--text);
  white-space: nowrap;
  cursor: pointer;
}

.radio-opt input[type="radio"] {
  margin: 0;
  width: auto;
}

.pbx-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pbx-field[hidden] {
  display: none;
}

.pbx-field-label {
  font-size: 0.85rem;
  color: var(--muted);
}

.domain-preview {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  min-height: 1.2em;
  overflow-wrap: anywhere;
}

.form-error {
  margin: 4px 0;
  color: #b42318;
  font-size: 0.85rem;
}

.form-error[hidden] {
  display: none;
}

/* Datenschutz-Popup */
#privacy-dialog {
  width: min(860px, 94vw);
  max-height: 88vh;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

#privacy-dialog[open] {
  display: flex;
  flex-direction: column;
}

#privacy-dialog::backdrop {
  background: rgba(15, 20, 30, 0.55);
}

.dialog-header,
.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--panel);
}

.dialog-header {
  border-bottom: 1px solid var(--border);
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.dialog-footer {
  border-top: 1px solid var(--border);
}

.dialog-close {
  padding: 2px 10px;
  font-size: 1.4rem;
  line-height: 1.2;
  background: transparent;
  color: var(--text);
}

.dialog-print {
  font-size: 0.85rem;
}

.privacy-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 24px 20px;
  line-height: 1.6;
  font-size: 0.95rem;
}

.privacy-body:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.privacy-body h1 { font-size: 1.35rem; line-height: 1.3; margin: 0.6em 0 0.5em; }
.privacy-body h2 { font-size: 1.08rem; margin: 1.6em 0 0.4em; padding-top: 0.2em; }
.privacy-body h3 { font-size: 1rem; }
.privacy-body p { margin: 0.65em 0; }
.privacy-body ul, .privacy-body ol { padding-left: 1.4em; margin: 0.5em 0; }
.privacy-body li { margin: 0.4em 0; }
.privacy-body hr { border: 0; border-top: 1px solid var(--border); margin: 1.6em 0; }
.privacy-body blockquote { margin: 1em 0; padding: 0.1em 1em; border-left: 3px solid var(--border); color: var(--muted); }

.page-footer {
  max-width: 1600px;
  margin: 0 auto;
  padding: 8px 24px 24px;
  font-size: 0.82rem;
  color: var(--muted);
}

/* Backup-Empfehlung und Kopfzeilen-Aktionen */
.chat-header-actions {
  display: flex;
  gap: 8px;
}

.backup-card {
  align-self: stretch;
  border: 1px solid #f59e0b;
  background: #fffbeb;
  color: #3b2f0b;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.92rem;
  line-height: 1.45;
}

.backup-card p {
  margin: 6px 0;
}

.backup-card .backup-info {
  font-size: 0.85rem;
}

.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

@media (prefers-color-scheme: dark) {
  .backup-card {
    background: #3a2f12;
    color: #fde9b0;
    border-color: #b7791f;
  }
}

/* Sitzungs-Timer (verbleibende Zeit bis zum Leerlauf-Ende) */
.chat-header-actions {
  align-items: center;
}

.session-timer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.82rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.session-timer[hidden] {
  display: none;
}

.session-timer.warn {
  border-color: #f59e0b;
  background: #fffbeb;
  color: #92400e;
}

.session-timer.critical {
  border-color: #dc2626;
  background: #fef2f2;
  color: #991b1b;
  font-weight: 600;
}

@media (prefers-color-scheme: dark) {
  .session-timer.warn { background: #3a2f12; color: #fde9b0; }
  .session-timer.critical { background: #3b1414; color: #fecaca; }
}

.link-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.link-button[hidden] {
  display: none;
}

/* Hilfe-Button in der Chat-Kopfzeile */
.help-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bubble-assistant);
  color: var(--text);
  font-weight: 700;
  font-size: 1rem;
  line-height: 1;
}

.help-btn:hover {
  background: var(--accent);
  color: var(--accent-contrast);
}

/* Rechte Spalte: Feedback-Box und Stimmenbox untereinander */
#feedback-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#feedback-panel[hidden] {
  display: none;
}

#voice-section h2 {
  margin-bottom: 4px;
}

.voice-hint {
  margin: 0 0 10px;
  font-size: 0.82rem;
  color: var(--muted);
}

.voice-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.voice-option {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.voice-option:has(input:checked) {
  border-color: var(--accent);
  background: var(--bubble-assistant);
}

.voice-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.voice-option audio {
  width: 100%;
  height: 34px;
}

.voice-option small {
  color: var(--muted);
  font-size: 0.78rem;
}
