/* ─────────────────────────────────────────────
   Skylark BI Agent — Premium Dark UI
   ───────────────────────────────────────────── */

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

:root {
  --bg-base:      #070711;
  --bg-surface:   #0d0d1a;
  --bg-elevated:  #13132a;
  --bg-border:    rgba(99,102,241,0.12);

  --primary:      #6366f1;
  --primary-glow: rgba(99,102,241,0.35);
  --primary-light:#818cf8;
  --accent:       #8b5cf6;
  --accent-glow:  rgba(139,92,246,0.3);

  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #475569;

  --success: #10b981;
  --warning: #f59e0b;
  --danger:  #ef4444;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --sidebar-w: 280px;
  --transition: 0.2s ease;
}

html { height: 100%; }

body {
  height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  overflow: hidden;
  line-height: 1.6;
}

/* ── Animated Background ── */
.bg-grid {
  position: fixed; inset: 0; z-index: 0;
  background-image:
    linear-gradient(rgba(99,102,241,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(99,102,241,0.04) 1px, transparent 1px);
  background-size: 48px 48px;
  pointer-events: none;
}

.bg-orb {
  position: fixed; border-radius: 50%; filter: blur(100px);
  pointer-events: none; z-index: 0; animation: floatOrb 12s ease-in-out infinite;
}
.bg-orb-1 { width: 600px; height: 600px; top: -200px; left: -200px; background: radial-gradient(circle, rgba(99,102,241,0.15), transparent 70%); animation-delay: 0s; }
.bg-orb-2 { width: 500px; height: 500px; bottom: -150px; right: -150px; background: radial-gradient(circle, rgba(139,92,246,0.12), transparent 70%); animation-delay: -4s; }
.bg-orb-3 { width: 400px; height: 400px; top: 40%; left: 40%; background: radial-gradient(circle, rgba(99,102,241,0.08), transparent 70%); animation-delay: -8s; }

@keyframes floatOrb {
  0%, 100% { transform: translate(0,0) scale(1); }
  33%  { transform: translate(30px, -20px) scale(1.05); }
  66%  { transform: translate(-20px, 30px) scale(0.95); }
}

/* ── Layout ── */
.app-layout {
  display: flex;
  height: 100vh;
  position: relative;
  z-index: 1;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: rgba(13,13,26,0.9);
  border-right: 1px solid var(--bg-border);
  backdrop-filter: blur(20px);
  transition: transform var(--transition);
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px;
  border-bottom: 1px solid var(--bg-border);
}

.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { width: 36px; height: 36px; flex-shrink: 0; }
.logo-icon svg { width: 100%; height: 100%; }
.logo-text { display: flex; flex-direction: column; }
.logo-name { font-weight: 700; font-size: 15px; letter-spacing: -0.3px; color: var(--text-primary); line-height: 1.2; }
.logo-sub  { font-size: 10px; font-weight: 500; color: var(--primary-light); letter-spacing: 0.5px; text-transform: uppercase; line-height: 1; }

.new-chat-btn {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--bg-border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.new-chat-btn svg { width: 16px; height: 16px; }
.new-chat-btn:hover { background: var(--primary); color: white; border-color: var(--primary); box-shadow: 0 0 16px var(--primary-glow); }

.sidebar-section { padding: 16px; }
.sidebar-label { display: block; font-size: 10px; font-weight: 600; letter-spacing: 0.8px; text-transform: uppercase; color: var(--text-muted); margin-bottom: 8px; }

.quick-questions { display: flex; flex-direction: column; gap: 4px; }
.quick-q-btn {
  text-align: left; background: transparent; border: 1px solid transparent;
  border-radius: var(--radius-sm); padding: 8px 10px;
  color: var(--text-secondary); font-size: 12px; cursor: pointer;
  transition: all var(--transition); line-height: 1.4;
}
.quick-q-btn:hover { background: var(--bg-elevated); border-color: var(--bg-border); color: var(--text-primary); }

.data-sources { display: flex; flex-direction: column; gap: 8px; }
.source-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--bg-elevated); border: 1px solid var(--bg-border);
}
.source-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; transition: background 0.5s; }
.source-dot.connected { background: var(--success); box-shadow: 0 0 8px rgba(16,185,129,0.5); }
.source-dot.error { background: var(--danger); }
.source-info { display: flex; flex-direction: column; }
.source-name { font-size: 12px; font-weight: 500; color: var(--text-primary); }
.source-status { font-size: 10px; color: var(--text-muted); }

