*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── THEMES ─────────────────────────────────────────────────────────── */
:root {
  --bg:        #212121;
  --sidebar:   #171717;
  --surface:   #2f2f2f;
  --surface2:  #3a3a3a;
  --border:    #383838;
  --text:      #ececec;
  --text-2:    #8e8e8e;
  --text-3:    #5a5a5a;
  --accent:    #10a37f;
  --accent-2:  #0d8f6e;
  --user-bg:   #2f2f2f;
  --red:       #e5534b;
  --yellow:    #d4a72c;
  --sans:      'Inter', system-ui, sans-serif;
  --mono:      'JetBrains Mono', monospace;
  --font:      var(--sans);
  --sidebar-w: 260px;
  --ease:      .15s ease;
}

[data-theme="light"] {
  --bg:        #ffffff;
  --sidebar:   #f7f7f7;
  --surface:   #f0f0f0;
  --surface2:  #e4e4e4;
  --border:    #d9d9d9;
  --text:      #1a1a1a;
  --text-2:    #5a5a5a;
  --text-3:    #a0a0a0;
  --user-bg:   #f0f0f0;
}

[data-font="jetbrains"] { --font: 'JetBrains Mono', monospace; }
[data-font="times"]     { --font: 'Times New Roman', serif; }
[data-font="georgia"]   { --font: 'Georgia', serif; }
[data-font="firacode"]  { --font: 'Fira Code', monospace; }
[data-font="system"]    { --font: system-ui, sans-serif; }

html, body { height: 100%; overflow: hidden; background: var(--bg); }
body { font-family: var(--font); color: var(--text); display: flex; transition: background .2s, color .2s; }

* { scrollbar-width: thin; scrollbar-color: var(--surface2) transparent; }
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 99px; }

/* ── AUTH ───────────────────────────────────────────────────────────── */
#auth-overlay {
  position: fixed; inset: 0; z-index: 999;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.auth-box { width: 100%; max-width: 340px; padding: 0 16px; }
.auth-logo {
  display: flex; align-items: center; justify-content: center;
  gap: 9px; margin-bottom: 32px;
}
.auth-logo-icon {
  width: 32px; height: 32px; border-radius: 8px; background: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.auth-logo-name { font-size: 16px; font-weight: 600; color: var(--text); letter-spacing: -.02em; }
.auth-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 24px;
}
.auth-tabs {
  display: flex; margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.auth-tab {
  flex: 1; text-align: center; padding: 8px;
  font-size: 13px; font-weight: 500; color: var(--text-2);
  cursor: pointer; border-bottom: 2px solid transparent;
  margin-bottom: -1px; transition: color var(--ease), border-color var(--ease);
}
.auth-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.auth-field { margin-bottom: 12px; }
.auth-field label { display: block; font-size: 12px; font-weight: 500; color: var(--text-2); margin-bottom: 5px; }
.auth-field input {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-family: var(--font);
  font-size: 14px; padding: 9px 12px; outline: none; transition: border-color var(--ease);
}
.auth-field input:focus { border-color: var(--accent); }
.auth-field input::placeholder { color: var(--text-3); }
.auth-btn {
  width: 100%; margin-top: 6px; padding: 10px;
  background: var(--accent); border: none; border-radius: 8px;
  color: #fff; font-family: var(--font); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: background var(--ease);
}
.auth-btn:hover { background: var(--accent-2); }
.auth-btn:disabled { opacity: .5; cursor: not-allowed; }
.auth-err { font-size: 12px; color: var(--red); margin-top: 8px; min-height: 16px; }

/* ── SIDEBAR ────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden; height: 100%;
  transition: width .22s ease, border-color .22s ease;
  position: relative; z-index: 10;
}

/* Collapsed sidebar state */
#sidebar.collapsed {
  width: 52px;
}
#sidebar.collapsed .sb-logo-name,
#sidebar.collapsed .sb-label,
#sidebar.collapsed #chat-list,
#sidebar.collapsed .sb-username,
#sidebar.collapsed .sb-logout,
#sidebar.collapsed .sb-nav-label { display: none; }
#sidebar.collapsed .sb-top { justify-content: center; padding: 12px 0 8px; flex-direction: column; gap: 4px; }
#sidebar.collapsed .sb-logo { display: none; }
#sidebar.collapsed .sb-nav { padding: 4px 0; align-items: center; }
#sidebar.collapsed .sb-nav-btn { width: 36px; height: 36px; justify-content: center; border-radius: 8px; padding: 0; }
#sidebar.collapsed .sb-nav-btn:hover { background: var(--surface); }
#sidebar.collapsed .sb-foot { justify-content: center; padding: 10px 0 14px; flex-direction: column; gap: 6px; }
#sidebar.collapsed .sb-user-avatar { margin: 0; }
#sidebar.collapsed .sb-toggle { margin: 0 auto; }

