:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1e222b; --border: #2a2f3a;
  --text: #e6e8ec; --muted: #9aa3b2; --brand: #6aa3ff; --brand2: #80036d;
  --ok: #46c98b; --warn: #e0a23c; --err: #e5635f; --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 14px 22px;
  border-bottom: 1px solid var(--border); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.topbar .logo { font-weight: 700; letter-spacing: .3px; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 13px; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 99px; background: var(--brand2); color: #fff; margin-left: 6px; }
.wrap { max-width: 920px; margin: 0 auto; padding: 26px 22px 80px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.card h2 { margin: 0 0 4px; font-size: 17px; }
.card .hint { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--panel2); margin-bottom: 10px; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .sub { color: var(--muted); font-size: 12.5px; word-break: break-all; }
.dot { width: 9px; height: 9px; border-radius: 99px; display: inline-block; margin-right: 6px; }
.dot.on { background: var(--ok); } .dot.off { background: var(--muted); }
input, select, button, textarea { font: inherit; }
input, select, textarea { background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 11px; width: 100%; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 5px; }
button { cursor: pointer; background: var(--brand); color: #07101f; border: none; border-radius: 8px;
  padding: 9px 15px; font-weight: 600; }
button.secondary { background: var(--panel2); color: var(--text); border: 1px solid var(--border); }
button.danger { background: transparent; color: var(--err); border: 1px solid var(--border); }
button.small { padding: 6px 10px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--border); color: var(--muted); }
.center { max-width: 380px; margin: 8vh auto; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tabs button { background: var(--panel2); color: var(--muted); border: 1px solid var(--border); }
.tabs button.active { background: var(--brand); color: #07101f; }
.msg { padding: 10px 12px; border-radius: 8px; margin: 10px 0; font-size: 13.5px; }
.msg.err { background: rgba(229,99,95,.12); color: #ff9b98; border: 1px solid rgba(229,99,95,.3); }
.msg.ok { background: rgba(70,201,139,.12); color: #7ee3b3; border: 1px solid rgba(70,201,139,.3); }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center;
  justify-content: center; z-index: 20; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 22px;
  width: 460px; max-width: 92vw; max-height: 88vh; overflow: auto; }
.modal h3 { margin: 0 0 12px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.tokenbox { background: var(--bg); border: 1px dashed var(--border); border-radius: 8px; padding: 10px; word-break: break-all; }
.empty { color: var(--muted); font-size: 13.5px; padding: 8px 2px; }
.usage { font-size: 12px; color: var(--muted); }

/* Chat */
.chat-log { max-height: 360px; overflow: auto; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; background: var(--bg); margin: 12px 0; display: flex; flex-direction: column; gap: 8px; }
.bubble { padding: 8px 11px; border-radius: 10px; max-width: 86%; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.bubble.user { align-self: flex-end; background: var(--brand); color: #07101f; }
.bubble.assistant { align-self: flex-start; background: var(--panel2); border: 1px solid var(--border); }
.composer { display: flex; gap: 8px; }
.composer textarea { flex: 1; min-height: 46px; resize: vertical; }

/* Top nav */
.nav { display: flex; align-items: center; gap: 4px; }
.nav a, .nav .navitem { padding: 7px 12px; border-radius: 8px; color: var(--muted); cursor: pointer; font-size: 14px; }
.nav a:hover, .nav .navitem:hover { background: var(--panel2); color: var(--text); text-decoration: none; }
.nav a.active, .nav .navitem.active { background: var(--brand); color: #07101f; font-weight: 600; }
.dropdown { position: relative; }
.dropdown .menu { position: absolute; top: 110%; left: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 6px; min-width: 200px; display: none; z-index: 30; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.dropdown.open .menu { display: block; }
.dropdown .menu a { display: block; padding: 8px 10px; border-radius: 7px; color: var(--text); }
.dropdown .menu .sep { height: 1px; background: var(--border); margin: 5px 6px; }
.dropdown .menu .grp { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; padding: 6px 10px 2px; }
.iconbtn { background: var(--panel2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 7px 11px; cursor: pointer; }
.iconbtn:hover { background: var(--border); }

/* Settings layout */
.settings { display: flex; gap: 22px; }
.settings-nav { width: 200px; flex: 0 0 200px; position: sticky; top: 72px; align-self: flex-start; }
.settings-nav a { display: block; padding: 8px 11px; border-radius: 8px; color: var(--muted); cursor: pointer; font-size: 14px; }
.settings-nav a:hover { background: var(--panel2); color: var(--text); text-decoration: none; }
.settings-nav a.active { background: var(--brand); color: #07101f; font-weight: 600; }
.settings-body { flex: 1; min-width: 0; }
@media (max-width: 760px) { .settings { flex-direction: column; } .settings-nav { width: auto; position: static; flex-basis: auto; display: flex; flex-wrap: wrap; } }

/* Chat sidebar */
.chat-sidebar { position: fixed; top: 0; right: 0; height: 100vh; width: 420px; background: var(--panel);
  border-left: 1px solid var(--border); z-index: 40; display: flex; flex-direction: column; box-shadow: -8px 0 24px rgba(0,0,0,.35); }
.chat-sidebar .sb-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.chat-sidebar .sb-head .title { font-weight: 700; flex: 1; }
.chat-sidebar .sb-body { flex: 1; overflow: auto; padding: 14px; }
.chat-resizer { position: absolute; left: -3px; top: 0; width: 6px; height: 100%; cursor: ew-resize; }
.chat-resizer:hover { background: var(--brand); opacity: .4; }
.sessrow { display: flex; align-items: center; gap: 8px; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel2); margin-bottom: 8px; }
.sessrow .grow { flex: 1; min-width: 0; }
.chat-root { display: flex; flex-direction: column; min-height: 0; }
.newpanel { border: 1px solid var(--border); border-radius: 8px; background: var(--panel2); padding: 12px; margin: 8px 0; }

/* Chat bubbles: timestamps + working indicator */
.bubble .time { display: block; font-size: 10px; opacity: .55; margin-top: 4px; text-align: right; }
.working { align-self: flex-start; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; padding: 6px 10px; }
.working .dots { display: inline-flex; gap: 3px; }
.working .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: gw-blink 1.2s infinite both; }
.working .dots i:nth-child(2) { animation-delay: .2s; }
.working .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes gw-blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

/* Chat conversation header */
.conv-head { display: flex; align-items: center; gap: 10px; padding: 4px 0 10px; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.conv-meta { line-height: 1.2; }
