/* ═══ DTech Chat Widget ═════════════════════════════════════ */

/* ── Bubble ─────────────────────────────────────────────── */
#chat-bubble {
  position: fixed; bottom: 24px; right: 24px;
  width: 58px; height: 58px; border-radius: 50%;
  background: linear-gradient(135deg, #6C47FF, #4c1d95);
  border: none; cursor: pointer; z-index: 9990;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 28px rgba(108,71,255,.5);
  transition: transform .3s cubic-bezier(.34,1.56,.64,1), box-shadow .3s;
  animation: bubblePop .5s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes bubblePop { from{transform:scale(0);opacity:0} to{transform:scale(1);opacity:1} }
#chat-bubble:hover { transform: scale(1.12); box-shadow: 0 12px 36px rgba(108,71,255,.6); }
.cb-icon { color: white; font-size: 1.35rem; display: flex; align-items: center; justify-content: center; }

.chat-badge {
  position: absolute; top: -4px; right: -4px;
  background: #FF6B35; color: white;
  width: 20px; height: 20px; border-radius: 50%;
  font-size: .65rem; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid white; animation: badgePulse 2s infinite;
}
@keyframes badgePulse { 0%,100%{transform:scale(1)} 50%{transform:scale(1.2)} }

.chat-status-dot {
  position: absolute; bottom: 3px; right: 3px;
  width: 13px; height: 13px; border-radius: 50%; border: 2px solid white;
}
.chat-status-dot.online  { background: #22c55e; }
.chat-status-dot.offline { background: #94a3b8; }

/* ── Window ─────────────────────────────────────────────── */
.chat-window {
  position: fixed; bottom: 92px; right: 24px;
  width: 360px;
  /* Use flex column + fixed height so footer is always visible */
  height: 540px;
  max-height: calc(100vh - 120px);
  background: white; border-radius: 20px;
  box-shadow: 0 24px 80px rgba(0,0,0,.2);
  z-index: 9989;
  display: flex; flex-direction: column;
  overflow: hidden;
  transform: scale(.88) translateY(24px);
  opacity: 0; pointer-events: none;
  transform-origin: bottom right;
  transition: transform .35s cubic-bezier(.34,1.56,.64,1), opacity .25s ease;
}
.chat-window.open {
  transform: scale(1) translateY(0);
  opacity: 1; pointer-events: all;
}

/* ── Header ─────────────────────────────────────────────── */
.chat-header {
  background: linear-gradient(135deg, #6C47FF, #4c1d95);
  padding: .875rem 1rem; display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
}
.chat-header-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; color: white; position: relative; flex-shrink: 0;
}
.chat-header-status-dot {
  position: absolute; bottom: 1px; right: 1px;
  width: 10px; height: 10px; border-radius: 50%; border: 2px solid #4c1d95;
}
.chat-header-status-dot.online  { background: #22c55e; }
.chat-header-status-dot.offline { background: #94a3b8; }
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-name   { font-weight: 800; color: white; font-size: .9rem; font-family: 'Syne', sans-serif; }
.chat-header-status { font-size: .7rem; color: rgba(255,255,255,.78); margin-top: 1px; }
.chat-action-btn {
  background: rgba(255,255,255,.15); border: none; color: white;
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer;
  font-size: .95rem; display: flex; align-items: center; justify-content: center;
  transition: background .2s; flex-shrink: 0;
}
.chat-action-btn:hover { background: rgba(255,255,255,.28); }

/* ── Body ───────────────────────────────────────────────── */
.chat-body {
  flex: 1; overflow-y: auto;
  padding: .875rem; display: flex; flex-direction: column; gap: .5rem;
  background: #f8f9fe; min-height: 0; /* critical for flex scroll */
}
.chat-body::-webkit-scrollbar { width: 3px; }
.chat-body::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 2px; }

/* ── Messages ───────────────────────────────────────────── */
.chat-msg {
  display: flex; align-items: flex-end; gap: 7px;
  animation: msgIn .28s ease both;
  max-width: 100%;
}
@keyframes msgIn { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:none} }
.chat-msg.user { flex-direction: row-reverse; }

.chat-msg-avatar {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: .65rem; font-weight: 800;
}
.chat-bubble-msg {
  max-width: 78%; padding: .55rem .85rem; font-size: .85rem;
  line-height: 1.55; word-break: break-word; position: relative;
  border-radius: 16px;
}
.chat-msg.bot   .chat-bubble-msg,
.chat-msg.admin .chat-bubble-msg {
  background: white; color: #1a1a2e;
  border: 1px solid #e8ecf3; border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
}
.chat-msg.user .chat-bubble-msg {
  background: linear-gradient(135deg, #6C47FF, #4c1d95);
  color: white; border-bottom-right-radius: 4px;
}
.chat-msg-time {
  font-size: .62rem; color: #94a3b8; margin-top: 2px;
  text-align: right; padding: 0 2px;
}
.chat-admin-badge {
  display: inline-flex; align-items: center;
  background: #00D4AA; color: white;
  font-size: .58rem; padding: 1px 6px; border-radius: 99px;
  font-weight: 800; margin-left: 5px; vertical-align: middle;
}

/* ── Typing ─────────────────────────────────────────────── */
#chat-typing .typing-dots { display: flex; gap: 4px; padding: .3rem 0; }
.typing-dots span {
  width: 7px; height: 7px; border-radius: 50%; background: #cbd5e1;
  animation: typeBounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .18s; }
.typing-dots span:nth-child(3) { animation-delay: .36s; }
@keyframes typeBounce {
  0%,60%,100% { transform: translateY(0); }
  30% { transform: translateY(-6px); background: #6C47FF; }
}

/* ── Quick suggestions ──────────────────────────────────── */
.chat-suggestions {
  display: flex; flex-wrap: wrap; gap: 5px;
  padding: .4rem 0 .2rem;
}
.chat-suggestion {
  background: white; border: 1.5px solid #e0d9ff;
  color: #6C47FF; border-radius: 99px;
  padding: 5px 12px; font-size: .75rem; font-weight: 600;
  cursor: pointer; transition: all .18s; font-family: inherit;
}
.chat-suggestion:hover { background: #6C47FF; color: white; border-color: #6C47FF; }

/* ── Footer ─────────────────────────────────────────────── */
.chat-footer {
  flex-shrink: 0; border-top: 1px solid #f1f5f9;
  background: white;
}
.chat-input-area {
  display: flex; align-items: center; gap: 7px;
  padding: .625rem .875rem;
}
.chat-input-field {
  flex: 1; padding: 9px 13px;
  border: 1.5px solid #e2e8f0; border-radius: 11px;
  font-size: .85rem; outline: none;
  font-family: inherit; transition: border-color .18s;
  width: 100%; background: white; color: #1a1a2e;
}
.chat-input-field:focus { border-color: #6C47FF; }
.chat-input-field::placeholder { color: #94a3b8; }
textarea.chat-input-field { resize: none; min-height: 70px; }

.chat-send-btn {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  background: #6C47FF; border: none; color: white;
  cursor: pointer; font-size: .9rem;
  display: flex; align-items: center; justify-content: center;
  transition: transform .18s, background .18s;
}
.chat-send-btn:hover:not(:disabled) { background: #4c1d95; transform: scale(1.06); }
.chat-send-btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }

.chat-human-btn {
  width: 100%; padding: 8px; border-radius: 9px;
  background: rgba(108,71,255,.07); border: 1.5px dashed #6C47FF;
  color: #6C47FF; font-weight: 700; font-size: .78rem;
  cursor: pointer; transition: all .18s; font-family: inherit;
  display: flex; align-items: center; justify-content: center; gap: 7px;
}
.chat-human-btn:hover { background: #6C47FF; color: white; }

.chat-footer-note {
  text-align: center; font-size: .62rem; color: #cbd5e1;
  padding: 0 1rem .5rem;
}

/* ── Mobile ─────────────────────────────────────────────── */
@media (max-width: 480px) {
  .chat-window {
    width: calc(100vw - 16px);
    right: 8px; bottom: 82px;
    height: calc(100vh - 110px);
    max-height: calc(100vh - 100px);
    border-radius: 16px;
  }
  #chat-bubble { right: 16px; bottom: 18px; }
}

/* ══════════════════════════════════════════════════════════
   ADMIN LIVE CHAT PANEL — Modern Design
══════════════════════════════════════════════════════════ */
.lcp-wrap {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: calc(100vh - 164px);
  min-height: 520px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 4px 32px rgba(0,0,0,.08);
  border: 1px solid var(--border-light);
}

/* Sidebar */
.lcp-sidebar {
  background: white;
  border-right: 1px solid var(--border-light);
  display: flex; flex-direction: column; overflow: hidden;
}
.lcp-sidebar-head {
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.lcp-sidebar-title { font-family: var(--font-display); font-size: .9rem; font-weight: 800; }
.lcp-search {
  padding: .625rem .875rem;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}
.lcp-search input {
  width: 100%; padding: 8px 12px;
  border: 1.5px solid var(--border-light); border-radius: 10px;
  font-size: .8rem; outline: none; font-family: var(--font-body);
  transition: border-color .2s;
}
.lcp-search input:focus { border-color: var(--accent); }
.lcp-sessions { overflow-y: auto; flex: 1; }
.lcp-sessions::-webkit-scrollbar { width: 3px; }
.lcp-sessions::-webkit-scrollbar-thumb { background: var(--border-light); }

.lcp-session-item {
  padding: .875rem 1rem; border-bottom: 1px solid #f8f9fe;
  cursor: pointer; transition: background .15s; display: flex; align-items: center; gap: 10px;
  position: relative;
}
.lcp-session-item:hover { background: #f8f9fe; }
.lcp-session-item.active { background: rgba(108,71,255,.06); }
.lcp-session-item.active::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--accent); border-radius: 0 2px 2px 0;
}
.lcp-avatar {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: white; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 900; font-size: .95rem;
}
.lcp-session-info { flex: 1; min-width: 0; }
.lcp-session-name { font-weight: 700; font-size: .82rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lcp-session-preview { font-size: .72rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.lcp-session-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; flex-shrink: 0; }
.lcp-session-time { font-size: .65rem; color: var(--text-light); }
.lcp-unread-badge {
  background: var(--accent); color: white;
  width: 18px; height: 18px; border-radius: 50%;
  font-size: .6rem; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
}
.lcp-mode-tag {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 1px 6px; border-radius: 99px;
  font-size: .58rem; font-weight: 700;
}
.lcp-mode-tag.bot    { background: rgba(108,71,255,.1); color: var(--accent); }
.lcp-mode-tag.human  { background: rgba(0,212,170,.1);  color: var(--accent-3); }
.lcp-mode-tag.offline{ background: rgba(239,68,68,.1);  color: #ef4444; }

/* Main panel */
.lcp-main {
  background: #f8f9fe;
  display: flex; flex-direction: column; overflow: hidden;
}
.lcp-topbar {
  background: white; padding: .875rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0; gap: 1rem;
}
.lcp-user-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.lcp-user-avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: white; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 900;
}
.lcp-user-name { font-weight: 800; font-size: .875rem; }
.lcp-user-meta { font-size: .72rem; color: var(--text-muted); }
.lcp-topbar-actions { display: flex; gap: .5rem; flex-shrink: 0; }

.lcp-messages {
  flex: 1; overflow-y: auto; padding: 1.25rem;
  display: flex; flex-direction: column; gap: .5rem; min-height: 0;
}
.lcp-messages::-webkit-scrollbar { width: 4px; }
.lcp-messages::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 2px; }

.lcp-msg { display: flex; align-items: flex-end; gap: 8px; }
.lcp-msg.user  { flex-direction: row; }
.lcp-msg.admin, .lcp-msg.bot { flex-direction: row-reverse; }
.lcp-msg-avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: .7rem; font-weight: 700;
}
.lcp-msg.user  .lcp-msg-avatar { background: #e8e3ff; color: var(--accent); }
.lcp-msg.admin .lcp-msg-avatar { background: var(--accent); color: white; }
.lcp-msg.bot   .lcp-msg-avatar { background: #f1f5f9; color: var(--text-muted); }
.lcp-msg-bubble {
  max-width: 72%; padding: .55rem .875rem; font-size: .85rem; line-height: 1.55;
  word-break: break-word; border-radius: 14px;
}
.lcp-msg.user  .lcp-msg-bubble { background: white; border: 1px solid #e8ecf3; border-bottom-left-radius: 4px; color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.04); }
.lcp-msg.admin .lcp-msg-bubble { background: linear-gradient(135deg, var(--accent), #4c1d95); color: white; border-bottom-right-radius: 4px; }
.lcp-msg.bot   .lcp-msg-bubble { background: #f1f5f9; color: var(--text-muted); border-bottom-right-radius: 4px; font-style: italic; font-size: .8rem; }
.lcp-msg-time { font-size: .62rem; color: #94a3b8; margin-top: 2px; padding: 0 2px; }

.lcp-date-divider {
  display: flex; align-items: center; gap: .75rem;
  margin: .5rem 0; color: var(--text-light); font-size: .7rem;
}
.lcp-date-divider::before, .lcp-date-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border-light);
}

.lcp-input-area {
  background: white; border-top: 1px solid var(--border-light);
  padding: .875rem 1.25rem; display: flex; gap: .75rem; align-items: flex-end; flex-shrink: 0;
}
.lcp-input {
  flex: 1; border: 1.5px solid var(--border-light); border-radius: 14px;
  padding: 10px 14px; font-size: .875rem; resize: none; outline: none;
  font-family: var(--font-body); line-height: 1.5; transition: border-color .2s;
  max-height: 100px; overflow-y: auto;
}
.lcp-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(108,71,255,.08); }
.lcp-send-btn {
  width: 42px; height: 42px; border-radius: 12px; flex-shrink: 0;
  background: var(--accent); border: none; color: white; font-size: 1rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: transform .2s, background .2s;
}
.lcp-send-btn:hover { background: #4c1d95; transform: scale(1.05); }
.lcp-send-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.lcp-no-session {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1rem; color: var(--text-muted);
}
.lcp-no-session-icon {
  width: 72px; height: 72px; border-radius: 50%;
  background: var(--bg-2); display: flex; align-items: center; justify-content: center;
  font-size: 1.75rem; color: var(--text-light);
}

/* Online toggle */
.lcp-toggle-wrap { display: flex; align-items: center; gap: 10px; }
.lcp-toggle { position: relative; width: 46px; height: 24px; cursor: pointer; }
.lcp-toggle input { opacity: 0; width: 0; height: 0; }
.lcp-toggle-slider {
  position: absolute; inset: 0; border-radius: 99px; background: #cbd5e1; transition: background .3s;
}
.lcp-toggle-slider::before {
  content: ''; position: absolute; height: 18px; width: 18px;
  left: 3px; bottom: 3px; border-radius: 50%; background: white;
  transition: transform .3s; box-shadow: 0 1px 4px rgba(0,0,0,.15);
}
.lcp-toggle input:checked + .lcp-toggle-slider { background: #22c55e; }
.lcp-toggle input:checked + .lcp-toggle-slider::before { transform: translateX(22px); }

/* Stats row */
.lcp-stats-row {
  display: flex; gap: 1rem; padding: .875rem 1.25rem;
  border-bottom: 1px solid var(--border-light); background: white; flex-shrink: 0;
}
.lcp-stat {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-2); border-radius: 10px;
  padding: .5rem .875rem; font-size: .8rem; color: var(--text-muted);
}
.lcp-stat strong { font-weight: 800; color: var(--text); font-size: .9rem; }

@media (max-width: 900px) {
  .lcp-wrap { grid-template-columns: 1fr; height: auto; }
  .lcp-sidebar { height: 280px; border-right: none; border-bottom: 1px solid var(--border-light); }
  .lcp-main { min-height: 400px; }
}
