/* ============================================================
   Nova — styles
   A polished ChatGPT-inspired theme with light/dark support.
   ============================================================ */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", "Fira Code", Consolas, monospace;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --transition: 160ms cubic-bezier(0.4, 0, 0.2, 1);

  --accent: #8b5cf6;
  --accent-hover: #7c3aed;
  --accent-soft: rgba(139, 92, 246, 0.14);
  --accent-2: #6366f1;
  --accent-gradient: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
}

/* Dark theme (default) */
[data-theme="dark"] {
  --bg: #212121;
  --bg-elevated: #2f2f2f;
  --bg-input: #2f2f2f;
  --bg-hover: #3a3a3a;
  --sidebar-bg: #171717;
  --text: #ececec;
  --text-dim: #a8a8a8;
  --text-muted: #777;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --bubble-user: #2f2f2f;
  --bubble-ai: transparent;
  --code-bg: #1a1a1a;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

/* Light theme */
[data-theme="light"] {
  --bg: #ffffff;
  --bg-elevated: #f7f7f8;
  --bg-input: #ffffff;
  --bg-hover: #ececee;
  --sidebar-bg: #f9f9f9;
  --text: #1a1a1a;
  --text-dim: #5d5d5d;
  --text-muted: #8e8e8e;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.14);
  --bubble-user: #f0f0f3;
  --bubble-ai: transparent;
  --code-bg: #f6f8fa;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

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

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }

/* ============================================================
   Layout
   ============================================================ */

.app {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Auth screen fills the viewport and centers the card */
.auth-screen {
  flex: 1;
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Main app shell: sidebar + main column side by side, fills screen */
.app-shell {
  flex: 1;
  display: flex;
  height: 100vh;
  width: 100%;
  min-height: 0;
  overflow: hidden;
}

/* ---------------- Sidebar ---------------- */

.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width var(--transition), transform var(--transition);
  flex-shrink: 0;
}
[data-theme="dark"] .sidebar {
  background: #131316;
}

.sidebar.collapsed { width: 0; border-right: none; overflow: hidden; }

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
}

.new-chat-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  transition: background var(--transition);
}
.new-chat-btn:hover { background: var(--bg-hover); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  flex-shrink: 0;
  transition: background var(--transition);
}
.icon-btn:hover { background: var(--bg-hover); }

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.empty-history {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 24px 12px;
}

.convo-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13.5px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  position: relative;
}
.convo-item:hover { background: var(--bg-hover); color: var(--text); }
.convo-item.active { background: var(--bg-hover); color: var(--text); }
.convo-item .convo-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.convo-item .convo-del {
  opacity: 0;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  transition: opacity var(--transition), background var(--transition);
}
.convo-item:hover .convo-del { opacity: 1; }
.convo-item .convo-del:hover { background: rgba(255,90,90,0.18); color: #ff7676; }

.sidebar-footer {
  padding: 8px;
  border-top: 1px solid var(--border);
}
.footer-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13.5px;
  transition: background var(--transition);
}
.footer-btn:hover { background: var(--bg-hover); color: var(--text); }
.brand {
  display: flex;
  flex-direction: column;
  padding: 8px 10px 4px;
}
.brand-name { font-size: 13px; font-weight: 600; color: var(--text); }
.brand-sub { font-size: 11px; color: var(--text-muted); }

/* ---------------- Main column ---------------- */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  height: 52px;
  flex-shrink: 0;
}
.menu-btn { display: none; }

.model-picker select {
  background: transparent;
  color: var(--text);
  border: none;
  font-size: 15px;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  outline: none;
  max-width: 260px;
}
.model-picker select:hover { background: var(--bg-hover); }
.model-picker select option { background: var(--bg-elevated); color: var(--text); }

.topbar .theme-btn { margin-left: auto; }
.icon-sun { display: none; }
[data-theme="light"] .icon-sun { display: inline; }
[data-theme="light"] .icon-moon { display: none; }

/* ---------------- Chat area ---------------- */

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.chat-container {
  max-width: 768px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* Welcome screen */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 8vh 20px 4vh;
}
.welcome-logo {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: var(--accent-gradient);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  box-shadow: 0 8px 28px rgba(139, 92, 246, 0.4);
}
.welcome h1 { font-size: 28px; font-weight: 600; margin-bottom: 8px; }
.welcome-tagline { color: var(--text-dim); font-size: 15px; margin-bottom: 32px; }
.prompt-suggestions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  width: 100%;
  max-width: 620px;
}
.suggestion {
  text-align: left;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--text);
  transition: background var(--transition), border-color var(--transition);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.suggestion:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.s-icon { font-size: 18px; margin-bottom: 6px; color: var(--accent); font-weight: 700; font-family: var(--font-mono);}
