:root {
  /* Brand / Website Look (Computer Expert) */
  --brand-blue: #0056b3;
  --brand-blue-dark: #004494;
  --brand-green: #00d64b;

  /* Surfaces */
  --surface: #ffffff;
  --surface-2: #fcfcfc;
  --surface-3: #f5f7fa;

  /* Text */
  --text: #1f2937;
  --text-muted: #6b7280;
  --text-on-brand: #ffffff;

  /* Borders / Shadow */
  --border: #dee2e6;
  --border-strong: #cfd6df;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.12);

  /* Inputs */
  --input-bg: #ffffff;
  --input-border: #d1d5db;
  --input-focus: rgba(0, 86, 179, 0.25);

  /* Messages */
  --user-msg-bg: #f0f2f5;
  --assistant-msg-bg: #eef5ff; /* sehr helles blau */
  --assistant-bubble-border: rgba(0, 86, 179, 0.18);

  --assistant-avatar-bg: var(--brand-blue);
  --user-avatar-bg: #9ca3af;

  /* Buttons */
  --button-bg: #ffffff;
  --button-border: var(--border-strong);
  --button-hover-bg: #f3f6fb;

  /* Error */
  --error-color: #e53e3e;
}

/* --- Popup wrapper (alt kompatibel) --- */
#aiAssist {
  position: fixed;
  top: 120px;
  right: 20px;
  width: 520px;
  max-width: 90vw;
  height: 80vh;
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 30000;

  border-radius: 12px;
  border: 1px solid var(--border);
  background-color: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

#aiAssist.visible {
  display: flex;
}

.ai-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px; 
  background: var(--brand-blue);
  color: var(--text-on-brand);
  border-bottom: 3px solid var(--brand-green);

  user-select: none;
}

.ai-popup-header-title {
  cursor: move;
  font-weight: 800;
  letter-spacing: 0.2px;
}

.ai-popup-header-controls {
  display: flex;
  align-items: center;
  gap: 8px; /* Abstand zwischen den beiden Buttons */
}


.ai-popup-close {
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: var(--text-on-brand);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 20px;
  line-height: 1;
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.ai-popup-close:hover {
  background: rgba(255, 255, 255, 0.28);
  transform: scale(1.06);
}

.ai-popup-content {
  flex: 1;
  overflow: hidden;
  background: var(--surface);
}

/* --- Chat Container (Neue Version, aber Light) --- */
#ai-chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  background-color: var(--surface);
  color: var(--text);
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Header im Chat */
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;

  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.chat-header h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text);
}

/* Icon button */
.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--brand-blue);
  cursor: pointer;
  padding: 6px;
  border-radius: 10px;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.icon-btn:hover {
  background-color: var(--button-hover-bg);
  border-color: var(--border);
  transform: translateY(-1px);
}

.icon-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

/* Chat history */
#chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--surface-2);
}

/* Scrollbar (optional, dezent) */
#chat-history::-webkit-scrollbar {
  width: 10px;
}
#chat-history::-webkit-scrollbar-thumb {
  background: rgba(31, 41, 55, 0.18);
  border-radius: 10px;
}
#chat-history::-webkit-scrollbar-track {
  background: transparent;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 92%;
}

.message .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  flex-shrink: 0;
  color: #fff;
}

.message .content {
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.55;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.message .content p { margin: 0 0 0.5em 0; }
.message .content ul,
.message .content ol { margin-top: 0.5em; padding-left: 20px; }

/* Assistant */
.message.assistant {
  align-self: flex-start;
}

.message.assistant .avatar {
  background-color: var(--assistant-avatar-bg);
}

.message.assistant .content {
  background-color: var(--assistant-msg-bg);
  border-color: var(--assistant-bubble-border);
  border-bottom-left-radius: 4px;
}

/* User */
.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message.user .avatar {
  background-color: var(--user-avatar-bg);
}

.message.user .content {
  background-color: var(--user-msg-bg);
  border-color: var(--border);
  border-bottom-right-radius: 4px;
}

/* Input Area */
.chat-input-area {
  display: flex;
  padding: 12px;
  border-top: 1px solid var(--border);
  background-color: var(--surface);
  gap: 10px;
  min-height: 96px;
}

.input-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

#prompt-input {
  width: 100%;
  background-color: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--input-border);
  border-radius: 10px;
  padding: 10px 48px 10px 12px;
  resize: none;
  font-family: inherit;
  font-size: 1rem;
  max-height: 120px;
  overflow-y: auto;
  transition: background-color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

