/* ═══════════════════════════════════════════════
   MAPLE BIOTECH — AI Sales Agent Chat UI
   Design: Glassmorphism SaaS — Dark Mode Premium
═══════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #070b18;
  --bg2:       #0d1226;
  --bg3:       #111827;
  --glass:     rgba(255,255,255,0.04);
  --glass-b:   rgba(255,255,255,0.07);
  --border:    rgba(255,255,255,0.08);
  --border-h:  rgba(255,255,255,0.14);
  --text:      #e2e8f0;
  --muted:     #64748b;
  --indigo:    #6366f1;
  --purple:    #a855f7;
  --pink:      #ec4899;
  --green:     #10b981;
  --orange:    #f97316;
  --red:       #ef4444;
  --radius:    14px;
  --radius-lg: 20px;
  --sidebar-w: 300px;
  --topbar-h:  64px;
  --font:      'Inter', system-ui, sans-serif;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

.glass {
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
}

/* ════════════════════════════
   APP LAYOUT
════════════════════════════ */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ════════════════════════════
   SIDEBAR
════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform 0.3s cubic-bezier(.4,0,.2,1),
              min-width 0.3s ease;
  position: relative;
  z-index: 10;
}

.sidebar.hidden {
  transform: translateX(-100%);
  min-width: 0;
  width: 0;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-h); border-radius: 2px; }

/* Sidebar Header */
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  background: var(--bg2);
  z-index: 2;
}

.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
}
.logo-icon { font-size: 22px; }
.logo-name {
  display: block; font-family: 'Poppins', var(--font);
  font-size: 14px; font-weight: 700;
  background: linear-gradient(135deg, var(--indigo), var(--purple));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.logo-tag { display: block; font-size: 10px; color: var(--muted); letter-spacing: 0.5px; }

.sidebar-close {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 16px; padding: 4px;
  display: none;
}

/* Lead Status Card */
.lead-status-wrap { padding: 16px; }

.lead-status-card {
  border-radius: var(--radius);
  padding: 16px;
}

.ls-top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.ls-label { font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: 1px; text-transform: uppercase; }

.ls-badge {
  font-size: 10px; font-weight: 800; letter-spacing: 1.5px;
  padding: 3px 10px; border-radius: 50px; text-transform: uppercase;
}
.ls-badge.cold   { background: rgba(100,116,139,0.2); color: #94a3b8; border: 1px solid rgba(100,116,139,0.3); }
.ls-badge.warm   { background: rgba(249,115,22,0.15); color: var(--orange); border: 1px solid rgba(249,115,22,0.3); }
.ls-badge.hot    { background: rgba(239,68,68,0.15);  color: var(--red);    border: 1px solid rgba(239,68,68,0.3); animation: hotPulse 2s infinite; }

@keyframes hotPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
  50%       { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}

.ls-stage, .ls-sentiment {
  font-size: 12px; color: var(--muted); margin-top: 4px;
}

/* CRM Sections */
.crm-section {
  padding: 12px 16px 8px;
  border-top: 1px solid var(--border);
}
.crm-section-title {
  font-size: 10px; font-weight: 700; letter-spacing: 1.5px;
  color: var(--muted); text-transform: uppercase;
  margin-bottom: 10px;
}

.crm-fields { display: flex; flex-direction: column; gap: 8px; }

.crm-field {
  display: flex; flex-direction: column; gap: 2px;
}
.crm-key { font-size: 11px; color: var(--muted); font-weight: 500; }
.crm-val {
  font-size: 13px; font-weight: 500; color: var(--text);
  word-break: break-all;
  transition: color 0.3s;
}
.crm-val.updated { color: var(--green); }

.crm-summary, .crm-next {
  border-radius: var(--radius);
  padding: 12px;
  font-size: 12px;
  color: var(--text);
  line-height: 1.5;
}

/* Sidebar Actions */
.crm-actions {
  padding: 16px;
  display: flex; flex-direction: column; gap: 8px;
  margin-top: auto;
  border-top: 1px solid var(--border);
}

.action-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--glass);
  color: var(--text);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;
  text-align: left;
}
.action-btn:hover { background: var(--glass-b); border-color: var(--border-h); transform: translateX(2px); }

