/* ═══════════════════════════════════════
   CHATTI — Clean Beta UI
   ═══════════════════════════════════════ */

:root {
  --bg-primary:    #09090b;
  --bg-secondary:  #0f0f12;
  --bg-tertiary:   #18181b;
  --bg-elevated:   #1f1f23;
  --bg-hover:      #27272a;
  --bg-active:     #2e2e33;

  --border:        #27272a;
  --border-subtle: #1f1f23;

  --text-primary:  #fafafa;
  --text-secondary:#a1a1aa;
  --text-tertiary: #71717a;
  --text-muted:    #52525b;

  --accent:        #3b82f6;
  --accent-hover:  #2563eb;
  --accent-subtle: rgba(59,130,246,.1);
  --accent-text:   #60a5fa;

  --success:       #22c55e;
  --warning:       #eab308;
  --error:         #ef4444;
  --error-subtle:  rgba(239,68,68,.1);

  --radius:        10px;
  --radius-sm:     6px;
  --radius-lg:     14px;
  --transition:    150ms ease;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

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

/* ── Screens ──────────────────────── */
.screen { height: 100vh; display: flex; align-items: center; justify-content: center; }

/* ── Login ─────────────────────────── */
.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.logo-mark {
  font-size: 36px;
  color: var(--accent);
  margin-bottom: 8px;
  font-weight: 700;
}
.login-card h1 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.5px;
  margin-bottom: 2px;
}
.login-sub { color: var(--text-tertiary); font-size: 13px; margin-bottom: 28px; }
.login-foot { color: var(--text-muted); font-size: 11px; margin-top: 20px; }

.field { text-align: left; margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 5px;
}
.field input,
.irow input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border var(--transition);
}
.field input:focus,
.irow input:focus { border-color: var(--accent); }

/* ── Buttons ──────────────────────── */
.btn-primary {
  display: flex; align-items: center; justify-content: center;
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.w-full { width: 100%; margin-top: 8px; }

.icon-btn {
  background: none; border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-sm {
  padding: 5px 10px; font-size: 11px; font-weight: 600;
  border: none; border-radius: var(--radius-sm);
  cursor: pointer; color: #fff; font-family: inherit;
}
.btn-danger { background: var(--error); }
.btn-success { background: var(--success); }

/* ── Badges ───────────────────────── */
.plan-badge {
  font-size: 10px; font-weight: 600;
  padding: 2px 8px;
  border-radius: 100px;
  background: var(--accent-subtle);
  color: var(--accent-text);
}
.badge-red {
  background: var(--error-subtle);
  color: var(--error);
}

/* ── Setup ─────────────────────────── */
.setup-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%; max-width: 480px;
  text-align: center;
}
.setup-card h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.5px; margin-bottom: 2px; }
.setup-card .login-sub { margin-bottom: 28px; }
.step { text-align: left; margin-bottom: 24px; }
.step h3 { font-size: 14px; font-weight: 600; margin-bottom: 4px; color: var(--text-primary); }
.step p { font-size: 12px; color: var(--text-tertiary); margin-bottom: 10px; }
.irow { display: flex; gap: 6px; }
.irow input { flex: 1; }
.pgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pcard {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
}
.pcard:hover { border-color: var(--text-muted); }
.pcard.sel { border-color: var(--accent); background: var(--accent-subtle); }
.pn { font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.pp { font-size: 24px; font-weight: 700; color: var(--accent-text); }
.pp small { font-size: 12px; color: var(--text-tertiary); font-weight: 400; }
.pd { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── Layout ────────────────────────── */
.layout { display: flex; height: 100vh; width: 100%; }

/* ── Sidebar ───────────────────────── */
.sidebar {
  width: 260px; min-width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sb-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
}
.sb-logo {
  font-size: 14px; font-weight: 700; letter-spacing: -0.3px;
  color: var(--text-primary);
}
.clist { flex: 1; overflow-y: auto; padding: 6px 8px; }

.conv-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
  margin-bottom: 1px;
}
.conv-item:hover { background: var(--bg-hover); }
.conv-item.active { background: var(--bg-active); }
.conv-title {
  flex: 1; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text-secondary);
}
.conv-item.active .conv-title { color: var(--text-primary); }
.conv-meta { font-size: 10px; color: var(--text-muted); }
.conv-del {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  opacity: 0; background: none; border: none;
  color: var(--text-muted); cursor: pointer; font-size: 12px;
  padding: 2px 4px; border-radius: 4px;
  transition: opacity var(--transition);
}
.conv-item:hover .conv-del { opacity: 1; }
.conv-del:hover { color: var(--error); }