.sidebar-footer {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid var(--bg-border);
}
.footer-meta { display: flex; align-items: center; justify-content: space-between; }
#sessionInfo { font-size: 11px; color: var(--text-muted); }
.clear-btn {
  display: flex; align-items: center; gap: 4px;
  background: transparent; border: 1px solid var(--bg-border);
  border-radius: var(--radius-sm); padding: 5px 10px;
  color: var(--text-muted); font-size: 11px; cursor: pointer;
  transition: all var(--transition);
}
.clear-btn svg { width: 12px; height: 12px; }
.clear-btn:hover { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); color: var(--danger); }

/* ── Main Chat ── */
.chat-main {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0; background: transparent;
}

.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--bg-border);
  background: rgba(13,13,26,0.7);
  backdrop-filter: blur(20px);
  flex-shrink: 0;
}

.sidebar-toggle {
  display: none;
  width: 36px; height: 36px;
  background: transparent; border: 1px solid var(--bg-border);
  border-radius: var(--radius-sm); cursor: pointer; color: var(--text-secondary);
  align-items: center; justify-content: center; transition: all var(--transition);
}
.sidebar-toggle svg { width: 18px; height: 18px; }
.sidebar-toggle:hover { background: var(--bg-elevated); color: var(--text-primary); }

.header-title { flex: 1; }
.header-title h1 { font-size: 16px; font-weight: 600; letter-spacing: -0.3px; }
.header-subtitle { font-size: 11px; color: var(--text-muted); }

.header-status {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 20px;
  background: rgba(16,185,129,0.1); border: 1px solid rgba(16,185,129,0.2);
  font-size: 11px; font-weight: 500; color: var(--success);
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.status-dot.pulsing { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:0.5;transform:scale(0.8)} }

/* ── Messages ── */
.messages-container {
  flex: 1; overflow-y: auto; padding: 24px;
  scroll-behavior: smooth;
}

.messages-container::-webkit-scrollbar { width: 4px; }
.messages-container::-webkit-scrollbar-track { background: transparent; }
.messages-container::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 2px; }

/* Welcome Screen */
.welcome-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 60px 24px;
  max-width: 600px; margin: 0 auto;
}
.welcome-screen.hidden { display: none; }

.welcome-icon { width: 80px; height: 80px; margin-bottom: 24px; animation: welcomeSpin 6s linear infinite; }
.welcome-icon svg { width: 100%; height: 100%; }
@keyframes welcomeSpin { from{transform:rotate(0deg)} to{transform:rotate(360deg)} }

.welcome-screen h2 { font-size: 28px; font-weight: 700; margin-bottom: 12px; letter-spacing: -0.5px; background: linear-gradient(135deg, var(--text-primary), var(--primary-light)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.welcome-screen p { font-size: 14px; color: var(--text-secondary); line-height: 1.7; margin-bottom: 28px; }

.welcome-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.welcome-chip {
  padding: 8px 14px; border-radius: 20px;
  border: 1px solid var(--bg-border); background: var(--bg-elevated);
  font-size: 12px; color: var(--text-secondary); cursor: pointer;
  transition: all var(--transition);
}
.welcome-chip:hover { border-color: var(--primary); color: var(--primary-light); background: rgba(99,102,241,0.08); }

/* Message bubbles */
#messagesList { display: flex; flex-direction: column; gap: 20px; }

.message { display: flex; gap: 12px; animation: msgIn 0.3s ease; max-width: 860px; margin: 0 auto; width: 100%; }
@keyframes msgIn { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:translateY(0)} }

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

.msg-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
}
.message.user .msg-avatar { background: linear-gradient(135deg, var(--primary), var(--accent)); color: white; }
.message.assistant .msg-avatar { background: var(--bg-elevated); border: 1px solid var(--bg-border); color: var(--primary-light); }

.msg-content { flex: 1; min-width: 0; }
.message.user .msg-content { display: flex; flex-direction: column; align-items: flex-end; }

.msg-bubble {
  padding: 12px 16px; border-radius: var(--radius-md);
  font-size: 14px; line-height: 1.7; max-width: 100%;
  word-break: break-word;
}
.message.user .msg-bubble {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white; border-radius: var(--radius-md) var(--radius-md) 4px var(--radius-md);
  box-shadow: 0 4px 20px var(--primary-glow);
}
.message.assistant .msg-bubble {
  background: var(--bg-elevated);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-md) var(--radius-md) var(--radius-md) 4px;
  color: var(--text-primary);
}