.sb-top {
  padding: 10px 10px 6px;
  display: flex; align-items: center; gap: 4px;
  flex-shrink: 0;
}
.sb-logo {
  display: flex; align-items: center; gap: 8px; flex: 1; padding: 4px 4px;
  overflow: hidden;
}
.sb-logo-icon {
  width: 24px; height: 24px; border-radius: 6px; background: var(--accent);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.sb-logo-name {
  font-size: 14px; font-weight: 600; color: var(--text); letter-spacing: -.02em;
  white-space: nowrap; overflow: hidden;
}
.sb-icon-btn {
  width: 30px; height: 30px; border-radius: 7px; border: none;
  background: none; color: var(--text-2); cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--ease), color var(--ease);
}
.sb-icon-btn:hover { background: var(--surface); color: var(--text); }

/* Toggle collapse button */
.sb-toggle {
  width: 28px; height: 28px; border-radius: 7px; border: none;
  background: none; color: var(--text-3); cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--ease), color var(--ease), transform var(--ease);
}
.sb-toggle:hover { background: var(--surface); color: var(--text); }
#sidebar.collapsed .sb-toggle { transform: scaleX(-1); }

/* Nav buttons section */
.sb-nav {
  padding: 6px 8px 4px;
  display: flex; flex-direction: column; gap: 2px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.sb-nav-btn {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 8px; border-radius: 8px; border: none;
  background: none; color: var(--text-2); cursor: pointer; width: 100%;
  font-family: var(--font); font-size: 13px; font-weight: 500;
  transition: background var(--ease), color var(--ease);
  white-space: nowrap; overflow: hidden;
  position: relative;
}
.sb-nav-btn:hover { background: var(--surface); color: var(--text); }
.sb-nav-btn.active { background: var(--surface2); color: var(--text); }
.sb-nav-btn svg { flex-shrink: 0; }
.sb-nav-label { overflow: hidden; text-overflow: ellipsis; }
.sb-nav-badge {
  margin-left: auto; font-size: 10px; font-weight: 600;
  background: var(--surface2); color: var(--text-3);
  padding: 2px 6px; border-radius: 99px; flex-shrink: 0;
}

.sb-label {
  padding: 10px 14px 4px; font-size: 11px; font-weight: 600;
  color: var(--text-3); text-transform: uppercase; letter-spacing: .06em;
  flex-shrink: 0;
}
#chat-list { flex: 1; overflow-y: auto; padding: 2px 8px 8px; }
.chat-item {
  display: flex; align-items: center; padding: 7px 8px; border-radius: 8px;
  cursor: pointer; transition: background var(--ease); margin-bottom: 1px;
}
.chat-item:hover { background: var(--surface); }
.chat-item.active { background: var(--surface2); }
.chat-item-name {
  flex: 1; font-size: 13.5px; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: color var(--ease);
}
.chat-item:hover .chat-item-name,
.chat-item.active .chat-item-name { color: var(--text); }
.chat-del {
  width: 22px; height: 22px; border-radius: 5px; border: none;
  background: none; color: var(--text-3); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; flex-shrink: 0; transition: opacity var(--ease), color var(--ease);
}
.chat-item:hover .chat-del { opacity: 1; }
.chat-del:hover { color: var(--red); }
.sb-foot {
  padding: 10px 10px 14px; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.sb-user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface2); color: var(--text); font-size: 12px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.sb-username {
  flex: 1; font-size: 13px; color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sb-logout {
  padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: none; color: var(--text-3); font-size: 12px; cursor: pointer;
  transition: all var(--ease); flex-shrink: 0; font-family: var(--font);
}
.sb-logout:hover { color: var(--red); border-color: rgba(229,83,75,.4); }

/* ── MAIN ───────────────────────────────────────────────────────────── */
#main {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
  min-width: 0; background: var(--bg); position: relative;
}

/* Pages inside main */
.main-page {
  display: none; flex: 1; overflow: hidden; flex-direction: column;
}
.main-page.active { display: flex; }

/* ── TOPBAR ─────────────────────────────────────────────────────────── */
#topbar {
  height: 50px; padding: 0 16px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}