.s-title { font-weight: 600; font-size: 14px; }
.s-sub { color: var(--text-dim); font-size: 12.5px; }

/* Message rows */
.msg {
  display: flex;
  gap: 16px;
  width: 100%;
  animation: fadein 240ms ease;
}
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: white;
}
.avatar.ai { background: var(--accent-gradient); }
.avatar.user { background: linear-gradient(135deg, #ec4899, #f43f5e); }

.msg-body { flex: 1; min-width: 0; padding-top: 3px; }
.msg-role { font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.4px; }

.msg-content {
  font-size: 15px;
  line-height: 1.7;
  word-wrap: break-word;
}
.msg-content p { margin: 0 0 12px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content ul, .msg-content ol { margin: 0 0 12px; padding-left: 24px; }
.msg-content li { margin-bottom: 4px; }
.msg-content h1, .msg-content h2, .msg-content h3 { margin: 16px 0 8px; line-height: 1.3; }
.msg-content h1 { font-size: 22px; }
.msg-content h2 { font-size: 19px; }
.msg-content h3 { font-size: 16px; }
.msg-content a { color: var(--accent); }
.msg-content blockquote {
  border-left: 3px solid var(--border-strong);
  padding-left: 14px;
  color: var(--text-dim);
  margin: 0 0 12px;
}
.msg-content code {
  font-family: var(--font-mono);
  font-size: 13.5px;
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 5px;
}
.msg-content pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 0 0 12px;
  position: relative;
}
.msg-content pre code {
  background: transparent;
  padding: 0;
  font-size: 13px;
  line-height: 1.55;
}
.msg-content table {
  border-collapse: collapse;
  margin: 0 0 12px;
  width: 100%;
  font-size: 14px;
}
.msg-content th, .msg-content td {
  border: 1px solid var(--border-strong);
  padding: 8px 12px;
  text-align: left;
}

/* Code block copy button */
.code-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 5px;
  opacity: 0;
  transition: opacity var(--transition);
}
.msg-content pre:hover .code-copy { opacity: 1; }
.code-copy:hover { color: var(--text); }

/* Message actions (copy / regen) */
.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity var(--transition);
}
.msg:hover .msg-actions { opacity: 1; }
.msg-action {
  display: flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 5px;
  transition: background var(--transition), color var(--transition);
}
.msg-action:hover { background: var(--bg-hover); color: var(--text); }

/* Streaming cursor */
.cursor-blink::after {
  content: "▍";
  animation: blink 1s steps(2) infinite;
  color: var(--accent);
  margin-left: 1px;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------------- Composer ---------------- */

.composer-wrap {
  background: linear-gradient(to top, var(--bg) 60%, transparent);
  padding: 8px 20px 18px;
  flex-shrink: 0;
}
.composer {
  max-width: 768px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow);
  transition: border-color var(--transition);
}
.composer:focus-within { border-color: var(--accent); }
.composer-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  outline: none;
  padding: 8px 0;
  max-height: 200px;
  overflow-y: auto;
}
.composer-input::placeholder { color: var(--text-muted); }
.send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--accent-gradient);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition), opacity var(--transition), transform var(--transition), filter var(--transition);
}
.send-btn:hover:not(:disabled) { filter: brightness(1.1); transform: scale(1.06); }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.send-btn.stop { background: #d9534f; }
.composer-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
  max-width: 768px;
  margin-left: auto;
  margin-right: auto;
}

/* ---------------- Modal ---------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-overlay.open { display: flex; animation: fadein 180ms ease; }
.modal {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 17px; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 20px; }
.setting-row { display: flex; flex-direction: column; gap: 6px; }
.setting-row label { font-size: 13.5px; font-weight: 600; }
.setting-row small { color: var(--text-muted); font-size: 12px; }
.setting-row textarea, .setting-row input[type="text"] {
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  resize: vertical;
  outline: none;
  font-family: inherit;
}
.setting-row textarea:focus { border-color: var(--accent); }
.range-row { display: flex; align-items: center; gap: 12px; }
.range-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.range-value { font-family: var(--font-mono); font-size: 14px; min-width: 32px; text-align: right; }
.status-box {
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  font-family: var(--font-mono);
}
.status-box.ok { border-color: var(--accent); color: var(--accent); }
.status-box.err { border-color: #d9534f; color: #ff7676; }
.modal-footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}
.btn-primary, .btn-secondary {
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background var(--transition);
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: transparent; color: #ff7676; border-color: var(--border-strong); }
.btn-secondary:hover { background: rgba(255,90,90,0.12); }

/* ---------------- Toast ---------------- */

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition);
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------- Scrollbar ---------------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------- Responsive ---------------- */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar.collapsed { width: 260px; }
  .menu-btn { display: inline-flex; }
  .sidebar-toggle { display: none; }
  .prompt-suggestions { grid-template-columns: 1fr; }
  .chat-container { padding: 16px 14px 30px; }
  .composer-wrap { padding: 8px 12px 14px; }
  .welcome { padding: 4vh 16px 2vh; }
  .settings-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   AUTH SCREEN
   ============================================================ */
