/* ══════════════════════════════════════════════════════
   AEROCITY AI CHATBOT — Flat · Dark-Green Header · Responsive
   ══════════════════════════════════════════════════════ */

:root {
  --cb-header:   #0b3d26;          /* dark green */
  --cb-header2:  #0f5233;          /* slightly lighter green */
  --cb-brand:    #1e3a8a;          /* blue (toggle + user bubble) */
  --cb-brand-lt: #2563eb;
  --cb-green:    #22c55e;
  --cb-red:      #ef4444;
  --cb-bg:       #f0f2f5;
  --cb-white:    #ffffff;
  --cb-border:   #e4e7ec;
  --cb-text:     #111827;
  --cb-muted:    #6b7280;
}

/* ── Base ─────────────────────────────────────────────── */
#cb-widget *,
#cb-widget *::before,
#cb-widget *::after {
  box-sizing: border-box;
}
#cb-widget {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 9990;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ══════════════════════════════════════════════════════
   TOGGLE BUTTON
   ══════════════════════════════════════════════════════ */
#cb-toggle {
  position: relative;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--cb-brand);
  border: none;
  cursor: pointer;
  color: #fff;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(30,58,138,0.45);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  -webkit-tap-highlight-color: transparent;
  overflow: visible;
  outline: none;
}
#cb-toggle:hover  { transform: scale(1.08); }
#cb-toggle:active { transform: scale(0.92); }

.cb-ti, .cb-tc {
  position: absolute;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.cb-tc { opacity: 0; transform: rotate(-90deg) scale(0.5); }
#cb-widget.cb-open .cb-ti { opacity: 0; transform: rotate(90deg) scale(0.5); }
#cb-widget.cb-open .cb-tc { opacity: 1; transform: rotate(0deg) scale(1); }

/* Pulse rings */
.cb-pulse {
  position: absolute;
  inset: -6px; border-radius: 50%;
  border: 2px solid rgba(59,130,246,0.35);
  animation: cbRing 2.4s ease-out infinite;
  pointer-events: none;
}
.cb-pulse-2 { inset: -12px; border-color: rgba(59,130,246,0.15); animation-delay: 0.5s; }
#cb-widget.cb-open .cb-pulse { animation: none; opacity: 0; }
@keyframes cbRing {
  0%   { transform: scale(1);    opacity: 1; }
  100% { transform: scale(1.6);  opacity: 0; }
}

/* Badge */
.cb-badge {
  position: absolute;
  top: -4px; right: -4px;
  min-width: 20px; height: 20px; padding: 0 4px;
  border-radius: 10px;
  background: var(--cb-red);
  color: #fff; font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
  animation: cbPop 0.3s cubic-bezier(0.34,1.56,0.64,1) both;
}
@keyframes cbPop { from { transform: scale(0); } to { transform: scale(1); } }

/* Firefly glow animation on the card border */
@keyframes cbFirefly {
  0%   {
    border-color: rgba(34,197,94,0.35);
    box-shadow:
      0 0 6px  rgba(34,197,94,0.25),
      0 0 18px rgba(34,197,94,0.10),
      0 8px 32px rgba(0,0,0,0.18);
  }
  25%  {
    border-color: rgba(74,222,128,0.55);
    box-shadow:
      0 0 12px rgba(74,222,128,0.40),
      0 0 30px rgba(74,222,128,0.18),
      0 0 50px rgba(34,197,94,0.07),
      0 8px 32px rgba(0,0,0,0.18);
  }
  50%  {
    border-color: rgba(16,185,129,0.45);
    box-shadow:
      0 0 8px  rgba(16,185,129,0.30),
      0 0 22px rgba(16,185,129,0.14),
      0 8px 32px rgba(0,0,0,0.18);
  }
  75%  {
    border-color: rgba(52,211,153,0.60);
    box-shadow:
      0 0 14px rgba(52,211,153,0.42),
      0 0 34px rgba(52,211,153,0.20),
      0 0 55px rgba(34,197,94,0.08),
      0 8px 32px rgba(0,0,0,0.18);
  }
  100% {
    border-color: rgba(34,197,94,0.35);
    box-shadow:
      0 0 6px  rgba(34,197,94,0.25),
      0 0 18px rgba(34,197,94,0.10),
      0 8px 32px rgba(0,0,0,0.18);
  }
}

/* ══════════════════════════════════════════════════════
   CHAT WINDOW — flat card with firefly glow border
   ══════════════════════════════════════════════════════ */
.cb-window {
  position: absolute;
  bottom: 70px;
  right: 0;
  width: 360px;
  height: 555px;
  max-height: calc(100vh - 100px);
  background: var(--cb-white);
  border-radius: 0;
  border: 1.5px solid rgba(34,197,94,0.35);
  box-shadow:
    0 0 6px  rgba(34,197,94,0.25),
    0 0 18px rgba(34,197,94,0.10),
    0 8px 32px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.97);
  transform-origin: bottom right;
  transition: opacity 0.26s ease, visibility 0.26s, transform 0.26s ease;
}
#cb-widget.cb-open .cb-window {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  animation: cbFirefly 4s ease-in-out infinite;
}

