/* CodeWebWise Live Chat — premium compact widget */
:root {
  --cww-fab-edge: 1rem;
  --cww-fab-slot: 3.75rem;
  --cww-chat-z: 50;
  --cww-chat-navy: #15233f;
  --cww-chat-blue: #2563eb;
  --cww-chat-blue-deep: #1e40af;
  --cww-chat-soft: #f3f7ff;
  --cww-chat-line: #e2e8f4;
  --cww-chat-ink: #152033;
  --cww-chat-muted: #667085;
}

.cww-chat { position: relative; z-index: var(--cww-chat-z); }

/* Launcher */
.cww-chat-fab {
  position: fixed;
  z-index: var(--cww-chat-z);
  right: var(--cww-fab-edge);
  bottom: var(--cww-fab-edge);
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 3.35rem;
  max-width: min(calc(100vw - 2rem), 210px);
  padding: 0.35rem 0.95rem 0.35rem 0.35rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(145deg, var(--cww-chat-blue-deep), var(--cww-chat-blue));
  color: #fff;
  font: inherit;
  font-weight: 650;
  font-size: 0.86rem;
  box-shadow: 0 12px 28px rgba(21, 35, 63, 0.22);
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease;
}
.cww-chat-fab:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 32px rgba(21, 35, 63, 0.28);
}
.cww-chat-fab:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 3px;
}
.cww-chat-fab[aria-expanded="true"] { display: none; }
.cww-chat-fab-avatar {
  position: relative;
  width: 2.55rem;
  height: 2.55rem;
  flex: 0 0 auto;
}
.cww-chat-fab-avatar img,
.cww-chat-header-avatar img,
.cww-chat-msg-avatar img,
.cww-chat-nudge-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
  background: #dbeafe;
}
.cww-chat-online-dot {
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 0.62rem;
  height: 0.62rem;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(21, 35, 63, 0.08);
}

/* Optional one-time nudge */
.cww-chat-nudge {
  position: fixed;
  z-index: calc(var(--cww-chat-z) - 1);
  right: var(--cww-fab-edge);
  bottom: calc(var(--cww-fab-edge) + 4.1rem);
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: min(290px, calc(100vw - 2rem));
  padding: 0.7rem 0.75rem;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--cww-chat-line);
  box-shadow: 0 14px 34px rgba(21, 35, 63, 0.14);
}
.cww-chat-nudge[hidden] { display: none !important; }
.cww-chat-nudge-avatar {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
}
.cww-chat-nudge-body {
  display: grid;
  gap: 0.1rem;
  min-width: 0;
  font-size: 0.82rem;
  color: var(--cww-chat-ink);
}
.cww-chat-nudge-body strong {
  font-size: 0.78rem;
  color: var(--cww-chat-navy);
}
.cww-chat-nudge-close {
  border: 0;
  background: transparent;
  color: var(--cww-chat-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem;
}

/* Panel */
.cww-chat-panel {
  position: fixed;
  z-index: calc(var(--cww-chat-z) + 1);
  right: var(--cww-fab-edge);
  bottom: calc(var(--cww-fab-edge) + 0.15rem);
  width: min(400px, calc(100vw - 1.75rem));
  height: min(640px, calc(100vh - 1.75rem));
  max-height: min(680px, calc(100dvh - 1.5rem));
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--cww-chat-line);
  border-radius: 18px;
  box-shadow: 0 22px 48px rgba(21, 35, 63, 0.2);
  overflow: hidden;
}
.cww-chat-panel[hidden] { display: none !important; }