.auth-screen {
  padding: 20px;
  position: relative;
  overflow: hidden;
}
[data-theme="dark"] .auth-screen {
  background: #0e0e12;
  background-image:
    radial-gradient(ellipse 60% 50% at 20% 30%, rgba(139,92,246,0.12) 0%, transparent 70%),
    radial-gradient(ellipse 50% 40% at 80% 70%, rgba(99,102,241,0.10) 0%, transparent 70%);
}
[data-theme="light"] .auth-screen {
  background: #f0eef5;
  background-image:
    radial-gradient(ellipse 60% 50% at 20% 30%, rgba(139,92,246,0.10) 0%, transparent 70%),
    radial-gradient(ellipse 50% 40% at 80% 70%, rgba(99,102,241,0.08) 0%, transparent 70%);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 36px 36px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.25), 0 0 80px rgba(139, 92, 246, 0.06);
  position: relative;
  animation: authCardIn 500ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes authCardIn {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}
.auth-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 32px;
}
.auth-logo svg {
  width: 36px;
  height: 36px;
  color: white;
  filter: drop-shadow(0 2px 8px rgba(139, 92, 246, 0.45));
}
[data-theme="dark"] .auth-card {
  background: rgba(35, 35, 42, 0.85);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-color: rgba(255, 255, 255, 0.06);
}
[data-theme="light"] .auth-card {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-color: rgba(0, 0, 0, 0.06);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.08), 0 0 80px rgba(139, 92, 246, 0.04);
}
.auth-form h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 24px;
  color: var(--text);
}
.auth-form .field { margin-bottom: 18px; }
.auth-form label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}
.auth-form input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  color: var(--text);
  font-size: 14.5px;
  outline: none;
  transition: border-color 200ms, box-shadow 200ms;
}
.auth-form input::placeholder { color: var(--text-muted); }
.auth-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}
.btn-full {
  width: 100%;
  margin-top: 6px;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  background: var(--accent-gradient);
  color: white;
  border: none;
  cursor: pointer;
  transition: filter 200ms, transform 150ms, box-shadow 200ms;
  box-shadow: 0 2px 12px rgba(139, 92, 246, 0.3);
}
.btn-full:hover {
  filter: brightness(1.08);
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
  transform: translateY(-1px);
}
.btn-full:active { transform: translateY(0); }
.btn-primary:not(.btn-full) {
  background: var(--accent-gradient);
  color: white;
  border: none;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.2);
}
.btn-primary:not(.btn-full):hover {
  filter: brightness(1.08);
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.3);
}
.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 16px;
  color: var(--text-muted);
  font-size: 12px;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-strong);
}
.auth-switch {
  margin-top: 20px;
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
}
.auth-switch a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.auth-switch a:hover { text-decoration: underline; }
.auth-error {
  background: rgba(217, 83, 79, 0.12);
  border: 1px solid rgba(217, 83, 79, 0.25);
  border-radius: 8px;
  padding: 10px 14px;
  color: #ff7676;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}
.auth-error.show { display: block; }

/* ============================================================
   PAGES (tab-based routing)
   ============================================================ */
.hidden { display: none !important; }
.page { display: none; }
.page.active { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.page-inner { max-width: 720px; margin: 0 auto; padding: 32px 24px; width: 100%; }
.page-header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.page-desc { color: var(--text-dim); font-size: 14px; margin-bottom: 24px; }
.page-desc a { color: var(--accent); }

/* ============================================================
   SIDEBAR NAV + USER BLOCK
   ============================================================ */
.sidebar-nav { display: flex; flex-direction: column; gap: 1px; }
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.user-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.user-avatar-sm {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-gradient); color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; flex-shrink: 0; overflow: hidden;
}
.user-avatar-sm img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.user-meta { display: flex; flex-direction: column; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-tier { font-size: 11px; color: var(--accent); font-weight: 500; }

/* ============================================================
   TOPBAR (updated)
   ============================================================ */
.topbar-title { font-size: 15px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.token-meter { display: flex; align-items: center; gap: 6px; }
.meter-label { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.model-select-inline {
  background: transparent; color: var(--text-dim); border: none;
  font-size: 12px; padding: 4px 6px; border-radius: 6px; outline: none; cursor: pointer;
}
.model-select-inline:hover { background: var(--bg-hover); }
.model-select-inline option { background: var(--bg-elevated); color: var(--text); }

/* ============================================================
   SETTINGS
   ============================================================ */
.settings-section {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.settings-section h3 { font-size: 15px; margin-bottom: 14px; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.settings-grid .field { display: flex; flex-direction: column; gap: 4px; }
.settings-grid label { font-size: 13px; font-weight: 600; color: var(--text-dim); }
.settings-grid input[type="text"],
.settings-grid input[type="password"],
.settings-grid textarea {
  background: var(--bg-input); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); color: var(--text);
  padding: 9px 12px; font-size: 14px; outline: none; font-family: inherit;
}
.settings-grid input:focus, .settings-grid textarea:focus { border-color: var(--accent); }
.avatar-upload { display: flex; align-items: center; gap: 12px; }
.avatar-preview { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; background: var(--bg-hover); }
.avatar-preview:empty { display: none; }
.range-row { display: flex; align-items: center; gap: 12px; }
.range-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.range-value { font-family: var(--font-mono); font-size: 14px; min-width: 32px; text-align: right; }
small { color: var(--text-muted); font-size: 12px; }

/* ============================================================
   PLAN CARD
   ============================================================ */
.plan-card {
  background: var(--bg); border: 1px solid var(--border-strong);
  border-radius: var(--radius); padding: 20px;
}
.plan-name { font-size: 20px; font-weight: 700; }
.plan-price { font-size: 14px; color: var(--text-dim); margin: 2px 0 12px; }
.plan-features { list-style: none; padding: 0; }
.plan-features li { padding: 4px 0; font-size: 13.5px; color: var(--text-dim); }
.plan-features li::before { content: "✓ "; color: var(--accent); font-weight: 700; }

/* ============================================================
   API KEYS PAGE
   ============================================================ */
.key-list { display: flex; flex-direction: column; gap: 8px; }
.key-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px;
}
.key-item-info { min-width: 0; }
.key-item-name { font-weight: 600; font-size: 14px; }
.key-item-prefix { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.key-item-dates { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.key-item-actions { display: flex; gap: 6px; }
.empty-state { color: var(--text-muted); font-size: 14px; text-align: center; padding: 32px 16px; }
.new-key-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.key-reveal {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 28px; max-width: 480px; width: 90%;
  text-align: center;
}
.key-reveal strong { font-size: 17px; display: block; margin-bottom: 8px; }
.key-warn { color: var(--text-dim); font-size: 13px; margin-bottom: 16px; }
.key-value {
  display: block; background: var(--bg); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 12px; font-family: var(--font-mono);
  font-size: 13px; word-break: break-all; text-align: left; margin-bottom: 16px;
}

/* ============================================================
   DOCS PAGE
   ============================================================ */
.doc-content h3 { font-size: 17px; margin: 24px 0 8px; }
.doc-content p { margin-bottom: 10px; line-height: 1.7; }
.doc-content ul { margin-bottom: 12px; padding-left: 20px; }
.doc-content li { margin-bottom: 4px; }
.doc-code {
  display: block; background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 14px; font-family: var(--font-mono);
  font-size: 13px; margin-bottom: 12px;
}
.doc-pre {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px; overflow-x: auto;
  margin-bottom: 12px;
}
.doc-pre code { font-family: var(--font-mono); font-size: 13px; line-height: 1.55; }
.doc-table {
  border-collapse: collapse; margin-bottom: 12px; width: 100%; font-size: 14px;
}
.doc-table th, .doc-table td {
  border: 1px solid var(--border-strong); padding: 8px 12px; text-align: left;
}

/* ============================================================
   ADMIN PAGE
   ============================================================ */
.admin-section { margin-bottom: 28px; }
.admin-section h3 { font-size: 17px; margin-bottom: 12px; }
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.stat-card {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 16px; text-align: center;
}
.stat-value { font-size: 24px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.admin-search { margin-bottom: 12px; }
.admin-search input {
  width: 100%; padding: 10px 14px; background: var(--bg-input);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  color: var(--text); font-size: 14px; outline: none;
}
.admin-search input:focus { border-color: var(--accent); }
.admin-user-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 6px;
}
.admin-user-name { font-weight: 600; font-size: 14px; }
.admin-user-email { font-size: 12px; color: var(--text-muted); }
.admin-user-tier {
  font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: 10px; background: var(--accent-soft); color: var(--accent); margin-left: auto;
}
.admin-user-actions { display: flex; gap: 4px; }
.admin-user-actions button {
  font-size: 11px; padding: 3px 8px; border-radius: 5px;
  border: 1px solid var(--border-strong); background: transparent;
  color: var(--text-dim); cursor: pointer; transition: all var(--transition);
}
.admin-user-actions button:hover { background: var(--bg-hover); color: var(--text); }