/* ── CUSTOM MODEL DROPDOWN ──────────────────────────────────────────── */
.model-picker { position: relative; }
.model-trigger {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); cursor: pointer; user-select: none;
  transition: border-color var(--ease), background var(--ease);
  min-width: 150px;
}
.model-trigger:hover { border-color: var(--text-3); }
.model-trigger.open { border-color: var(--accent); }
.model-trigger-name {
  flex: 1; font-size: 13px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.model-trigger-arrow {
  flex-shrink: 0; color: var(--text-3);
  transition: transform .15s ease;
}
.model-trigger.open .model-trigger-arrow { transform: rotate(180deg); }
.model-dropdown {
  display: none; position: absolute; top: calc(100% + 6px); left: 0;
  min-width: 240px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.3);
  z-index: 100; overflow: hidden; padding: 4px;
}
.model-dropdown.open { display: block; }
.model-option {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 7px; cursor: pointer;
  transition: background var(--ease);
}
.model-option:hover { background: var(--surface2); }
.model-option.selected { background: rgba(16,163,127,.1); }
.model-option-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.dot-gemini     { background: #4285f4; }
.dot-openrouter { background: #7c3aed; }
.dot-groq       { background: #f97316; }
.model-option-info { flex: 1; min-width: 0; }
.model-option-name { font-size: 13px; font-weight: 500; color: var(--text); }
.model-option-sub  { font-size: 11px; color: var(--text-3); margin-top: 1px; }
.model-option-check { width: 14px; height: 14px; color: var(--accent); opacity: 0; flex-shrink: 0; }
.model-option.selected .model-option-check { opacity: 1; }

.topbar-title {
  flex: 1; font-size: 13.5px; font-weight: 500; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.token-badge {
  font-size: 11.5px; padding: 4px 9px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-2); white-space: nowrap; flex-shrink: 0;
}
.token-badge.warn  { color: var(--yellow); border-color: rgba(212,167,44,.35); background: rgba(212,167,44,.08); }
.token-badge.empty { color: var(--red);    border-color: rgba(229,83,75,.35);  background: rgba(229,83,75,.08); }

/* ── CHAT AREA (page) ───────────────────────────────────────────────── */
#page-chat {
  display: none; flex: 1; overflow: hidden; flex-direction: column;
}
#page-chat.active { display: flex; }

#no-chat {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  padding: 40px; gap: 10px;
}
.no-chat-icon {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; margin-bottom: 6px;
}
.no-chat-title { font-size: 20px; font-weight: 600; color: var(--text); letter-spacing: -.02em; }
.no-chat-sub { font-size: 13.5px; color: var(--text-2); line-height: 1.6; max-width: 300px; }
.no-chat-cta {
  margin-top: 6px; padding: 9px 20px;
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  font-family: var(--font); font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background var(--ease);
}
.no-chat-cta:hover { background: var(--accent-2); }

#chat-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
#messages { flex: 1; overflow-y: auto; padding: 16px 0 8px; display: flex; flex-direction: column; }

/* ── MESSAGES ───────────────────────────────────────────────────────── */
.msg-row {
  padding: 6px 20px; display: flex; max-width: 100%;
  animation: fadeUp .18s ease forwards;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* User message — right aligned bubble */
.msg-row.user { justify-content: flex-end; }
.msg-row.user > div { max-width: min(70%, 640px); }
.msg-row.user .bubble {
  background: var(--user-bg); border: 1px solid var(--border);
  border-radius: 16px 16px 4px 16px;
  padding: 11px 16px; font-size: 14px; line-height: 1.6; color: var(--text);
  word-break: break-word;
}
.msg-time {
  font-size: 11px; color: var(--text-3); margin-top: 4px;
  text-align: right; padding-right: 4px;
}

/* Assistant message — left aligned with avatar */
.msg-row.assistant { justify-content: flex-start; align-items: flex-start; gap: 12px; }
.asst-av {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 2px;
}
.asst-body { flex: 1; min-width: 0; max-width: min(85%, 720px); }
.asst-name { font-size: 11.5px; font-weight: 600; color: var(--text-3); margin-bottom: 6px; letter-spacing: .01em; }
.bubble { font-size: 14px; line-height: 1.65; color: var(--text); }

/* Code blocks */
.code-block {
  border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; margin: 10px 0; font-family: var(--mono);
  background: var(--sidebar);
}
.code-block-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.code-block-lang { font-size: 11.5px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; }
.code-block-tabs { display: flex; gap: 2px; }
.code-tab-btn {
  padding: 3px 10px; border-radius: 6px; border: none;
  background: none; color: var(--text-3); font-family: var(--font); font-size: 12px;
  cursor: pointer; transition: background var(--ease), color var(--ease);
}
.code-tab-btn:hover { background: var(--surface2); color: var(--text-2); }
.code-tab-btn.active { background: var(--surface2); color: var(--text); }
.code-block-copy {
  padding: 3px 10px; border-radius: 6px; border: none;
  background: none; color: var(--text-3); font-family: var(--font); font-size: 12px;
  cursor: pointer; transition: all var(--ease);
}
.code-block-copy:hover { color: var(--text); }
.code-block pre {
  margin: 0; border: none; border-radius: 0;
  padding: 14px 16px; background: transparent; font-size: 13px;
  overflow-x: auto; line-height: 1.6;
}
.code-block-preview { display: none; background: #fff; border-radius: 0; min-height: 80px; }
.code-block-preview.active { display: block; }
.code-block-preview iframe { width: 100%; border: none; display: block; min-height: 120px; }
.bubble code:not(pre code) {
  font-family: 'JetBrains Mono', monospace; font-size: .87em;
  background: var(--surface2); padding: 1px 5px; border-radius: 4px; color: var(--text);
}
.bubble p { margin-bottom: 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 6px 0 8px 20px; }
.bubble li { margin-bottom: 4px; line-height: 1.6; }
.bubble strong { color: var(--text); font-weight: 600; }
.bubble h2, .bubble h3, .bubble h4 { margin: 12px 0 6px; font-weight: 600; }
.bubble h2 { font-size: 16px; } .bubble h3 { font-size: 15px; } .bubble h4 { font-size: 14px; }

.typing-dots { display: flex; align-items: center; gap: 4px; padding: 6px 0; }
.typing-dots span {
  width: 5px; height: 5px; border-radius: 50%; background: var(--text-3);
  animation: blink 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,60%,100% { opacity:.3; transform:scale(.85); } 30% { opacity:1; transform:scale(1); } }

#empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 40px; gap: 6px;
}
.es-icon {
  width: 44px; height: 44px; border-radius: 10px; background: var(--surface);
  border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; margin-bottom: 10px;
}
.es-title { font-size: 17px; font-weight: 600; color: var(--text); }
.es-sub { font-size: 13.5px; color: var(--text-2); line-height: 1.6; max-width: 300px; }
.es-chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 10px; }
.es-chip { font-size: 11.5px; padding: 4px 10px; border-radius: 99px; background: var(--surface); border: 1px solid var(--border); color: var(--text-3); }

.msg-err { font-size: 12.5px; color: var(--red); text-align: center; padding: 6px; }

/* ── INPUT ──────────────────────────────────────────────────────────── */
#input-area {
  padding: 12px 20px 16px; flex-shrink: 0;
  max-width: 760px; width: 100%; margin: 0 auto; align-self: center;
}
.input-shell {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; transition: border-color var(--ease); padding: 4px 6px 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.input-shell:focus-within { border-color: var(--text-3); }
#msg-input {
  display: block; width: 100%; background: none; border: none; outline: none;
  color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.55;
  padding: 10px 10px 4px; resize: none; min-height: 44px; max-height: 200px;
}
#msg-input::placeholder { color: var(--text-3); }
.input-footer { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 2px; }
.input-hint { font-size: 11px; color: var(--text-3); }
#send-btn {
  width: 32px; height: 32px; border-radius: 8px; border: none;
  background: var(--accent); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--ease), opacity var(--ease);
}
#send-btn:hover:not(:disabled) { background: var(--accent-2); }
#send-btn:disabled { opacity: .35; cursor: not-allowed; }
.rate-note { text-align: center; font-size: 11px; color: var(--text-3); padding: 6px 0 0; }

