/**
 * VoizPanda chat widget — all rules scoped under #voizpanda-chat-root only
 * (no :root / html / body) so themes and Elementor are unaffected.
 *
 * === DO NOT REGRESS (historical breakages) ===
 * - NEVER add  pointer-events: none   on #voizpanda-chat-root (broke FAB clicks)
 * - NEVER add  contain: paint          on #voizpanda-chat-root (hid SVG icon)
 * - NEVER add  isolation: isolate      on #voizpanda-chat-root (broke stacking in some themes)
 * If the FAB stops clicking, check for overlapping third-party widgets (WhatsApp, cookie banners)
 * and adjust --voizpanda-offset-bottom / --voizpanda-offset-right in WP admin or below.
 */

#voizpanda-chat-root {
  --voizpanda-chat-accent: #6c63ff;
  --voizpanda-chat-bg: #ffffff;
  --voizpanda-chat-text: #1e1e1e;
  --voizpanda-chat-muted: #6b7280;
  --voizpanda-chat-border: #e5e7eb;
  --voizpanda-chat-shadow: 0 8px 32px rgba(15, 23, 42, 0.12);
  --voizpanda-offset-bottom: 90px;
  --voizpanda-offset-right: 20px;

  box-sizing: border-box;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--voizpanda-chat-text);
  z-index: 2147483646;
  position: fixed;
  bottom: var(--voizpanda-offset-bottom);
  right: var(--voizpanda-offset-right);
  left: auto;
  top: auto;
  margin: 0;
  padding: 0;
  width: auto;
  height: auto;
  max-width: none;
  background: transparent;
  border: none;
  box-shadow: none;
  pointer-events: auto;
}

#voizpanda-chat-root *,
#voizpanda-chat-root *::before,
#voizpanda-chat-root *::after {
  box-sizing: border-box;
}

#voizpanda-chat-root button,
#voizpanda-chat-root textarea {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

#voizpanda-chat-root.voizpanda-pos-bottom-left {
  right: auto;
  left: var(--voizpanda-offset-right);
}

#voizpanda-chat-root #voizpanda-chat-toggle {
  position: relative;
  z-index: 2;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--voizpanda-chat-accent);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--voizpanda-chat-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

#voizpanda-chat-root #voizpanda-chat-toggle:hover {
  transform: scale(1.05);
}

#voizpanda-chat-root #voizpanda-chat-toggle:focus-visible {
  outline: 2px solid var(--voizpanda-chat-accent);
  outline-offset: 3px;
}

#voizpanda-chat-root #voizpanda-chat-toggle svg {
  width: 26px;
  height: 26px;
  min-width: 26px;
  min-height: 26px;
  display: block;
  flex-shrink: 0;
  overflow: visible;
  opacity: 1;
  visibility: visible;
  stroke: #ffffff;
  fill: none;
  color: #ffffff;
  pointer-events: none;
}

#voizpanda-chat-root #voizpanda-chat-panel {
  position: absolute;
  z-index: 1;
  bottom: 72px;
  right: 0;
  width: min(100vw - 40px, 380px);
  max-height: min(70vh, 520px);
  background: var(--voizpanda-chat-bg);
  border-radius: 16px;
  box-shadow: var(--voizpanda-chat-shadow);
  border: 1px solid var(--voizpanda-chat-border);
  display: none;
  flex-direction: column;
  overflow: hidden;
}

#voizpanda-chat-root.voizpanda-pos-bottom-left #voizpanda-chat-panel {
  right: auto;
  left: 0;
}

#voizpanda-chat-root #voizpanda-chat-panel.voizpanda-open {
  display: flex;
}

#voizpanda-chat-root #voizpanda-chat-header {
  padding: 14px 16px;
  background: var(--voizpanda-chat-accent);
  color: #fff;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

#voizpanda-chat-root #voizpanda-chat-close {
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  padding: 0 4px;
  opacity: 0.9;
}

#voizpanda-chat-root #voizpanda-chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
  min-height: 200px;
  max-height: 360px;
  background: #f9fafb;
  display: flex;
  flex-direction: column;
  gap: 0;
}

#voizpanda-chat-root .voizpanda-msg {
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  max-width: 92%;
  word-break: break-word;
}

#voizpanda-chat-root .voizpanda-msg-user {
  margin-left: auto;
  margin-right: 0;
  background: var(--voizpanda-chat-accent);
  color: #fff;
}

#voizpanda-chat-root .voizpanda-msg-assistant {
  margin-right: auto;
  margin-left: 0;
  background: #fff;
  border: 1px solid var(--voizpanda-chat-border);
  color: var(--voizpanda-chat-text);
}

#voizpanda-chat-root .voizpanda-msg-system {
  margin-right: auto;
  margin-left: 0;
  background: #fef3c7;
  color: #92400e;
  font-size: 13px;
}

#voizpanda-chat-root .voizpanda-typing {
  display: none;
  padding: 8px 12px;
  color: var(--voizpanda-chat-muted);
  font-size: 13px;
  flex-shrink: 0;
}

#voizpanda-chat-root .voizpanda-typing.voizpanda-active {
  display: block;
}

#voizpanda-chat-root #voizpanda-chat-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--voizpanda-chat-border);
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

#voizpanda-chat-root #voizpanda-chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#voizpanda-chat-root #voizpanda-chat-input {
  flex: 1;
  border: 1px solid var(--voizpanda-chat-border);
  border-radius: 10px;
  padding: 10px 12px;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  margin: 0;
  width: auto;
  background: #fff;
  color: var(--voizpanda-chat-text);
}

#voizpanda-chat-root #voizpanda-chat-send {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  background: var(--voizpanda-chat-accent);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
}

#voizpanda-chat-root #voizpanda-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#voizpanda-chat-root #voizpanda-voice-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

#voizpanda-chat-root #voizpanda-mic-btn {
  border: 1px solid var(--voizpanda-chat-border);
  background: #fff;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--voizpanda-chat-text);
}

#voizpanda-chat-root #voizpanda-mic-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#voizpanda-chat-root #voizpanda-mic-btn .voizpanda-mic-icon {
  display: inline-block;
  transition: transform 0.2s ease;
}

#voizpanda-chat-root #voizpanda-mic-btn.voizpanda-recording {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #b91c1c;
  animation: voizpanda-pulse 1.5s ease-in-out infinite;
}

#voizpanda-chat-root #voizpanda-mic-btn.voizpanda-recording .voizpanda-mic-icon {
  animation: voizpanda-mic-glow 1s ease-in-out infinite alternate;
}

#voizpanda-chat-root #voizpanda-mic-btn.voizpanda-processing {
  background: #fef3c7;
  border-color: #fcd34d;
  color: #92400e;
}

#voizpanda-chat-root #voizpanda-mic-btn.voizpanda-listening {
  background: #d1fae5;
  border-color: #6ee7b7;
  color: #065f46;
}

@keyframes voizpanda-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50%      { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

@keyframes voizpanda-mic-glow {
  0%   { transform: scale(1); }
  100% { transform: scale(1.15); }
}

#voizpanda-chat-root #voizpanda-voice-hint {
  font-size: 12px;
  color: var(--voizpanda-chat-muted);
  transition: color 0.2s ease;
}

@media (max-width: 480px) {
  #voizpanda-chat-root {
    bottom: 76px;
    right: 12px;
    left: 12px;
  }

  #voizpanda-chat-root.voizpanda-pos-bottom-left {
    left: 12px;
    right: 12px;
  }

  #voizpanda-chat-root #voizpanda-chat-panel {
    width: 100%;
    max-height: calc(100vh - 100px);
    bottom: 68px;
  }
}
