/* ==========================================================================
   ZCS AI Chatbot — Soft Modern UI
   Rounded, friendly, snappy. Light + dark themes.
   ========================================================================== */

.zcsbot-root {
  --z-accent:        #6366f1;
  --z-accent-dark:   #4f46e5;
  --z-accent-soft:   rgba(99,102,241,.12);
  --z-bg:            #ffffff;
  --z-panel:         #ffffff;
  --z-elev:          #f8fafc;
  --z-text:          #1e2433;
  --z-text-soft:     #6b7280;
  --z-border:        rgba(17,24,39,.08);
  --z-user-bubble:   linear-gradient(135deg,#6366f1,#7c83f6);
  --z-bot-bubble:    #f1f3f9;
  --z-radius:        22px;
  --z-shadow:        0 12px 40px rgba(17,24,39,.14), 0 2px 8px rgba(17,24,39,.06);
  --z-font:          -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;

  position: fixed;
  right: 22px;
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 2147483000;
  font-family: var(--z-font);
}

.zcsbot-root.dark {
  --z-bg:          #0d1117;
  --z-panel:       #11161f;
  --z-elev:        #161c27;
  --z-text:        #e8ebf2;
  --z-text-soft:   #9aa3b2;
  --z-border:      rgba(255,255,255,.09);
  --z-bot-bubble:  #1b2230;
  --z-shadow:      0 16px 48px rgba(0,0,0,.55), 0 2px 10px rgba(0,0,0,.4);
}

.zcsbot-root *, .zcsbot-root *::before, .zcsbot-root *::after { box-sizing: border-box; }

/* ── Floating button ───────────────────────────────────────────────────── */
.zcsbot-fab {
  width: 60px; height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--z-user-bubble);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(99,102,241,.42);
  transition: transform .22s cubic-bezier(.34,1.56,.64,1), box-shadow .22s ease;
  overflow: hidden;
  padding: 0;
}
.zcsbot-fab:hover  { transform: translateY(-2px) scale(1.04); box-shadow: 0 12px 30px rgba(99,102,241,.5); }
.zcsbot-fab:active { transform: scale(.96); }
.zcsbot-fab.open   { transform: scale(.9); opacity: .9; }
.zcsbot-fab-img    { width: 30px; height: 30px; object-fit: contain; }
.zcsbot-fab .zcsbot-glyph-lg svg { width: 26px; height: 26px; }

