/* ============================================
   STROPHANTHIN-WISSEN – Community-KI Widget
   Ausschließlich CSS Custom Properties aus
   styles.css – keine eigenen Farbwerte.
   ============================================ */

/* --- Floating Trigger-Button --- */
#sw-chat-btn {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9000;

  display: inline-flex;
  align-items: center;
  gap: 14px;

  padding: 14px 22px 14px 18px;
  background: linear-gradient(135deg, #b8471f 0%, var(--color-primary) 55%, #7a2e14 100%);
  color: var(--color-white);
  border: none;
  border-radius: 18px;
  cursor: pointer;

  font-family: var(--font-family);

  box-shadow:
    0 6px 24px rgba(153, 60, 29, 0.45),
    0 2px 8px rgba(0, 0, 0, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
  transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
  user-select: none;
}

#sw-chat-btn:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow:
    0 10px 32px rgba(153, 60, 29, 0.55),
    0 4px 12px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
  filter: brightness(1.06);
}

#sw-chat-btn:active {
  transform: translateY(-1px) scale(0.99);
  box-shadow: 0 4px 16px rgba(153, 60, 29, 0.4);
}

/* Herzschlag-Icon */
.sw-btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.sw-btn-icon svg {
  display: block;
  animation: sw-heartbeat 1.8s ease-in-out infinite;
  transform-origin: center;
}

@keyframes sw-heartbeat {
  0%   { transform: scale(1);    }
  12%  { transform: scale(1.28); }
  24%  { transform: scale(1.08); }
  36%  { transform: scale(1.22); }
  50%  { transform: scale(1);    }
  100% { transform: scale(1);    }
}

/* Zweizeiliger Button-Text */
.sw-btn-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.sw-btn-line1 {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.85;
  line-height: 1;
}

.sw-btn-line2 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.2;
  white-space: nowrap;
}

/* Aufmerksamkeits-Puls beim ersten Laden (Button-Schatten) */
@keyframes sw-pulse {
  0%, 100% { box-shadow: 0 6px 24px rgba(153, 60, 29, 0.45), 0 2px 8px rgba(0,0,0,0.18), inset 0 1px 0 rgba(255,255,255,0.12); }
  50%       { box-shadow: 0 6px 36px rgba(153, 60, 29, 0.75), 0 2px 8px rgba(0,0,0,0.18), inset 0 1px 0 rgba(255,255,255,0.12); }
}
#sw-chat-btn.sw-pulse-once {
  animation: sw-pulse 1.4s ease 0.8s 4;
}

/* --- Modal Overlay --- */
#sw-chat-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9001;
  background: rgba(44, 44, 42, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: sw-fade-in 0.2s ease;
}

#sw-chat-overlay.sw-open {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 0 28px 100px 28px; /* Platz über dem Floating Button */
}

@keyframes sw-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* --- Chat-Container --- */
#sw-chat-container {
  width: 100%;
  max-width: 480px;
  height: 580px;
  max-height: calc(100dvh - 120px);

  display: flex;
  flex-direction: column;

  background: var(--color-white);
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(44, 44, 42, 0.18);

  overflow: hidden;
  animation: sw-slide-up 0.25s ease;
}

@keyframes sw-slide-up {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* --- Header --- */
#sw-chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  background: var(--color-primary);
  color: var(--color-white);
  flex-shrink: 0;
}

#sw-chat-header .sw-header-title {
  font-weight: 600;
  font-size: 0.95rem;
  flex: 1;
}

#sw-chat-header .sw-header-sub {
  font-size: 0.72rem;
  opacity: 0.75;
  white-space: nowrap;
}

#sw-chat-close {
  background: transparent;
  border: none;
  color: var(--color-white);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  border-radius: 4px;
  opacity: 0.8;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
#sw-chat-close:hover { opacity: 1; }

/* --- Nachrichten-Bereich --- */
#sw-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

/* Scrollbar dezent */
#sw-chat-messages::-webkit-scrollbar { width: 4px; }
#sw-chat-messages::-webkit-scrollbar-track { background: transparent; }
#sw-chat-messages::-webkit-scrollbar-thumb {
  background: var(--color-gray-medium);
  border-radius: 2px;
}

/* Einzelne Nachricht */
.sw-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}

.sw-msg-user {
  align-self: flex-end;
  background: var(--color-primary);
  color: var(--color-white);
  border-bottom-right-radius: 4px;
}

.sw-msg-bot {
  align-self: flex-start;
  background: var(--color-gray-light);
  color: var(--color-text);
  border-bottom-left-radius: 4px;
}

/* Tipp-Indikator (drei Punkte) */
.sw-msg-bot.sw-typing::after {
  content: ' ●●●';
  font-size: 0.6rem;
  opacity: 0.5;
  animation: sw-blink 1s infinite;
}
@keyframes sw-blink {
  0%, 100% { opacity: 0.5; }
  50%       { opacity: 0.15; }
}

/* --- Input-Bereich --- */
#sw-chat-input-area {
  flex-shrink: 0;
  border-top: 1px solid var(--color-gray-medium);
  background: var(--color-white);
  padding: 10px 14px 14px;
}

#sw-disclaimer {
  font-size: 0.68rem;
  color: var(--color-gray-dark);
  margin-bottom: 8px;
  text-align: center;
  letter-spacing: 0.01em;
}

