/* Deepwraite Chat-Widget — Dunkles Theme, responsive, barrierefrei */

/* ── Reset & Design-Tokens ─────────────────────────────────────── */

.dw-chatbot,
.dw-chatbot *,
.dw-chatbot *::before,
.dw-chatbot *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border: 0;
  font: inherit;
  color: inherit;
  line-height: inherit;
}

.dw-chatbot {
  --dw-primary: #0ee2cf;
  --dw-primary-hover: #0bb6a8;
  --dw-bg-dark: #0c1013;
  --dw-bg-chat: #151a1e;
  --dw-bg-input: #1c2228;
  --dw-bg-user: #0d3640;
  --dw-bg-assistant: #1e252b;
  --dw-bg-error: #2a1415;
  --dw-text: #eef2f6;
  --dw-text-muted: #9aa7b4;
  --dw-border: rgba(255, 255, 255, 0.12);
  --dw-error: #e04040;
  --dw-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  --dw-radius: 12px;
  --dw-radius-msg: 16px;
  --dw-widget-width: 400px;
  --dw-widget-height: 560px;
  --dw-transition: 0.2s ease;

  font-family: var(--dw-font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--dw-text);
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 99999;
}

/* ── Bubble (FAB) ──────────────────────────────────────────────── */

.dw-chatbot__bubble {
  height: 48px;
  padding: 0 20px 0 14px;
  border-radius: 24px;
  background: var(--dw-primary);
  color: var(--dw-bg-dark);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  transition: background var(--dw-transition), transform var(--dw-transition);
  position: absolute;
  bottom: 0;
  right: 0;
  font-family: var(--dw-font);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}

.dw-chatbot__bubble:hover {
  background: var(--dw-primary-hover);
  transform: scale(1.05);
}

.dw-chatbot__bubble:focus-visible {
  outline: 2px solid var(--dw-primary);
  outline-offset: 3px;
}

.dw-chatbot__bubble svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
}

.dw-chatbot--open .dw-chatbot__bubble {
  display: none;
}

/* ── Panel ─────────────────────────────────────────────────────── */

.dw-chatbot__panel {
  width: var(--dw-widget-width);
  height: var(--dw-widget-height);
  max-height: calc(100vh - 40px);
  background: var(--dw-bg-dark);
  border-radius: var(--dw-radius);
  border: 1px solid var(--dw-border);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  display: none;
  flex-direction: column;
  overflow: hidden;
  position: absolute;
  bottom: 0;
  right: 0;
}

.dw-chatbot--open .dw-chatbot__panel {
  display: flex;
}

/* ── Header ────────────────────────────────────────────────────── */

.dw-chatbot__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  background: var(--dw-bg-dark);
  border-bottom: 1px solid var(--dw-border);
  flex-shrink: 0;
}

.dw-chatbot__header-label {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--dw-text-muted);
  line-height: 1.3;
}

.dw-chatbot__close {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: transparent;
  color: var(--dw-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--dw-transition), color var(--dw-transition);
}

.dw-chatbot__close:hover {
  background: var(--dw-border);
  color: var(--dw-text);
}

.dw-chatbot__close:focus-visible {
  outline: 2px solid var(--dw-primary);
  outline-offset: -2px;
}

.dw-chatbot__close svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* ── Messages Area ─────────────────────────────────────────────── */

.dw-chatbot__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--dw-bg-chat);
  scroll-behavior: smooth;
}

/* Scrollbar styling */
.dw-chatbot__messages::-webkit-scrollbar {
  width: 6px;
}

.dw-chatbot__messages::-webkit-scrollbar-track {
  background: transparent;
}

.dw-chatbot__messages::-webkit-scrollbar-thumb {
  background: var(--dw-border);
  border-radius: 3px;
}

/* ── Message Bubbles ───────────────────────────────────────────── */

.dw-chatbot__msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--dw-radius-msg);
  word-wrap: break-word;
  overflow-wrap: break-word;
  font-size: 14px;
  line-height: 1.5;
}

.dw-chatbot__msg--user {
  align-self: flex-end;
  background: var(--dw-bg-user);
  border-bottom-right-radius: 4px;
}

.dw-chatbot__msg--assistant {
  align-self: flex-start;
  background: var(--dw-bg-assistant);
  border-bottom-left-radius: 4px;
}

