:root {
  --bg: #0b1120;
  --border: rgba(148, 163, 184, 0.18);
  --text: #e5eefc;
  --muted: #93a4c3;
  --primary: #3b82f6;
  --ai-bubble: #1e293b;
  --user-bubble: linear-gradient(135deg, #2563eb, #38bdf8);
  --shadow: 0 20px 60px rgba(2, 6, 23, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(59, 130, 246, 0.18), transparent 32%),
    radial-gradient(circle at bottom right, rgba(14, 165, 233, 0.14), transparent 28%),
    linear-gradient(180deg, #020617 0%, #0b1120 100%);
  color: var(--text);
  font-family: "Inter", sans-serif;
}

body { overflow: hidden; }
.hidden { display: none !important; }

.app-shell {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: 100vh;
}

.sidebar {
  background: rgba(2, 6, 23, 0.9);
  border-right: 1px solid var(--border);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  backdrop-filter: blur(22px);
}

.sidebar.collapsed .wide,
.sidebar.collapsed .section-label,
.sidebar.collapsed .chat-item-content,
.sidebar.collapsed .user-meta,
.sidebar.collapsed #logoutBtn { display: none; }

.sidebar.collapsed .chat-item,
.sidebar.collapsed .user-card { justify-content: center; }

.sidebar-top,
.topbar,
.chat-header,
.user-card,
.composer { display: flex; align-items: center; }

.sidebar-top,
.topbar,
.chat-header { justify-content: space-between; }

.sidebar-section {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.section-label,
.auth-note,
#activeChatMeta,
.chat-time,
.model-picker span {
  color: var(--muted);
  font-size: 0.9rem;
}

.chat-list,
.messages {
  overflow-y: auto;
  scrollbar-width: thin;
}

.chat-list { display: flex; flex-direction: column; gap: 8px; padding-right: 4px; }

.chat-item {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: 18px;
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
  transition: 0.2s ease;
  display: flex;
  gap: 12px;
  align-items: center;
}

.chat-item:hover,
.chat-item.active {
  background: rgba(37, 99, 235, 0.12);
  border-color: rgba(59, 130, 246, 0.2);
}

.chat-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, #38bdf8, #2563eb);
  flex: 0 0 auto;
}

.chat-item-content { min-width: 0; }

.chat-item-title,
.user-meta strong,
.user-meta span {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-title { font-weight: 600; }

.main-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(7, 11, 24, 0.5);
  backdrop-filter: blur(16px);
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand h1, .chat-header h2, .auth-card h2 { margin: 0; font-size: 1.2rem; }
.brand p, .auth-card p { margin: 4px 0 0; color: var(--muted); }
.mobile-menu { display: none; }

.auth-screen, .chat-layout { flex: 1; min-height: 0; }

.auth-screen {
  display: grid;
  place-items: center;
  padding: 28px;
}

.auth-card {
  width: min(520px, 100%);
  padding: 32px;
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.95), rgba(15, 23, 42, 0.84));
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.auth-badge {
  display: inline-flex;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  background: rgba(59, 130, 246, 0.16);
  color: #bfdbfe;
  margin-bottom: 14px;
}

.terms-box {
  margin: 22px 0 18px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--border);
}

.chat-layout {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0 24px 24px;
}

.chat-header { padding: 18px 4px 10px; }

.messages {
  flex: 1;
  min-height: 0;
  padding: 10px 4px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}

.empty-state {
  margin: auto;
  width: min(720px, 100%);
  padding: 28px;
  border-radius: 28px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--border);
  text-align: center;
}

.empty-state h3 { margin: 0 0 8px; }
.empty-state p { margin: 0; color: var(--muted); }

.message-row { display: flex; }
.message-row.user { justify-content: flex-end; }
.message-row.assistant { justify-content: flex-start; }

.bubble {
  max-width: min(760px, 82%);
  padding: 16px 18px;
  border-radius: 22px;
  line-height: 1.6;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  word-break: break-word;
}

.message-row.user .bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: 8px;
}

.message-row.assistant .bubble {
  background: var(--ai-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 8px;
}

.composer-wrap { padding-top: 12px; }

.composer {
  gap: 12px;
  padding: 14px;
  border-radius: 26px;
  background: rgba(15, 23, 42, 0.84);
  border: 1px solid var(--border);
}

.composer textarea {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  max-height: 220px;
}

.primary-btn, .ghost-btn, .chat-item, .model-picker select { font: inherit; }

.primary-btn, .ghost-btn {
  border: none;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.primary-btn:hover, .ghost-btn:hover { transform: translateY(-1px); }

.primary-btn {
  background: linear-gradient(135deg, var(--primary), #0ea5e9);
  color: white;
  padding: 12px 18px;
  border-radius: 16px;
  font-weight: 600;
}

.ghost-btn {
  background: rgba(30, 41, 59, 0.7);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 16px;
}

.ghost-btn.small { padding: 8px 10px; font-size: 0.9rem; }
.ghost-btn.icon-only { width: 48px; }

.model-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.74);
  border: 1px solid var(--border);
}

.model-picker select {
  background: transparent;
  color: var(--text);
  border: none;
  outline: none;
}

.model-picker option { background: #0f172a; }

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--muted);
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #60a5fa;
  animation: pulse 1.2s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

.user-card {
  gap: 12px;
  padding: 12px;
  border-radius: 20px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border);
}

.user-card img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
}

.user-meta { flex: 1; min-width: 0; }
.send-btn { align-self: stretch; }

@keyframes pulse {
  0%, 80%, 100% { transform: scale(0.75); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    z-index: 20;
    inset: 0 auto 0 0;
    width: min(86vw, 320px);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu { display: inline-flex; }
  .topbar, .chat-layout { padding-left: 18px; padding-right: 18px; }
  .bubble { max-width: 92%; }
}

@media (max-width: 640px) {
  .topbar { align-items: flex-start; gap: 14px; flex-direction: column; }
  .composer { align-items: stretch; flex-direction: column; }
  .send-btn { width: 100%; }
}
