/* ============================================================
   Taikai Chat Widget
   All selectors are prefixed with .tc- to avoid collisions.
   ============================================================ */

#taikai-chat-root {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99990;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  box-sizing: border-box;
}

#taikai-chat-root *, #taikai-chat-root *::before, #taikai-chat-root *::after {
  box-sizing: border-box;
}

/* ── Bubble ──────────────────────────────────────────────────── */
.tc-bubble {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: #dc2626;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(220, 38, 38, 0.45);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
  color: #fff;
}
.tc-bubble:hover {
  transform: scale(1.07);
  box-shadow: 0 6px 28px rgba(220, 38, 38, 0.6);
}
.tc-bubble svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.tc-badge {
  position: absolute;
  top: 0;
  right: 0;
  background: #ef4444;
  color: #fff;
  border-radius: 999px;
  min-width: 18px;
  height: 18px;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid #0f0f14;
  line-height: 1;
}
.tc-badge.hidden { display: none; }

/* ── Panel ───────────────────────────────────────────────────── */
.tc-panel {
  position: absolute;
  bottom: 66px;
  right: 0;
  width: 360px;
  max-height: 560px;
  background: #1a1212;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  box-shadow: 0 16px 56px rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: tc-open 0.18s ease;
}
.tc-panel.hidden { display: none; }