.dw-chatbot__msg--error {
  align-self: flex-start;
  background: var(--dw-bg-error);
  border-left: 3px solid var(--dw-error);
  color: var(--dw-error);
  font-size: 13px;
  border-bottom-left-radius: 4px;
}

/* Markdown content inside assistant messages */
.dw-chatbot__msg--assistant strong {
  font-weight: 700;
}

.dw-chatbot__msg--assistant a {
  color: var(--dw-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.dw-chatbot__msg--assistant a:hover {
  color: var(--dw-primary-hover);
}

.dw-chatbot__msg--assistant a:focus-visible {
  outline: 2px solid var(--dw-primary);
  outline-offset: 2px;
}

.dw-chatbot__msg--assistant ul,
.dw-chatbot__msg--assistant ol {
  margin: 6px 0;
  padding-left: 20px;
}

.dw-chatbot__msg--assistant li {
  margin: 2px 0;
}

/* ── Typing Indicator ──────────────────────────────────────────── */

.dw-chatbot__typing {
  align-self: flex-start;
  background: var(--dw-bg-assistant);
  padding: 12px 18px;
  border-radius: var(--dw-radius-msg);
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.dw-chatbot__typing[hidden] {
  display: none;
}

.dw-chatbot__typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dw-text-muted);
  animation: dw-typing 1.4s ease-in-out infinite;
}

.dw-chatbot__typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.dw-chatbot__typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes dw-typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* ── Input Area ────────────────────────────────────────────────── */

.dw-chatbot__input-area {
  padding: 12px 16px;
  background: var(--dw-bg-dark);
  border-top: 1px solid var(--dw-border);
  flex-shrink: 0;
}

.dw-chatbot__input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--dw-bg-input);
  border-radius: 10px;
  border: 1px solid var(--dw-border);
  padding: 6px 6px 6px 14px;
  transition: border-color var(--dw-transition);
}

.dw-chatbot__input-row:focus-within {
  border-color: var(--dw-primary);
}

.dw-chatbot__input {
  flex: 1;
  background: transparent;
  color: var(--dw-text);
  font-family: var(--dw-font);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  min-height: 24px;
  max-height: 120px;
  padding: 4px 0;
  overflow-y: auto;
}

.dw-chatbot__input::placeholder {
  color: var(--dw-text-muted);
}

.dw-chatbot__input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.dw-chatbot__send {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--dw-primary);
  color: var(--dw-bg-dark);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--dw-transition), opacity var(--dw-transition);
}

.dw-chatbot__send:hover:not(:disabled) {
  background: var(--dw-primary-hover);
}

.dw-chatbot__send:focus-visible {
  outline: 2px solid var(--dw-primary);
  outline-offset: 2px;
}

.dw-chatbot__send:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.dw-chatbot__send svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* ── Input Meta (Char Counter + Legal) ─────────────────────────── */

.dw-chatbot__input-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 4px 0;
  font-size: 11px;
  color: var(--dw-text-muted);
}

.dw-chatbot__char-count {
  font-variant-numeric: tabular-nums;
}

.dw-chatbot__char-count--warn {
  color: #e8a838;
}

.dw-chatbot__char-count--danger {
  color: var(--dw-error);
}

.dw-chatbot__legal {
  text-align: right;
}

.dw-chatbot__legal a {
  color: var(--dw-text-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.dw-chatbot__legal a:hover {
  color: var(--dw-text);
}

.dw-chatbot__legal a:focus-visible {
  outline: 2px solid var(--dw-primary);
  outline-offset: 2px;
}

/* ── Responsive: Mobile Fullscreen ─────────────────────────────── */

@media (max-width: 480px) {
  .dw-chatbot {
    bottom: 16px;
    right: 16px;
  }

  .dw-chatbot--open {
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
  }

  .dw-chatbot--open .dw-chatbot__panel {
    width: 100%;
    height: 100dvh;
    height: 100vh; /* Fallback */
    max-height: none;
    border-radius: 0;
    border: none;
    position: fixed;
    inset: 0;
  }
}

/* ── Reduced Motion ────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .dw-chatbot__typing span {
    animation: none;
    opacity: 0.6;
  }

  .dw-chatbot__bubble {
    transition: none;
  }

  .dw-chatbot__messages {
    scroll-behavior: auto;
  }
}
