@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --bg-0: #030508;
  --bg-1: #0a0e17;
  --bg-2: rgba(14, 20, 33, 0.7);
  --bg-3: rgba(20, 28, 45, 0.6);
  --border: rgba(56, 189, 248, 0.12);
  --border-focus: rgba(56, 189, 248, 0.5);

  --cyan: #06b6d4;
  --blue: #3b82f6;
  --indigo: #6366f1;
  --purple: #a855f7;
  --emerald: #10b981;
  --rose: #f43f5e;
  --amber: #f59e0b;

  --text: #f1f5f9;
  --text-2: #94a3b8;
  --text-3: #475569;

  --font: 'Inter', sans-serif;
  --font-display: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

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

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(56, 189, 248, 0.15); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(56, 189, 248, 0.35); }

body {
  font-family: var(--font);
  background: var(--bg-0);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

/* ── Ambient BG ────────────────────────────────────── */
.bg-ambient { position: fixed; inset: 0; z-index: -1; pointer-events: none; }
.bg-ambient::before {
  content: ''; position: absolute; top: -30%; left: -20%; width: 60%; height: 60%;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.12) 0%, transparent 70%);
  filter: blur(100px); animation: drift 30s alternate infinite ease-in-out;
}
.bg-ambient::after {
  content: ''; position: absolute; bottom: -25%; right: -15%; width: 50%; height: 50%;
  background: radial-gradient(circle, rgba(6, 182, 212, 0.08) 0%, transparent 60%);
  filter: blur(100px); animation: drift 22s alternate-reverse infinite ease-in-out;
}
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(8%, 12%) scale(1.1); }
}

/* ── Glass ─────────────────────────────────────────── */
.glass-panel {
  background: var(--bg-2);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

/* ── Screens ───────────────────────────────────────── */
.screen { display: none; width: 100vw; height: 100vh; }
.screen.active { display: flex; }

/* ════════════════════════════════════════════════════
   AUTH SCREEN
   ════════════════════════════════════════════════════ */
.auth-wrapper {
  width: 100%; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.auth-card {
  width: 100%; max-width: 420px; padding: 40px; text-align: center;
  position: relative; overflow: hidden;
}
.auth-card::before {
  content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 3px;
  background: linear-gradient(90deg, var(--cyan), var(--indigo), var(--purple));
}
.auth-header { margin-bottom: 32px; }
.logo {
  font-family: var(--font-display); font-weight: 800; font-size: 2.6rem;
  letter-spacing: -1px;
  background: linear-gradient(135deg, #fff 30%, var(--cyan));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  display: inline-flex; align-items: center; gap: 6px;
}
.dot {
  width: 9px; height: 9px; background: var(--cyan); border-radius: 50%;
  box-shadow: 0 0 12px var(--cyan); animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0%   { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(6,182,212,0.6); }
  70%  { transform: scale(1.15); box-shadow: 0 0 0 10px rgba(6,182,212,0); }
  100% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(6,182,212,0); }
}
.auth-subtitle {
  font-size: 0.8rem; font-weight: 600; letter-spacing: 2px;
  color: var(--text-3); margin-top: 6px; text-transform: uppercase;
}

.field { text-align: left; margin-bottom: 18px; }
.field label {
  display: block; font-size: 0.78rem; font-weight: 600; color: var(--text-2);
  margin-bottom: 6px; letter-spacing: 0.3px;
}
.field input {
  width: 100%; padding: 13px 14px; background: rgba(6, 10, 18, 0.85);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text);
  font-family: var(--font); font-size: 0.95rem; outline: none;
  transition: border-color 0.3s var(--ease), box-shadow 0.3s var(--ease);
}
.field input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 16px rgba(6, 182, 212, 0.12), inset 0 0 4px rgba(6, 182, 212, 0.04);
}
.btn-auth {
  width: 100%; padding: 14px; margin-top: 8px;
  background: linear-gradient(135deg, var(--cyan), var(--blue));
  border: none; border-radius: 8px; color: #fff;
  font-family: var(--font-display); font-weight: 700; font-size: 1rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px;
  box-shadow: 0 0 20px rgba(6,182,212,0.2);
  transition: transform 0.2s var(--ease), box-shadow 0.3s var(--ease);
}
.btn-auth:hover { transform: translateY(-2px); box-shadow: 0 0 30px rgba(6,182,212,0.35); }
.btn-auth:disabled { opacity: 0.6; cursor: wait; }

.auth-error {
  margin-top: 14px; font-size: 0.85rem; color: var(--rose);
  min-height: 20px; transition: opacity 0.3s;
}

/* ════════════════════════════════════════════════════
   MAIN APP LAYOUT
   ════════════════════════════════════════════════════ */
