/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0a0f;
  --surface: rgba(255,255,255,0.04);
  --surface-hover: rgba(255,255,255,0.07);
  --border: rgba(255,255,255,0.08);
  --accent: #7c6ff7;
  --accent-2: #a78bfa;
  --accent-glow: rgba(124,111,247,0.3);
  --user-bubble: linear-gradient(135deg, #7c6ff7, #a78bfa);
  --ai-bubble: rgba(255,255,255,0.05);
  --text: #f0f0f5;
  --text-muted: rgba(240,240,245,0.45);
  --text-dim: rgba(240,240,245,0.25);
  --radius: 16px;
  --sidebar-w: 270px;
  --font: 'Inter', sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ── Animated Background Orbs ────────────────────────────────────────────── */
.bg-orbs {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 0;
  overflow: hidden;
}
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.18;
  animation: drift 20s ease-in-out infinite;
}
.orb-1 { width: 500px; height: 500px; background: #7c6ff7; top: -100px; left: -100px; animation-delay: 0s; }
.orb-2 { width: 400px; height: 400px; background: #ec4899; bottom: -80px; right: -80px; animation-delay: -7s; }
.orb-3 { width: 300px; height: 300px; background: #06b6d4; top: 50%; left: 50%; transform: translate(-50%,-50%); animation-delay: -14s; }

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

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

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: rgba(10,10,20,0.7);
  backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  gap: 24px;
  transition: transform 0.3s ease;
}

.sidebar-header { display: flex; flex-direction: column; gap: 14px; }

.logo {
  display: flex; align-items: center; gap: 10px;
}
.logo-icon {
  font-size: 22px;
  background: var(--user-bubble);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.logo-text { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }

.new-chat-btn {
  width: 100%;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.new-chat-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
}

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

/* ── Model List ──────────────────────────────────────────────────────────── */
.model-section, .mode-section { display: flex; flex-direction: column; }

.model-list { display: flex; flex-direction: column; gap: 4px; }

.model-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}
.model-btn .flag { font-size: 16px; }
.model-btn:hover { background: var(--surface-hover); color: var(--text); }
.model-btn.active {
  background: rgba(124,111,247,0.15);
  border-color: rgba(124,111,247,0.4);
  color: var(--accent-2);
}

/* ── Mode Toggle ─────────────────────────────────────────────────────────── */
.mode-toggle { display: flex; flex-direction: column; gap: 4px; }
.mode-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.mode-btn:hover { background: var(--surface-hover); color: var(--text); }
.mode-btn.active {
  background: rgba(124,111,247,0.15);
  border-color: rgba(124,111,247,0.4);
  color: var(--accent-2);
}

/* ── Sidebar Footer ──────────────────────────────────────────────────────── */
.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border-radius: 10px;
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 6px #22c55e;
  flex-shrink: 0;
  transition: all 0.3s;
}
.status-dot.busy { background: #f59e0b; box-shadow: 0 0 6px #f59e0b; animation: pulse 1s infinite; }
.status-dot.error { background: #ef4444; box-shadow: 0 0 6px #ef4444; }
.status-text { font-size: 12px; color: var(--text-muted); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

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

/* ── Header ──────────────────────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,10,20,0.4);
  backdrop-filter: blur(12px);
}
.sidebar-toggle {
  display: none;
  background: none; border: none; color: var(--text-muted);
  font-size: 18px; cursor: pointer; padding: 4px 8px;
}
.chat-title { flex: 1; }
.chat-title h1 { font-size: 16px; font-weight: 600; }
.chat-subtitle { font-size: 12px; color: var(--text-muted); }
.clear-btn {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-muted);
  font-size: 14px; padding: 6px 10px; cursor: pointer;
  transition: all 0.2s;
}
.clear-btn:hover { background: rgba(239,68,68,0.15); border-color: rgba(239,68,68,0.4); color: #ef4444; }

/* ── Messages ────────────────────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

/* ── Welcome Screen ──────────────────────────────────────────────────────── */
.welcome-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; text-align: center; gap: 16px;
  padding: 40px 20px;
  animation: fadeIn 0.6s ease;
}
.welcome-icon {
  font-size: 48px;
  background: var(--user-bubble);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 20px var(--accent-glow));
}
.welcome-screen h2 { font-size: 24px; font-weight: 700; }
.welcome-screen p { color: var(--text-muted); font-size: 14px; max-width: 440px; line-height: 1.6; }
.welcome-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.chip {
  padding: 8px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.chip:hover { background: var(--surface-hover); color: var(--text); border-color: var(--accent); }

/* ── Message Bubbles ─────────────────────────────────────────────────────── */
.message {
  display: flex;
  gap: 12px;
  animation: slideUp 0.3s ease;
  max-width: 820px;
}
.message.user { flex-direction: row-reverse; align-self: flex-end; }
.message.assistant { align-self: flex-start; }

.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0;
}
.message.user .avatar { background: var(--user-bubble); }
.message.assistant .avatar { background: var(--surface); border: 1px solid var(--border); }

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.65;
  max-width: 640px;
  white-space: pre-wrap;
  word-break: break-word;
}
.message.user .bubble {
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 20px rgba(124,111,247,0.3);
}
.message.assistant .bubble {
  background: var(--ai-bubble);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
  backdrop-filter: blur(8px);
}

/* ── Typing Indicator ─────────────────────────────────────────────────────── */
.typing-indicator {
  display: flex; gap: 4px; align-items: center; padding: 6px 0;
}
.typing-indicator span {
  width: 7px; height: 7px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.2s ease infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-8px); opacity: 1; }
}

/* ── Input Area ──────────────────────────────────────────────────────────── */
.input-area {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  background: rgba(10,10,20,0.4);
  backdrop-filter: blur(12px);
}
.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 10px 10px 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-wrapper:focus-within {
  border-color: rgba(124,111,247,0.5);
  box-shadow: 0 0 0 3px rgba(124,111,247,0.1);
}
.user-input {
  flex: 1;
  background: none; border: none; outline: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  max-height: 160px;
  overflow-y: auto;
}
.user-input::placeholder { color: var(--text-dim); }
.send-btn {
  width: 38px; height: 38px; flex-shrink: 0;
  background: var(--user-bubble);
  border: none; border-radius: 10px;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}
.send-btn:hover { opacity: 0.85; transform: scale(1.05); }
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.input-hint { font-size: 11px; color: var(--text-dim); margin-top: 8px; text-align: center; }

/* ── Animations ──────────────────────────────────────────────────────────── */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 50;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: block; }
}