.sb-bot { border-top: 1px solid var(--border-subtle); padding: 12px 14px; }
.sb-user { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.avatar-sm {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--bg-active);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: var(--text-secondary);
}
.sb-user-info { display: flex; flex-direction: column; min-width: 0; }
#u-email { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-actions { display: flex; gap: 2px; }
.empty-sb { text-align: center; color: var(--text-muted); font-size: 12px; padding: 40px 16px; }

/* ── Main ──────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ── Topbar ─────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  min-height: 48px;
}
.model-select {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  outline: none;
}
.model-select:focus { border-color: var(--accent); }
.model-select option:disabled { color: var(--text-muted); }
.budget-area { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.budget-track { width: 100px; height: 4px; background: var(--bg-active); border-radius: 2px; overflow: hidden; }
.budget-fill { height: 100%; border-radius: 2px; transition: width 0.5s, background 0.5s; }
.budget-label { font-size: 10px; color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ── Model Info ────────────────────── */
.model-info {
  padding: 6px 16px;
  font-size: 11px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  background: var(--bg-secondary);
}
.model-info .mi-cost { color: var(--text-tertiary); }
.model-info .mi-lock { color: var(--error); font-weight: 500; }

/* ── Chat Area ─────────────────────── */
.chat-area { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 16px 0; display: flex; flex-direction: column; gap: 2px; }

.welcome { text-align: center; margin: auto; padding: 60px 20px; }
.welcome-mark { font-size: 40px; color: var(--accent); font-weight: 700; margin-bottom: 12px; }
.welcome h2 { font-size: 20px; font-weight: 600; letter-spacing: -0.3px; margin-bottom: 6px; }
.welcome p { color: var(--text-tertiary); font-size: 13px; }

/* ── Messages ──────────────────────── */
.message {
  padding: 12px 20px;
  animation: fadeIn 0.2s ease;
  max-width: 100%;
}
.msg-user { background: transparent; }
.msg-asst { background: var(--bg-secondary); border-top: 1px solid var(--border-subtle); border-bottom: 1px solid var(--border-subtle); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } }

.msg-inner { max-width: 720px; margin: 0 auto; display: flex; gap: 12px; }
.msg-icon {
  width: 28px; height: 28px; flex-shrink: 0;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.msg-user .msg-icon { background: var(--accent-subtle); color: var(--accent-text); }
.msg-asst .msg-icon { background: var(--bg-active); color: var(--text-secondary); }
.msg-body { flex: 1; min-width: 0; }
.msg-label {
  font-size: 10px; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.msg-text { font-size: 14px; line-height: 1.7; color: var(--text-primary); word-break: break-word; }
.msg-text h2, .msg-text h3, .msg-text h4 { margin: 14px 0 6px; }
.msg-text li { margin-left: 20px; }
.msg-tokens { font-size: 10px; color: var(--text-muted); margin-top: 6px; font-variant-numeric: tabular-nums; }
.msg-img { max-width: 300px; max-height: 200px; border-radius: var(--radius-sm); margin-bottom: 8px; border: 1px solid var(--border); }

/* Code blocks */
.codeblock {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin: 10px 0;
  overflow: hidden;
}
.cb-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 10px;
  background: var(--bg-tertiary);
  font-size: 10px; color: var(--text-muted);
}
.cp-btn {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 11px; padding: 2px 6px; border-radius: 3px;
}
.cp-btn:hover { background: var(--bg-active); color: var(--text-primary); }
.codeblock pre { padding: 12px; overflow-x: auto; font-size: 12px; line-height: 1.6; }
.codeblock code { font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; color: var(--text-secondary); }
.ic {
  background: var(--bg-elevated);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
  font-family: 'SF Mono', monospace;
  color: var(--accent-text);
}

/* Cursor & Typing */
.cursor { animation: blink 1s step-end infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }
.typing { display: flex; gap: 4px; padding: 4px 0; }
.typing span {
  width: 6px; height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 0.6s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay: 0.1s; }
.typing span:nth-child(3) { animation-delay: 0.2s; }
@keyframes bounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

/* ── Input Area ────────────────────── */
.input-wrapper {
  padding: 10px 16px 16px;
  background: var(--bg-primary);
}
.chat-input-form {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  transition: border var(--transition);
}
.chat-input-form:focus-within { border-color: var(--accent); }

.input-actions-left { display: flex; align-items: center; gap: 0; }
.input-actions-right { display: flex; align-items: center; gap: 2px; }

.chat-input-form textarea {
  flex: 1; resize: none;
  background: transparent;
  color: var(--text-primary);
  border: none;
  padding: 8px 8px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  max-height: 200px;
  line-height: 1.5;
}
.chat-input-form textarea:disabled { opacity: 0.4; }

.send-button {
  background: var(--accent);
  border: none;
  color: #fff;
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition);
}
.send-button:hover { background: var(--accent-hover); }