/* ── SETTINGS PAGE ──────────────────────────────────────────────────── */
#page-settings {
  display: none; flex: 1; overflow: hidden; flex-direction: column;
}
#page-settings.active { display: flex; }

.settings-page-head {
  height: 50px; padding: 0 24px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.settings-page-title { font-size: 15px; font-weight: 600; color: var(--text); }

.settings-page-body {
  flex: 1; overflow-y: auto; padding: 28px 24px;
  max-width: 640px; width: 100%;
}

.setting-section {
  margin-bottom: 32px;
}
.setting-section-title {
  font-size: 11px; font-weight: 600; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .07em; margin-bottom: 14px;
}
.setting-group { margin-bottom: 20px; }
.setting-label { font-size: 13px; font-weight: 500; color: var(--text-2); margin-bottom: 8px; }

.setting-cards { display: flex; gap: 8px; flex-wrap: wrap; }
.setting-card {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 16px; border-radius: 10px; border: 1.5px solid var(--border);
  background: var(--surface); cursor: pointer; min-width: 90px;
  transition: border-color var(--ease), background var(--ease);
  color: var(--text-2);
}
.setting-card:hover { border-color: var(--text-3); color: var(--text); }
.setting-card.active { border-color: var(--accent); background: rgba(16,163,127,.08); color: var(--accent); }
.setting-card-icon { display: flex; }
.setting-card-label { font-size: 12px; font-weight: 500; }

.font-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.font-card {
  padding: 12px 14px; border-radius: 10px; border: 1.5px solid var(--border);
  background: var(--surface); cursor: pointer;
  transition: border-color var(--ease), background var(--ease);
}
.font-card:hover { border-color: var(--text-3); }
.font-card.active { border-color: var(--accent); background: rgba(16,163,127,.08); }
.font-card-sample { font-size: 22px; color: var(--text); margin-bottom: 4px; }
.font-card-name { font-size: 11.5px; color: var(--text-3); }
.font-card.active .font-card-name { color: var(--accent); }

/* Danger zone */
.danger-zone {
  border: 1px solid rgba(229,83,75,.35); border-radius: 10px;
  padding: 16px; background: rgba(229,83,75,.04);
}
.danger-zone-title {
  font-size: 11px; font-weight: 600; color: var(--red);
  text-transform: uppercase; letter-spacing: .07em; margin-bottom: 12px;
  display: flex; align-items: center; gap: 6px;
}
.api-token-label { font-size: 12px; color: var(--text-2); margin-bottom: 8px; line-height: 1.5; }
.api-token-label strong { color: var(--text); }
.api-token-algo {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; font-weight: 600; padding: 2px 7px;
  border-radius: 99px; margin-left: 4px;
  background: rgba(16,163,127,.12); color: var(--accent); border: 1px solid rgba(16,163,127,.25);
  letter-spacing: .04em;
}
.api-token-box {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px;
  font-family: 'JetBrains Mono', monospace; font-size: 11.5px;
  color: var(--text); word-break: break-all; line-height: 1.5;
  filter: blur(5px); user-select: none; transition: filter .2s;
  cursor: pointer;
}
.api-token-box.revealed { filter: none; user-select: text; cursor: text; }
.api-token-hint { text-align: center; font-size: 11px; color: var(--text-3); margin-top: 5px; transition: opacity .2s; }
.api-token-hint.hidden { opacity: 0; pointer-events: none; }
.danger-actions { display: flex; gap: 8px; margin-top: 10px; }
.dz-btn {
  flex: 1; padding: 7px 10px; border-radius: 8px; font-size: 12px;
  font-weight: 500; cursor: pointer; font-family: var(--font);
  display: flex; align-items: center; justify-content: center; gap: 5px;
  transition: all var(--ease);
}
.dz-btn-reveal { background: var(--surface); border: 1px solid var(--border); color: var(--text-2); }
.dz-btn-reveal:hover { border-color: var(--text-3); color: var(--text); }
.dz-btn-copy  { background: var(--surface); border: 1px solid var(--border); color: var(--text-2); }
.dz-btn-copy:hover  { border-color: var(--text-3); color: var(--text); }
.dz-btn-rotate { background: rgba(229,83,75,.08); border: 1px solid rgba(229,83,75,.3); color: var(--red); }
.dz-btn-rotate:hover { background: rgba(229,83,75,.15); border-color: rgba(229,83,75,.5); }
.dz-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── ARTIFACTS PAGE ─────────────────────────────────────────────────── */
#page-artifacts {
  display: none; flex: 1; overflow: hidden; flex-direction: column;
}
#page-artifacts.active { display: flex; }