@keyframes tc-open {
  from { opacity: 0; transform: scale(0.92) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Header ──────────────────────────────────────────────────── */
.tc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  color: #fff;
  flex-shrink: 0;
  border-radius: 16px 16px 0 0;
}
.tc-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
}
.tc-status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #9ca3af;
  flex-shrink: 0;
  transition: background 0.3s;
}
.tc-status-dot.online  { background: #22c55e; }
.tc-status-dot.away    { background: #f59e0b; }
.tc-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.75);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
.tc-close:hover { color: #fff; background: rgba(255,255,255,0.12); }

/* ── Tabs ────────────────────────────────────────────────────── */
.tc-tabs {
  display: flex;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  background: #161010;
  flex-shrink: 0;
}
.tc-tab {
  flex: 1;
  background: none;
  border: none;
  color: #9ca3af;
  padding: 10px 0;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tc-tab.active {
  color: #fca5a5;
  border-bottom-color: #dc2626;
}

/* ── Unauthenticated banner ──────────────────────────────────── */
.tc-unauth {
  padding: 32px 20px;
  text-align: center;
  color: #9ca3af;
  flex: 1;
}
.tc-unauth p { margin-bottom: 12px; font-size: 15px; }
.tc-unauth a {
  display: inline-block;
  padding: 8px 18px;
  background: #dc2626;
  color: #fff;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 500;
  font-size: 13px;
}

/* ── Messages ────────────────────────────────────────────────── */
.tc-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  scroll-behavior: smooth;
}
.tc-messages::-webkit-scrollbar { width: 4px; }
.tc-messages::-webkit-scrollbar-track { background: transparent; }
.tc-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

.tc-msg {
  max-width: 82%;
  display: flex;
  flex-direction: column;
}
.tc-msg-user  { align-self: flex-end;  align-items: flex-end; }
.tc-msg-ai,
.tc-msg-admin { align-self: flex-start; align-items: flex-start; }

.tc-msg-label {
  font-size: 10px;
  color: #6b7280;
  margin-bottom: 2px;
  font-weight: 500;
}

.tc-msg-bubble {
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.tc-msg-user  .tc-msg-bubble { background: #dc2626; color: #fff; border-bottom-right-radius: 4px; }
.tc-msg-ai    .tc-msg-bubble { background: #201c1c; color: #e2e8f0; border-bottom-left-radius: 4px; }
.tc-msg-admin .tc-msg-bubble { background: #1e293b; color: #e2e8f0; border: 1px solid rgba(255,255,255,0.08); border-bottom-left-radius: 4px; }

.tc-msg-time {
  font-size: 10px;
  color: #4b5563;
  margin-top: 3px;
}

.tc-msg img.tc-attachment {
  max-width: 180px;
  border-radius: 8px;
  margin-top: 6px;
  cursor: zoom-in;
}

/* Typing indicator */
.tc-typing .tc-msg-bubble {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 10px 14px;
}
.tc-typing .tc-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #6b7280;
  animation: tc-blink 1.2s infinite;
}
.tc-typing .tc-dot:nth-child(2) { animation-delay: 0.2s; }
.tc-typing .tc-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes tc-blink {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.9); }
  40% { opacity: 1; transform: scale(1.1); }
}

.tc-empty-hint {
  text-align: center;
  color: #4b5563;
  font-size: 13px;
  margin: auto;
  padding: 20px;
}

/* ── Status bar ──────────────────────────────────────────────── */
.tc-status-bar {
  text-align: center;
  font-size: 11px;
  color: #6b7280;
  padding: 4px 14px;
  background: #161010;
  border-top: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

/* ── Escalate bar ────────────────────────────────────────────── */
.tc-escalate-bar {
  padding: 8px 14px;
  background: #1f0a0a;
  border-top: 1px solid rgba(220,38,38,0.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 8px;
}
.tc-escalate-bar span {
  font-size: 12px;
  color: #fca5a5;
  flex: 1;
}
.tc-escalate-bar button {
  background: #dc2626;
  border: none;
  color: #fff;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

/* ── Away bar ────────────────────────────────────────────────── */
.tc-away-bar {
  padding: 10px 14px;
  background: #1c1a12;
  border-top: 1px solid rgba(245,158,11,0.2);
  font-size: 12px;
  color: #fbbf24;
  text-align: center;
  flex-shrink: 0;
}

/* ── Input area ──────────────────────────────────────────────── */
.tc-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid rgba(255,255,255,0.07);
  background: #161010;
  flex-shrink: 0;
}
#tc-input {
  flex: 1;
  background: #0f0c0c;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  color: #e2e8f0;
  font-size: 13px;
  font-family: inherit;
  padding: 8px 10px;
  resize: none;
  outline: none;
  line-height: 1.45;
  max-height: 100px;
  overflow-y: auto;
  transition: border-color 0.15s;
}
#tc-input:focus { border-color: #dc2626; }
#tc-input::placeholder { color: #4b5563; }
.tc-input-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.tc-attach-btn {
  cursor: pointer;
  font-size: 18px;
  opacity: 0.55;
  transition: opacity 0.15s;
  line-height: 1;
}
.tc-attach-btn:hover { opacity: 0.9; }
.tc-send-btn {
  background: #dc2626;
  border: none;
  color: #fff;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.tc-send-btn:hover { background: #b91c1c; }
.tc-send-btn:disabled { opacity: 0.5; cursor: default; }

/* ── Attachment preview ──────────────────────────────────────── */
.tc-attachment-preview {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px 6px;
  background: #161010;
  font-size: 12px;
  color: #9ca3af;
  flex-shrink: 0;
}
.tc-attachment-preview span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tc-attachment-preview button { background: none; border: none; color: #6b7280; cursor: pointer; font-size: 14px; }

/* ── Past conversations tab ──────────────────────────────────── */
.tc-past-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}
.tc-past-item {
  padding: 10px 12px;
  border-radius: 10px;
  background: #161010;
  margin-bottom: 8px;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.06);
  transition: border-color 0.15s;
}
.tc-past-item:hover { border-color: rgba(220,38,38,0.4); }
.tc-past-subject { font-weight: 500; font-size: 13px; color: #e2e8f0; margin-bottom: 3px; }
.tc-past-preview { font-size: 12px; color: #6b7280; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tc-past-date { font-size: 10px; color: #374151; margin-top: 4px; }

.tc-past-thread {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}
.tc-past-back {
  background: none;
  border: none;
  color: #dc2626;
  cursor: pointer;
  font-size: 13px;
  padding: 4px 8px;
  margin-bottom: 8px;
  display: block;
}

/* ── Auth content wrapper ────────────────────────────────────── */
.tc-auth-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* hidden utility */
.tc-hidden { display: none !important; }

/* ── Launcher menu (3 modes) ── */
.tc-menu-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  padding: 14px; border-radius: 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  color: #fff; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.tc-menu-item:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.18); }
.tc-menu-ico { flex-shrink: 0; color: #dc2626; display: flex; }
.tc-menu-txt { display: flex; flex-direction: column; gap: 2px; }
.tc-menu-txt strong { font-size: 14px; }
.tc-menu-txt span { font-size: 12px; color: rgba(255,255,255,0.55); }

/* ── Knowledge-base results ── */
.tc-kb-result {
  display: block; padding: 10px 12px; border-radius: 8px; text-decoration: none;
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08); color: #fff;
  font-size: 13px;
}
.tc-kb-result:hover { background: rgba(255,255,255,0.08); }
.tc-kb-result small { display: block; color: rgba(255,255,255,0.5); margin-top: 3px; }