.email-btn  { color: var(--indigo); border-color: rgba(99,102,241,0.2); }
.email-btn:hover  { background: rgba(99,102,241,0.08); }
.export-btn { color: var(--green);  border-color: rgba(16,185,129,0.2); }
.export-btn:hover { background: rgba(16,185,129,0.08); }
.reset-btn  { color: var(--muted);  }

/* ════════════════════════════
   CHAT MAIN
════════════════════════════ */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  position: relative;
}

/* Background decoration */
.chat-main::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 200px;
  background: radial-gradient(ellipse at top, rgba(99,102,241,0.06) 0%, transparent 70%);
  pointer-events: none;
}

/* Top Bar */
.chat-topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(7,11,24,0.8);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
  position: relative; z-index: 5;
}

.menu-btn {
  background: none; border: none; color: var(--muted);
  cursor: pointer; padding: 6px; border-radius: 8px;
  display: flex; align-items: center;
  transition: all 0.2s;
}
.menu-btn:hover { background: var(--glass-b); color: var(--text); }

.agent-info {
  display: flex; align-items: center; gap: 10px;
  flex: 1;
}
.agent-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--indigo), var(--purple));
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: #fff;
  position: relative; flex-shrink: 0;
}
.agent-online {
  position: absolute; bottom: 1px; right: 1px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--green);
  border: 2px solid var(--bg);
  animation: onlinePulse 2s ease infinite;
}
@keyframes onlinePulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

.agent-name { font-size: 14px; font-weight: 600; }
.agent-status {
  font-size: 11px; color: var(--muted);
  display: flex; align-items: center; gap: 5px;
}
.status-dot {
  display: inline-block; width: 6px; height: 6px;
  border-radius: 50%; background: var(--green);
}
.status-dot.thinking { background: var(--orange); animation: blink 0.8s step-end infinite; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

.channel-selector select {
  background: var(--glass);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  outline: none;
}
.channel-selector select:focus { border-color: var(--indigo); }

/* ── Provider Badge ── */
.provider-badge {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600;
  padding: 5px 12px; border-radius: 50px;
  flex-shrink: 0;
  transition: all 0.3s;
}
.provider-badge.gemini {
  background: rgba(66,133,244,0.12);
  border: 1px solid rgba(66,133,244,0.3);
  color: #4285f4;
}
.provider-badge.claude {
  background: rgba(168,85,247,0.12);
  border: 1px solid rgba(168,85,247,0.3);
  color: var(--purple);
}
.provider-badge.unknown {
  background: var(--glass);
  border: 1px solid var(--border);
  color: var(--muted);
}

.token-info {
  display: flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--muted);
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 8px;
  flex-shrink: 0;
}

/* Messages */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative; z-index: 1;
}
.messages-container::-webkit-scrollbar { width: 4px; }
.messages-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Welcome Screen */
.welcome-screen {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center;
  margin: auto;
  max-width: 440px;
  padding: 32px;
}
.welcome-icon { font-size: 48px; margin-bottom: 16px; }
.welcome-screen h2 {
  font-family: 'Poppins', var(--font);
  font-size: 22px; font-weight: 700; margin-bottom: 12px;
}
.welcome-screen p {
  font-size: 14px; color: var(--muted); margin-bottom: 20px; line-height: 1.7;
}
.welcome-tips {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
  margin-bottom: 24px;
}
.welcome-tips span {
  font-size: 12px; background: var(--glass);
  border: 1px solid var(--border); border-radius: 50px;
  padding: 5px 14px; color: var(--muted);
}
.start-chat-btn {
  background: linear-gradient(135deg, var(--indigo), var(--purple));
  color: #fff; border: none; border-radius: 50px;
  padding: 12px 28px; font-size: 14px; font-weight: 600;
  cursor: pointer;
  box-shadow: 0 0 24px rgba(99,102,241,0.35);
  transition: all 0.3s;
}
.start-chat-btn:hover { transform: translateY(-2px); box-shadow: 0 0 36px rgba(99,102,241,0.5); }

