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

/* ===================== DESIGN TOKENS ===================== */
:root {
  --bg:           #0d0d0d;
  --surface:      #141414;
  --card:         #1a1a1a;
  --border:       #2a2a2a;
  --accent:       #6c63ff;
  --accent-hover: #5a52e0;
  --accent-dim:   rgba(108, 99, 255, 0.15);
  --text:         #f0f0f0;
  --text-muted:   #888888;
  --text-subtle:  #555;
  --success:      #22c55e;
  --danger:       #ef4444;
  --warning:      #f59e0b;
  --sidebar-w:    260px;
  --radius:       10px;
  --radius-sm:    6px;
  --radius-lg:    16px;
  --transition:   0.18s ease;
  --shadow:       0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm:    0 2px 8px rgba(0,0,0,0.3);
}

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

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

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
  transition: var(--transition);
}

input, textarea, select {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--transition);
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #444; }

/* ===================== LAYOUT ===================== */
#app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ===================== SIDEBAR ===================== */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 100;
  transition: transform var(--transition);
}

#sidebar-logo {
  padding: 20px 18px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

#sidebar-logo .logo-text {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

#sidebar-logo .logo-cai {
  color: var(--accent);
}

#sidebar-logo .logo-chat {
  color: var(--text);
}

.sidebar-new-chat {
  margin: 12px 12px 8px;
  padding: 9px 16px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13.5px;
  width: calc(100% - 24px);
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  transition: background var(--transition), transform var(--transition);
}

.sidebar-new-chat:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.sidebar-search {
  margin: 0 12px 8px;
  padding: 8px 12px;
  width: calc(100% - 24px);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--card);
  border: 1px solid var(--border);
}

#sidebar-chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.sidebar-chat-item {
  display: flex;
  align-items: center;
  padding: 9px 14px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  margin: 1px 6px;
  position: relative;
  transition: background var(--transition);
}

.sidebar-chat-item:hover {
  background: var(--card);
}

.sidebar-chat-item.active {
  background: var(--accent-dim);
  border: 1px solid rgba(108, 99, 255, 0.3);
}

.sidebar-chat-info {
  flex: 1;
  min-width: 0;
}

.sidebar-chat-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.sidebar-chat-model {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-chat-actions {
  display: none;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

.sidebar-chat-item:hover .sidebar-chat-actions {
  display: flex;
}

.sidebar-action-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  transition: background var(--transition), color var(--transition);
}

.sidebar-action-btn:hover {
  background: var(--border);
  color: var(--text);
}

.sidebar-action-btn.delete:hover {
  background: rgba(239,68,68,0.15);
  color: var(--danger);
}

#sidebar-bottom {
  border-top: 1px solid var(--border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}

.sidebar-nav-link:hover {
  background: var(--card);
  color: var(--text);
}

.sidebar-nav-link.active {
  background: var(--accent-dim);
  color: var(--accent);
}

#clerk-user-button-wrapper {
  margin-top: 6px;
  padding: 4px 6px;
}

/* ===================== MAIN CONTENT ===================== */
#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ===================== ANNOUNCEMENT BANNER ===================== */
#announcement-banner {
  background: linear-gradient(90deg, var(--accent), #8b5cf6);
  color: #fff;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13.5px;
  font-weight: 500;
  z-index: 50;
}

#announcement-banner button {
  background: rgba(255,255,255,0.2);
  color: #fff;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
  flex-shrink: 0;
}

#announcement-banner button:hover {
  background: rgba(255,255,255,0.35);
}

/* ===================== FOOTER ===================== */
#site-footer {
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding: 12px 24px;
  text-align: center;
  flex-shrink: 0;
}

/* ===================== HAMBURGER ===================== */
#hamburger-btn {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
  z-index: 200;
  color: var(--text);
  font-size: 18px;
}

#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 90;
}

/* ===================== BUTTONS ===================== */
.btn {
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(108,99,255,0.4);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--card);
  color: var(--text);
  border-color: #444;
}

.btn-danger {
  background: rgba(239,68,68,0.15);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,0.3);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239,68,68,0.25);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===================== CARDS ===================== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

