:root {
  --bg: #0b0d12;
  --bg-2: #11141c;
  --panel: #161a24;
  --panel-2: #1c2130;
  --border: #242a3a;
  --text: #e8ecf4;
  --text-dim: #9aa3b5;
  --accent: #6d5efc;
  --accent-2: #8b7bff;
  --accent-glow: rgba(109, 94, 252, 0.35);
  --danger: #f87171;
  --ok: #34d399;
  --radius: 14px;
  --user-bubble: #6d5efc;
  --ai-bubble: #1c2130;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
}

.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }

/* ── Auth screen ── */
.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(1200px 600px at 20% -10%, var(--accent-glow), transparent 60%),
    radial-gradient(900px 500px at 90% 110%, rgba(139, 123, 255, 0.18), transparent 60%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.auth-brand { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
.auth-brand span { background: linear-gradient(90deg, var(--accent-2), #c4b5fd); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tagline { color: var(--text-dim); margin: 6px 0 22px; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab {
  flex: 1; padding: 10px; background: transparent; border: 1px solid var(--border);
  color: var(--text-dim); border-radius: 10px; font-weight: 600; transition: .15s;
}
.tab.active { background: var(--panel-2); color: var(--text); border-color: var(--accent); }
.subtabs { display: flex; gap: 6px; margin-bottom: 12px; }
.subtab {
  flex: 1; padding: 8px; background: transparent; border: none; color: var(--text-dim);
  border-radius: 8px; font-weight: 600;
}
.subtab.active { background: rgba(109,94,252,0.18); color: var(--accent-2); }
.panel input {
  width: 100%; padding: 12px 14px; margin-bottom: 10px; background: var(--bg-2);
  border: 1px solid var(--border); border-radius: 10px; color: var(--text); font-size: 15px;
}
.panel input:focus { outline: none; border-color: var(--accent); }
.hint { color: var(--text-dim); font-size: 13px; }
.hint.small { margin-top: 14px; font-size: 12px; text-align: center; }
.hint.warn { color: var(--danger); margin-top: 10px; }
.error { color: var(--danger); font-size: 13px; margin: 12px 0 0; text-align: center; }
.primary {
  background: var(--accent); color: #fff; border: none; border-radius: 10px;
  padding: 12px 16px; font-weight: 700; font-size: 15px; width: 100%; transition: .15s;
}
.primary:hover { background: var(--accent-2); }
.primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── App layout ── */
#app { display: flex; height: 100vh; }
#sidebar {
  width: 280px; min-width: 280px; background: var(--bg-2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px;
}
.sidebar-brand { font-size: 20px; font-weight: 800; padding: 6px 8px 14px; }
.sidebar-brand span { background: linear-gradient(90deg, var(--accent-2), #c4b5fd); -webkit-background-clip: text; background-clip: text; color: transparent; }
.new { width: 100%; margin-bottom: 14px; }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.conv-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 9px;
  color: var(--text-dim); cursor: pointer; font-size: 14px; position: relative;
}
.conv-item:hover { background: var(--panel-2); color: var(--text); }
.conv-item.active { background: rgba(109,94,252,0.18); color: var(--text); }
.conv-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .del { opacity: 0; background: none; border: none; color: var(--text-dim); font-size: 15px; padding: 2px 6px; border-radius: 6px; }
.conv-item:hover .del { opacity: 1; }
.conv-item .del:hover { color: var(--danger); background: rgba(248,113,113,0.12); }
.sidebar-footer { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 8px; }
.user { font-size: 13px; color: var(--text-dim); padding: 0 4px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.footer-row { display: flex; align-items: center; gap: 6px; }
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 20px; background: var(--panel-2); color: var(--text-dim); border: 1px solid var(--border); }
.badge.premium { color: #fbbf24; border-color: rgba(251,191,36,0.4); }
.badge.exhausted { color: var(--danger); border-color: rgba(248,113,113,0.4); }
.ghost { background: transparent; border: 1px solid var(--border); color: var(--text-dim); border-radius: 8px; padding: 5px 10px; font-size: 13px; }
.ghost:hover { color: var(--text); border-color: var(--accent); }

/* ── Main ── */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 18px;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
.icon { font-size: 16px; padding: 6px 10px; }
.model-wrap { display: flex; align-items: center; gap: 8px; }
.model-label { font-size: 12px; color: var(--text-dim); font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
#model-picker {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 9px; padding: 8px 10px; font-size: 14px; font-weight: 600;
}
#model-picker:focus { outline: none; border-color: var(--accent); }
#model-picker optgroup { background: var(--panel-2); }
.model-desc { color: var(--text-dim); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.welcome { text-align: center; margin: auto; max-width: 460px; color: var(--text-dim); }
.welcome-logo { font-size: 52px; margin-bottom: 8px; }
.welcome h2 { color: var(--text); margin: 0 0 6px; font-weight: 800; }
.welcome p { margin: 0; font-size: 14px; }

.msg { display: flex; flex-direction: column; max-width: 78%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.ai { align-self: flex-start; align-items: flex-start; }
.msg .who { font-size: 11px; color: var(--text-dim); margin-bottom: 3px; font-weight: 700; }
.bubble {
  padding: 11px 14px; border-radius: var(--radius); white-space: pre-wrap; word-wrap: break-word;
  font-size: 15px;
}
.msg.user .bubble { background: var(--user-bubble); color: #fff; border-bottom-right-radius: 4px; }
.msg.ai .bubble { background: var(--ai-bubble); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble.cursor::after { content: '▋'; animation: blink 1s steps(1) infinite; color: var(--accent-2); }
@keyframes blink { 50% { opacity: 0; } }
.bubble.error { border-color: rgba(248,113,113,0.5); color: #fca5a5; }
.bubble code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: rgba(0,0,0,0.3); padding: 1px 5px; border-radius: 5px; }
.bubble pre { background: #0b0d12; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; overflow-x: auto; }
.bubble pre code { background: none; padding: 0; }

.thinking { display: inline-flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: 13px; padding: 8px 14px; }
.thinking .dots { display: inline-flex; gap: 3px; }
.thinking .dots span { width: 5px; height: 5px; border-radius: 50%; background: var(--accent-2); animation: bounce 1.2s infinite; }
.thinking .dots span:nth-child(2) { animation-delay: .15s; }
.thinking .dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,80%,100% { transform: translateY(0); opacity: .5; } 40% { transform: translateY(-4px); opacity: 1; } }

/* ── Composer ── */
#composer { padding: 14px 18px 10px; border-top: 1px solid var(--border); background: var(--bg); }
.composer-inner {
  display: flex; align-items: flex-end; gap: 10px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 16px; padding: 10px 10px 10px 16px;
}
.composer-inner:focus-within { border-color: var(--accent); }
#input {
  flex: 1; background: transparent; border: none; resize: none; color: var(--text);
  font-size: 15px; font-family: inherit; line-height: 1.5; max-height: 180px; outline: none;
}
.send { width: auto; padding: 10px 16px; border-radius: 10px; }
.composer-hint { text-align: center; color: var(--text-dim); font-size: 11px; margin-top: 8px; }

/* ── Mobile ── */
@media (max-width: 720px) {
  #sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,0.6); }
  #sidebar.open { transform: translateX(0); }
  .msg { max-width: 92%; }
  .model-desc { display: none; }
}
