/* ═══════════════════════════════════════════════════════
   BW Studio — Live Chat Widget
   Professional dark theme, Crisp-style bottom-right popup
   ═══════════════════════════════════════════════════════ */

:root {
  --bw-chat-accent: #a855f7;
  --bw-chat-accent-hover: #9333ea;
  --bw-chat-bg: #1a1a2e;
  --bw-chat-bg-secondary: #16213e;
  --bw-chat-bg-header: #0f0f23;
  --bw-chat-bg-input: #252547;
  --bw-chat-text: #e2e8f0;
  --bw-chat-text-muted: #94a3b8;
  --bw-chat-bubble-visitor: #7c3aed;
  --bw-chat-bubble-support: #2d2d5e;
  --bw-chat-border: rgba(148, 163, 184, 0.12);
  --bw-chat-shadow: 0 12px 48px rgba(0, 0, 0, 0.45);
  --bw-chat-radius: 16px;
  --bw-chat-width: 380px;
  --bw-chat-height: 540px;
  --bw-chat-btn-size: 60px;
  --bw-chat-z: 999999;
}

/* ── Toggle Button ── */
#bw-chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--bw-chat-z);
  width: var(--bw-chat-btn-size);
  height: var(--bw-chat-btn-size);
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--bw-chat-accent), #6d28d9);
  box-shadow: 0 4px 20px rgba(168, 85, 247, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
  outline: none;
}

#bw-chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(168, 85, 247, 0.6);
}

#bw-chat-toggle:active {
  transform: scale(0.95);
}

#bw-chat-toggle svg {
  width: 28px;
  height: 28px;
  fill: #fff;
  transition: opacity 0.2s, transform 0.3s;
}

#bw-chat-toggle .bw-chat-icon-close {
  position: absolute;
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

#bw-chat-toggle.bw-open .bw-chat-icon-open {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

#bw-chat-toggle.bw-open .bw-chat-icon-close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

/* Badge */
#bw-chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  background: #ef4444;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.5);
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  line-height: 1;
  animation: bw-badge-pulse 2s ease-in-out infinite;
}

#bw-chat-badge.bw-visible {
  display: flex;
}

@keyframes bw-badge-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* ── Chat Window ── */
#bw-chat-window {
  position: fixed;
  bottom: 100px;
  right: 24px;
  z-index: calc(var(--bw-chat-z) - 1);
  width: var(--bw-chat-width);
  height: var(--bw-chat-height);
  background: var(--bw-chat-bg);
  border-radius: var(--bw-chat-radius);
  box-shadow: var(--bw-chat-shadow);
  border: 1px solid var(--bw-chat-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  opacity: 0;
  transform: scale(0.85) translateY(20px);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

#bw-chat-window.bw-open {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

/* ── Header ── */
.bw-chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: var(--bw-chat-bg-header);
  border-bottom: 1px solid var(--bw-chat-border);
  flex-shrink: 0;
}

.bw-chat-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--bw-chat-accent), #6d28d9);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.bw-chat-header-avatar svg {
  width: 22px;
  height: 22px;
  fill: #fff;
}

.bw-chat-header-info {
  flex: 1;
  min-width: 0;
}

.bw-chat-header-title {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  margin: 0;
  line-height: 1.3;
}

.bw-chat-header-subtitle {
  font-size: 12px;
  color: var(--bw-chat-text-muted);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 5px;
}

.bw-chat-header-subtitle::before {
  content: '';
  width: 7px;
  height: 7px;
  background: #22c55e;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.bw-chat-header-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}

.bw-chat-header-close:hover {
  background: rgba(255, 255, 255, 0.08);
}

.bw-chat-header-close svg {
  width: 18px;
  height: 18px;
  fill: var(--bw-chat-text-muted);
}

/* ── Welcome Screen ── */
.bw-chat-welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
}

.bw-chat-welcome-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--bw-chat-accent), #6d28d9);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  box-shadow: 0 4px 24px rgba(168, 85, 247, 0.35);
}

.bw-chat-welcome-icon svg {
  width: 32px;
  height: 32px;
  fill: #fff;
}

.bw-chat-welcome h3 {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  margin: 0 0 8px;
}

.bw-chat-welcome p {
  font-size: 13px;
  color: var(--bw-chat-text-muted);
  margin: 0 0 24px;
  line-height: 1.5;
}

.bw-chat-welcome-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bw-chat-welcome-form input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--bw-chat-border);
  background: var(--bw-chat-bg-input);
  color: var(--bw-chat-text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
  box-sizing: border-box;
  font-family: inherit;
}

.bw-chat-welcome-form input::placeholder {
  color: var(--bw-chat-text-muted);
}

.bw-chat-welcome-form input:focus {
  border-color: var(--bw-chat-accent);
}

.bw-chat-welcome-form button {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, var(--bw-chat-accent), #6d28d9);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
  font-family: inherit;
}

.bw-chat-welcome-form button:hover {
  opacity: 0.9;
}

.bw-chat-welcome-form button:active {
  transform: scale(0.97);
}

.bw-chat-welcome-form .bw-chat-hint {
  font-size: 11px;
  color: var(--bw-chat-text-muted);
  margin-top: 2px;
}

/* ── Chat Body Container ── */
#bw-chat-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* ── Messages Area ── */
.bw-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.2) transparent;
}

.bw-chat-messages::-webkit-scrollbar {
  width: 5px;
}

.bw-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.bw-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.2);
  border-radius: 3px;
}

