/* ============================================================
   Chat-Widget. Punk/DIY/Zine: harte Kanten, Mono, Signal-Rot.
   Nutzt die Design-System-Tokens aus ds/colors.css.
   ============================================================ */

.ap-chat-bubble {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 1000;
  width: 3.25rem;
  height: 3.25rem;
  padding: 0;
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-invert);
  background: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 0;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--red);
}
.ap-chat-bubble:hover {
  color: var(--text-invert);
  background: var(--red);
  border-color: var(--red);
}

.ap-chat-panel {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 1001;
  display: flex;
  flex-direction: column;
  width: 22.5rem;
  max-width: calc(100vw - 2rem);
  height: 32rem;
  max-height: calc(100vh - 2rem);
  font-family: var(--font-mono);
  background: var(--paper);
  border: 3px solid var(--ink);
  box-shadow: 6px 6px 0 var(--red);
}
.ap-chat-panel[hidden] { display: none; }

.ap-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.85rem;
  color: var(--text-invert);
  background: var(--ink);
}
.ap-chat-title { font-size: 0.95rem; font-weight: 700; letter-spacing: 0.02em; }
.ap-chat-close {
  padding: 0 0.35rem;
  font-family: var(--font-mono);
  font-size: 1.3rem;
  line-height: 1;
  color: var(--text-invert);
  background: transparent;
  border: none;
  cursor: pointer;
}
.ap-chat-close:hover { color: var(--red); }

.ap-chat-msgs {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.85rem;
}
.ap-chat-msg {
  max-width: 85%;
  padding: 0.5rem 0.65rem;
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.ap-chat-msg.user {
  align-self: flex-end;
  color: var(--text-invert);
  background: var(--ink);
}
.ap-chat-msg.bot {
  align-self: flex-start;
  color: var(--ink);
  background: var(--cream-2);
  border-left: 3px solid var(--red);
  white-space: normal;
}
.ap-chat-msg.bot p { margin: 0 0 0.5rem; }
.ap-chat-msg.bot p:last-child { margin-bottom: 0; }
.ap-chat-msg.bot ul,
.ap-chat-msg.bot ol { margin: 0 0 0.5rem; padding-left: 1.2rem; }
.ap-chat-msg.bot li { margin: 0.15rem 0; }
.ap-chat-msg.bot strong { color: var(--ink); font-weight: 700; }
.ap-chat-msg.bot a { color: var(--red); text-decoration: underline; }
.ap-chat-msg.bot code {
  padding: 0.05rem 0.25rem;
  font-size: 0.85em;
  background: var(--paper);
  border: 1px solid var(--ink);
}
.ap-chat-msg.bot pre {
  margin: 0 0 0.5rem;
  padding: 0.5rem 0.6rem;
  overflow-x: auto;
  background: var(--ink);
  color: var(--text-invert);
}
.ap-chat-msg.bot pre code { padding: 0; background: none; border: none; color: inherit; }
.ap-chat-msg.bot.streaming::after {
  content: '\2589';
  animation: ap-chat-blink 1s steps(2) infinite;
}
@keyframes ap-chat-blink { 50% { opacity: 0; } }

/* Nachricht vom Team (nach Handoff): wie der Bot, aber dunkler Akzent plus Absender. */
.ap-chat-msg.human {
  align-self: flex-start;
  max-width: 85%;
  padding: 0.5rem 0.65rem;
  color: var(--ink);
  background: var(--cream-2);
  border-left: 3px solid var(--ink);
}
.ap-chat-who {
  display: block;
  margin-bottom: 0.2rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--red);
}
.ap-chat-msg.human .ap-chat-body p { margin: 0 0 0.5rem; }
.ap-chat-msg.human .ap-chat-body p:last-child { margin-bottom: 0; }
.ap-chat-msg.human .ap-chat-body a { color: var(--red); text-decoration: underline; }

/* System-Hinweis (z.B. "Ein Mensch übernimmt gleich"). Mittig, gedämpft. */
.ap-chat-system {
  align-self: center;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  font-style: italic;
  color: var(--ink);
  opacity: 0.7;
  text-align: center;
}

/* Handoff-Leiste über dem Eingabefeld. */
.ap-chat-actions {
  display: flex;
  justify-content: center;
  padding: 0.4rem 0.5rem 0;
}
.ap-chat-actions[hidden] { display: none; }
.ap-chat-human-btn {
  padding: 0.35rem 0.7rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--ink);
  background: transparent;
  border: 2px solid var(--ink);
  border-radius: 0;
  cursor: pointer;
}
.ap-chat-human-btn:hover { color: var(--text-invert); background: var(--ink); }

.ap-chat-form {
  display: flex;
  margin-top: 0.4rem;
  border-top: 2px solid var(--ink);
}
.ap-chat-input {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 0.7rem;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--paper);
  border: none;
}
.ap-chat-input:focus { outline: 2px solid var(--red); outline-offset: -2px; }
.ap-chat-send {
  padding: 0 0.9rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-invert);
  background: var(--red);
  border: none;
  cursor: pointer;
}
.ap-chat-send:hover { background: var(--red-deep); }

@media (max-width: 480px) {
  .ap-chat-panel {
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border: none;
    box-shadow: none;
  }
}