/* ── Panel ─────────────────────────────────────────────────────────────── */
.zcsbot-panel {
  position: absolute;
  right: 0;
  bottom: 76px;
  width: 384px;
  max-width: calc(100vw - 36px);
  height: 600px;
  max-height: calc(100vh - 120px);
  background: var(--z-panel);
  border: 1px solid var(--z-border);
  border-radius: var(--z-radius);
  box-shadow: var(--z-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transform: translateY(12px) scale(.96);
  opacity: 0;
  pointer-events: none;
  transition: transform .26s cubic-bezier(.34,1.56,.64,1), opacity .2s ease;
}
.zcsbot-panel.open { transform: translateY(0) scale(1); opacity: 1; pointer-events: auto; }

/* ── Header ────────────────────────────────────────────────────────────── */
.zcsbot-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--z-user-bubble);
  color: #fff;
  flex-shrink: 0;
}
.zcsbot-h-left { display: flex; align-items: center; gap: 11px; min-width: 0; }
.zcsbot-brandmark {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; flex: 0 0 40px;
  backdrop-filter: blur(4px);
}
.zcsbot-logo    { width: 100%; height: 100%; object-fit: contain; padding: 7px; }
.zcsbot-logo-fb { font-weight: 700; font-size: 17px; color: #fff; }
.zcsbot-h-titles { min-width: 0; }
.zcsbot-title {
  font-weight: 700; font-size: 15.5px; letter-spacing: .1px; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.zcsbot-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: rgba(255,255,255,.85); margin-top: 1px; }
.zcsbot-status-dot { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 0 rgba(74,222,128,.6); animation: zcsbot-pulse 2s infinite; }
@keyframes zcsbot-pulse { 0%{box-shadow:0 0 0 0 rgba(74,222,128,.5);} 70%{box-shadow:0 0 0 6px rgba(74,222,128,0);} 100%{box-shadow:0 0 0 0 rgba(74,222,128,0);} }

.zcsbot-h-actions { display: flex; align-items: center; gap: 4px; }
.zcsbot-icon-btn {
  width: 34px; height: 34px;
  border: none; background: transparent; color: rgba(255,255,255,.9);
  border-radius: 10px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s ease;
}
.zcsbot-icon-btn:hover { background: rgba(255,255,255,.18); }
.zcsbot-icon-btn svg { width: 18px; height: 18px; }

/* ── Body ──────────────────────────────────────────────────────────────── */
.zcsbot-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 16px 8px;
  display: flex; flex-direction: column; gap: 12px;
  background:
    radial-gradient(120% 80% at 50% 0%, var(--z-elev) 0%, var(--z-panel) 60%);
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.zcsbot-body::-webkit-scrollbar { width: 5px; }
.zcsbot-body::-webkit-scrollbar-thumb { background: var(--z-border); border-radius: 5px; }
.zcsbot-body::-webkit-scrollbar-track { background: transparent; }

/* ── Messages ──────────────────────────────────────────────────────────── */
.zcsbot-msg { display: flex; animation: zcsbot-in .26s cubic-bezier(.22,1,.36,1); }
@keyframes zcsbot-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.zcsbot-row { display: flex; align-items: flex-end; gap: 9px; max-width: 90%; }
.zcsbot-msg.user  { justify-content: flex-end; }
.zcsbot-msg.user  .zcsbot-row { flex-direction: row-reverse; margin-left: auto; }
.zcsbot-msg.assistant { justify-content: flex-start; }

.zcsbot-av {
  width: 30px; height: 30px; flex: 0 0 30px;
  border-radius: 50%;
  background: var(--z-accent-soft);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.zcsbot-av-img { width: 100%; height: 100%; object-fit: contain; padding: 5px; }
.zcsbot-av-fallback { font-size: 13px; font-weight: 700; color: var(--z-accent); }

.zcsbot-bubble {
  padding: 11px 14px;
  font-size: 14.5px;
  line-height: 1.5;
  border-radius: 18px;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-width: 100%;
}
.zcsbot-msg.assistant .zcsbot-bubble {
  background: var(--z-bot-bubble);
  color: var(--z-text);
  border-bottom-left-radius: 6px;
}
.zcsbot-msg.user .zcsbot-bubble {
  background: var(--z-user-bubble);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 2px 10px rgba(99,102,241,.28);
}

/* Typing dots */
.zcsbot-bubble-typing { padding: 13px 15px; }
.zcsbot-dots { display: flex; gap: 5px; }
.zcsbot-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--z-text-soft); opacity: .5;
  animation: zcsbot-bounce 1.2s infinite ease-in-out;
}
.zcsbot-dot:nth-child(2) { animation-delay: .16s; }
.zcsbot-dot:nth-child(3) { animation-delay: .32s; }
@keyframes zcsbot-bounce { 0%,80%,100%{transform:translateY(0);opacity:.4;} 40%{transform:translateY(-5px);opacity:.9;} }

