/* ── Public Chat Widget ──────────────────────────────────────── */

.cw-fab {
  position: fixed;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: max(20px, env(safe-area-inset-bottom, 0px));
  z-index: 9000;
}

.cw-fab-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(180deg, #0ea5e9 0%, #0284c7 100%);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(0,0,0,0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s, box-shadow 0.18s;
  position: relative;
  animation: cw-pulse 3s ease-in-out infinite;
}
.cw-fab-btn:hover {
  transform: scale(1.07);
  box-shadow: 0 6px 24px rgba(0,0,0,0.28);
}
.cw-fab-btn:active { transform: scale(0.96); }
.cw-fab-btn.is-open { animation: none; }

@keyframes cw-pulse {
  0%, 100% { box-shadow: 0 4px 18px rgba(0,0,0,0.22), 0 0 0 0 rgba(14,165,233,0.4); }
  55%       { box-shadow: 0 4px 18px rgba(0,0,0,0.22), 0 0 0 10px rgba(14,165,233,0); }
}

.cw-fab-unread {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ef4444;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid #fff;
}
.cw-fab-unread[hidden] { display: none; }

/* Chat panel */
.cw-panel {
  position: fixed;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: max(84px, calc(env(safe-area-inset-bottom, 0px) + 84px));
  width: min(360px, calc(100vw - 24px));
  height: min(520px, calc(100vh - 120px));
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.16), 0 2px 8px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  z-index: 8999;
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
  overflow: hidden;
}
.cw-panel.is-open {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

@media (max-width: 400px) {
  .cw-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    border-radius: 18px 18px 0 0;
    height: min(80vh, 520px);
    transform: translateY(100%);
  }
  .cw-panel.is-open { transform: none; }
  .cw-fab {
    right: max(16px, env(safe-area-inset-right, 0px));
    bottom: max(20px, env(safe-area-inset-bottom, 0px));
  }
}

/* Panel header */
.cw-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 12px;
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
  color: #fff;
  flex-shrink: 0;
}
.cw-head-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.1rem;
}
.cw-head-info { flex: 1; min-width: 0; }
.cw-head-name {
  font-size: 0.9rem;
  font-weight: 700;
  margin: 0 0 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cw-head-status {
  font-size: 0.72rem;
  opacity: 0.85;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 5px;
}
.cw-head-status::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #86efac;
}
.cw-head-close {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
.cw-head-close:hover { background: rgba(255,255,255,0.28); }

/* Messages */
.cw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cw-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.cw-msg--visitor { flex-direction: row-reverse; }

.cw-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #e0f2fe;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
}
.cw-msg--visitor .cw-msg-avatar { background: #d1fae5; }

.cw-msg-bubble {
  max-width: 80%;
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 0.875rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.cw-msg--bot .cw-msg-bubble,
.cw-msg--ai .cw-msg-bubble,
.cw-msg--staff .cw-msg-bubble {
  background: #f3f4f6;
  color: #1f2937;
  border-bottom-left-radius: 4px;
}
.cw-msg--visitor .cw-msg-bubble {
  background: #0ea5e9;
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Typing indicator */
.cw-typing {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.cw-typing-dots {
  background: #f3f4f6;
  padding: 10px 14px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 4px;
  align-items: center;
}
.cw-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca3af;
  animation: cw-blink 1.2s infinite;
}
.cw-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.cw-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes cw-blink {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40%           { opacity: 1;   transform: scale(1); }
}

/* Input area */
.cw-input-area {
  padding: 10px 12px;
  border-top: 1px solid #f0f0f0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}
.cw-input {
  flex: 1;
  border: 1px solid #e5e7eb;
  border-radius: 22px;
  padding: 9px 14px;
  font-size: 0.875rem;
  font-family: inherit;
  resize: none;
  line-height: 1.4;
  max-height: 100px;
  overflow-y: auto;
  transition: border-color 0.15s;
  box-sizing: border-box;
}
.cw-input:focus { outline: none; border-color: #0ea5e9; }
.cw-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: #0ea5e9;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.12s;
}
.cw-send-btn:hover { background: #0284c7; }
.cw-send-btn:active { transform: scale(0.92); }
.cw-send-btn:disabled { background: #d1d5db; cursor: not-allowed; }