/* ===================== BADGES ===================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-accent {
  background: var(--accent-dim);
  color: var(--accent);
}

.badge-success {
  background: rgba(34,197,94,0.12);
  color: var(--success);
}

.badge-warning {
  background: rgba(245,158,11,0.12);
  color: var(--warning);
}

.badge-danger {
  background: rgba(239,68,68,0.12);
  color: var(--danger);
}

/* ===================== FORM ELEMENTS ===================== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 9px 12px;
}

.form-group textarea {
  min-height: 80px;
  resize: vertical;
}

/* ===================== TOGGLE SWITCH ===================== */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 24px;
  cursor: pointer;
  transition: background var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* ===================== PROGRESS BAR ===================== */
.progress-bar-container {
  background: var(--border);
  border-radius: 10px;
  height: 8px;
  overflow: hidden;
  margin: 8px 0;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #8b5cf6);
  border-radius: 10px;
  transition: width 0.4s ease;
}

.progress-bar-fill.warning {
  background: linear-gradient(90deg, var(--warning), #ef4444);
}

/* ===================== TABS ===================== */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
}

.tab-btn {
  padding: 14px 20px;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--transition), border-color var(--transition);
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ===================== TABLE ===================== */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.data-table tr:hover td {
  background: rgba(255,255,255,0.02);
}

/* ===================== INDEX PAGE ===================== */
#home-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  overflow-y: auto;
}

#home-heading {
  text-align: center;
  margin-bottom: 36px;
}

#home-heading h1 {
  font-size: 42px;
  font-weight: 700;
  letter-spacing: -1px;
  margin-bottom: 8px;
}

#home-heading h1 span.cai {
  color: var(--accent);
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

#home-heading p {
  font-size: 15px;
  color: var(--text-muted);
}

#home-form-container {
  width: 100%;
  max-width: 760px;
}

#model-select-container {
  margin-bottom: 12px;
}

.model-select-wrapper {
  position: relative;
}

#model-select {
  width: 100%;
  padding: 11px 36px 11px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

#chat-input-wrapper {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition);
}

#chat-input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

#home-chat-input {
  width: 100%;
  background: transparent;
  border: none;
  padding: 16px 60px 16px 18px;
  color: var(--text);
  font-size: 15px;
  resize: none;
  min-height: 56px;
  max-height: 200px;
  line-height: 1.5;
}

#home-chat-input:focus {
  border: none;
  box-shadow: none;
}

#home-send-btn {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: background var(--transition), transform var(--transition);
}

#home-send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: scale(1.08);
}

#home-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

#home-hint {
  font-size: 12px;
  color: var(--text-subtle);
  margin-top: 8px;
  text-align: center;
}

#recent-chats-section {
  width: 100%;
  max-width: 760px;
  margin-top: 40px;
}

#recent-chats-section h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 14px;
}

#recent-chats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.recent-chat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}

.recent-chat-card:hover {
  background: #1f1f1f;
  border-color: #3a3a3a;
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.recent-chat-card-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.recent-chat-card-meta {
  font-size: 11.5px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

/* ===================== CHAT PAGE ===================== */
#chat-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#chat-header {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
  background: var(--surface);
}

#chat-title-display {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 400px;
}

#chat-title-display:hover {
  background: var(--card);
}

#chat-title-input {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  padding: 4px 8px;
  max-width: 400px;
  display: none;
}

#chat-model-badge {
  background: var(--accent-dim);
  color: var(--accent);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

#chat-delete-btn {
  background: transparent;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

#chat-delete-btn:hover {
  background: rgba(239,68,68,0.15);
  color: var(--danger);
}

#messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
  scroll-behavior: smooth;
}

