/* =========================================================
   Synapse · assistant.css
   Rundes KI-Assistenten-Fenster (Floating-Widget, alle Seiten)
   Nutzt die globalen Theme-Variablen aus main.css (hell/dunkel).
   ========================================================= */

.sa-root {
  --sa-grad: linear-gradient(135deg, #6366f1 0%, #ec4899 100%);
  position: fixed;
  right: clamp(1rem, 3vw, 2rem);
  bottom: clamp(1rem, 3vw, 2rem);
  z-index: 1000;
  font-family: inherit;
}

/* ── Runder Trigger-Button (FAB) ───────────────────────────────────────── */
.sa-fab {
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 50%;
  background: var(--sa-grad);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-lg), 0 0 28px rgba(99, 102, 241, 0.45);
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.22s;
  position: relative;
}
.sa-fab:hover { transform: scale(1.07); box-shadow: var(--shadow-lg), 0 0 38px rgba(236, 72, 153, 0.5); }
.sa-fab:active { transform: scale(0.96); }
.sa-fab svg { width: 26px; height: 26px; transition: transform 0.25s, opacity 0.2s; }

/* Icon-Wechsel Chat ↔ Schliessen, ohne zweiten Button */
.sa-fab .sa-ic-close { position: absolute; opacity: 0; transform: rotate(-90deg) scale(0.6); }
.sa-root.sa-open .sa-fab .sa-ic-chat  { opacity: 0; transform: rotate(90deg) scale(0.6); }
.sa-root.sa-open .sa-fab .sa-ic-close { opacity: 1; transform: rotate(0) scale(1); }

/* Ungelesener „Ping" beim ersten Laden */
.sa-fab .sa-badge {
  position: absolute; top: -2px; right: -2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: #ec4899; border: 2px solid var(--bg);
  animation: sa-pulse 1.8s ease-in-out infinite;
}
.sa-root.sa-open .sa-fab .sa-badge,
.sa-root.sa-seen .sa-fab .sa-badge { display: none; }
@keyframes sa-pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.25); opacity: 0.7; } }

/* ── Chat-Panel ────────────────────────────────────────────────────────── */
.sa-panel {
  position: absolute;
  right: 0;
  bottom: 76px;
  width: 374px;
  max-width: calc(100vw - 2rem);
  height: min(560px, calc(100vh - 7rem));
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform-origin: bottom right;
  opacity: 0;
  transform: translateY(14px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.24s cubic-bezier(0.34, 1.4, 0.64, 1);
}
.sa-root.sa-open .sa-panel { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }

/* ── Header ────────────────────────────────────────────────────────────── */
.sa-head {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.85rem 1rem;
  background: var(--sa-grad);
  color: #fff;
  flex-shrink: 0;
}
.sa-head .sa-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: grid; place-items: center; flex-shrink: 0;
}
.sa-head .sa-avatar svg { width: 20px; height: 20px; }
.sa-head .sa-meta { line-height: 1.2; flex: 1; min-width: 0; }
.sa-head .sa-title { font-weight: 700; font-size: 0.98rem; }
.sa-head .sa-status { font-size: 0.74rem; opacity: 0.9; display: flex; align-items: center; gap: 0.35rem; }
.sa-head .sa-status::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: #34d399; box-shadow: 0 0 6px #34d399;
}
.sa-head .sa-x {
  background: rgba(255, 255, 255, 0.12); border: none; color: #fff;
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer;
  display: grid; place-items: center; transition: background 0.15s;
}
.sa-head .sa-x:hover { background: rgba(255, 255, 255, 0.28); }
.sa-head .sa-x svg { width: 16px; height: 16px; }

/* ── Nachrichten-Bereich ───────────────────────────────────────────────── */
.sa-body {
  flex: 1; overflow-y: auto;
  padding: 1rem;
  display: flex; flex-direction: column; gap: 0.6rem;
  scroll-behavior: smooth;
}
.sa-body::-webkit-scrollbar { width: 8px; }
.sa-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.sa-msg {
  max-width: 86%;
  padding: 0.6rem 0.85rem;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.sa-msg.bot {
  align-self: flex-start;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.sa-msg.user {
  align-self: flex-end;
  background: var(--sa-grad);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.sa-msg.bot a { color: var(--accent-hover); text-decoration: underline; }
.sa-msg.bot strong { color: var(--text); }

/* Tipp-Animation */
.sa-typing { display: inline-flex; gap: 4px; align-items: center; }
.sa-typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim);
  animation: sa-blink 1.3s infinite ease-in-out both;
}
.sa-typing span:nth-child(2) { animation-delay: 0.18s; }
.sa-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes sa-blink { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* Vorschlags-Chips */
.sa-chips { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.2rem; }
.sa-chip {
  background: var(--accent-soft);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: var(--accent-hover);
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem; font-family: inherit;
  cursor: pointer; transition: background 0.15s, transform 0.1s;
  text-align: left;
}
.sa-chip:hover { background: rgba(99, 102, 241, 0.22); }
.sa-chip:active { transform: scale(0.97); }

/* ── Eingabe ───────────────────────────────────────────────────────────── */
.sa-foot {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 0.65rem 0.75rem 0.45rem;
  background: var(--bg-elev);
}
.sa-input-row { display: flex; align-items: flex-end; gap: 0.5rem; }
.sa-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 12px;
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem; font-family: inherit;
  line-height: 1.4;
  max-height: 110px;
  outline: none;
  transition: border-color 0.15s;
}
.sa-input:focus { border-color: var(--accent); }
.sa-input::placeholder { color: var(--text-mute); }
.sa-send {
  flex-shrink: 0;
  width: 40px; height: 40px; border: none; border-radius: 50%;
  background: var(--sa-grad); color: #fff; cursor: pointer;
  display: grid; place-items: center; transition: transform 0.12s, opacity 0.15s;
}
.sa-send:hover { transform: scale(1.08); }
.sa-send:disabled { opacity: 0.45; cursor: default; transform: none; }
.sa-send svg { width: 18px; height: 18px; }
.sa-note { text-align: center; font-size: 0.68rem; color: var(--text-mute); margin-top: 0.4rem; }

/* ── Mobil ─────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .sa-root { right: 1rem; bottom: 1rem; }
  .sa-panel {
    width: calc(100vw - 1.5rem);
    height: min(72vh, calc(100vh - 6rem));
    right: -0.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sa-fab, .sa-panel, .sa-send, .sa-chip { transition: none; }
  .sa-fab .sa-badge, .sa-typing span { animation: none; }
  .sa-body { scroll-behavior: auto; }
}
