/* =============================================================================
   CyberHQ AMC Chatbot — Minimal White UI
   Matches header dropdown: white bg, soft shadow, rounded, clean zinc tones
   ============================================================================= */

/* ── RESET ──────────────────────────────────────────────────────────────────── */
:where(#ch-fab, #ch-panel, #ch-panel *, #ch-fab *) {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── FLOATING BUTTON ─────────────────────────────────────────────────────────── */
#ch-fab {
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: #111827;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  box-shadow: 0 4px 18px rgba(0,0,0,0.20);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  outline: none;
}

#ch-fab:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 24px rgba(0,0,0,0.26);
}

.ch-fab-icon {
  position: relative;
  width: 22px;
  height: 22px;
}

.ch-fab-chat,
.ch-fab-close {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #fff;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.ch-fab-close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.7);
}

#ch-fab.ch-open .ch-fab-chat {
  opacity: 0;
  transform: rotate(90deg) scale(0.7);
}

#ch-fab.ch-open .ch-fab-close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

/* Badge */
.ch-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 16px;
  height: 16px;
  background: #10b981;
  border-radius: 50%;
  border: 2px solid #fff;
  font-size: 8.5px;
  font-weight: 800;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

/* ── PANEL ───────────────────────────────────────────────────────────────────── */
#ch-panel {
  position: fixed;
  bottom: 86px;
  left: 24px;
  width: 350px;
  height: 520px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 1.5rem;
  box-shadow: 0 20px 50px -12px rgba(0,0,0,0.14), 0 4px 16px rgba(0,0,0,0.06);
  z-index: 9997;
  display: flex;
  flex-direction: column;
  overflow: hidden;

  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.97);
  transform-origin: bottom left;
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;

  font-size: 13px;
  color: #111827;
}

#ch-panel.ch-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ── HEADER ──────────────────────────────────────────────────────────────────── */
.ch-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: #fff;
  border-bottom: 1px solid #f3f4f6;
  padding: 10px 14px;
}

.ch-header-top {
  order: 2;
  display: flex;
  align-items: center;
}

.ch-brand {
  display: none !important;
}

.ch-avatar {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: #f0fdf4;
  border: 1.5px solid #d1fae5;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #10b981;
  font-size: 16px;
  flex-shrink: 0;
}

.ch-brand-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ch-brand-name {
  font-size: 12.5px;
  font-weight: 700;
  color: #111827;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.ch-brand-status {
  font-size: 10px;
  color: #6b7280;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
  line-height: 1.2;
}

.ch-status-dot {
  width: 6px;
  height: 6px;
  background: #10b981;
  border-radius: 50%;
  flex-shrink: 0;
  animation: ch-pulse-dot 2s ease-in-out infinite;
}

@keyframes ch-pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.ch-header-actions {
  display: flex;
  align-items: center;
}

.ch-icon-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: 7px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9ca3af;
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.ch-icon-btn:hover {
  background: #f3f4f6;
  color: #374151;
}

/* ── LANGUAGE BAR ─────────────────────────────────────────────────────────────── */
.ch-lang-bar {
  order: 1;
  display: flex;
  gap: 6px;
  padding: 0;
}

.ch-lang-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid #e5e7eb;
  background: #fff;
  font-size: 11px;
  font-weight: 600;
  color: #6b7280;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  line-height: 1.2;
}

.ch-lang-btn:hover {
  background: #f9fafb;
  color: #374151;
}

.ch-lang-btn.ch-lang-active {
  background: #111827;
  color: #fff;
  border-color: #111827;
}

/* ── QUICK REPLIES ────────────────────────────────────────────────────────────── */
.ch-quick-replies {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-bottom: 1px solid #f3f4f6;
  flex-shrink: 0;
}

.ch-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 20px;
  border: 1px solid #e5e7eb;
  background: #fff;
  font-size: 10px;
  font-weight: 600;
  color: #374151;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.2;
}

.ch-chip:hover {
  background: #f0fdf4;
  border-color: #a7f3d0;
  color: #059669;
}

/* ── MESSAGES ─────────────────────────────────────────────────────────────────── */
.ch-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  min-height: 0;
}

.ch-messages::-webkit-scrollbar {
  width: 3px;
}

.ch-messages::-webkit-scrollbar-track {
  background: transparent;
}

