/* Chat Widget CSS - taplai.com */
/* ===== Desktop panel (≥1200px) ===== */
.chat-widget { --chat-primary: #2563eb; --chat-bg: #f8fafc; --chat-header: #1e293b; }

body.chat-active { padding-right: 340px; }
body.chat-active.chat-collapsed { padding-right: 0; }

.chat-panel {
  position: fixed; top: 0; right: 0; width: 340px;
  height: 100vh;
  background: #fff; border-radius: 0;
  box-shadow: -4px 0 24px rgba(0,0,0,.1);
  display: flex; flex-direction: column; z-index: 999;
  border-left: 1px solid #e2e8f0; overflow: hidden;
  transition: transform .3s, opacity .3s;
}
.chat-panel.collapsed { transform: translateX(100%); opacity: 0; pointer-events: none; }

.chat-panel-header {
  background: var(--chat-header); color: #fff;
  padding: 12px 16px; display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; user-select: none;
}
.chat-header-info { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
.chat-header-icon { color: #60a5fa; font-size: 16px; }
.chat-online-dot { width: 8px; height: 8px; background: #22c55e; border-radius: 50%; animation: chat-pulse 2s infinite; }
@keyframes chat-pulse { 0%,100%{opacity:1} 50%{opacity:.5} }

.chat-toggle-btn {
  background: none; border: none; color: #fff; cursor: pointer;
  font-size: 14px; padding: 4px 8px; border-radius: 6px; transition: background .2s;
}
.chat-toggle-btn:hover { background: rgba(255,255,255,.15); }

.chat-panel-body { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.chat-messages {
  flex: 1; overflow-y: auto; padding: 12px; background: var(--chat-bg);
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

.chat-loading { text-align: center; color: #94a3b8; padding: 20px; font-size: 13px; }

.chat-msg { margin-bottom: 10px; animation: chat-fadein .3s; }
@keyframes chat-fadein { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:translateY(0)} }

.chat-msg-bubble {
  display: inline-block; max-width: 85%; padding: 8px 12px;
  border-radius: 12px; font-size: 13px; line-height: 1.5;
  word-wrap: break-word; position: relative;
}
.chat-msg-name { font-size: 11px; font-weight: 700; margin-bottom: 2px; color: #64748b; }
.chat-msg-time { font-size: 10px; color: #94a3b8; margin-left: 6px; }

.chat-msg-other .chat-msg-bubble { background: #fff; border: 1px solid #e2e8f0; border-bottom-left-radius: 4px; }
.chat-msg-self .chat-msg-bubble { background: var(--chat-primary); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg-self .chat-msg-name { color: rgba(255,255,255,.7); }
.chat-msg-self .chat-msg-time { color: rgba(255,255,255,.5); }
.chat-msg-self { text-align: right; }
.chat-msg-self .chat-msg-name { display: inline; }

.chat-msg-admin .chat-msg-bubble { border-left: 3px solid #ef4444; }

/* Input area */
.chat-input-area { padding: 10px 12px; border-top: 1px solid #e2e8f0; background: #fff; }
.chat-user-badge {
  display: flex; align-items: center; gap: 6px; padding: 4px 10px; margin-bottom: 8px;
  background: #f1f5f9; border-radius: 8px; font-size: 12px; font-weight: 600; color: #64748b;
}
.chat-input-row { display: flex; gap: 6px; align-items: center; }
.chat-text-input {
  flex: 1; padding: 8px 12px; border: 1px solid #e2e8f0; border-radius: 8px;
  font-size: 13px; outline: none; transition: border-color .2s;
}
.chat-text-input:focus { border-color: var(--chat-primary); }
.chat-send-btn {
  width: 36px; height: 36px; border: none; border-radius: 8px;
  background: var(--chat-primary); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s; flex-shrink: 0;
}
.chat-send-btn:hover { background: #1d4ed8; }
.chat-send-btn:disabled { background: #94a3b8; cursor: not-allowed; }

/* Chat content wrapper */
.chat-content { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* Welcome bar (bottom area, replaces input when not joined) */
.chat-welcome-bar {
  padding: 14px 16px; border-top: 1px solid #e2e8f0; background: #fff;
  text-align: center;
}
.chat-welcome-bar-title { font-size: 13px; font-weight: 600; color: #475569; margin-bottom: 10px; }
.chat-welcome-buttons { display: flex; gap: 8px; margin-bottom: 10px; }
.chat-welcome-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 12px; border: none; border-radius: 8px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .2s;
}
.chat-welcome-guest { background: #f1f5f9; color: #475569; }
.chat-welcome-guest:hover { background: #e2e8f0; }
.chat-welcome-login { background: var(--chat-primary); color: #fff; }
.chat-welcome-login:hover { background: #1d4ed8; }
.chat-welcome-register {
  font-size: 11px; color: #94a3b8; text-decoration: none; display: block;
}
.chat-welcome-register:hover { color: var(--chat-primary); }
.chat-welcome-register strong { color: var(--chat-primary); }

/* Welcome screen (full panel, not used now but kept for reference) */
.chat-welcome {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center; background: var(--chat-bg);
}
.chat-welcome-icon {
  width: 64px; height: 64px; border-radius: 50%; background: #dbeafe;
  display: flex; align-items: center; justify-content: center; margin-bottom: 16px;
}
.chat-welcome-icon i { font-size: 28px; color: var(--chat-primary); }
.chat-welcome-title { font-size: 16px; font-weight: 700; color: #1e293b; margin-bottom: 6px; }
.chat-welcome-sub { font-size: 13px; color: #64748b; margin-bottom: 24px; }

/* Banned screen */
.chat-banned {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center; background: #fef2f2;
}
.chat-banned-icon {
  width: 64px; height: 64px; border-radius: 50%; background: #fee2e2;
  display: flex; align-items: center; justify-content: center; margin-bottom: 16px;
}
.chat-banned-icon i { font-size: 28px; color: #ef4444; }
.chat-banned-title { font-size: 16px; font-weight: 700; color: #dc2626; margin-bottom: 6px; }
.chat-banned-sub { font-size: 13px; color: #991b1b; }

/* ===== Mobile FAB (<1200px) ===== */
.chat-fab {
  display: none; position: fixed; bottom: 20px; right: 20px;
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: var(--chat-primary); color: #fff; font-size: 22px;
  cursor: pointer; z-index: 999; box-shadow: 0 4px 16px rgba(37,99,235,.4);
  transition: transform .2s; align-items: center; justify-content: center;
}
.chat-fab:hover { transform: scale(1.08); }
.chat-fab-badge {
  position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px;
  background: #ef4444; color: #fff; border-radius: 10px; font-size: 11px;
  font-weight: 700; display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}

/* ===== Mobile modal ===== */
.chat-modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 1001; align-items: flex-end; justify-content: center;
}
.chat-modal-overlay.show { display: flex; }
.chat-modal {
  width: 100%; max-width: 500px; height: 80vh; background: #fff;
  border-radius: 16px 16px 0 0; display: flex; flex-direction: column;
  animation: chat-slideup .3s;
}
@keyframes chat-slideup { from{transform:translateY(100%)} to{transform:translateY(0)} }
.chat-modal-header {
  padding: 14px 18px; background: var(--chat-header); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  border-radius: 16px 16px 0 0;
}
.chat-modal-header span { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.chat-modal-close { background: none; border: none; color: #fff; font-size: 18px; cursor: pointer; }
.chat-modal-messages { flex: 1; overflow-y: auto; padding: 12px; background: var(--chat-bg); }
.chat-modal-input { padding: 10px 12px; border-top: 1px solid #e2e8f0; }

/* Context menu */
.chat-context-menu {
  display: none; position: fixed; z-index: 2000; min-width: 180px;
  background: #fff; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.18);
  border: 1px solid #e2e8f0; overflow: hidden; padding: 4px;
}
.chat-context-menu.show { display: block; }
.chat-ctx-item {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px 14px;
  border: none; background: none; cursor: pointer; font-size: 13px; color: #374151;
  border-radius: 6px; transition: background .15s; text-align: left;
}
.chat-ctx-item:hover { background: #f1f5f9; }
.chat-ctx-danger { color: #ef4444; }
.chat-ctx-danger:hover { background: #fef2f2; }

/* ===== Responsive ===== */
@media (max-width: 1199px) {
  .chat-panel { display: none; }
  body.chat-active { padding-right: 0; }
  .chat-fab { display: flex; }
}
@media (min-width: 1200px) {
  .chat-fab { display: none; }
  .chat-modal-overlay { display: none !important; }
}

/* ===== Quiz message ===== */
.chat-msg-quiz { width: 100%; margin: 8px 0; }
.chat-quiz-bubble {
  background: linear-gradient(135deg, #eff6ff, #dbeafe);
  border: 2px solid #3b82f6; border-radius: 12px; padding: 12px;
  box-shadow: 0 2px 8px rgba(59,130,246,.15);
}
.chat-quiz-header {
  font-size: 13px; font-weight: 700; color: #1d4ed8; margin-bottom: 8px;
  display: flex; align-items: center; gap: 6px;
}
.chat-quiz-question {
  font-size: 13px; color: #1e293b; line-height: 1.5; margin-bottom: 10px;
  font-weight: 500;
}
.chat-quiz-image-wrap {
  position: relative; margin-bottom: 10px; border-radius: 8px; overflow: hidden;
  cursor: zoom-in;
}
.chat-quiz-image {
  width: 100%; max-height: 200px; object-fit: contain; border-radius: 8px;
  background: #f8fafc; display: block;
}
.chat-quiz-zoom-btn {
  position: absolute; top: 6px; right: 6px; width: 30px; height: 30px;
  border: none; border-radius: 6px; background: rgba(0,0,0,.6); color: #fff;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 14px; transition: background .2s;
}
.chat-quiz-zoom-btn:hover { background: rgba(0,0,0,.8); }
.chat-quiz-answers { display: flex; flex-direction: column; gap: 6px; }
.chat-quiz-answer {
  position: relative; overflow: hidden; display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border: 2px solid #cbd5e1; border-radius: 8px;
  background: #fff; cursor: pointer; transition: all .2s; text-align: left;
  font-size: 12px; line-height: 1.4;
}
.chat-quiz-answer:hover:not(:disabled) { border-color: #3b82f6; background: #eff6ff; }
.chat-quiz-answer:disabled { cursor: default; }
.chat-quiz-answer-label {
  flex-shrink: 0; width: 24px; height: 24px; border-radius: 50%; background: #e2e8f0;
  color: #475569; font-weight: 700; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
}
.chat-quiz-answer-text { flex: 1; color: #334155; }
.chat-quiz-answer-correct {
  border-color: #22c55e !important; background: #f0fdf4 !important;
}
.chat-quiz-answer-correct .chat-quiz-answer-label { background: #22c55e; color: #fff; }
.chat-quiz-answer-wrong {
  border-color: #ef4444 !important; background: #fef2f2 !important;
}
.chat-quiz-answer-wrong .chat-quiz-answer-label { background: #ef4444; color: #fff; }
.chat-quiz-answer-picked {
  box-shadow: 0 0 0 2px rgba(59,130,246,.3);
}
.chat-quiz-answer-bar {
  position: absolute; bottom: 0; left: 0; height: 3px; background: #3b82f6;
  transition: width .5s ease;
}
.chat-quiz-answer-correct .chat-quiz-answer-bar { background: #22c55e; }
.chat-quiz-answer-wrong .chat-quiz-answer-bar { background: #ef4444; }
.chat-quiz-answer-count {
  flex-shrink: 0; font-size: 11px; color: #64748b; font-weight: 600;
  white-space: nowrap;
}
.chat-quiz-result { margin-top: 10px; padding-top: 10px; border-top: 1px solid #cbd5e1; }
.chat-quiz-result-correct {
  font-size: 13px; font-weight: 700; color: #16a34a; margin-bottom: 4px;
  display: flex; align-items: center; gap: 6px;
}
.chat-quiz-result-wrong {
  font-size: 13px; font-weight: 700; color: #dc2626; margin-bottom: 4px;
  display: flex; align-items: center; gap: 6px;
}
.chat-quiz-result-stats { font-size: 12px; color: #475569; margin-bottom: 6px; }
.chat-quiz-explanation {
  font-size: 12px; color: #64748b; background: #f8fafc; border-radius: 6px;
  padding: 8px; margin-top: 6px; line-height: 1.5;
}
.chat-quiz-explanation i { color: #eab308; margin-right: 4px; }
.chat-quiz-time { font-size: 10px; color: #94a3b8; text-align: right; margin-top: 6px; }

/* ===== Image zoom modal ===== */
.chat-image-modal {
  display: none; position: fixed; inset: 0; z-index: 9999;
  align-items: center; justify-content: center;
}
.chat-image-modal.show { display: flex; }
.chat-image-modal-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,.8);
}
.chat-image-modal-content {
  position: relative; max-width: 90vw; max-height: 90vh;
  display: flex; align-items: center; justify-content: center;
}
.chat-image-modal-img {
  max-width: 90vw; max-height: 90vh; object-fit: contain; border-radius: 8px;
  box-shadow: 0 4px 24px rgba(0,0,0,.4);
}
.chat-image-modal-close {
  position: absolute; top: -40px; right: 0; width: 36px; height: 36px;
  border: none; border-radius: 50%; background: rgba(255,255,255,.2); color: #fff;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 18px; transition: background .2s;
}
.chat-image-modal-close:hover { background: rgba(255,255,255,.4); }

/* ===== Loading older messages ===== */
.chat-loading-older {
  text-align: center; padding: 10px; font-size: 12px; color: #64748b;
  background: #f1f5f9; border-radius: 8px; margin: 4px 0;
}
.chat-loading-older::before {
  content: ''; display: inline-block; width: 14px; height: 14px;
  border: 2px solid #cbd5e1; border-top-color: #3b82f6; border-radius: 50%;
  animation: chat-spin .8s linear infinite; margin-right: 6px; vertical-align: middle;
}
@keyframes chat-spin { to { transform: rotate(360deg); } }

/* ===== Donate button ===== */
.chat-donate-bar {
  padding: 8px 10px;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
}
.chat-donate-btn {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff; border: none; border-radius: 10px;
  padding: 8px 12px; font-size: 13px; font-weight: 700;
  cursor: pointer; transition: all .2s;
  box-shadow: 0 2px 8px rgba(239,68,68,.3);
}
.chat-donate-btn:hover {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  box-shadow: 0 3px 12px rgba(239,68,68,.4);
  transform: translateY(-1px);
}
.chat-donate-btn i { animation: chat-heart-pulse 1.5s ease-in-out infinite; }
@keyframes chat-heart-pulse { 0%,100%{transform:scale(1)} 50%{transform:scale(1.2)} }

/* ===== Donate modal ===== */
.chat-donate-overlay {
  position: fixed; inset: 0; z-index: 10000;
  background: rgba(0,0,0,.6); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; padding: 16px;
}
.chat-donate-overlay.show { display: flex; }
.chat-donate-modal {
  background: #fff; border-radius: 20px; max-width: 720px; width: 100%;
  max-height: 90vh; overflow-y: auto; position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  animation: chat-donate-in .3s ease;
}
@keyframes chat-donate-in { from{opacity:0;transform:scale(.95)} to{opacity:1;transform:scale(1)} }
.chat-donate-close {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: #f1f5f9; color: #64748b; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 14px;
  transition: all .2s;
}
.chat-donate-close:hover { background: #e2e8f0; color: #1e293b; }
.chat-donate-content { padding: 20px; display: flex; gap: 20px; align-items: flex-start; }
.chat-donate-left { flex: 0 0 340px; }
.chat-donate-right { flex: 1; min-width: 0; }
.chat-donate-qr {
  width: 340px; height: auto; max-height: 420px;
  border-radius: 14px; box-shadow: 0 4px 12px rgba(0,0,0,.15);
  object-fit: contain; display: block;
}
.chat-donate-title {
  margin-top: 0; font-size: 20px; font-weight: 700;
  color: #1e293b; text-align: left;
}
.chat-donate-text {
  margin-top: 12px; font-size: 15px; line-height: 1.7;
  color: #475569; text-align: left;
}
.chat-donate-highlight {
  margin-top: 12px; font-size: 15px; font-weight: 600;
  color: #2563eb; text-align: left; line-height: 1.5;
}
.chat-donate-note {
  margin-top: 12px; padding: 8px 10px; border-radius: 10px;
  background: #fffbeb; border: 1px solid #fde68a;
  color: #92400e; font-size: 11px; text-align: left; line-height: 1.5;
}
.chat-donate-note i { margin-right: 4px; }
