:root {
  --bg: #0a0a0a;
  --bg-2: #111;
  --bg-3: #1a1a1a;
  --fg: #d4d4d4;
  --fg-dim: #888;
  --accent: #ffb000;
  --accent-2: #ff3b3b;
  --ok: #4ade80;
  --border: #2a2a2a;
  --code-bg: #0f0f0f;
  --shadow: 0 0 18px rgba(255, 176, 0, .12);
  --radius: 8px;
  --font: 'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;
}

body[data-theme='cyan'] { --accent: #22d3ee; --shadow: 0 0 18px rgba(34,211,238,.15); }
body[data-theme='red']  { --accent: #ff4d4d; --shadow: 0 0 18px rgba(255,77,77,.15); }
body[data-theme='matrix'] { --accent: #39ff14; --shadow: 0 0 18px rgba(57,255,20,.15); }
body[data-theme='minimal'] { --accent: #ffffff; --shadow: 0 0 12px rgba(255,255,255,.06); }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font-family: var(--font); font-size: 15px; line-height: 1.5;
  overflow: hidden;
}

#matrix-bg { position: fixed; inset: 0; z-index: 0; opacity: .06; pointer-events: none; }
body[data-theme='minimal'] #matrix-bg { opacity: 0; }

.view { position: relative; z-index: 1; height: 100dvh; display: flex; }
.hidden { display: none !important; }

/* ============ AUTH ============ */
#auth-view { align-items: center; justify-content: center; padding: 16px; }
.auth-card {
  width: 100%; max-width: 420px;
  background: rgba(10,10,10,.85); backdrop-filter: blur(12px);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 28px; box-shadow: var(--shadow);
}
.boot-log {
  font-family: var(--mono); font-size: 12px; color: var(--fg-dim);
  margin-bottom: 18px; line-height: 1.7;
}
.boot-log .ok { color: var(--ok); }
.boot-log .blink { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.brand { margin: 0; font-family: var(--mono); font-size: 28px; font-weight: 700; letter-spacing: -.5px; }
.brand-accent { color: var(--accent); }
.brand-sub { margin: 4px 0 24px; color: var(--fg-dim); font-size: 13px; font-family: var(--mono); }

.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tab {
  flex: 1; background: none; border: 0; padding: 10px;
  color: var(--fg-dim); cursor: pointer; font-family: var(--mono);
  font-size: 14px; text-transform: lowercase;
  border-bottom: 2px solid transparent; transition: all .15s;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab:hover { color: var(--fg); }

.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label {
  display: flex; flex-direction: column; gap: 6px;
  font-family: var(--mono); font-size: 12px; color: var(--fg-dim); text-transform: lowercase;
}
.auth-form input {
  background: var(--bg-2); border: 1px solid var(--border);
  color: var(--fg); padding: 10px 12px; border-radius: 6px;
  font-family: var(--font); font-size: 14px; outline: none;
  transition: border-color .15s;
}
.auth-form input:focus { border-color: var(--accent); }

.auth-error {
  color: var(--accent-2); font-family: var(--mono); font-size: 12px;
  background: rgba(255,59,59,.08); border: 1px solid rgba(255,59,59,.3);
  padding: 8px 10px; border-radius: 6px;
}

.btn-primary {
  background: var(--accent); color: #000; border: 0;
  padding: 12px; border-radius: 6px; font-family: var(--mono);
  font-size: 14px; font-weight: 700; cursor: pointer;
  transition: transform .1s, box-shadow .15s;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-primary:disabled { opacity: .5; cursor: wait; }

/* ============ CHAT LAYOUT ============ */
#chat-view { flex-direction: row; }

#sidebar {
  width: 280px; min-width: 220px;
  background: var(--bg-2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px; gap: 14px;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; }
.brand-mini { font-family: var(--mono); font-size: 14px; font-weight: 700; }
.user-badge {
  font-family: var(--mono); font-size: 11px; color: var(--fg-dim);
  background: var(--bg-3); padding: 3px 8px; border-radius: 4px;
  border: 1px solid var(--border);
}

.btn-new {
  background: transparent; border: 1px dashed var(--border);
  color: var(--accent); font-family: var(--mono); font-size: 13px;
  padding: 10px; border-radius: 6px; cursor: pointer; transition: all .15s;
}
.btn-new:hover { border-color: var(--accent); background: rgba(255,176,0,.06); }

.session-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.session-item {
  padding: 10px 12px; border-radius: 6px; cursor: pointer;
  font-size: 13px; color: var(--fg-dim);
  display: flex; flex-direction: column; gap: 2px;
  border: 1px solid transparent; transition: all .1s; position: relative;
}
.session-item:hover { background: var(--bg-3); color: var(--fg); }
.session-item.active { background: rgba(255,176,0,.08); border-color: rgba(255,176,0,.3); color: var(--fg); }
.session-item .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 16px; }
.session-item .meta { font-family: var(--mono); font-size: 10px; color: var(--fg-dim); }
.session-item .del {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  opacity: 0; background: none; border: 0; color: var(--accent-2);
  font-family: var(--mono); font-size: 14px; cursor: pointer;
}
.session-item:hover .del { opacity: .7; }

.sidebar-foot { display: flex; flex-direction: column; gap: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.model-picker, .theme-picker { display: flex; flex-direction: column; gap: 4px; }
.model-picker label, .theme-picker label {
  font-family: var(--mono); font-size: 10px; color: var(--fg-dim); text-transform: lowercase;
}
.model-picker select, .theme-picker select {
  background: var(--bg-3); color: var(--fg); border: 1px solid var(--border);
  padding: 6px 8px; border-radius: 4px; font-family: var(--mono); font-size: 11px;
  cursor: pointer; outline: none;
}

.btn-ghost {
  background: transparent; border: 1px solid var(--border);
  color: var(--fg-dim); font-family: var(--mono); font-size: 12px;
  padding: 8px; border-radius: 6px; cursor: pointer; transition: all .15s;
}
.btn-ghost:hover { color: var(--fg); border-color: var(--fg-dim); }

/* main */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px; border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.btn-menu {
  display: none; background: none; border: 1px solid var(--border);
  color: var(--fg); width: 36px; height: 36px; border-radius: 6px; cursor: pointer;
  font-size: 18px;
}
.session-title { font-family: var(--mono); font-size: 14px; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-status { font-family: var(--mono); font-size: 11px; color: var(--fg-dim); text-transform: lowercase; }
.chat-status.streaming { color: var(--accent); }

.messages { flex: 1; overflow-y: auto; padding: 24px 0; }
.messages-inner { max-width: 880px; margin: 0 auto; padding: 0 20px; display: flex; flex-direction: column; gap: 18px; }

.empty-state { display: flex; align-items: center; justify-content: center; height: 100%; }
.empty-art { font-family: var(--mono); font-size: 12px; color: var(--fg-dim); text-align: center; line-height: 1.4; }

.msg { display: flex; gap: 14px; }
.msg .avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 12px; font-weight: 700;
  border: 1px solid var(--border);
}
.msg.user .avatar { background: var(--bg-3); color: var(--fg); }
.msg.assistant .avatar { background: var(--accent); color: #000; }
.msg .body { flex: 1; min-width: 0; }
.msg .role { font-family: var(--mono); font-size: 11px; color: var(--fg-dim); margin-bottom: 4px; text-transform: lowercase; }
.msg .role .model-tag { color: var(--accent); margin-left: 8px; }
.msg .content {
  font-size: 14px; line-height: 1.6; color: var(--fg);
  white-space: pre-wrap; word-wrap: break-word;
}
.msg .content p { margin: 0 0 10px; }
.msg .content p:last-child { margin-bottom: 0; }
.msg .content pre {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 12px; overflow-x: auto;
  font-family: var(--mono); font-size: 13px; margin: 10px 0;
}
.msg .content code {
  font-family: var(--mono); font-size: 13px;
  background: var(--bg-3); padding: 1px 5px; border-radius: 3px;
}
.msg .content pre code { background: none; padding: 0; }
.msg .content strong { color: #fff; font-weight: 600; }
.msg .content em { color: var(--accent); }
.msg .content ul, .msg .content ol { margin: 8px 0; padding-left: 22px; }
.msg .content a { color: var(--accent); text-decoration: underline; }
.streaming-cursor::after { content: '▌'; color: var(--accent); animation: blink .8s steps(2) infinite; margin-left: 2px; }

/* composer */
#composer { border-top: 1px solid var(--border); padding: 14px 20px; background: var(--bg); }
.composer-inner { max-width: 880px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; }
#composer textarea {
  flex: 1; background: var(--bg-2); border: 1px solid var(--border);
  color: var(--fg); padding: 12px 14px; border-radius: 8px;
  font-family: var(--font); font-size: 14px; resize: none;
  max-height: 200px; outline: none; transition: border-color .15s; line-height: 1.5;
}
#composer textarea:focus { border-color: var(--accent); }
.composer-actions { display: flex; gap: 8px; }

.btn-send, .btn-stop {
  border: 1px solid var(--border); background: var(--bg-2);
  color: var(--fg); font-family: var(--mono); font-size: 13px;
  padding: 10px 16px; border-radius: 8px; cursor: pointer; transition: all .15s;
}
.btn-send:hover { border-color: var(--accent); color: var(--accent); }
.btn-send:disabled { opacity: .4; cursor: wait; }
.btn-stop { border-color: rgba(255,59,59,.4); color: var(--accent-2); }
.btn-stop:hover { background: rgba(255,59,59,.1); }

/* toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-3); border: 1px solid var(--border);
  padding: 10px 18px; border-radius: 8px; font-family: var(--mono);
  font-size: 13px; z-index: 100; box-shadow: var(--shadow);
}

/* scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--fg-dim); }

/* mobile */
@media (max-width: 760px) {
  #sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 10;
    transform: translateX(-100%); transition: transform .2s; width: 260px;
  }
  #sidebar.open { transform: translateX(0); }
  .btn-menu { display: block; }
  .messages { padding: 14px 0; }
  .messages-inner { padding: 0 12px; }
  #composer { padding: 10px 12px; }
  .msg .avatar { width: 24px; height: 24px; font-size: 11px; }
}

#sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 9; background: rgba(0,0,0,.5);
}
#sidebar-overlay.visible { display: block; }