.artifacts-page-head {
  height: 50px; padding: 0 16px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.artifacts-page-title { font-size: 15px; font-weight: 600; color: var(--text); }
.artifacts-count {
  font-size: 11.5px; padding: 2px 8px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-3);
}

/* loading / empty shared state */
.artifacts-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px; text-align: center; padding: 40px;
}
.artifacts-state-text { font-size: 13.5px; color: var(--text-3); }
.artifacts-spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.artifacts-empty-icon {
  width: 56px; height: 56px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; margin-bottom: 4px;
}
.artifacts-empty-title { font-size: 17px; font-weight: 600; color: var(--text); }
.artifacts-empty-sub { font-size: 13.5px; color: var(--text-2); line-height: 1.6; max-width: 320px; }

/* file list */
.artifacts-list {
  flex: 1; overflow-y: auto; padding: 20px 24px;
  display: flex; flex-direction: column; gap: 24px;
}
.artifacts-group-title {
  font-size: 11px; font-weight: 600; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .07em;
  margin-bottom: 10px;
  display: flex; align-items: center; gap: 8px;
}
.artifacts-group-title::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.artifacts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.artifact-card {
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; transition: border-color var(--ease), background var(--ease);
}
.artifact-card:hover { border-color: var(--accent); background: var(--surface2); }
.artifact-card-top { display: flex; align-items: center; gap: 10px; }
.artifact-card-icon {
  width: 34px; height: 34px; border-radius: 8px;
  background: rgba(16,163,127,.1);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.artifact-card-name {
  font-size: 13px; font-weight: 500; color: var(--text);
  font-family: var(--mono);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}
.artifact-card-meta {
  font-size: 11.5px; color: var(--text-3);
  display: flex; align-items: center; justify-content: space-between;
}
.artifact-card-ext {
  display: inline-block; font-size: 10.5px; font-weight: 600;
  padding: 1px 6px; border-radius: 4px;
  background: var(--surface2); color: var(--text-3);
  font-family: var(--mono); text-transform: uppercase;
}
.artifact-card-del {
  width: 22px; height: 22px; border-radius: 5px; border: none;
  background: none; color: var(--text-3); cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity var(--ease), color var(--ease);
}
.artifact-card:hover .artifact-card-del { opacity: 1; }
.artifact-card-del:hover { color: var(--red); }

@media (max-width: 640px) {
  .artifacts-list { padding: 16px; }
  .artifacts-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
}

/* ── MOBILE SUPPORT ─────────────────────────────────────────────────── */
#sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.5);
}
#sidebar-overlay.open { display: block; }