/* ── Suggestion chips ──────────────────────────────────────────────────── */
.zcsbot-suggest { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 0 4px 39px; animation: zcsbot-in .3s ease; }
.zcsbot-chip {
  border: 1px solid var(--z-border);
  background: var(--z-panel);
  color: var(--z-text);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.zcsbot-chip:hover { background: var(--z-accent-soft); border-color: var(--z-accent); color: var(--z-accent); }
.zcsbot-chip:active { transform: scale(.97); }

/* ── Lead form ─────────────────────────────────────────────────────────── */
.zcsbot-lead {
  background: var(--z-elev);
  border: 1px solid var(--z-border);
  border-radius: 16px;
  padding: 14px;
  width: 100%;
}
.zcsbot-lead-title { font-weight: 700; font-size: 15px; color: var(--z-text); margin-bottom: 3px; }
.zcsbot-lead-sub   { font-size: 12.5px; color: var(--z-text-soft); line-height: 1.45; margin-bottom: 11px; }
.zcsbot-field {
  width: 100%;
  font-family: inherit; font-size: 13.5px;
  color: var(--z-text);
  background: var(--z-panel);
  border: 1px solid var(--z-border);
  border-radius: 11px;
  padding: 9px 12px;
  margin-bottom: 8px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.zcsbot-field:focus { border-color: var(--z-accent); box-shadow: 0 0 0 3px var(--z-accent-soft); }
.zcsbot-field-area  { resize: vertical; min-height: 52px; }
.zcsbot-lead-btn {
  width: 100%;
  font-family: inherit; font-size: 14px; font-weight: 600;
  color: #fff; background: var(--z-user-bubble);
  border: none; border-radius: 11px;
  padding: 11px; cursor: pointer; margin-top: 2px;
  transition: transform .1s ease, opacity .15s ease;
}
.zcsbot-lead-btn:hover  { opacity: .94; }
.zcsbot-lead-btn:active { transform: scale(.98); }
.zcsbot-lead-btn:disabled { opacity: .6; cursor: default; }
.zcsbot-lead-status { font-size: 12.5px; color: var(--z-text-soft); margin-top: 8px; text-align: center; }
.zcsbot-lead-status.err { color: #ef4444; }
.zcsbot-lead-success { display: flex; align-items: center; gap: 9px; color: var(--z-text); font-size: 14px; font-weight: 500; padding: 4px 2px; }
.zcsbot-lead-success .zcsbot-glyph { color: #22c55e; }

/* ── Footer ────────────────────────────────────────────────────────────── */
.zcsbot-footer { padding: 12px 14px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--z-border); background: var(--z-panel); flex-shrink: 0; }
.zcsbot-input-wrap {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--z-elev);
  border: 1px solid var(--z-border);
  border-radius: 16px;
  padding: 5px 5px 5px 14px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.zcsbot-input-wrap:focus-within { border-color: var(--z-accent); box-shadow: 0 0 0 3px var(--z-accent-soft); }
.zcsbot-input {
  flex: 1;
  border: none; background: transparent; outline: none; resize: none;
  font-family: inherit; font-size: 14.5px; line-height: 1.45;
  color: var(--z-text);
  padding: 7px 0;
  max-height: 110px;
}
.zcsbot-input::placeholder { color: var(--z-text-soft); }
.zcsbot-send {
  width: 38px; height: 38px; flex: 0 0 38px;
  border: none; border-radius: 12px; cursor: pointer;
  background: var(--z-user-bubble); color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: transform .1s ease, opacity .15s ease;
}
.zcsbot-send:hover  { opacity: .94; }
.zcsbot-send:active { transform: scale(.92); }
.zcsbot-send:disabled { background: var(--z-border); color: var(--z-text-soft); cursor: default; }
.zcsbot-send svg { width: 17px; height: 17px; }

.zcsbot-glyph { display: inline-flex; align-items: center; justify-content: center; line-height: 0; }

/* ── Overlay (mobile) ──────────────────────────────────────────────────── */
.zcsbot-overlay { position: fixed; inset: 0; background: rgba(15,18,28,.45); opacity: 0; pointer-events: none; transition: opacity .22s ease; }
.zcsbot-overlay.open { opacity: 1; pointer-events: auto; }
body.zcsbot-lock { overflow: hidden !important; }

@media (min-width: 521px) { .zcsbot-overlay { display: none; } }

/* ── Mobile ────────────────────────────────────────────────────────────── */
@media (max-width: 520px) {
  .zcsbot-root { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); }
  .zcsbot-panel {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    width: 100vw; max-width: 100vw;
    height: 88vh; height: 88dvh; max-height: none;
    border-radius: 22px 22px 0 0;
    transform-origin: bottom center;
    transform: translateY(100%);
  }
  .zcsbot-panel.open { transform: translateY(0); }
  .zcsbot-input { font-size: 16px; } /* prevent iOS zoom */
  .zcsbot-row { max-width: 94%; }
}

/* ── Reduced motion ────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .zcsbot-root *, .zcsbot-root *::before, .zcsbot-root *::after {
    animation-duration: .001ms !important;
    transition-duration: .05ms !important;
  }
  .zcsbot-panel { transition: opacity .1s ease; transform: none; }
}