/* ══════════════════════════════════════════════════════
   HEADER — flat, dark-green
   ══════════════════════════════════════════════════════ */
.cb-header {
  background: var(--cb-header);
  padding: 13px 14px 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  position: relative;
}

.cb-header-left {
  display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1;
}

.cb-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  border: 2px solid rgba(255,255,255,0.25);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: #fff;
  flex-shrink: 0; position: relative;
}
.cb-avatar-online {
  position: absolute; bottom: 1px; right: 1px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--cb-green);
  border: 2px solid var(--cb-header);
}

.cb-header-info { flex: 1; min-width: 0; }
.cb-header-name {
  font-size: 14px; font-weight: 700; color: #fff;
  display: flex; align-items: center; gap: 6px;
}
.cb-ai-tag {
  font-size: 8px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.22);
  color: rgba(255,255,255,0.88);
  padding: 2px 5px;
}
.cb-header-sub {
  font-size: 11px; color: rgba(255,255,255,0.58);
  display: flex; align-items: center; gap: 4px; margin-top: 2px;
}
.cb-online-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--cb-green);
}

.cb-header-btns { display: flex; gap: 4px; flex-shrink: 0; }
.cb-hbtn {
  width: 28px; height: 28px;
  background: rgba(255,255,255,0.1);
  border: none; color: rgba(255,255,255,0.75);
  font-size: 11px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s; border-radius: 4px;
  -webkit-tap-highlight-color: transparent;
}
.cb-hbtn:hover { background: rgba(255,255,255,0.2); color: #fff; }

/* ══════════════════════════════════════════════════════
   MESSAGES BODY
   ══════════════════════════════════════════════════════ */
.cb-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 12px;
  background: var(--cb-bg);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  min-height: 0;                     /* critical for flex scroll */
}
.cb-body::-webkit-scrollbar { width: 3px; }
.cb-body::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); }

/* Welcome card */
.cb-welcome-card {
  background: var(--cb-white);
  border: 1px solid rgba(11,61,38,0.14);
  border-radius: 16px;
  padding: 18px 16px 14px;
  text-align: center;
  margin-bottom: 14px;
  box-shadow: 0 4px 16px rgba(11,61,38,0.08), 0 1px 4px rgba(0,0,0,0.05);
  animation: cbIn 0.3s ease both;
  overflow: hidden;
}
.cb-wc-icon {
  width: 90px; height: 90px;
  background: transparent;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 10px;
}
.cb-wc-logo {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
}
.cb-wc-title {
  font-size: 14px; font-weight: 800;
  color: var(--cb-header); margin: 0 0 5px;
  letter-spacing: -0.2px;
}
.cb-wc-sub {
  font-size: 12px; color: var(--cb-muted);
  margin: 0; line-height: 1.6;
}
.cb-wc-stats {
  display: flex; margin-top: 14px;
  border: 1px solid rgba(11,61,38,0.12);
  border-radius: 12px; overflow: hidden;
  background: #f8fdf9;
}
.cb-wc-stat {
  flex: 1; padding: 8px 4px; text-align: center;
  border-right: 1px solid rgba(11,61,38,0.10);
}
.cb-wc-stat:last-child { border-right: none; }
.cb-wc-stat strong {
  display: block; font-size: 13px; font-weight: 800; color: var(--cb-header);
}
.cb-wc-stat span { font-size: 10px; color: var(--cb-muted); }

/* Message groups */
.cb-group {
  display: flex; flex-direction: column; gap: 2px;
  margin-bottom: 10px;
  animation: cbIn 0.24s ease both;
}
@keyframes cbIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.cb-group.cb-bot  { align-items: flex-start; }
.cb-group.cb-user { align-items: flex-end; }

.cb-bot-row { display: flex; align-items: flex-end; gap: 6px; }
.cb-mini-av {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--cb-header);
  color: #fff; font-size: 9px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-bottom: 2px;
}