#mobile-topbar {
  display: none; height: 50px; padding: 0 12px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  align-items: center; gap: 10px; background: var(--bg);
}
.mobile-hamburger {
  width: 36px; height: 36px; border-radius: 8px; border: none;
  background: none; color: var(--text-2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--ease), color var(--ease); flex-shrink: 0;
}
.mobile-hamburger:hover { background: var(--surface); color: var(--text); }
.mobile-title {
  flex: 1; font-size: 14px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.02em;
}
.mobile-new-btn {
  width: 36px; height: 36px; border-radius: 8px; border: none;
  background: none; color: var(--text-2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--ease), color var(--ease); flex-shrink: 0;
}
.mobile-new-btn:hover { background: var(--surface); color: var(--text); }

@media (max-width: 640px) {
  #sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    z-index: 300; transform: translateX(-100%);
    transition: transform .22s ease;
    width: 280px !important;
  }
  #sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.4);
  }
  #sidebar.collapsed { width: 280px !important; }
  #sidebar.collapsed .sb-logo-name,
  #sidebar.collapsed .sb-label,
  #sidebar.collapsed #chat-list,
  #sidebar.collapsed .sb-username,
  #sidebar.collapsed .sb-logout,
  #sidebar.collapsed .sb-nav-label { display: initial; }
  #sidebar.collapsed .sb-top { flex-direction: row; justify-content: initial; padding: 10px 10px 6px; }
  #sidebar.collapsed .sb-logo { display: flex; }
  #sidebar.collapsed .sb-nav { align-items: initial; }
  #sidebar.collapsed .sb-nav-btn { width: 100%; justify-content: flex-start; padding: 7px 8px; }
  #sidebar.collapsed .sb-foot { flex-direction: row; justify-content: initial; padding: 10px 10px 14px; }
  #topbar { display: none; }
  #mobile-topbar { display: flex; }
  #input-area { padding: 10px 12px 14px; }
  .msg-row { padding: 6px 14px; }
  .token-badge { display: none; }
  .model-trigger { min-width: unset; }
  .model-trigger-name { max-width: 100px; }
  .settings-page-body { padding: 20px 16px; }
}
/* ── FILE MODAL (Monaco viewer) ─────────────────────────────────────── */
#file-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,.6);
  align-items: center;
  justify-content: center;
  padding: 24px;
  backdrop-filter: blur(4px);
}
#file-modal-overlay.open {
  display: flex;
}
#file-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 860px;
  height: min(80vh, 680px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
#file-modal-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--sidebar);
  flex-shrink: 0;
  min-height: 44px;
}
#file-modal-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--mono);
}
.file-modal-badge {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-3);
  background: var(--surface2);
  border-radius: 4px;
  padding: 2px 7px;
  flex-shrink: 0;
}
.file-modal-btn {
  height: 28px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--ease), color var(--ease);
}
.file-modal-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}
.file-modal-close {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: none;
  color: var(--text-3);
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--ease), color var(--ease);
  line-height: 1;
}
.file-modal-close:hover {
  background: var(--surface2);
  color: var(--red);
}
#file-modal-editor {
  flex: 1;
  min-height: 0; /* critical — lets flexbox shrink the editor */
  overflow: hidden;
  position: relative;
}

@media (max-width: 640px) {
  #file-modal-overlay { padding: 0; }
  #file-modal {
    border-radius: 0;
    height: 100dvh;
    max-width: 100%;
    border: none;
  }
}

/* ── FILE EXPIRY BADGE ───────────────────────────────────────────────── */
.file-expiry-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(212, 167, 44, 0.15);
  color: var(--yellow);
  margin-left: 4px;
  font-family: var(--mono);
}

/* ── AI FILE CARD (inline in chat) ──────────────────────────────────── */
.ai-file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin: 8px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  max-width: 320px;
  transition: background var(--ease), border-color var(--ease);
  user-select: none;
}
.ai-file-card:hover {
  background: var(--surface2);
  border-color: var(--accent);
}
.ai-file-card-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 7px;
  background: rgba(16,163,127,.12);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ai-file-card-info {
  flex: 1;
  min-width: 0;
}
.ai-file-card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--mono);
}
.ai-file-card-meta {
  font-size: 11.5px;
  color: var(--text-3);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.ai-file-card-arrow {
  flex-shrink: 0;
  color: var(--text-3);
  transition: color var(--ease);
}
.ai-file-card:hover .ai-file-card-arrow {
  color: var(--accent);
}