.messages-inner {
  max-width: 820px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Message styles */
.message-group {
  display: flex;
  flex-direction: column;
}

/* User messages */
.message-user {
  align-self: flex-end;
  max-width: 75%;
}

.message-user .message-bubble {
  background: #1e1b4b;
  border: 1px solid rgba(108,99,255,0.3);
  border-radius: var(--radius) var(--radius) 2px var(--radius);
  padding: 12px 16px;
  font-size: 14.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  position: relative;
}

/* Assistant messages */
.message-assistant {
  align-self: flex-start;
  width: 100%;
}

.message-assistant .message-bubble {
  background: transparent;
  padding: 4px 0;
  font-size: 14.5px;
  line-height: 1.7;
}

/* Message bubbles hover for actions */
.message-group {
  position: relative;
}

.message-actions {
  display: none;
  gap: 4px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.message-group:hover .message-actions {
  display: flex;
}

.message-user .message-actions {
  justify-content: flex-end;
}

.msg-action-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all var(--transition);
}

.msg-action-btn:hover {
  background: var(--border);
  color: var(--text);
}

.msg-action-btn.danger:hover {
  background: rgba(239,68,68,0.12);
  color: var(--danger);
  border-color: rgba(239,68,68,0.3);
}

/* Thinking blocks */
.thinking-block {
  background: #0f0f0f;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-bottom: 12px;
  overflow: hidden;
}

.thinking-block summary {
  padding: 8px 14px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}

.thinking-block summary::-webkit-details-marker { display: none; }

.thinking-toggle-icon {
  margin-left: auto;
  font-size: 11px;
  transition: transform var(--transition);
}

.thinking-block[open] .thinking-toggle-icon {
  transform: rotate(180deg);
}

.thinking-content {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12.5px;
  color: var(--text-muted);
  padding: 10px 14px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  border-top: 1px solid var(--border);
  max-height: 300px;
  overflow-y: auto;
}

/* Typing indicator */
#typing-indicator {
  display: none;
  padding: 12px 0;
  max-width: 820px;
  margin: 0 auto;
  padding: 0 20px;
}

.typing-dots {
  display: flex;
  gap: 5px;
  padding: 14px 16px;
  background: var(--card);
  border-radius: var(--radius);
  width: fit-content;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.3s ease-in-out infinite;
  opacity: 0.6;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-8px); }
}

/* Markdown content inside assistant messages */
.md-content h1, .md-content h2, .md-content h3 {
  margin: 16px 0 8px;
  line-height: 1.3;
}

.md-content h1 { font-size: 22px; }
.md-content h2 { font-size: 18px; }
.md-content h3 { font-size: 16px; }

.md-content p { margin: 8px 0; }

.md-content ul, .md-content ol {
  margin: 8px 0;
  padding-left: 24px;
}

.md-content li { margin: 4px 0; }

.md-content code {
  background: #1f1f2e;
  color: #c4b5fd;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
}

.md-content pre {
  background: #0a0a0f;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0;
  margin: 12px 0;
  overflow: hidden;
}

.md-content pre .hljs {
  background: transparent;
  padding: 14px 16px;
  font-size: 13px;
  overflow-x: auto;
}

.md-content pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: 13px;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: #111;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.code-copy-btn {
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.code-copy-btn:hover {
  background: var(--border);
  color: var(--text);
}

.md-content blockquote {
  border-left: 3px solid var(--accent);
  padding: 8px 16px;
  background: var(--accent-dim);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 10px 0;
  color: var(--text-muted);
}

.md-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13.5px;
}

.md-content table th,
.md-content table td {
  border: 1px solid var(--border);
  padding: 8px 12px;
}

.md-content table th {
  background: var(--surface);
  font-weight: 600;
}

.md-content a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Chat input bar */
#chat-input-bar {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 12px 20px;
  flex-shrink: 0;
}

#usage-display {
  font-size: 11.5px;
  color: var(--text-subtle);
  margin-bottom: 8px;
  text-align: center;
}

#chat-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  max-width: 820px;
  margin: 0 auto;
}

#chat-model-switcher {
  padding: 9px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  min-width: 160px;
  max-width: 200px;
  flex-shrink: 0;
}

#chat-message-input {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text);
  font-size: 14.5px;
  resize: none;
  min-height: 44px;
  max-height: 150px;
  line-height: 1.5;
  transition: border-color var(--transition), box-shadow var(--transition);
}