/* Bubbles */
.cb-bubble {
  max-width: 80%;
  padding: 10px 14px;
  font-size: 13.5px; line-height: 1.65;
  word-break: break-word;
}
.cb-bot .cb-bubble {
  background: var(--cb-white);
  color: var(--cb-text);
  border: 1px solid rgba(11,61,38,0.12);
  border-radius: 4px 18px 18px 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.cb-user .cb-bubble {
  background: var(--cb-brand);
  color: #fff;
  border-radius: 18px 4px 18px 18px;
  box-shadow: 0 2px 8px rgba(30,58,138,0.2);
}
.cb-bubble strong { font-weight: 700; }
.cb-bubble.cb-success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
  border-radius: 4px 18px 18px 18px;
  box-shadow: 0 2px 8px rgba(22,163,74,0.08);
}

.cb-meta {
  font-size: 10px; color: var(--cb-muted);
  margin-top: 2px; padding: 0 2px;
  display: flex; align-items: center; gap: 3px;
}
.cb-bot  .cb-meta { margin-left: 32px; }
.cb-user .cb-meta { justify-content: flex-end; }
.cb-check { color: #60a5fa; font-size: 9px; }

/* Typing dots */
.cb-typing {
  background: var(--cb-white);
  border: 1px solid rgba(11,61,38,0.12);
  border-radius: 4px 18px 18px 18px;
  padding: 11px 16px;
  display: flex; align-items: center; gap: 5px;
  width: fit-content;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.cb-tdot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #c0ccd8;
  animation: cbDot 1.2s ease-in-out infinite;
}
.cb-tdot:nth-child(2) { animation-delay: 0.16s; }
.cb-tdot:nth-child(3) { animation-delay: 0.32s; }
@keyframes cbDot {
  0%,60%,100% { transform: translateY(0);    background: #c0ccd8; }
  30%          { transform: translateY(-5px); background: var(--cb-header); }
}

/* ══════════════════════════════════════════════════════
   QUICK REPLIES — horizontal scroll
   ══════════════════════════════════════════════════════ */
.cb-qr-area {
  padding: 8px 10px;
  background: var(--cb-white);
  border-top: 1px solid var(--cb-border);
  display: flex; gap: 6px;
  overflow-x: auto; overflow-y: hidden;
  flex-wrap: nowrap; flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.cb-qr-area::-webkit-scrollbar { display: none; }
.cb-qr-area:empty { display: none; padding: 0; border-top: none; }

.cb-qr {
  font-family: inherit; font-size: 12px; font-weight: 600;
  padding: 5px 12px;
  border: 1.5px solid var(--cb-header);
  background: var(--cb-white); color: var(--cb-header);
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
  border-radius: 20px;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
.cb-qr:hover  { background: var(--cb-header); color: #fff; }
.cb-qr:active { opacity: 0.85; }
.cb-qr:disabled { opacity: 0.35; cursor: default; }

/* ══════════════════════════════════════════════════════
   INPUT FOOTER — flat, advanced
   ══════════════════════════════════════════════════════ */
.cb-footer {
  flex-shrink: 0;
  background: var(--cb-white);
  border-top: 1px solid var(--cb-border);
  padding: 10px 12px;
  /* safe area for iPhone home bar */
  padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
}

.cb-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #f3f4f6;
  border: 1.5px solid #d1d5db;
  border-radius: 28px;
  padding: 7px 7px 7px 16px;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
  min-height: 46px;
}
.cb-input-row:focus-within {
  border-color: var(--cb-header);
  background: var(--cb-white);
  box-shadow: 0 0 0 3px rgba(11,61,38,0.10), 0 0 10px rgba(34,197,94,0.15);
}

#cb-input {
  flex: 1;
  border: none; outline: none; background: transparent;
  font-family: inherit; font-size: 14px; color: var(--cb-text);
  resize: none; line-height: 1.5;
  min-height: 22px; max-height: 88px;
  padding: 0; align-self: center;
  overflow-y: auto;
  scrollbar-width: none;
}
#cb-input::-webkit-scrollbar { display: none; }
#cb-input::placeholder { color: #9ca3af; }

#cb-send {
  width: 36px; height: 36px; min-width: 36px; min-height: 36px;
  background: var(--cb-header);
  border: none; color: #fff; font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; align-self: flex-end;
  border-radius: 50%;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
#cb-send:hover  {
  background: var(--cb-header2);
  box-shadow: 0 0 10px rgba(34,197,94,0.35);
  transform: scale(1.06);
}
#cb-send:active { transform: scale(0.9); }
#cb-send:disabled { opacity: 0.35; cursor: not-allowed; transform: none; box-shadow: none; }

.cb-input-hint {
  font-size: 10px; color: #c0ccd8;
  text-align: center; margin-top: 5px;
  user-select: none;
}

/* ══════════════════════════════════════════════════════
   MOBILE — Full bottom sheet, zero overflow
   ══════════════════════════════════════════════════════ */
@media (max-width: 600px) {

  #cb-widget {
    bottom: 14px;
    right: 14px;
  }

  #cb-toggle {
    width: 54px; height: 54px; font-size: 21px;
  }

  /* Bottom sheet — slides up from bottom edge */
  .cb-window {
    position: fixed;
    left:   0;
    right:  0;
    bottom: 0;
    top:    auto;
    width:  100%;
    height: 82vh;
    max-height: 82vh;
    border-radius: 0;
    border:  none;
    border-top: 2px solid rgba(34,197,94,0.45);
    box-shadow: 0 -4px 24px rgba(0,0,0,0.18);
    transform-origin: bottom center;
    transform: translateY(100%);
    transition: transform 0.3s ease, opacity 0.3s ease, visibility 0.3s;
    animation: none !important;       /* no glow on bottom sheet */
  }
  #cb-widget.cb-open .cb-window {
    transform: translateY(0);
    opacity: 1; visibility: visible;
  }

  /* Drag-handle bar at top of header */
  .cb-header {
    padding-top: 18px;
  }
  .cb-header::before {
    content: '';
    position: absolute;
    top: 7px; left: 50%;
    transform: translateX(-50%);
    width: 36px; height: 4px;
    background: rgba(255,255,255,0.25);
    border-radius: 2px;
  }

  /* Larger tap areas on mobile */
  .cb-bubble { max-width: 86%; font-size: 14px; }

  /* Prevent iOS input zoom (must be 16px+) */
  #cb-input { font-size: 16px; }

  .cb-input-row {
    min-height: 50px;
    padding: 8px 8px 8px 16px;
    border-radius: 28px;
  }
  #cb-send {
    width: 38px; height: 38px;
    min-width: 38px; min-height: 38px;
  }

  .cb-qr { font-size: 13px; padding: 6px 13px; }

  .cb-input-hint { display: none; }
  #cb-emoji-panel { grid-template-columns: repeat(7, 1fr); }
}