/* Markdown content in assistant messages */
.msg-bubble h1,.msg-bubble h2,.msg-bubble h3 { font-weight: 600; margin: 12px 0 6px; color: var(--text-primary); }
.msg-bubble h1 { font-size: 16px; } .msg-bubble h2 { font-size: 15px; } .msg-bubble h3 { font-size: 14px; }
.msg-bubble p { margin-bottom: 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul,.msg-bubble ol { padding-left: 20px; margin-bottom: 8px; }
.msg-bubble li { margin-bottom: 3px; }
.msg-bubble strong { font-weight: 600; color: var(--primary-light); }
.msg-bubble em { color: var(--text-secondary); font-style: italic; }
.msg-bubble code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px; background: rgba(99,102,241,0.15);
  padding: 1px 5px; border-radius: 4px; color: var(--primary-light);
}
.msg-bubble pre { background: rgba(0,0,0,0.3); border: 1px solid var(--bg-border); border-radius: var(--radius-sm); padding: 12px; overflow-x: auto; margin: 8px 0; }
.msg-bubble pre code { background: none; padding: 0; color: var(--text-primary); }
.msg-bubble table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 13px; }
.msg-bubble th { background: rgba(99,102,241,0.15); padding: 8px 12px; text-align: left; font-weight: 600; color: var(--primary-light); border-bottom: 1px solid var(--bg-border); }
.msg-bubble td { padding: 7px 12px; border-bottom: 1px solid rgba(255,255,255,0.04); }
.msg-bubble tr:last-child td { border-bottom: none; }
.msg-bubble blockquote { border-left: 3px solid var(--primary); padding-left: 12px; color: var(--text-secondary); margin: 8px 0; font-style: italic; }
.msg-bubble a { color: var(--primary-light); text-decoration: underline; }

.msg-meta { font-size: 10px; color: var(--text-muted); margin-top: 4px; }

/* Typing indicator */
.typing-indicator .msg-bubble { background: var(--bg-elevated); border: 1px solid var(--bg-border); }
.typing-dots { display: flex; gap: 4px; align-items: center; height: 20px; }
.typing-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--primary); animation: typingBounce 1.2s ease-in-out infinite; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce { 0%,80%,100%{transform:translateY(0);opacity:0.4} 40%{transform:translateY(-6px);opacity:1} }

/* ── Input Area ── */
.input-area {
  padding: 16px 24px 20px;
  background: rgba(13,13,26,0.8);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--bg-border);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-lg);
  padding: 12px 12px 12px 18px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input-wrapper:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }

.message-input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text-primary); font-family: 'Inter', sans-serif;
  font-size: 14px; line-height: 1.6; resize: none;
  max-height: 160px; overflow-y: auto;
}
.message-input::placeholder { color: var(--text-muted); }
.message-input::-webkit-scrollbar { width: 4px; }
.message-input::-webkit-scrollbar-thumb { background: var(--bg-border); border-radius: 2px; }

.send-btn {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  border: none; cursor: pointer;
  background: var(--primary); color: white;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  box-shadow: 0 4px 12px var(--primary-glow);
}
.send-btn svg { width: 16px; height: 16px; }
.send-btn:disabled { background: var(--bg-border); box-shadow: none; cursor: not-allowed; color: var(--text-muted); }
.send-btn:not(:disabled):hover { background: var(--accent); transform: scale(1.05); box-shadow: 0 6px 18px var(--accent-glow); }

.input-footer {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 8px; padding: 0 4px;
}
.input-hint { font-size: 11px; color: var(--text-muted); }
.input-hint kbd { background: var(--bg-elevated); border: 1px solid var(--bg-border); border-radius: 3px; padding: 1px 4px; font-size: 10px; font-family: inherit; }
.char-count { font-size: 11px; color: var(--text-muted); }

/* ── Toast ── */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 18px; border-radius: var(--radius-md);
  background: var(--bg-elevated); border: 1px solid var(--bg-border);
  font-size: 13px; color: var(--text-primary);
  backdrop-filter: blur(20px);
  animation: toastIn 0.3s ease;
  max-width: 320px;
}
.toast.error { border-color: rgba(239,68,68,0.3); background: rgba(239,68,68,0.1); color: #fca5a5; }
.toast.success { border-color: rgba(16,185,129,0.3); background: rgba(16,185,129,0.1); color: #6ee7b7; }
@keyframes toastIn { from{opacity:0;transform:translateX(20px)} to{opacity:1;transform:translateX(0)} }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 40px rgba(0,0,0,0.5); }
  .sidebar-toggle { display: flex; }
  .messages-container { padding: 16px; }
  .input-area { padding: 12px 16px 16px; }
}