/* Message Bubble */
.bw-msg {
  max-width: 82%;
  display: flex;
  flex-direction: column;
  animation: bw-msg-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes bw-msg-in {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.bw-msg.bw-visitor {
  align-self: flex-end;
}

.bw-msg.bw-support {
  align-self: flex-start;
}

.bw-msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.bw-msg.bw-visitor .bw-msg-bubble {
  background: var(--bw-chat-bubble-visitor);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.bw-msg.bw-support .bw-msg-bubble {
  background: var(--bw-chat-bubble-support);
  color: var(--bw-chat-text);
  border-bottom-left-radius: 4px;
}

.bw-msg-time {
  font-size: 11px;
  color: var(--bw-chat-text-muted);
  margin-top: 3px;
  padding: 0 4px;
}

.bw-msg.bw-visitor .bw-msg-time {
  text-align: right;
}

/* Date separator */
.bw-chat-date-sep {
  text-align: center;
  font-size: 11px;
  color: var(--bw-chat-text-muted);
  padding: 8px 0;
  position: relative;
}

.bw-chat-date-sep::before,
.bw-chat-date-sep::after {
  content: '';
  position: absolute;
  top: 50%;
  height: 1px;
  width: 30%;
  background: var(--bw-chat-border);
}

.bw-chat-date-sep::before { left: 0; }
.bw-chat-date-sep::after { right: 0; }

/* Typing indicator */
.bw-chat-typing {
  display: none;
  align-self: flex-start;
  padding: 10px 16px;
  background: var(--bw-chat-bubble-support);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  gap: 4px;
  align-items: center;
}

.bw-chat-typing.bw-visible {
  display: flex;
}

.bw-chat-typing span {
  width: 6px;
  height: 6px;
  background: var(--bw-chat-text-muted);
  border-radius: 50%;
  animation: bw-typing-dot 1.4s infinite;
}

.bw-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.bw-chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bw-typing-dot {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}

/* ── Input Area ── */
.bw-chat-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: var(--bw-chat-bg-header);
  border-top: 1px solid var(--bw-chat-border);
  flex-shrink: 0;
}

.bw-chat-input-wrap {
  flex: 1;
  position: relative;
}

.bw-chat-input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--bw-chat-border);
  background: var(--bw-chat-bg-input);
  color: var(--bw-chat-text);
  font-size: 14px;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
  min-height: 20px;
  max-height: 100px;
  line-height: 1.4;
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.2) transparent;
}

.bw-chat-input::-webkit-scrollbar {
  width: 5px;
}

.bw-chat-input::-webkit-scrollbar-track {
  background: transparent;
}

.bw-chat-input::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.2);
  border-radius: 3px;
}

.bw-chat-input::placeholder {
  color: var(--bw-chat-text-muted);
}

.bw-chat-input:focus {
  border-color: var(--bw-chat-accent);
}

.bw-chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, var(--bw-chat-accent), #6d28d9);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s, transform 0.15s;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.bw-chat-send-btn:hover {
  opacity: 0.9;
}

.bw-chat-send-btn:active {
  transform: scale(0.92);
}

.bw-chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.bw-chat-send-btn svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

/* ── Attach Button ── */
.bw-chat-attach-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
  margin-bottom: 2px;
}

.bw-chat-attach-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.bw-chat-attach-btn svg {
  width: 20px;
  height: 20px;
  fill: var(--bw-chat-text-muted);
}

/* ── Attachments in messages ── */
.bw-attach-img {
  display: block;
  margin-top: 6px;
}

.bw-attach-img img {
  max-width: 100%;
  max-height: 200px;
  border-radius: 8px;
  display: block;
  cursor: zoom-in;
}

.bw-attach-pdf {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--bw-chat-text);
  text-decoration: none;
  font-size: 13px;
  transition: background 0.2s;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.bw-attach-pdf:hover {
  background: rgba(255, 255, 255, 0.14);
}

.bw-attach-pdf-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.bw-attach-pdf-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--bw-chat-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bw-attach-pdf-action {
  font-size: 10px;
  color: var(--bw-chat-text-muted);
}

.bw-attach-dl-icon {
  flex-shrink: 0;
  opacity: 0.5;
}

.bw-attach-pdf:hover .bw-attach-dl-icon {
  opacity: 1;
}

.bw-attach-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--bw-chat-text);
  text-decoration: none;
  font-size: 13px;
}

.bw-attach-loading {
  margin-top: 6px;
  font-size: 12px;
  color: var(--bw-chat-text-muted);
  font-style: italic;
}

.bw-attach-error {
  margin-top: 6px;
  font-size: 12px;
  color: #ef4444;
}

/* ── Powered By ── */
.bw-chat-powered {
  text-align: center;
  padding: 6px 0;
  font-size: 10px;
  color: rgba(148, 163, 184, 0.4);
  background: var(--bw-chat-bg-header);
  flex-shrink: 0;
}

/* ── Mobile ── */
@media (max-width: 480px) {
  #bw-chat-window {
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    transform: translateY(100%);
    transform-origin: bottom center;
  }

  #bw-chat-window.bw-open {
    transform: translateY(0);
  }

  :root {
    --bw-chat-width: 100%;
    --bw-chat-height: 100%;
  }

  #bw-chat-toggle {
    bottom: 16px;
    right: 16px;
  }

  #bw-chat-toggle.bw-open {
    display: none;
  }
}

@media (min-width: 481px) and (max-width: 768px) {
  :root {
    --bw-chat-width: 340px;
    --bw-chat-height: 480px;
  }
}