.app-layout {
  width: 100%; height: 100%; display: flex; flex-direction: column;
}

/* ── Top Bar ───────────────────────────────────────── */
.top-bar {
  height: 54px; padding: 0 20px; display: flex; align-items: center; justify-content: space-between;
  background: rgba(8, 12, 22, 0.85); backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255,255,255,0.04); flex-shrink: 0; z-index: 10;
}
.top-left, .top-right { display: flex; align-items: center; gap: 14px; }
.top-logo {
  font-family: var(--font-display); font-weight: 800; font-size: 1.15rem;
  background: linear-gradient(135deg, #fff, var(--cyan));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  display: flex; align-items: center; gap: 5px;
}
.top-logo .dot { width: 6px; height: 6px; }

.connection-badge {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.72rem; font-weight: 600; font-family: var(--font-mono);
  color: var(--text-3); padding: 4px 10px;
  background: rgba(255,255,255,0.02); border: 1px solid rgba(255,255,255,0.05);
  border-radius: 20px;
}
.conn-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--amber); box-shadow: 0 0 6px var(--amber);
  transition: all 0.4s;
}
.connection-badge.online .conn-dot { background: var(--emerald); box-shadow: 0 0 8px var(--emerald); }
.connection-badge.offline .conn-dot { background: var(--rose); box-shadow: 0 0 8px var(--rose); }

.top-center {
  font-size: 0.72rem; color: var(--text-3); font-family: var(--font-mono);
  display: flex; align-items: center; gap: 16px;
}
.stat-item { display: flex; align-items: center; gap: 4px; }
.stat-item i { font-size: 0.65rem; color: var(--cyan); }

.top-btn {
  background: transparent; border: 1px solid rgba(255,255,255,0.05);
  color: var(--text-3); width: 34px; height: 34px; border-radius: 8px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; transition: all 0.2s;
}
.top-btn:hover { color: var(--text); background: rgba(255,255,255,0.04); border-color: var(--border); }
.top-btn.btn-logout:hover { color: var(--rose); border-color: rgba(244,63,94,0.3); }

/* ── Chat Viewport ─────────────────────────────────── */
.chat-viewport {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
  position: relative;
}
.messages-container {
  flex: 1; overflow-y: auto; padding: 24px 20px; display: flex;
  flex-direction: column; gap: 16px;
}

/* ── Message Blocks ────────────────────────────────── */
.msg { display: flex; gap: 12px; max-width: 85%; animation: msgIn 0.35s var(--ease); }
.msg.no-anim { animation: none; }
@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.spark { align-self: flex-start; }
.msg.system { align-self: center; max-width: 90%; }

.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700; color: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}
.msg.user .msg-avatar { background: linear-gradient(135deg, var(--cyan), var(--blue)); }
.msg.spark .msg-avatar { background: linear-gradient(135deg, var(--purple), var(--indigo)); }

.msg-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.msg-meta {
  font-size: 0.68rem; color: var(--text-3);
  display: flex; align-items: center; gap: 6px;
}
.msg.user .msg-meta { justify-content: flex-end; }
.msg-name { font-weight: 600; color: var(--text-2); }

.msg-bubble {
  padding: 12px 16px; border-radius: 14px;
  font-size: 0.9rem; line-height: 1.6; word-wrap: break-word;
}
.msg.user .msg-bubble {
  background: rgba(6, 182, 212, 0.08); border: 1px solid rgba(6, 182, 212, 0.18);
  border-top-right-radius: 4px;
}
.msg.spark .msg-bubble {
  background: var(--bg-3); border: 1px solid var(--border);
  border-top-left-radius: 4px;
}
.msg.system .msg-bubble {
  background: rgba(99, 102, 241, 0.06); border: 1px solid rgba(99, 102, 241, 0.15);
  text-align: center; font-size: 0.8rem; color: var(--text-2); border-radius: 8px;
}

/* Markdown-rendered elements */
.msg-bubble strong { color: #fff; font-weight: 600; }
.msg-bubble em { color: var(--text-2); }
.msg-bubble code {
  background: rgba(255,255,255,0.06); padding: 1px 6px; border-radius: 4px;
  font-family: var(--font-mono); font-size: 0.85em; color: var(--cyan);
}

/* ── Command Result Block ──────────────────────────── */
.cmd-result {
  align-self: flex-start; width: 90%; max-width: 750px;
  animation: msgIn 0.35s var(--ease);
}
.cmd-result.no-anim { animation: none; }
.cmd-result-card {
  background: rgba(6, 10, 18, 0.9); border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px; overflow: hidden;
}
.cmd-header {
  padding: 10px 16px; display: flex; align-items: center; justify-content: space-between;
  background: rgba(255,255,255,0.02); border-bottom: 1px solid rgba(255,255,255,0.04);
}
.cmd-label {
  font-family: var(--font-mono); font-size: 0.78rem; color: var(--cyan);
  display: flex; align-items: center; gap: 8px;
}
.cmd-label i { font-size: 0.7rem; }
.cmd-stats {
  font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-3);
  display: flex; gap: 12px;
}
.cmd-stats .exit-ok { color: var(--emerald); }
.cmd-stats .exit-err { color: var(--rose); }

