/* FinanzHub — KI-Chat (animierter Border, Glass, Partikel — Style angelehnt an
   das AIChatCard-Demo des Users) */

#chat-root { position: fixed; z-index: 60; pointer-events: none; }
#chat-root > * { pointer-events: auto; }

/* ── Bubble ── */
.chat-bubble {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 1.5px solid var(--accent, #FFFFFF);
  background: var(--surface, linear-gradient(135deg, #1f2937 0%, #000 50%, #111827 100%));
  color: var(--accent, #FFFFFF);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 28px rgba(0,0,0,.5),
              0 0 24px var(--accent-soft, rgba(255,255,255,0.4)),
              0 2px 6px rgba(255,255,255,.05) inset;
  transition: transform .18s cubic-bezier(.34,1.56,.64,1), box-shadow .18s, border-color .18s;
}
.chat-bubble:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 14px 36px rgba(0,0,0,.6),
              0 0 32px var(--accent-soft, rgba(255,255,255,0.55)),
              0 2px 6px rgba(255,255,255,.08) inset;
}
.chat-bubble svg { width: 26px; height: 26px; opacity: .95; }
.chat-bubble-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ef4444;
  border: 2px solid #0a0b0f;
  animation: chat-pulse 1.6s ease-in-out infinite;
}
@keyframes chat-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* ── Panel (Frame) ── */
.chat-panel {
  position: fixed;
  right: 24px;
  bottom: 96px;
  width: 400px;
  height: 580px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 120px);
  padding: 2px;                /* "Rahmen-Dicke" — der rotierende Border wird hier sichtbar */
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(0,0,0,.7);
  animation: chat-slide-up .22s cubic-bezier(.22,.61,.36,1);
  background: rgba(8,8,12,1);
}
@keyframes chat-slide-up {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
@media (max-width: 600px) {
  .chat-panel {
    right: 12px;
    left: 12px;
    bottom: 88px;
    width: auto;
    height: calc(100vh - 110px);
  }
}

/* Rotierender Border via conic-gradient — schwebt unter Inner-Card */
.chat-panel-rotor {
  position: absolute;
  inset: -150%;
  width: 400%;
  height: 400%;
  background: conic-gradient(
    from 0deg,
    rgba(255,255,255,0)    0%,
    rgba(255,255,255,.45) 15%,
    rgba(255,255,255,0)   30%,
    rgba(255,255,255,0)   50%,
    rgba(255,255,255,.45) 65%,
    rgba(255,255,255,0)   80%,
    rgba(255,255,255,0)  100%
  );
  animation: chat-rotor 25s linear infinite;
  z-index: 0;
  pointer-events: none;
}
@keyframes chat-rotor {
  to { transform: rotate(360deg); }
}

/* Innen-Card: Glass, deckt den Rotor außer am Rand ab */
.chat-panel-inner {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(8,8,12,.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Animierter Hintergrund-Gradient (innen) */
.chat-panel-bg {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #1f2937 0%, #000 50%, #111827 100%);
  background-size: 220% 220%;
  animation: chat-bg-shift 20s linear infinite;
  z-index: 0;
  pointer-events: none;
  opacity: .85;
}
@keyframes chat-bg-shift {
  0%   { background-position: 0% 0%; }
  50%  { background-position: 100% 100%; }
  100% { background-position: 0% 0%; }
}

/* Schwebende Partikel */
.chat-panel-particles {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
}
.chat-particle {
  position: absolute;
  bottom: -8%;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(255,255,255,.12);
  --drift: 0px;
  --dur: 6s;
  --delay: 0s;
  animation: chat-particle-rise var(--dur) ease-in-out infinite;
  animation-delay: var(--delay);
}
@keyframes chat-particle-rise {
  0%   { transform: translate(0, 0);            opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 1; }
  100% { transform: translate(var(--drift), -560px); opacity: 0; }
}

/* ── Head: Titel + Buttons ── */
.chat-head {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.chat-head-title {
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -.01em;
  color: rgba(255,255,255,.95);
  flex: 1;
}
.chat-menu-btn,
.chat-close-btn {
  background: transparent;
  border: 0;
  color: rgba(255,255,255,.5);
  font-size: 18px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}
.chat-menu-btn:hover,
.chat-close-btn:hover {
  background: rgba(255,255,255,.1);
  color: rgba(255,255,255,.95);
}
.chat-close-btn { font-size: 22px; line-height: 1; }

/* ── Tabs ── */
.chat-tabs {
  position: relative;
  z-index: 2;
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.chat-tabs button {
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.06);
  color: rgba(255,255,255,.55);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .02em;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.chat-tabs button:hover {
  color: rgba(255,255,255,.85);
  background: rgba(255,255,255,.07);
}
.chat-tabs button.is-active {
  background: rgba(255,255,255,.22);
  color: #0a0b0f;
  font-weight: 600;
  border-color: rgba(255,255,255,.35);
}

/* ── Messages ── */
.chat-messages {
  position: relative;
  z-index: 2;
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 3px; }

.chat-msg {
  display: flex;
  max-width: 88%;
  animation: chat-msg-in .35s cubic-bezier(.22,.61,.36,1);
}
@keyframes chat-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.chat-msg-user      { align-self: flex-end; }
.chat-msg-assistant { align-self: flex-start; }

.chat-msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: normal;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.chat-msg-assistant .chat-msg-bubble {
  background: rgba(255,255,255,.1);
  color: rgba(255,255,255,.95);
  border: 1px solid rgba(255,255,255,.06);
  border-bottom-left-radius: 4px;
}
.chat-msg-user .chat-msg-bubble {
  background: rgba(255,255,255,.3);
  color: #0a0b0f;
  font-weight: 600;
  border-bottom-right-radius: 4px;
}
.chat-msg-bubble strong { font-weight: 700; }
.chat-msg-bubble em { font-style: normal; }
.chat-msg-bubble code {
  background: rgba(0,0,0,.3);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}
.chat-msg-bubble ul { margin: 6px 0 4px; padding-left: 18px; }
.chat-msg-bubble li { margin-bottom: 2px; }

/* Typing-Dots — wie im Demo */
.chat-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 2px 0;
}
.chat-typing span {
  width: 7px;
  height: 7px;
  background: #fff;
  border-radius: 50%;
  animation: chat-typing-pulse 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes chat-typing-pulse {
  0%, 80%, 100% { opacity: .25; }
  40% { opacity: 1; }
}

/* ── Greeting + Quick-Prompts ── */
.chat-greeting {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
  padding: 4px 4px;
}
.chat-greeting-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,.12);
  color: rgba(255,255,255,.95);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,255,255,.1);
}
.chat-greeting-icon svg { width: 20px; height: 20px; }
.chat-greeting-text {
  font-size: 15px;
  line-height: 1.4;
  color: rgba(255,255,255,.92);
  font-weight: 500;
}
.chat-greeting-prompts {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}
.chat-quick-prompt {
  text-align: left;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
  color: rgba(255,255,255,.85);
  padding: 10px 14px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: border-color .15s, background .15s, transform .15s;
}
.chat-quick-prompt:hover {
  background: rgba(255,255,255,.12);
  border-color: rgba(255,255,255,.25);
  transform: translateX(2px);
}

/* ── Input ── */
.chat-input-row {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,.08);
  background: rgba(0,0,0,.3);
}
.chat-input-row input {
  flex: 1;
  background: rgba(0,0,0,.5);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px;
  color: rgba(255,255,255,.95);
  padding: 9px 12px;
  font-family: inherit;
  font-size: 13.5px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.chat-input-row input:focus {
  border-color: rgba(255,255,255,.5);
  box-shadow: 0 0 0 3px rgba(255,255,255,.06);
}
.chat-input-row input::placeholder {
  color: rgba(255,255,255,.35);
}
.chat-send-btn {
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px;
  color: #fff;
  width: 38px;
  height: 38px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .15s;
}
.chat-send-btn:hover {
  background: rgba(255,255,255,.22);
  transform: scale(1.04);
}
.chat-send-btn svg { width: 16px; height: 16px; }

/* ────────────────────────────────────────────────────────────────────
   Sending-State + Shake-Feedback (Fix 2026-05: User dachte Chat hängt,
   weil bei Doppel-Submit nichts sichtbar passierte.)
   ──────────────────────────────────────────────────────────────────── */
.chat-input-row.is-sending input,
.chat-input-row.is-sending .chat-send-btn {
  opacity: 0.55;
  cursor: not-allowed;
}
.chat-input-row.is-sending .chat-send-btn {
  background: rgba(255,255,255,.06);
}
.chat-input-row .chat-send-btn[aria-busy="true"] svg {
  animation: chat-pulse 1s ease-in-out infinite;
}
@keyframes chat-pulse {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50%      { opacity: 1;   transform: scale(1.1); }
}

.chat-input-row.is-shake {
  animation: chat-shake 0.45s cubic-bezier(.36,.07,.19,.97);
}
@keyframes chat-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}

/* Markdown-Renderer für Bot-Antworten */
.chat-msg-bubble .chat-h {
  margin: 14px 0 6px;
  font-family: var(--font-head, 'Inter', sans-serif);
  font-weight: 700;
  letter-spacing: -0.2px;
  color: inherit;
}
.chat-msg-bubble .chat-h-1 { font-size: 18px; font-weight: 800; letter-spacing: -0.4px; }
.chat-msg-bubble .chat-h-2 { font-size: 16px; }
.chat-msg-bubble .chat-h-3 { font-size: 14px; opacity: 0.92; }
.chat-msg-bubble .chat-h:first-child { margin-top: 0; }

.chat-msg-bubble ul,
.chat-msg-bubble ol {
  margin: 6px 0 10px;
  padding-left: 18px;
}
.chat-msg-bubble li {
  margin: 3px 0;
  line-height: 1.5;
}

.chat-msg-bubble .chat-hr {
  margin: 12px 0;
  border: none;
  border-top: 1px solid rgba(255,255,255,.12);
}

.chat-msg-bubble .chat-quote {
  margin: 8px 0;
  padding: 6px 12px;
  border-left: 3px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.04);
  font-style: normal;
  opacity: 0.92;
}

.chat-msg-bubble .chat-code {
  margin: 8px 0;
  padding: 10px 12px;
  background: rgba(0,0,0,.35);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 8px;
  overflow-x: auto;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.5;
}
.chat-msg-bubble code {
  padding: 1px 5px;
  background: rgba(255,255,255,.10);
  border-radius: 4px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.92em;
}
.chat-msg-bubble pre.chat-code code {
  padding: 0;
  background: transparent;
  font-size: inherit;
}

.chat-msg-bubble a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
.chat-msg-bubble a:hover { opacity: 0.8; }

/* User-Bubbles brauchen die Markdown-Heading-Styles nicht (User schreibt selten Markdown).
   Aber falls doch — gleich behandeln, mit angepasstem Kontrast. */
.chat-msg-user .chat-msg-bubble .chat-h { color: inherit; }
.chat-msg-user .chat-msg-bubble code,
.chat-msg-user .chat-msg-bubble pre.chat-code {
  background: rgba(0,0,0,.20);
}

/* ── Modal-Variante: zentriert, ~70% Viewport, mit Backdrop ── */
.chat-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 59;
  animation: chat-backdrop-in .18s ease-out;
}
@keyframes chat-backdrop-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.chat-panel-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  right: auto;
  bottom: auto;
  transform: translate(-50%, -50%);
  width: min(760px, 90vw);
  height: min(700px, 88vh);
  max-width: none;
  max-height: none;
  z-index: 60;
  animation: chat-modal-in .24s cubic-bezier(.22,.61,.36,1);
}
@keyframes chat-modal-in {
  from { transform: translate(-50%, -48%) scale(0.96); opacity: 0; }
  to   { transform: translate(-50%, -50%) scale(1);     opacity: 1; }
}
@media (max-width: 600px) {
  .chat-panel-modal {
    width: calc(100vw - 16px);
    height: calc(100vh - 32px);
    border-radius: 18px;
  }
}
body.chat-modal-open { overflow: hidden; }
