/* ═══════════════════════════════════════════════════════════
   NannyHub — chat-widget.css
   FB-style floating chat widget, bottom-right corner
   All classes scoped with .cw- prefix to prevent collisions
   ═══════════════════════════════════════════════════════════ */

/* ── Design tokens ──────────────────────────────────────── */
:root {
  --cw-accent:       #E07B54;
  --cw-accent-dark:  #C5623B;
  --cw-primary:      #1A2332;
  --cw-header-bg:    #1A2332;
  --cw-bubble-mine:  #1A2332;
  --cw-bubble-other: #f1f1f1;
  --cw-msg-bg:       #F0EBE3;
  --cw-input-bg:     #FDFCFA;
  --cw-border:       #E8E4DD;
  --cw-text-sub:     #7C8A98;
  --cw-text-muted:   #B4BDC8;
  --cw-radius:       14px;
  --cw-shadow:       0 8px 40px rgba(26,35,50,0.22), 0 2px 8px rgba(26,35,50,0.10);
}


/* ════════════════════════════════════════════════════════
   TRIGGER BUTTON  (circle, always visible)
   ════════════════════════════════════════════════════════ */

.cw-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9998;

  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  outline: none;

  background: var(--cw-primary);
  color: #fff;
  box-shadow: 0 4px 20px rgba(26,35,50,0.35);
  transition: transform 0.2s cubic-bezier(0.34,1.56,0.64,1),
              box-shadow 0.2s ease,
              background 0.15s ease;

  display: flex;
  align-items: center;
  justify-content: center;
}

.cw-trigger:hover {
  background: #253547;
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(26,35,50,0.40);
}

.cw-trigger:active {
  transform: scale(0.94);
}

/* Trigger icon swaps between chat-bubble and × when open */
.cw-trigger .cw-icon-open,
.cw-trigger .cw-icon-close { transition: opacity 0.18s, transform 0.18s; }
.cw-trigger .cw-icon-close { position: absolute; opacity: 0; transform: scale(0.6) rotate(-90deg); }

body.cw-is-open .cw-trigger .cw-icon-open  { opacity: 0; transform: scale(0.6) rotate(90deg); }
body.cw-is-open .cw-trigger .cw-icon-close { opacity: 1; transform: scale(1) rotate(0deg); }

/* Unread badge */
.cw-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--cw-accent);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-shadow: 0 0 0 2px #fff;
  pointer-events: none;
}
.cw-badge.cw-hidden { display: none; }


/* ════════════════════════════════════════════════════════
   PANEL  (the expanding chat window)
   ════════════════════════════════════════════════════════ */

.cw-panel {
  position: fixed;
  bottom: 92px;   /* sits just above the trigger */
  right: 24px;
  z-index: 9999;

  width: 320px;
  height: 440px;
  border-radius: var(--cw-radius);
  overflow: hidden;
  box-shadow: var(--cw-shadow);

  display: flex;
  flex-direction: column;
  background: var(--cw-msg-bg);

  /* Enter / leave animation */
  transform-origin: bottom right;
  transition: opacity 0.22s cubic-bezier(0.4,0,0.2,1),
              transform 0.22s cubic-bezier(0.34,1.2,0.64,1);
}

/* Hidden state */
.cw-panel.cw-hidden {
  opacity: 0;
  transform: scale(0.80) translateY(16px);
  pointer-events: none;
}

/* ── Minimised state: only header visible ─────────────── */
.cw-panel.cw-minimised {
  height: auto !important;
}
.cw-panel.cw-minimised .cw-messages,
.cw-panel.cw-minimised .cw-input-area {
  display: none;
}


/* ════════════════════════════════════════════════════════
   HEADER
   ════════════════════════════════════════════════════════ */

.cw-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  background: var(--cw-header-bg);
  flex-shrink: 0;
  user-select: none;
}

/* Avatar */
.cw-avatar {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--cw-accent) 0%, var(--cw-accent-dark) 100%);
  color: #fff;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 0.9375rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(224,123,84,0.35);
  border: 2px solid rgba(255,255,255,0.15);
}

.cw-avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.cw-avatar-img.cw-hidden { display: none; }

/* Online dot on avatar */
.cw-avatar::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #9ca3af;   /* offline default */
  border: 2px solid var(--cw-header-bg);
  transition: background 0.3s;
}
.cw-panel.cw-online .cw-avatar::after {
  background: #22c55e;
  box-shadow: 0 0 0 2px rgba(34,197,94,.3);
}

/* Header text */
.cw-header-info { flex: 1; min-width: 0; }

