/* ── Chat widget ─────────────────────────────────────────────────────────── */

#chat-fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #000080;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,128,.35);
  z-index: 9990;
  transition: transform .2s, box-shadow .2s;
}
#chat-fab:hover { transform: scale(1.08); box-shadow: 0 6px 26px rgba(0,0,128,.45); }
#chat-fab svg { width: 28px; height: 28px; }

#chat-fab .chat-fab-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}
#chat-fab .chat-fab-badge.visible { display: flex; }

/* ── Widget container ───────────────────────────────────────────────────── */

#chat-widget {
  position: fixed;
  bottom: 100px;
  right: 28px;
  width: 360px;
  height: 520px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 8px 40px rgba(0,0,0,.18);
  display: flex;
  flex-direction: column;
  z-index: 9991;
  overflow: hidden;
  transform: scale(0.92) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform .22s cubic-bezier(.4,0,.2,1), opacity .22s;
}
#chat-widget.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

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

.cw-header {
  background: #000080;
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.cw-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.cw-header-avatar svg { width: 22px; height: 22px; }
.cw-header-info { flex: 1; }
.cw-header-title { font-weight: 700; font-size: 15px; }
.cw-header-sub { font-size: 12px; opacity: .75; margin-top: 2px; }
.cw-close {
  background: none;
  border: none;
  color: rgba(255,255,255,.8);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  border-radius: 6px;
  transition: color .15s;
}
.cw-close:hover { color: #fff; }

/* ── Body ───────────────────────────────────────────────────────────────── */

.cw-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Screens ────────────────────────────────────────────────────────────── */

.cw-screen {
  flex: 1;
  display: none;
  flex-direction: column;
  padding: 24px 20px;
  overflow-y: auto;
}
.cw-screen.active { display: flex; }

/* Welcome screen */
.cw-welcome-icon {
  width: 56px;
  height: 56px;
  background: #f0f0ff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}
.cw-welcome-icon svg { width: 30px; height: 30px; color: #000080; }
.cw-welcome-title {
  text-align: center;
  font-size: 17px;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 6px;
}
.cw-welcome-sub {
  text-align: center;
  font-size: 13px;
  color: #6b7280;
  margin-bottom: 24px;
  line-height: 1.5;
}
.cw-question {
  font-size: 14px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 12px;
  text-align: center;
}
.cw-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cw-choice {
  padding: 12px 16px;
  border-radius: 12px;
  border: 1.5px solid #e5e7eb;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: #0f172a;
  text-align: left;
  transition: border-color .15s, background .15s;
  display: flex;
  align-items: center;
  gap: 10px;
}
.cw-choice:hover { border-color: #000080; background: #f0f0ff; }
.cw-choice-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.cw-choice.registered .cw-choice-icon { background: #dbeafe; }
.cw-choice.new-user .cw-choice-icon { background: #dcfce7; }

/* Email screen */
.cw-form-label {
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 8px;
  display: block;
}
.cw-form-hint {
  font-size: 12px;
  color: #9ca3af;
  margin-bottom: 16px;
}
.cw-input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid #e5e7eb;
  border-radius: 10px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
  box-sizing: border-box;
}
.cw-input:focus { border-color: #000080; }
.cw-input.error { border-color: #ef4444; }
.cw-error-msg {
  font-size: 12px;
  color: #ef4444;
  margin-top: 6px;
  display: none;
}
.cw-error-msg.visible { display: block; }
.cw-btn {
  width: 100%;
  margin-top: 14px;
  padding: 11px 0;
  background: #000080;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}
.cw-btn:hover { background: #0000a0; }
.cw-btn:disabled { background: #9ca3af; cursor: not-allowed; }
.cw-back-link {
  text-align: center;
  margin-top: 12px;
  font-size: 12px;
  color: #6b7280;
  cursor: pointer;
  text-decoration: underline;
}
.cw-back-link:hover { color: #000080; }

/* Chat screen */
.cw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.cw-msg {
  max-width: 80%;
  display: flex;
  flex-direction: column;
}
.cw-msg.user { align-self: flex-end; align-items: flex-end; }
.cw-msg.admin { align-self: flex-start; align-items: flex-start; }

.cw-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}
.cw-msg.user .cw-bubble {
  background: #000080;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.cw-msg.admin .cw-bubble {
  background: #f1f5f9;
  color: #0f172a;
  border-bottom-left-radius: 4px;
}

.cw-msg-time {
  font-size: 10px;
  color: #9ca3af;
  margin-top: 3px;
  padding: 0 4px;
}

/* Typing indicator */
.cw-typing {
  display: none;
  align-self: flex-start;
  background: #f1f5f9;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 10px 14px;
}
.cw-typing.visible { display: flex; gap: 4px; align-items: center; }
.cw-dot {
  width: 7px;
  height: 7px;
  background: #9ca3af;
  border-radius: 50%;
  animation: cw-bounce .9s infinite;
}
.cw-dot:nth-child(2) { animation-delay: .15s; }
.cw-dot:nth-child(3) { animation-delay: .3s; }
@keyframes cw-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* Chat input */
.cw-input-row {
  padding: 10px 12px;
  border-top: 1px solid #f1f5f9;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}
.cw-chat-input {
  flex: 1;
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 14px;
  resize: none;
  outline: none;
  max-height: 100px;
  min-height: 40px;
  line-height: 1.4;
  font-family: inherit;
  transition: border-color .15s;
}
.cw-chat-input:focus { border-color: #000080; }
.cw-send-btn {
  width: 40px;
  height: 40px;
  background: #000080;
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}
.cw-send-btn:hover { background: #0000a0; }
.cw-send-btn:disabled { background: #d1d5db; cursor: not-allowed; }
.cw-send-btn svg { width: 18px; height: 18px; }

/* Closed state */
.cw-closed-notice {
  text-align: center;
  padding: 20px;
  color: #6b7280;
  font-size: 13px;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #chat-widget {
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100dvh;
    border-radius: 0;
  }
  #chat-fab { bottom: 20px; right: 20px; }
}