#prompt-input::placeholder {
  color: rgba(31, 41, 55, 0.45);
}

#prompt-input:focus {
  outline: none;
  border-color: var(--brand-blue);
  box-shadow: 0 0 0 3px var(--input-focus);
}

/* Disabled state für beendete Konversation */
#prompt-input:disabled {
  background-color: #f8f9fa;
  border-color: #e5e7eb;
  color: #9ca3af;
  cursor: not-allowed;
  opacity: 0.7;
}

#prompt-input:disabled::placeholder {
  color: #9ca3af;
  font-style: italic;
}

.chat-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-input-area button {
  background-color: var(--button-bg);
  border: 1px solid var(--button-border);
  color: var(--brand-blue);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.chat-input-area button:hover:not(:disabled) {
  background-color: var(--button-hover-bg);
  border-color: var(--border);
  transform: translateY(-1px);
}

.chat-input-area button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

/* "Neue Konversation" Button hervorheben wenn Konversation beendet ist */
.chat-header .icon-btn:not(:disabled) {
  animation: none;
}

.ai-header-actions {
  display: flex;
  align-items: center;
  gap: 8px; /* Hier steuerst du den Abstand zwischen den Buttons */
}

/* Spezifisches Styling für den New-Conversation Button im Header */
#btn-new-conversation {
  background-color: var(--brand-green) !important; /* Auffälliges Grün */
  color: white !important;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  transition: transform 0.15s ease, background-color 0.15s ease;
}

#btn-new-conversation:hover {
  transform: scale(1.1);
  background-color: #00bf43 !important; /* Etwas dunkler beim Hover */
    box-shadow: 0 3px 8px rgba(0,0,0,0.2);
}



#btn-new-conversation svg {
  width: 18px;
  height: 18px;
}

/* Voice button positioned inside textarea */
#btn-voice {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  background-color: transparent;
  border: 1px solid transparent;
  padding: 0;
  color: var(--text-muted);
  border-radius: 10px;
}

#btn-voice:hover:not(:disabled) {
  background: rgba(0, 86, 179, 0.06);
  border-color: rgba(0, 86, 179, 0.10);
  color: var(--brand-blue);
}

#btn-voice:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Recording indicator ring */
.recording-indicator {
  display: none;
  position: absolute;
  inset: -4px;
  border-radius: 12px; /* passt zum Button */
  border: 2px solid var(--error-color);
  animation: pulse 1.2s infinite;
  pointer-events: none;
}

#audio-level-indicator {
  display: none;
}

#btn-voice.recording #audio-level-indicator {
  display: block;
}

/* Audio level visualizer */
.audio-level-visualizer {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: rgba(229, 62, 62, 0.20);
  border-radius: 999px;
  transition: width 0.1s, height 0.1s;
  width: 0px;
  height: 0px;
}

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

/* Spinner for send */
.spinner {
  border: 3px solid rgba(0, 0, 0, 0.12);
  border-radius: 50%;
  border-top: 3px solid var(--brand-blue);
  width: 18px;
  height: 18px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* TTS states (alt-kompatible Klassen) */
#btn-tts-toggle.active {
  border-color: rgba(0, 86, 179, 0.35);
  box-shadow: 0 0 0 3px rgba(0, 86, 179, 0.12);
}

#btn-tts-toggle.playing {
  border-color: rgba(0, 214, 75, 0.55);
  box-shadow: 0 0 0 3px rgba(0, 214, 75, 0.14);
}

#btn-tts-toggle:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Error message (alt IDs) */
.error-message {
  padding: 8px 16px;
  color: var(--error-color);
  font-size: 0.9rem;
  text-align: center;
  min-height: 25px;
  background: #fff;
  border-top: 1px solid var(--border);
}

/* Screen-reader helper */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}