/* Chat Message Bubbles */
.message-row {
  display: flex; gap: 10px; align-items: flex-end;
  animation: slideIn 0.3s ease;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message-row.user-row { flex-direction: row-reverse; }

.msg-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.agent-msg-avatar {
  background: linear-gradient(135deg, var(--indigo), var(--purple));
  color: #fff;
}
.user-msg-avatar {
  background: var(--glass);
  border: 1px solid var(--border);
  color: var(--muted);
}

.msg-bubble-wrap {
  display: flex; flex-direction: column; gap: 4px;
  max-width: 72%;
}
.user-row .msg-bubble-wrap { align-items: flex-end; }

.msg-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px; line-height: 1.65;
  word-break: break-word;
}
.agent-bubble {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text);
}
.user-bubble {
  background: linear-gradient(135deg, var(--indigo), var(--purple));
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-time {
  font-size: 10px; color: var(--muted);
  padding: 0 4px;
}

/* Typing Indicator */
.typing-indicator {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 24px;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.typing-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--indigo), var(--purple));
  color: #fff; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.typing-bubbles {
  display: flex; gap: 4px; align-items: center;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 18px; padding: 10px 16px;
}
.typing-bubbles span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--indigo);
  animation: bounce 1.2s ease infinite;
}
.typing-bubbles span:nth-child(2) { animation-delay: 0.2s; }
.typing-bubbles span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40%           { transform: scale(1);   opacity: 1; }
}
.typing-text { font-size: 12px; color: var(--muted); }

/* ── INPUT AREA ── */
.input-area {
  padding: 12px 20px 16px;
  background: rgba(7,11,24,0.9);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  position: relative; z-index: 5;
}

.input-wrap {
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex; align-items: flex-end; gap: 10px;
  transition: border-color 0.2s;
}
.input-wrap:focus-within {
  border-color: var(--indigo);
  box-shadow: 0 0 0 2px rgba(99,102,241,0.12);
}

.input-wrap textarea {
  flex: 1;
  background: none;
  border: none; outline: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
  padding: 2px 0;
}
.input-wrap textarea::placeholder { color: var(--muted); }

.input-actions {
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
}
.char-count { font-size: 11px; color: var(--muted); }

.send-btn {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--indigo), var(--purple));
  border: none; color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.send-btn:not(:disabled):hover { transform: scale(1.08); box-shadow: 0 0 16px rgba(99,102,241,0.5); }

.input-footer {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 8px; font-size: 11px; color: var(--muted);
}
.session-tag {
  font-size: 10px;
  font-family: monospace;
  opacity: 0.5;
}

/* ════════════════════════════
   MODALS
════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: fadeIn 0.2s ease;
}

.modal {
  width: 100%; max-width: 560px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp {
  from { transform: translateY(24px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 18px; padding: 4px;
}

.modal-body { padding: 20px 24px; }
.modal-body textarea {
  width: 100%; background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px; line-height: 1.7;
  padding: 14px; resize: vertical; outline: none;
}
.modal-body textarea:focus { border-color: var(--indigo); }

.export-pre {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-family: 'Courier New', monospace;
  font-size: 12px; line-height: 1.6;
  color: var(--green);
  overflow-x: auto; overflow-y: auto;
  max-height: 360px;
  white-space: pre;
}

.modal-footer {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* ── TOAST ── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 10px 20px;
  font-size: 13px; font-weight: 500;
  z-index: 200;
  opacity: 0;
  transition: all 0.3s ease;
  white-space: nowrap;
}
.toast.show {
  opacity: 1; transform: translateX(-50%) translateY(0);
}
.toast.success { border-color: rgba(16,185,129,0.4); color: var(--green); }
.toast.error   { border-color: rgba(239,68,68,0.4);  color: var(--red); }

/* ════════════════════════════
   RESPONSIVE
════════════════════════════ */
@media (max-width: 768px) {
  .sidebar {
    position: absolute; top: 0; bottom: 0; left: 0;
    height: 100vh;
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  }
  .sidebar-close { display: flex; }
  .sidebar.hidden { transform: translateX(-100%); }
  .chat-main { width: 100%; }
  .token-info { display: none; }
  .msg-bubble-wrap { max-width: 88%; }
}

@media (max-width: 480px) {
  .messages-container { padding: 16px 12px; }
  .input-area { padding: 10px 12px 14px; }
  .channel-selector select { display: none; }
}
