/* frontend/css/chatbot.css
 * Chatbot V1: Floating-Bubble + Slide-in-Panel.
 * Alle Selektoren mit .tth-chat-* Prefix damit nichts in andere Pages leakt.
 */

.tth-chat-bubble {
  position: fixed;
  bottom: calc(72px + env(safe-area-inset-bottom));
  right: 16px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent, #c75c43);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  z-index: 1200;
  transition: transform 120ms ease;
  animation: tth-chat-pulse 1.6s ease-out 1 800ms;
}
.tth-chat-bubble:hover { transform: scale(1.05); }
.tth-chat-bubble:active { transform: scale(0.95); }

@keyframes tth-chat-pulse {
  0% { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35), 0 0 0 0 rgba(199, 92, 67, 0.6); }
  70% { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35), 0 0 0 12px rgba(199, 92, 67, 0); }
  100% { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35), 0 0 0 0 rgba(199, 92, 67, 0); }
}

.tth-chat-panel {
  position: fixed;
  z-index: 1201;
  background: var(--bg, #0f0f12);
  color: var(--text, #eaeaea);
  border: 1px solid var(--border, #2a2a2e);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.tth-chat-panel[hidden] { display: none; }

/* Desktop: kompaktes Panel neben dem Bubble */
@media (min-width: 768px) {
  .tth-chat-panel {
    width: 380px;
    height: 600px;
    right: 24px;
    bottom: 88px;
  }
}

/* Mobile: full-screen damit es bedienbar bleibt.
   Wichtig: 100vh schliesst die Browser-URL-Leiste ein, dadurch ruschte
   die Input-Bar unter den Fold. 100dvh (dynamic viewport) respektiert
   die tatsaechlich sichtbare Hoehe. Fallback fuer aeltere Browser. */
@media (max-width: 767px) {
  .tth-chat-panel {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: 100vh;          /* Fallback */
    height: 100dvh;         /* Moderne Browser */
    max-height: 100dvh;
    border-radius: 0;
    border: none;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

.tth-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border, #2a2a2e);
  font-family: var(--ff-sans);
  font-size: 14px;
  flex: 0 0 auto;
}
.tth-chat-header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.tth-chat-header-actions {
  display: flex;
  gap: 4px;
}
.tth-chat-icon-btn {
  background: transparent;
  border: 0;
  color: var(--text-soft, #b0b0b0);
  padding: 8px;
  cursor: pointer;
  font-size: 16px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 6px;
}
.tth-chat-icon-btn:hover { background: var(--surface, #1a1a1e); color: var(--text); }

.tth-chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.tth-chat-msg {
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 10px;
  font-family: var(--ff-sans);
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.tth-chat-msg.user {
  align-self: flex-end;
  background: var(--accent, #c75c43);
  color: #fff;
  border-bottom-right-radius: 2px;
}
.tth-chat-msg.assistant {
  align-self: flex-start;
  background: var(--surface, #1a1a1e);
  color: var(--text-soft, #b0b0b0);
  border: 1px solid var(--border, #2a2a2e);
  border-bottom-left-radius: 2px;
}
.tth-chat-msg.assistant.streaming::after {
  content: " ▋";
  opacity: 0.6;
  animation: tth-chat-blink 1s steps(2) infinite;
}
.tth-chat-msg.assistant.error {
  background: rgba(180, 60, 60, 0.15);
  border-color: rgba(180, 60, 60, 0.4);
  color: #f0c0c0;
}
@keyframes tth-chat-blink {
  50% { opacity: 0; }
}

/* Markdown-Rendering nur fuer Bot-Bubbles (innerHTML). User-Bubbles
   bleiben textContent + white-space: pre-wrap. */
.tth-chat-msg.assistant {
  white-space: normal;
}
.tth-chat-msg.assistant h1,
.tth-chat-msg.assistant h2,
.tth-chat-msg.assistant h3,
.tth-chat-msg.assistant h4 {
  font-family: var(--ff-sans);
  color: var(--text, #eaeaea);
  margin: 8px 0 4px;
  line-height: 1.25;
}
.tth-chat-msg.assistant h1 { font-size: 15px; font-weight: 600; }
.tth-chat-msg.assistant h2 { font-size: 14px; font-weight: 600; }
.tth-chat-msg.assistant h3 { font-size: 13px; font-weight: 600; }
.tth-chat-msg.assistant h4 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.tth-chat-msg.assistant > *:first-child { margin-top: 0; }
.tth-chat-msg.assistant > *:last-child { margin-bottom: 0; }
.tth-chat-msg.assistant p {
  margin: 4px 0;
}
.tth-chat-msg.assistant strong {
  color: var(--text, #eaeaea);
  font-weight: 600;
}
.tth-chat-msg.assistant em {
  color: var(--text, #eaeaea);
  font-style: italic;
}
.tth-chat-msg.assistant ul,
.tth-chat-msg.assistant ol {
  margin: 4px 0;
  padding-left: 20px;
}
.tth-chat-msg.assistant li {
  margin: 2px 0;
}
.tth-chat-msg.assistant code {
  font-family: var(--ff-mono, ui-monospace, monospace);
  font-size: 12px;
  background: rgba(255,255,255,0.06);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--text, #eaeaea);
}
.tth-chat-msg.assistant pre {
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--border, #2a2a2e);
  padding: 8px 10px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 6px 0;
}
.tth-chat-msg.assistant pre code {
  background: transparent;
  padding: 0;
  font-size: 12px;
  color: var(--text, #eaeaea);
}
.tth-chat-msg.assistant a {
  color: var(--accent, #c75c43);
  text-decoration: underline;
}
.tth-chat-msg.assistant blockquote {
  border-left: 2px solid var(--border, #2a2a2e);
  margin: 4px 0;
  padding: 2px 10px;
  color: var(--muted, #888);
}
.tth-chat-msg.assistant hr {
  border: 0;
  border-top: 1px solid var(--border, #2a2a2e);
  margin: 8px 0;
}
/* Markdown-Tabellen koennen breiter sein als das Bubble-Panel.
   Horizontal-Scroll-Container mit Fade-Hint rechts, damit der User erkennt
   dass er scrollen kann. (UX: scrollable-content visibility) */
.tth-chat-msg.assistant table {
  border-collapse: collapse;
  margin: 6px 0;
  font-size: 12px;
  display: block;
  overflow-x: auto;
  max-width: 100%;
  /* Fade-Edge rechts: zeigt scrollbare Area an */
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent 100%);
          mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent 100%);
  /* Scrollbar dezent */
  scrollbar-width: thin;
}
.tth-chat-msg.assistant table::-webkit-scrollbar {
  height: 4px;
}
.tth-chat-msg.assistant table::-webkit-scrollbar-thumb {
  background: var(--border, #2a2a2e);
  border-radius: 2px;
}
.tth-chat-msg.assistant th,
.tth-chat-msg.assistant td {
  border: 1px solid var(--border, #2a2a2e);
  padding: 4px 8px;
  text-align: left;
  vertical-align: top;
}
.tth-chat-msg.assistant th {
  background: rgba(255,255,255,0.04);
  color: var(--text, #eaeaea);
  font-weight: 600;
}

.tth-chat-input-bar {
  border-top: 1px solid var(--border, #2a2a2e);
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex: 0 0 auto;
}
.tth-chat-input {
  flex: 1 1 auto;
  min-height: 72px;        /* ~3 sichtbare Zeilen initial */
  max-height: 160px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border, #2a2a2e);
  background: var(--surface, #1a1a1e);
  color: var(--text, #eaeaea);
  font-family: inherit;
  font-size: 14px;
  resize: none;
  line-height: 1.4;
  box-sizing: border-box;
}
.tth-chat-input:focus { outline: 1px solid var(--accent, #c75c43); }

/* Mobile: Send-Button neben mehrzeiligem Eingabe-Feld nicht riesig stretchen */
@media (max-width: 767px) {
  .tth-chat-input {
    min-height: 80px;
    max-height: 180px;
  }
}

.tth-chat-send {
  flex: 0 0 auto;
  padding: 0 16px;
  align-self: stretch;
  border: 0;
  border-radius: 8px;
  background: var(--accent, #c75c43);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  min-width: 56px;
}
.tth-chat-send:disabled {
  opacity: 0.5;
  cursor: default;
}

.tth-chat-empty {
  text-align: center;
  color: var(--muted, #888);
  font-size: 13px;
  font-style: italic;
  padding: 24px 12px;
}

/* ============================================================
 * Voice-Modus (siehe docs/superpowers/specs/2026-05-25-voice-bot-design.md)
 * 📞-Button in der Input-Bar, Indicator-Container ueber Eingabe,
 * Pulsing / Wellen-Animationen je nach State.
 * ============================================================ */

.tth-chat-voice-btn {
  flex: 0 0 auto;
  padding: 0;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  align-self: flex-end;
  background: transparent;
  color: var(--text-soft, #b0b0b0);
  border: 1px solid var(--border, #2a2a2e);
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tth-chat-voice-btn:hover {
  background: var(--surface, #1a1a1e);
  color: var(--text, #eaeaea);
}
.tth-chat-voice-btn.active {
  background: var(--accent, #c75c43);
  color: #fff;
  border-color: var(--accent, #c75c43);
}

/* Feature-Detection: ohne Plugin (Web-Browser) wird .hidden gesetzt */
.tth-chat-voice-btn.hidden {
  display: none;
}

/* Voice-Indicator-Container: erscheint UEBER der Eingabe-Bar wenn Voice aktiv */
.tth-chat-voice-indicator {
  display: none;
  padding: 12px 14px;
  background: var(--surface, #1a1a1e);
  border-top: 1px solid var(--border, #2a2a2e);
  border-bottom: 1px solid var(--border, #2a2a2e);
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}
.tth-chat-voice-indicator.visible {
  display: flex;
}

.tth-chat-voice-icon {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  background: var(--bg, #0f0f12);
  border: 2px solid var(--border, #2a2a2e);
}
.tth-chat-voice-icon.listening {
  border-color: var(--accent, #c75c43);
  animation: tth-voice-pulse 1.4s ease-out infinite;
}
.tth-chat-voice-icon.speaking {
  border-color: #4a9eff;
  animation: tth-voice-waves 0.8s ease-in-out infinite alternate;
}
.tth-chat-voice-icon.sending {
  border-color: var(--muted, #888);
  opacity: 0.5;
}

@keyframes tth-voice-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(199, 92, 67, 0.6); }
  70%  { box-shadow: 0 0 0 12px rgba(199, 92, 67, 0); }
  100% { box-shadow: 0 0 0 0 rgba(199, 92, 67, 0); }
}
@keyframes tth-voice-waves {
  from { box-shadow: 0 0 0 0 rgba(74, 158, 255, 0.5); }
  to   { box-shadow: 0 0 0 8px rgba(74, 158, 255, 0); }
}

.tth-chat-voice-text {
  flex: 1 1 auto;
  font-family: var(--ff-sans);
  font-size: 13px;
  color: var(--text-soft, #b0b0b0);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.tth-chat-voice-text.hint {
  color: var(--c-bad, #c75c43);
  font-style: italic;
}

/* Im Voice-Modus: Eingabe + Send disabled (greyed-out) */
.tth-chat-input-bar.voice-active .tth-chat-input,
.tth-chat-input-bar.voice-active .tth-chat-send {
  opacity: 0.4;
  pointer-events: none;
}