.cww-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.8rem 0.85rem;
  background: linear-gradient(135deg, #13233f 0%, #1e3a8a 48%, #2563eb 100%);
  color: #fff;
  flex: 0 0 auto;
}
.cww-chat-header-main {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}
.cww-chat-header-avatar {
  position: relative;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.35);
}
.cww-chat-header h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
}
.cww-chat-status {
  margin: 0.15rem 0 0;
  font-size: 0.74rem;
  opacity: 0.92;
}
.cww-chat-header-actions {
  display: flex;
  gap: 0.3rem;
  flex: 0 0 auto;
}
.cww-chat-icon-btn {
  border: 0;
  background: rgba(255,255,255,0.14);
  color: #fff;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 8px;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
}
.cww-chat-icon-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* Messages */
.cww-chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.85rem 0.8rem 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  background:
    radial-gradient(120% 80% at 100% 0%, rgba(37, 99, 235, 0.06), transparent 55%),
    var(--cww-chat-soft);
  min-height: 0;
  scroll-behavior: smooth;
}
.cww-chat-row {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  max-width: 100%;
}
.cww-chat-row.is-visitor { justify-content: flex-end; }
.cww-chat-row.is-assistant,
.cww-chat-row.is-admin,
.cww-chat-row.is-system { justify-content: flex-start; }
.cww-chat-msg-avatar {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: 50%;
  overflow: hidden;
  align-self: flex-end;
  margin-bottom: 0.15rem;
}
.cww-chat-msg-avatar.is-spacer {
  visibility: hidden;
}
.cww-chat-bubble {
  max-width: 80%;
  padding: 0.55rem 0.72rem;
  border-radius: 14px;
  font-size: 0.875rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(21, 35, 63, 0.04);
}
.cww-chat-bubble-text {
  margin: 0;
}
.cww-chat-bubble .cww-chat-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  align-items: baseline;
  margin-bottom: 0.18rem;
}
.cww-chat-bubble .cww-chat-meta strong {
  font-size: 0.7rem;
  font-weight: 650;
  opacity: 0.8;
}
.cww-chat-bubble .cww-chat-time {
  font-size: 0.66rem;
  opacity: 0.65;
  white-space: nowrap;
}
.cww-chat-row.is-visitor .cww-chat-bubble {
  background: linear-gradient(145deg, #1d4ed8, #2563eb);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.cww-chat-row.is-failed .cww-chat-bubble {
  opacity: 0.78;
  outline: 1px dashed rgba(255, 255, 255, 0.55);
  cursor: pointer;
}
.cww-chat-fail-hint {
  margin-top: 0.35rem;
  font-size: 0.7rem;
  opacity: 0.9;
  line-height: 1.3;
}
.cww-chat-row.is-assistant .cww-chat-bubble {
  background: #fff;
  color: var(--cww-chat-ink);
  border: 1px solid rgba(226, 232, 244, 0.95);
  border-bottom-left-radius: 5px;
}
.cww-chat-row.is-admin .cww-chat-bubble {
  background: #eef2ff;
  color: var(--cww-chat-ink);
  border: 1px solid #dde4ff;
  border-bottom-left-radius: 5px;
}
.cww-chat-row.is-system {
  justify-content: center;
}
.cww-chat-row.is-system .cww-chat-bubble {
  max-width: 92%;
  background: transparent;
  box-shadow: none;
  color: var(--cww-chat-muted);
  font-size: 0.78rem;
  text-align: center;
  padding: 0.25rem 0.4rem;
}

/* Typing */
.cww-chat-typing-bubble {
  padding: 0.5rem 0.7rem;
}
.cww-chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.05rem 0;
}
.cww-chat-typing-label {
  font-size: 0.72rem;
  color: var(--cww-chat-muted);
  white-space: nowrap;
}
.cww-chat-typing-dots {
  display: inline-flex;
  gap: 0.22rem;
  align-items: center;
}
.cww-chat-typing-dots span {
  width: 0.38rem;
  height: 0.38rem;
  border-radius: 50%;
  background: #94a3b8;
  animation: cww-dot 1.1s infinite ease-in-out;
}
.cww-chat-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.cww-chat-typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes cww-dot {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
  40% { transform: translateY(-2px); opacity: 1; }
}

/* Quick actions — compact, under messages */
.cww-chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.45rem 0.75rem 0.35rem;
  border-top: 1px solid transparent;
  background: #fff;
  flex: 0 0 auto;
}
.cww-chat-quick[hidden],
.cww-chat-quick.is-hidden {
  display: none !important;
}
.cww-chat-chip {
  border: 1px solid #d7e0ef;
  background: #f8faff;
  color: #1e3a5f;
  border-radius: 999px;
  padding: 0.28rem 0.65rem;
  font-size: 0.74rem;
  font-weight: 560;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.cww-chat-chip:hover {
  background: #eef4ff;
  border-color: #bfd0ef;
}
.cww-chat-chip:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

/* Composer */
.cww-chat-composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
  padding: 0.55rem 0.7rem 0.65rem;
  border-top: 1px solid var(--cww-chat-line);
  background: #fff;
  flex: 0 0 auto;
}
.cww-chat-composer textarea {
  resize: none;
  min-height: 2.45rem;
  max-height: 5.5rem;
  border: 1px solid #d5dde8;
  border-radius: 999px;
  padding: 0.58rem 0.95rem;
  font: inherit;
  font-size: 0.88rem;
  color: var(--cww-chat-ink);
  background: #fbfcfe;
}
.cww-chat-composer textarea:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 1px;
  background: #fff;
}
.cww-chat-send {
  width: 2.45rem;
  height: 2.45rem;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(145deg, #1d4ed8, #2563eb);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(37, 99, 235, 0.28);
}
.cww-chat-send:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}
.cww-chat-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}
.cww-chat-alt {
  padding: 0 0.75rem 0.65rem;
  text-align: center;
  font-size: 0.76rem;
  background: #fff;
}
.cww-chat-alt a {
  color: #0f766e;
  font-weight: 600;
  text-decoration: none;
}
.cww-chat-alt a:hover { text-decoration: underline; }

/* Open chat: keep WhatsApp accessible but tuck it up */
body.cww-chat-open .wa-float {
  bottom: calc(var(--cww-fab-edge) + 5.1rem + var(--cww-fab-slot));
  opacity: 0.92;
  transform: scale(0.96);
}

@media (max-width: 430px) {
  .cww-chat-fab-label { display: none; }
  .cww-chat-fab {
    width: 3.35rem;
    height: 3.35rem;
    padding: 0.28rem;
    justify-content: center;
  }
  .cww-chat-fab-avatar {
    width: 2.7rem;
    height: 2.7rem;
  }
  .cww-chat-panel {
    left: 0.7rem;
    right: 0.7rem;
    width: auto;
    bottom: 0.7rem;
    height: min(78dvh, 620px);
    max-height: min(80dvh, 640px);
    border-radius: 16px;
  }
  .cww-chat-nudge {
    left: 0.7rem;
    right: 0.7rem;
    width: auto;
    bottom: calc(0.7rem + 4rem);
  }
  .cww-chat-bubble { max-width: 82%; }
  .cww-chat-composer textarea { border-radius: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .cww-chat-fab,
  .cww-chat-messages,
  body.cww-chat-open .wa-float { transition: none; }
  .cww-chat-typing-dots span { animation: none; }
}