.cmd-output {
  padding: 14px 16px; font-family: var(--font-mono); font-size: 0.8rem;
  line-height: 1.55; color: #c8d6e5; white-space: pre-wrap; word-break: break-all;
  max-height: 400px; overflow-y: auto;
}
.cmd-output::-webkit-scrollbar { width: 4px; }
.cmd-output::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 4px; }

.cmd-truncated {
  padding: 6px 16px; font-size: 0.7rem; color: var(--amber);
  border-top: 1px solid rgba(255,255,255,0.03); text-align: center;
  font-family: var(--font-mono);
}

/* ── Typing Indicator ──────────────────────────────── */
.typing-indicator {
  display: none; align-items: center; gap: 10px;
  padding: 8px 24px; align-self: flex-start;
}
.typing-indicator.active { display: flex; }
.typing-dots { display: flex; gap: 4px; }
.typing-dots span {
  width: 6px; height: 6px; background: var(--cyan); border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}
.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}
.typing-label {
  font-size: 0.75rem; font-family: var(--font-mono); color: var(--text-3);
}

/* ── Input Bar ─────────────────────────────────────── */
.input-bar {
  padding: 12px 20px 14px; border-top: 1px solid rgba(255,255,255,0.03);
  background: rgba(8, 12, 22, 0.6); backdrop-filter: blur(12px);
  flex-shrink: 0;
}
.input-wrapper {
  display: flex; align-items: flex-end; gap: 0;
  background: rgba(6, 10, 18, 0.85); border: 1px solid var(--border);
  border-radius: 12px; padding: 6px 8px 6px 16px;
  transition: border-color 0.3s var(--ease), box-shadow 0.3s var(--ease);
}
.input-wrapper.focused {
  border-color: var(--cyan);
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.1);
}
.input-wrapper textarea {
  flex: 1; background: transparent; border: none; color: var(--text);
  font-family: var(--font); font-size: 0.92rem; resize: none;
  outline: none; min-height: 24px; max-height: 140px; padding: 6px 0;
  line-height: 1.5;
}
.input-wrapper textarea::placeholder { color: var(--text-3); }
.input-wrapper textarea:disabled { opacity: 0.4; }

.input-actions { display: flex; align-items: center; gap: 6px; padding-bottom: 2px; }
.input-btn {
  border: none; border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.hint-btn {
  background: transparent; color: var(--text-3); width: 34px; height: 34px; font-size: 1rem;
}
.hint-btn:hover { color: var(--amber); }
.send-btn {
  background: linear-gradient(135deg, var(--cyan), var(--blue));
  color: #fff; width: 36px; height: 36px; font-size: 0.95rem;
  box-shadow: 0 0 14px rgba(6,182,212,0.2);
}
.send-btn:hover { transform: scale(1.05); box-shadow: 0 0 20px rgba(6,182,212,0.35); }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

.input-hints {
  display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap;
}
.hint-tag {
  padding: 4px 10px; font-size: 0.72rem; font-weight: 600;
  background: rgba(255,255,255,0.02); border: 1px solid rgba(255,255,255,0.06);
  border-radius: 6px; color: var(--text-3); cursor: pointer;
  transition: all 0.2s; user-select: none;
}
.hint-tag:hover {
  background: rgba(6, 182, 212, 0.08); border-color: rgba(6, 182, 212, 0.2);
  color: var(--cyan);
}

/* ── Toast ─────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 20px; right: 20px;
  background: rgba(10, 14, 23, 0.92); backdrop-filter: blur(10px);
  border: 1px solid var(--cyan); box-shadow: 0 0 20px rgba(6,182,212,0.2);
  padding: 12px 18px; border-radius: 8px;
  display: flex; align-items: center; gap: 10px; z-index: 200;
  transform: translateY(120%); transition: transform 0.4s cubic-bezier(0.175,0.885,0.32,1.275);
  font-size: 0.85rem;
}
.toast.active { transform: translateY(0); }
.toast.error { border-color: var(--rose); box-shadow: 0 0 20px rgba(244,63,94,0.2); }
.toast.error i { color: var(--rose); }
.toast i { color: var(--cyan); }

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 768px) {
  .top-center { display: none; }
  .messages-container { padding: 16px 12px; }
  .msg { max-width: 95%; }
  .cmd-result { width: 98%; }
  .input-hints { display: none; }
}