.stop-button {
  background: var(--error);
  border: none;
  color: #fff;
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* Think Toggle */
.think-toggle {
  display: flex; align-items: center; gap: 4px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.think-toggle:hover { border-color: var(--text-muted); color: var(--text-secondary); }
.think-toggle.active {
  background: var(--accent-subtle);
  border-color: var(--accent);
  color: var(--accent-text);
}

/* Disabled feature */
.disabled-feat { opacity: 0.3; cursor: not-allowed !important; position: relative; }
.disabled-feat:hover { background: none !important; }
.soon-tag {
  position: absolute;
  top: -4px; right: -10px;
  font-size: 7px; font-weight: 700;
  background: var(--warning);
  color: #000;
  padding: 1px 3px;
  border-radius: 3px;
  letter-spacing: 0.3px;
}

/* Image Preview */
.img-preview { margin-bottom: 6px; padding: 0 8px; }
.prev { display: inline-block; position: relative; }
.prev img { max-height: 60px; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.prev button {
  position: absolute; top: -4px; right: -4px;
  width: 18px; height: 18px;
  border-radius: 50%; background: var(--error); color: #fff;
  border: none; font-size: 10px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* ── Admin ─────────────────────────── */
.admin-box { padding: 20px; overflow-y: auto; flex: 1; }
.admin-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.admin-head h2 { font-size: 16px; font-weight: 600; }
.a-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.a-card.blocked { border-color: var(--error); opacity: 0.6; }
.a-card-top { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.a-card-top strong { font-size: 13px; }
.a-actions { display: flex; gap: 6px; align-items: center; }
.a-actions select {
  background: var(--bg-elevated); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 3px 6px; font-size: 11px; cursor: pointer; outline: none; font-family: inherit;
}
.a-stats { font-size: 11px; }
.a-row { display: flex; justify-content: space-between; padding: 2px 0; color: var(--text-secondary); }
.bar { height: 3px; background: var(--bg-active); border-radius: 2px; margin: 4px 0; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 2px; transition: width 0.5s; }
.load-text { text-align: center; color: var(--text-muted); padding: 40px; font-size: 12px; }
.empty { text-align: center; color: var(--text-muted); font-size: 12px; }

/* ── Toasts ────────────────────────── */
#toasts {
  position: fixed; top: 16px; right: 16px; z-index: 9999;
  display: flex; flex-direction: column; gap: 6px;
}
.toast {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 500;
  transform: translateX(120%);
  transition: transform 0.25s ease;
  max-width: 340px;
  font-family: inherit;
}
.toast.show { transform: translateX(0); }
.t-info { background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text-secondary); }
.t-error { background: var(--error-subtle); border: 1px solid var(--error); color: var(--error); }
.t-success { background: rgba(34,197,94,.1); border: 1px solid var(--success); color: var(--success); }
.t-warning { background: rgba(234,179,8,.1); border: 1px solid var(--warning); color: var(--warning); }

/* ── Mobile ────────────────────────── */
.mobile-only { display: none; }
@media (max-width: 768px) {
  .mobile-only { display: inline-flex; }
  .sidebar {
    position: fixed; left: -280px; top: 0; z-index: 100;
    height: 100vh; transition: left 0.2s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,.5);
  }
  .sidebar.open { left: 0; }
  .model-select { min-width: 100px; font-size: 11px; }
  .budget-area { display: none; }
  .login-card, .setup-card { margin: 16px; padding: 28px 20px; }
  .pgrid { grid-template-columns: 1fr 1fr; }
  .msg-inner { max-width: 100%; }
}
@media (max-width: 480px) {
  .pgrid { grid-template-columns: 1fr; }
  .think-toggle span { display: none; }
}