/* Very small screens */
@media (max-width: 380px) {
  .cb-window { height: 90vh; max-height: 90vh; }
  .cb-bubble  { max-width: 90%; font-size: 13.5px; }
}

/* Backdrop overlay for mobile */
.cb-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 9985;
  opacity: 0;
  transition: opacity 0.28s ease;
}
.cb-backdrop.cb-show {
  display: block;
  opacity: 1;
}

/* ── Emoji toggle button ─────────────────────────────── */
#cb-emoji-btn {
  width: 30px; height: 30px; min-width: 30px;
  background: transparent; border: none;
  color: #9ca3af; font-size: 17px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; align-self: center;
  transition: color 0.15s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
  outline: none; border-radius: 50%; padding: 0;
}
#cb-emoji-btn:hover { color: var(--cb-header); transform: scale(1.18); }
#cb-emoji-btn.cb-active { color: var(--cb-header); }

/* ── Emoji picker panel ──────────────────────────────── */
#cb-emoji-panel {
  background: var(--cb-white);
  border: 1px solid var(--cb-border);
  border-radius: 14px;
  padding: 10px;
  margin-bottom: 8px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.10);
  animation: cbIn 0.18s ease both;
}
#cb-emoji-panel[hidden] { display: none !important; }

.cb-emoji {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; cursor: pointer; border-radius: 8px;
  border: none; background: transparent;
  transition: background 0.1s, transform 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.cb-emoji:hover { background: #f0f2f5; transform: scale(1.22); }

/* ── Input meta row (hint + char count) ──────────────── */
.cb-input-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 5px;
  padding: 0 2px;
}
.cb-input-hint  { font-size: 10px; color: #c0ccd8; user-select: none; }
#cb-char-count  { font-size: 10px; color: #c0ccd8; transition: color 0.2s; }
#cb-char-count.cb-warn  { color: #f59e0b; }
#cb-char-count.cb-limit { color: var(--cb-red); font-weight: 700; }

/* Back-to-top stays below chatbot */
#backToTop { z-index: 9980; }
