/* Datei: httpdocs/ai_chat/assets/chat-widget.css */
/* Angepasst an SWS-Webseite: Noto Sans, SWS-Blau #4c69a2, Grüner Bot-Button */

/* Root */
.sws-chat-root {
  position: fixed;
  bottom: 16px;
  right: 16px;
  font-family: 'Noto Sans', Arial, sans-serif;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

/* Panel */
.sws-chat-panel {
  width: 420px;
  max-width: 95vw;
  max-height: 600px;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  order: 1;
}

.sws-chat-root--open .sws-chat-panel {
  display: flex;
}

/* Toggle-Button immer unten */
.sws-chat-toggle {
  order: 2;
}

/* Toggle-Button - Grün ohne Verlauf, GRÖSSER */
.sws-chat-toggle {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: none;
  background: #22c55e;
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(34, 197, 94, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: width 0.3s ease, height 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease, background 0.3s ease;
  position: relative;
  overflow: visible;
}

/* Kleinerer Toggle-Button wenn Chat geöffnet (Schließen-Button) */
.sws-chat-root--open .sws-chat-toggle {
  width: 44px;
  height: 44px;
}

.sws-chat-toggle:hover {
  transform: scale(1.05);
  background: #16a34a;
  box-shadow: 0 6px 24px rgba(34, 197, 94, 0.5);
}

.sws-chat-toggle:active {
  transform: scale(0.95);
}

/* Puls-Animation für Aufmerksamkeit */
.sws-chat-toggle::before {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #22c55e;
  animation: sws-pulse 2s ease-in-out infinite;
  z-index: -1;
}

@keyframes sws-pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 0.5;
  }
  50% {
    transform: scale(1.2);
    opacity: 0;
  }
}