.ch-messages::-webkit-scrollbar-thumb {
  background: #e5e7eb;
  border-radius: 3px;
}

/* Message rows */
.ch-msg-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
}

.ch-msg-row.ch-user {
  flex-direction: row-reverse;
}

/* Bot avatar in messages */
.ch-msg-avatar {
  width: 24px;
  height: 24px;
  min-width: 24px;
  border-radius: 7px;
  background: #f0fdf4;
  border: 1px solid #d1fae5;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #10b981;
  font-size: 11px;
  flex-shrink: 0;
  margin-top: 2px;
}

/* Content wrapper next to avatar */
.ch-msg-row > div:not(.ch-msg-avatar) {
  max-width: 80%;
  min-width: 0;
}

/* Bubbles */
.ch-bubble {
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 12.5px;
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
}

.ch-bubble strong {
  font-weight: 700;
}

.ch-bubble em {
  font-style: italic;
}

.ch-bubble code {
  background: rgba(0,0,0,0.05);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 11.5px;
  word-break: break-all;
}

.ch-msg-row.ch-bot .ch-bubble {
  background: #f9fafb;
  border: 1px solid #f0f0f0;
  border-bottom-left-radius: 4px;
  color: #1f2937;
}

.ch-msg-row.ch-user .ch-bubble {
  background: #111827;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ch-error-bubble {
  background: #fef2f2 !important;
  border-color: #fecaca !important;
  color: #991b1b !important;
}

/* Timestamp */
.ch-timestamp {
  font-size: 9px;
  color: #c4c9d0;
  margin-top: 3px;
  font-weight: 500;
  padding: 0 2px;
}

.ch-msg-row.ch-user .ch-timestamp {
  text-align: right;
}

/* ── TYPING INDICATOR ──────────────────────────────────────────────────────────── */
.ch-typing {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.ch-typing-dots {
  background: #f9fafb;
  border: 1px solid #f0f0f0;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 10px 14px;
  display: flex;
  gap: 4px;
  align-items: center;
}

.ch-typing-dots span {
  width: 5px;
  height: 5px;
  background: #cbd5e1;
  border-radius: 50%;
  display: inline-block;
  animation: ch-bounce 1.2s ease-in-out infinite;
}

.ch-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.ch-typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ch-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* ── FOOTER / INPUT ────────────────────────────────────────────────────────────── */
.ch-footer {
  flex-shrink: 0;
  padding: 10px 12px 11px;
  border-top: 1px solid #f3f4f6;
  background: #fff;
}

.ch-input-row {
  display: flex;
  align-items: center;
  gap: 7px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 7px 7px 7px 12px;
  transition: border-color 0.15s, background 0.15s;
}

.ch-input-row:focus-within {
  border-color: #d1d5db;
  background: #fff;
}

#ch-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  outline: none;
  font-size: 12.5px;
  font-weight: 500;
  color: #111827;
  resize: none;
  line-height: 1.5;
  max-height: 80px;
  overflow-y: auto;
  display: block;
}

#ch-input::placeholder {
  color: #9ca3af;
  font-weight: 400;
}

#ch-send {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 9px;
  background: #111827;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

#ch-send:hover {
  background: #000;
  transform: scale(1.05);
}

#ch-send:disabled {
  background: #e5e7eb;
  color: #9ca3af;
  cursor: not-allowed;
  transform: none;
}

/* Admin rebuild button (hidden by default) */
#ch-rebuild-btn {
  display: none;
  width: 100%;
  margin-top: 7px;
  padding: 6px 10px;
  border: 1px dashed #d1d5db;
  border-radius: 8px;
  background: transparent;
  font-size: 10.5px;
  color: #6b7280;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.15s;
  text-align: center;
}

#ch-rebuild-btn.ch-show { display: block; }

#ch-rebuild-btn:hover {
  background: #f9fafb;
  color: #374151;
}

.ch-footer-note {
  font-size: 9.5px;
  color: #c4c9d0;
  text-align: center;
  margin-top: 7px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

/* ── MOBILE ──────────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #ch-panel {
    width: calc(100vw - 28px);
    left: 14px;
    bottom: 78px;
    height: 480px;
    border-radius: 1.25rem;
  }

  #ch-fab {
    left: 16px;
    bottom: 16px;
  }

  .ch-chip {
    font-size: 9.5px;
    padding: 4px 8px;
  }
}