.cw-header-name {
  font-size: 0.875rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

.cw-header-status {
  font-size: 0.6875rem;
  font-weight: 500;
  color: rgba(255,255,255,0.55);
  margin-top: 1px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.cw-status-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #9ca3af;
  flex-shrink: 0;
  transition: background 0.3s;
}
.cw-panel.cw-online .cw-status-dot  { background: #22c55e; }
.cw-panel.cw-online .cw-header-status { color: #86efac; }

/* Header action buttons */
.cw-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.cw-btn-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(255,255,255,0.10);
  border: none;
  color: rgba(255,255,255,0.75);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  font-size: 1rem;
  line-height: 1;
}
.cw-btn-icon:hover {
  background: rgba(255,255,255,0.20);
  color: #fff;
}

/* "Open full chat" link icon */
.cw-btn-link {
  text-decoration: none;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(255,255,255,0.10);
  border: none;
  color: rgba(255,255,255,0.75);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.cw-btn-link:hover {
  background: rgba(255,255,255,0.20);
  color: #fff;
}


/* ════════════════════════════════════════════════════════
   MESSAGES AREA
   ════════════════════════════════════════════════════════ */

.cw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  scroll-behavior: smooth;

  background-image: radial-gradient(circle, rgba(26,35,50,0.06) 1px, transparent 1px);
  background-size: 22px 22px;
  background-color: var(--cw-msg-bg);
}

.cw-messages::-webkit-scrollbar { width: 3px; }
.cw-messages::-webkit-scrollbar-track { background: transparent; }
.cw-messages::-webkit-scrollbar-thumb {
  background: rgba(26,35,50,0.12);
  border-radius: 4px;
}

/* Loading spinner (inside messages area) */
.cw-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 120px;
}

.cw-spinner {
  width: 24px;
  height: 24px;
  border: 2.5px solid rgba(26,35,50,0.12);
  border-top-color: var(--cw-accent);
  border-radius: 50%;
  animation: cw-spin 0.7s linear infinite;
}

@keyframes cw-spin { to { transform: rotate(360deg); } }

/* Empty state */
.cw-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  margin: auto;
  padding: 24px 16px;
}
.cw-empty svg { color: #ccc; }
.cw-empty p {
  font-size: 0.78rem;
  color: var(--cw-text-sub);
}

/* Date separator */
.cw-date-sep {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 10px 0 5px;
}
.cw-date-sep span {
  background: rgba(26,35,50,0.08);
  color: var(--cw-text-sub);
  font-size: 0.625rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: 0.04em;
}

/* Message groups */
.cw-msg-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cw-msg-group.mine   { align-items: flex-end; }
.cw-msg-group.theirs { align-items: flex-start; }

/* Bubbles */
.cw-bubble {
  max-width: 78%;
  padding: 8px 12px;
  font-size: 0.8125rem;
  line-height: 1.55;
  word-break: break-word;
  animation: cw-msg-in 0.18s cubic-bezier(0.34,1.4,0.64,1) both;
}

.cw-bubble.sent {
  background: var(--cw-bubble-mine);
  color: #fff;
  border-radius: 14px 14px 0 14px;
  box-shadow: 0 2px 8px rgba(26,35,50,0.20);
}

.cw-bubble.received {
  background: var(--cw-bubble-other);
  color: #1A2332;
  border-radius: 14px 14px 14px 0;
  box-shadow: 0 1px 4px rgba(26,35,50,0.08);
}

/* Remove tail radius on non-last bubbles in a group */
.cw-msg-group.mine   .cw-bubble:not(:last-of-type) { border-radius: 14px; }
.cw-msg-group.theirs .cw-bubble:not(:last-of-type) { border-radius: 14px; }

.cw-msg-time {
  font-size: 0.625rem;
  color: var(--cw-text-muted);
  padding: 0 4px;
  margin-top: 1px;
}

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


/* ════════════════════════════════════════════════════════
   INPUT AREA
   ════════════════════════════════════════════════════════ */

.cw-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 14px;
  background: var(--cw-input-bg);
  border-top: 1px solid var(--cw-border);
  flex-shrink: 0;
}

.cw-input-wrap {
  flex: 1;
  background: #fff;
  border: 1.5px solid var(--cw-border);
  border-radius: 18px;
  padding: 8px 13px;
  transition: border-color 0.18s, box-shadow 0.18s;
  box-shadow: 0 1px 4px rgba(26,35,50,0.05);
}

.cw-input-wrap:focus-within {
  border-color: var(--cw-accent);
  box-shadow: 0 1px 6px rgba(224,123,84,0.14);
}

.cw-input {
  display: block;
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  font-family: 'DM Sans', 'Nunito', system-ui, sans-serif;
  font-size: 0.8125rem;
  color: #1A2332;
  line-height: 1.5;
  max-height: 90px;
  overflow-y: auto;
}
.cw-input::placeholder { color: var(--cw-text-muted); }

.cw-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #DDD9D3;
  color: #fff;
  border: none;
  cursor: not-allowed;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.18s, transform 0.1s, box-shadow 0.18s;
}
.cw-send-btn:not(:disabled) {
  background: var(--cw-accent);
  box-shadow: 0 3px 12px rgba(224,123,84,0.38);
  cursor: pointer;
}
.cw-send-btn:not(:disabled):hover {
  background: var(--cw-accent-dark);
  transform: scale(1.07);
}
.cw-send-btn:not(:disabled):active {
  transform: scale(0.93);
  box-shadow: none;
}


/* ════════════════════════════════════════════════════════
   RESPONSIVE — hide widget on very small screens
   (they use the full-page chat.html instead)
   ════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
  .cw-trigger { bottom: 16px; right: 16px; }
  .cw-panel   { right: 8px; bottom: 84px; width: calc(100vw - 16px); height: 380px; }
}