/* Bot-Icon im Button - groß */
.sws-chat-toggle svg.sws-chat-icon-open {
  width: 42px;
  height: 42px;
  fill: currentColor;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Schließen-Icon - deutlich kleiner */
.sws-chat-toggle svg.sws-chat-icon-close {
  width: 22px;
  height: 22px;
  fill: currentColor;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Icon-Wechsel: Bot-Icon vs. X */
.sws-chat-icon-open {
  display: block;
}
.sws-chat-icon-close {
  display: none;
}

/* Wenn Chat offen ist: X-Icon zeigen, Bot-Icon verstecken */
.sws-chat-root--open .sws-chat-icon-open {
  display: none;
}
.sws-chat-root--open .sws-chat-icon-close {
  display: block;
}

/* Wenn Chat offen ist: Puls stoppen */
.sws-chat-root--open .sws-chat-toggle::before {
  animation: none;
  opacity: 0;
}

/* Label "Frag SWS" über dem Button - grün mit weißer Schrift */
.sws-chat-toggle::after {
  content: 'Frag SWS';
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px); /* 10px über dem Button */
  transform: translateX(-50%);
  background: #22c55e;
  color: #ffffff;
  padding: 10px 20px;
  border-radius: 16px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.4);
  opacity: 1;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Label ausblenden wenn Chat geöffnet */
.sws-chat-root--open .sws-chat-toggle::after {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(4px);
}

/* Hop-Animation für Aufmerksamkeit, nur wenn geschlossen */
@keyframes sws-hop {
  0%, 90%, 100% { transform: translateY(0); }
  94% { transform: translateY(-8px); }
  96% { transform: translateY(0); }
}
.sws-chat-root:not(.sws-chat-root--open) .sws-chat-toggle {
  animation: sws-hop 4s ease-in-out infinite;
}

/* Header - SWS-Blau */
.sws-chat-header {
  padding: 12px 16px;
  background: #4c69a2;
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
}

.sws-chat-header-note {
  font-size: 11px;
  margin-top: 4px;
  opacity: 0.85;
  font-weight: 400;
}

/* Messages */
.sws-chat-messages {
  flex: 1;
  padding: 12px 14px;
  overflow-y: auto;
  background: #f5f5f5;
}

/* Scrollbar-Styling */
.sws-chat-messages::-webkit-scrollbar {
  width: 6px;
}
.sws-chat-messages::-webkit-scrollbar-track {
  background: #e5e5e5;
  border-radius: 3px;
}
.sws-chat-messages::-webkit-scrollbar-thumb {
  background: #4c69a2;
  border-radius: 3px;
}

.sws-chat-message {
  margin-bottom: 12px;
  max-width: 100%;
}

.sws-chat-message--user {
  text-align: right;
}

.sws-chat-message--bot {
  text-align: left;
}

.sws-chat-bubble {
  display: inline-block;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
  max-width: 85%;
}

/* User-Bubble - SWS-Blau */
.sws-chat-message--user .sws-chat-bubble {
  background: #4c69a2;
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

/* Bot-Bubble - Weiß */
.sws-chat-message--bot .sws-chat-bubble {
  background: #ffffff;
  color: #1d1d1d;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* Meta-Info */
.sws-chat-meta {
  font-size: 10px;
  color: #6b7280;
  margin-top: 4px;
}

/* Footer */
.sws-chat-footer {
  padding: 10px 12px;
  border-top: 1px solid #e5e7eb;
  background: #fafafa;
  display: flex;
  gap: 8px;
}

.sws-chat-input {
  flex: 1;
  font-family: 'Noto Sans', Arial, sans-serif;
  font-size: 14px;
  resize: none;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  padding: 8px 12px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.sws-chat-input:focus {
  outline: none;
  border-color: #4c69a2;
  box-shadow: 0 0 0 2px rgba(76, 105, 162, 0.2);
}

/* Input-Container mit Zeichenzähler */
.sws-chat-input-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sws-chat-input-container .sws-chat-input {
  flex: 1;
}

/* Zeichenzähler */
.sws-chat-char-count {
  font-size: 10px;
  color: #9ca3af;
  text-align: right;
  padding-right: 4px;
  transition: color 0.2s ease;
}

.sws-chat-char-count--warning {
  color: #f59e0b;
  font-weight: 500;
}

.sws-chat-char-count--limit {
  color: #ef4444;
  font-weight: 600;
}

/* Senden-Button - Grün */
.sws-chat-send {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  background: #22c55e;
  color: #ffffff;
  font-family: 'Noto Sans', Arial, sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}

.sws-chat-send:hover {
  background: #16a34a;
}

.sws-chat-send:disabled {
  background: #9ca3af;
  cursor: not-allowed;
}

/* Quellenliste - SWS-Blau Akzent */
.sws-chat-sources {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f0f4ff;
  border-left: 3px solid #4c69a2;
  font-size: 12px;
  color: #4b5563;
}

.sws-chat-sources-title {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 10px;
  color: #4c69a2;
  margin-bottom: 6px;
}

.sws-chat-sources-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sws-chat-sources-item {
  margin-bottom: 6px;
}

/* Links - SWS-Blau */
.sws-chat-source-link {
  color: #4c69a2;
  text-decoration: none;
  font-weight: 500;
}

.sws-chat-source-link:hover {
  color: #1a203c;
  text-decoration: underline;
}

.sws-chat-source-snippet {
  font-size: 11px;
  color: #6b7280;
  margin-top: 2px;
}

/* Fallback-Box */
.sws-chat-fallback-box {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fef3c7;
  border: 1px solid #fbbf24;
}

.sws-chat-fallback-text {
  font-size: 11px;
  margin-bottom: 4px;
}

.sws-chat-fallback-btn {
  display: inline-block;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  background: #22c55e;
  color: #ffffff;
  text-decoration: none;
  transition: background 0.2s ease;
}

.sws-chat-fallback-btn:hover {
  background: #16a34a;
}

/* Typing Indicator (3 animierte Punkte) */
.sws-chat-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
  background: #ffffff;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  width: fit-content;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.sws-chat-typing-dot {
  width: 8px;
  height: 8px;
  background: #9ca3af;
  border-radius: 50%;
  animation: sws-typing-bounce 1.4s ease-in-out infinite;
}

.sws-chat-typing-dot:nth-child(1) {
  animation-delay: 0s;
}

.sws-chat-typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.sws-chat-typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes sws-typing-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    background: #9ca3af;
  }
  30% {
    transform: translateY(-8px);
    background: #22c55e;
  }
}

/* Links in Bot-Nachrichten */
.sws-chat-bubble a {
  color: #4c69a2;
  text-decoration: underline;
}

.sws-chat-bubble a:hover {
  color: #1a203c;
}

/* Formatierte Bot-Antworten */

/* Absätze */
.sws-chat-p {
  margin: 0 0 8px 0;
}

.sws-chat-p:last-child {
  margin-bottom: 0;
}

/* Überschriften in Antworten */
.sws-chat-h3 {
  font-size: 15px;
  font-weight: 700;
  color: #4c69a2;
  margin: 12px 0 6px 0;
}

.sws-chat-h3:first-child {
  margin-top: 0;
}

.sws-chat-h4 {
  font-size: 14px;
  font-weight: 600;
  color: #1d1d1d;
  margin: 10px 0 4px 0;
}

.sws-chat-h4:first-child {
  margin-top: 0;
}

/* Listen (ul/ol) */
.sws-chat-list {
  margin: 8px 0;
  padding-left: 20px;
  list-style-position: outside;
}

.sws-chat-bubble ul.sws-chat-list {
  list-style-type: disc;
}

.sws-chat-bubble ol.sws-chat-list {
  list-style-type: decimal;
}

.sws-chat-list li {
  margin-bottom: 4px;
  line-height: 1.4;
}

.sws-chat-list li:last-child {
  margin-bottom: 0;
}

/* Verschachtelte Listen */
.sws-chat-list .sws-chat-list {
  margin: 4px 0;
}

/* Fett und Kursiv */
.sws-chat-bubble strong {
  font-weight: 700;
}

.sws-chat-bubble em {
  font-style: italic;
}

/* Horizontale Linie (Trenner) */
.sws-chat-hr {
  border: none;
  border-top: 1px solid #e5e7eb;
  margin: 12px 0 8px 0;
}

/* Kursiver Text nach horizontaler Linie = kleiner Hinweis */
.sws-chat-hr + .sws-chat-p em,
.sws-chat-bubble .sws-chat-p:last-child em:only-child {
  font-size: 11px;
  color: #6b7280;
  line-height: 1.4;
}

/* Hinweis-Absatz (kursiv am Ende) kleiner */
.sws-chat-bubble .sws-chat-p em {
  font-size: 12px;
  color: #6b7280;
}

/* Zeilenumbrüche zwischen Blöcken reduzieren */
.sws-chat-bubble br + br {
  display: none;
}

/* Hinweis für wiederhergestellten Gesprächsverlauf */
.sws-chat-history-notice {
  text-align: center;
  padding: 8px 12px;
  margin: 8px 16px 12px;
  background: linear-gradient(135deg, #e0f2fe 0%, #f0fdf4 100%);
  border: 1px solid #bae6fd;
  border-radius: 8px;
  font-size: 12px;
  color: #0369a1;
  font-weight: 500;
}

/* Confidence-Anzeige (Ampel) */
.sws-chat-confidence {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 6px 10px;
  background: #f8fafc;
  border-radius: 6px;
  font-size: 11px;
}

.sws-chat-confidence-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sws-chat-confidence-dot--high {
  background: #22c55e;
  box-shadow: 0 0 4px rgba(34, 197, 94, 0.5);
}

.sws-chat-confidence-dot--medium {
  background: #f59e0b;
  box-shadow: 0 0 4px rgba(245, 158, 11, 0.5);
}

.sws-chat-confidence-dot--low {
  background: #ef4444;
  box-shadow: 0 0 4px rgba(239, 68, 68, 0.5);
}

.sws-chat-confidence-text {
  color: #64748b;
  font-weight: 500;
}

/* "Antwort verbessern" Button */
.sws-chat-refine-wrapper {
  margin-top: 8px;
  text-align: right;
}

.sws-chat-refine-btn {
  background: #22c55e;
  border: none;
  border-radius: 12px;
  padding: 4px 10px;
  font-size: 11px;
  color: #ffffff;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.sws-chat-refine-btn:hover {
  background: #16a34a;
  transform: translateY(-1px);
}

.sws-chat-refine-btn:active {
  background: #15803d;
  transform: translateY(0);
}

.sws-chat-refine-icon {
  width: 12px;
  height: 12px;
  fill: #ffffff;
  flex-shrink: 0;
}

/* Hinweis bei verbesserter Antwort */
.sws-chat-refined-note {
  margin-top: 8px;
  padding: 6px 10px;
  background: #fef3c7;
  border-radius: 6px;
  font-size: 11px;
  color: #92400e;
  font-style: italic;
}

/* ==================== VORSCHLÄGE ==================== */

.sws-chat-suggestions {
  padding: 8px 12px;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
}

.sws-chat-suggestions-title {
  font-size: 11px;
  color: #64748b;
  margin-bottom: 6px;
  font-weight: 500;
}

.sws-chat-suggestions-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sws-chat-suggestion-btn {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 5px 12px;
  font-size: 11px;
  color: #334155;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.sws-chat-suggestion-btn:hover {
  background: #22c55e;
  border-color: #22c55e;
  color: #ffffff;
}

/* ==================== FEEDBACK-BUTTONS ==================== */

.sws-chat-feedback {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #f1f5f9;
}

.sws-chat-feedback-label {
  font-size: 11px;
  color: #94a3b8;
}

.sws-chat-feedback-btn {
  background: none;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1;
}

.sws-chat-feedback-btn:hover {
  transform: scale(1.1);
}

.sws-chat-feedback-btn--up:hover {
  background: #dcfce7;
  border-color: #22c55e;
}

.sws-chat-feedback-btn--down:hover {
  background: #fee2e2;
  border-color: #ef4444;
}

.sws-chat-feedback-thanks {
  font-size: 11px;
  color: #22c55e;
  font-weight: 500;
}

.sws-chat-feedback-error {
  font-size: 11px;
  color: #ef4444;
}

/* ==================== RESPONSIVE STYLES ==================== */

/* Tablets und kleine Desktops */
@media (max-width: 768px) {
  .sws-chat-root {
    bottom: 12px;
    right: 12px;
  }
  
  .sws-chat-panel {
    width: 360px;
    max-height: 500px;
  }
  
  .sws-chat-toggle {
    width: 64px;
    height: 64px;
  }
  
  .sws-chat-root--open .sws-chat-toggle {
    width: 40px;
    height: 40px;
  }
  
  .sws-chat-toggle svg.sws-chat-icon-open {
    width: 36px;
    height: 36px;
  }
  
  .sws-chat-toggle::after {
    padding: 8px 16px;
    font-size: 13px;
  }
}

/* Smartphones */
@media (max-width: 480px) {
  .sws-chat-root {
    bottom: 12px;
    right: 12px;
    left: auto;
    align-items: flex-end;
  }
  
  /* Chat-Panel auf Smartphones */
  .sws-chat-panel {
    width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 100px);
    border-radius: 12px;
    margin: 0;
  }
  
  /* Toggle-Button */
  .sws-chat-toggle {
    width: 60px;
    height: 60px;
  }
  
  .sws-chat-root--open .sws-chat-toggle {
    width: 40px;
    height: 40px;
  }
  
  .sws-chat-toggle svg.sws-chat-icon-open {
    width: 32px;
    height: 32px;
  }
  
  .sws-chat-toggle svg.sws-chat-icon-close {
    width: 20px;
    height: 20px;
  }
  
  /* Label "Frag SWS" auf Mobil ausblenden */
  .sws-chat-toggle::after {
    display: none;
  }
  
  /* Header */
  .sws-chat-header {
    padding: 14px 16px;
    font-size: 16px;
  }
  
  /* Messages: mehr Platz */
  .sws-chat-messages {
    padding: 10px 12px;
  }
  
  /* Eingabebereich */
  .sws-chat-footer {
    padding: 10px 12px;
    gap: 8px;
  }
  
  .sws-chat-input {
    font-size: 16px; /* verhindert iOS Zoom */
    padding: 10px 12px;
  }
  
  .sws-chat-send {
    padding: 10px 16px;
    font-size: 14px;
  }
  
  /* Quellen: kompakter */
  .sws-chat-sources {
    padding: 8px 10px;
  }
  
  .sws-chat-sources-title {
    font-size: 11px;
  }
}

/* Sehr kleine Smartphones */
@media (max-width: 360px) {
  .sws-chat-toggle {
    width: 54px;
    height: 54px;
  }
  
  .sws-chat-toggle svg.sws-chat-icon-open {
    width: 28px;
    height: 28px;
  }
  
  .sws-chat-bubble {
    padding: 10px 12px;
    font-size: 13px;
  }
}