#chat-message-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

#chat-send-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition);
}

#chat-send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: scale(1.05);
}

#chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* Edit mode for message */
.message-edit-area {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  resize: vertical;
  min-height: 80px;
  margin-bottom: 8px;
}

.message-edit-actions {
  display: flex;
  gap: 8px;
}

/* ===================== SETTINGS PAGE ===================== */
#settings-page {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
}

.settings-section {
  max-width: 680px;
  margin: 0 auto 32px;
}

.settings-section-header {
  margin-bottom: 18px;
}

.settings-section-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.settings-section-header p {
  font-size: 13.5px;
  color: var(--text-muted);
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.settings-row-info strong {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  display: block;
}

.settings-row-info small {
  font-size: 12px;
  color: var(--text-muted);
}

/* Model list in settings */
.model-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.model-list-item:hover {
  background: rgba(255,255,255,0.02);
}

.model-list-item.starred {
  background: var(--accent-dim);
}

.star-btn {
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.star-btn.active {
  color: #f59e0b;
}

.star-btn:hover {
  background: var(--card);
}

/* ===================== ADMIN PAGE ===================== */
#admin-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#admin-tabs-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
}

.admin-tab-btn {
  padding: 14px 22px;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--transition), border-color var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.admin-tab-btn:hover { color: var(--text); }
.admin-tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

#admin-tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.admin-section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
}

/* Stats cards */
#stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.stat-card-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

.stat-card-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 500;
}

/* Top models bar chart */
.model-bar-item {
  margin-bottom: 12px;
}

.model-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  margin-bottom: 5px;
  color: var(--text-muted);
}

.model-bar-track {
  background: var(--border);
  border-radius: 10px;
  height: 8px;
  overflow: hidden;
}

.model-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #a78bfa);
  border-radius: 10px;
  transition: width 0.5s ease;
}

/* Key list items */
.key-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
}

.key-list-item code {
  flex: 1;
  font-family: monospace;
  font-size: 13px;
  color: var(--text-muted);
}

.key-remove-btn {
  background: transparent;
  color: var(--text-subtle);
  font-size: 18px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all var(--transition);
}

.key-remove-btn:hover {
  background: rgba(239,68,68,0.12);
  color: var(--danger);
}

/* Pagination */
.pagination {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  margin-top: 20px;
}

.pg-btn {
  padding: 6px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  transition: all var(--transition);
}

.pg-btn:hover:not(:disabled) {
  background: var(--border);
  color: var(--text);
}

.pg-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.pg-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ===================== MODAL ===================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 440px;
  width: 90%;
  box-shadow: var(--shadow);
}

.modal-box h3 { font-size: 17px; margin-bottom: 10px; }
.modal-box p { color: var(--text-muted); font-size: 14px; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ===================== LOADING ===================== */
.loading-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===================== EMPTY STATE ===================== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 48px;
  display: block;
  margin-bottom: 14px;
  opacity: 0.4;
}

.empty-state h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 13.5px;
}

/* ===================== UTILITIES ===================== */
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-accent { color: var(--accent); }
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.w-full { width: 100%; }

/* ===================== INLINE EDIT ===================== */
.inline-edit-input {
  background: var(--card);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--text);
  padding: 3px 7px;
  font-size: 13px;
  width: 80px;
}

/* ===================== MOBILE RESPONSIVE ===================== */
@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    z-index: 150;
  }

  #sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow);
  }

  #sidebar-overlay.show {
    display: block;
  }

  #hamburger-btn {
    display: flex;
  }

  #home-heading h1 {
    font-size: 28px;
  }

  #chat-header {
    padding-left: 60px;
  }

  #admin-tab-content {
    padding: 16px;
  }

  .settings-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  #recent-chats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .message-user {
    max-width: 90%;
  }

  #stats-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 480px) {
  #recent-chats-grid {
    grid-template-columns: 1fr;
  }

  #stats-grid {
    grid-template-columns: 1fr;
  }

  .admin-tab-btn {
    padding: 12px 14px;
    font-size: 13px;
  }
}