#sw-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#sw-chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--color-gray-medium);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: var(--font-family);
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--color-text);
  background: var(--color-bg);
  outline: none;
  transition: border-color 0.2s;
  max-height: 100px;
  overflow-y: auto;
}

#sw-chat-input:focus {
  border-color: var(--color-primary);
}

#sw-chat-input::placeholder {
  color: var(--color-gray-dark);
}

#sw-chat-send {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  background: var(--color-primary);
  color: var(--color-white);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s;
}
#sw-chat-send:hover { background: var(--color-primary-dark); }
#sw-chat-send:active { transform: scale(0.93); }
#sw-chat-send:disabled {
  background: var(--color-gray-medium);
  cursor: not-allowed;
  transform: none;
}

/* --- Markdown-Rendering in Bot-Nachrichten --- */
.sw-msg-bot h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-primary-dark);
  margin: 10px 0 4px;
}
.sw-msg-bot h3:first-child {
  margin-top: 2px;
}
.sw-msg-bot h4 {
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 8px 0 3px;
}
.sw-msg-bot p {
  margin: 0 0 6px;
  line-height: 1.55;
}
.sw-msg-bot p:last-child {
  margin-bottom: 0;
}
.sw-msg-bot ul {
  margin: 4px 0 8px 0;
  padding-left: 1.2em;
}
.sw-msg-bot li {
  margin-bottom: 3px;
  line-height: 1.5;
}
.sw-msg-bot strong {
  font-weight: 600;
  color: var(--color-text);
}
.sw-msg-bot em {
  font-style: italic;
}
.sw-msg-bot code {
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
  background: var(--color-gray-medium);
  padding: 1px 5px;
  border-radius: 4px;
}
.sw-msg-bot hr {
  border: none;
  border-top: 1px solid var(--color-gray-medium);
  margin: 10px 0;
}
.sw-msg-bot br {
  line-height: 0.5;
}

/* --- Fehler-Nachricht --- */
.sw-msg-error {
  align-self: center;
  background: var(--color-red-highlight);
  color: var(--color-primary-dark);
  font-size: 0.8rem;
  padding: 8px 12px;
  border-radius: 8px;
  max-width: 92%;
}

/* --- Scroll-to-Top: über dem Chat-Button platzieren --- */
/* Chat-Button: bottom 28px + Höhe ~70px + 12px Abstand = 110px */
#scrollTop {
  bottom: 110px;
}

/* --- Mobile: Vollbild --- */
@media (max-width: 600px) {
  #sw-chat-overlay.sw-open {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
  }
  #sw-chat-container {
    max-width: 100%;
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    animation: none;
  }
  #sw-chat-btn {
    bottom: 16px;
    right: 16px;
    padding: 12px 18px 12px 14px;
    gap: 10px;
    border-radius: 14px;
    max-width: calc(100vw - 32px);
  }
  .sw-btn-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }
  .sw-btn-line1 {
    font-size: 0.72rem;
  }
  .sw-btn-line2 {
    font-size: 0.875rem;
  }
  /* Chat-Button: bottom 16px + Höhe ~62px + 10px Abstand = 88px */
  #scrollTop {
    bottom: 92px;
    right: 16px;
  }
}

/* Sehr schmale Screens: Button-Text komprimieren */
@media (max-width: 380px) {
  #sw-chat-btn {
    padding: 10px 14px 10px 12px;
    gap: 8px;
  }
  .sw-btn-icon {
    width: 32px;
    height: 32px;
  }
  .sw-btn-line1 {
    font-size: 0.65rem;
  }
  .sw-btn-line2 {
    font-size: 0.8rem;
  }
}

/* --- Barrierefreiheit: Focus-Styles --- */
#sw-chat-btn:focus-visible,
#sw-chat-close:focus-visible,
#sw-chat-send:focus-visible,
#sw-chat-input:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* --- NEM Affiliate-Links --- */
.sw-nem-link {
  position: relative;
  color: var(--color-primary);
  text-decoration: none;
  font-size: 0.82em;
  font-weight: 600;
}

.sw-nem-link:hover {
  text-decoration: underline;
}

/* CSS-Tooltip aus styles.css ([data-tooltip]::after) für NEM-Links deaktivieren –
   stattdessen JS-Tooltip via #sw-nem-tooltip (position: fixed) verwenden */
.sw-nem-link::after,
.sw-nem-link::before {
  display: none !important;
}

/* Globaler JS-Tooltip (position: fixed, nicht vom overflow abgeschnitten) */
#sw-nem-tooltip {
  position: fixed;
  background: #333;
  color: #fff;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.78em;
  font-weight: 400;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 99999;
  transform: translate(-50%, -100%);
}

#sw-nem-tooltip.sw-tooltip-visible {
  opacity: 1;
}


/* Link-Block am Ende der Bot-Antwort */
.sw-nem-links {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--color-gray-medium);
  display: flex;
  flex-direction: column;
  gap: 0;
}

.sw-nem-group {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 4px;
  font-size: 0.875em;
  line-height: 1.5;
  padding: 4px 0;
}

.sw-nem-group + .sw-nem-group {
  border-top: 1px dotted var(--color-gray-medium);
}

.sw-nem-name {
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
}
