:root {
  --bg: #0b0f1a; --bg-2: #0f1524; --panel: #141b2d; --panel-2: #1a2336;
  --line: #243049; --line-2: #2f3d5c;
  --text: #e9edf6; --text-2: #aab4c9; --text-3: #7c889f;
  --accent: #6d8cff; --accent-2: #8a6dff; --accent-tint: rgba(109,140,255,.15);
  --user-bubble: #223049; --ok: #3ecf8e; --warn: #f0a742; --err: #ff6b6b;
  --radius: 14px; --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- auth / centered cards ---------- */
.center { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.brand .logo { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: grid; place-items: center; font-weight: 700; color: #fff; }
.brand h1 { font-size: 20px; margin: 0; }
.sub { color: var(--text-2); font-size: 13.5px; margin: 2px 0 20px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.input, textarea, select { width: 100%; background: var(--bg-2); border: 1px solid var(--line-2); color: var(--text); border-radius: 10px; padding: 11px 12px; font-size: 14.5px; font-family: inherit; }
.input:focus, textarea:focus { border-color: var(--accent); outline: none; }
.btn { width: 100%; border: 0; border-radius: 10px; padding: 12px; font-size: 15px; font-weight: 600; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.secondary { background: var(--panel-2); border: 1px solid var(--line-2); color: var(--text); }
.btn.sm { width: auto; padding: 7px 12px; font-size: 13px; }
.btn.danger { background: transparent; border: 1px solid var(--err); color: var(--err); }
.tabs { display: flex; gap: 4px; background: var(--bg-2); border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.tabs button { flex: 1; border: 0; background: transparent; color: var(--text-2); padding: 9px; border-radius: 7px; font-weight: 600; font-size: 14px; }
.tabs button.on { background: var(--panel-2); color: var(--text); }
.msg-line { font-size: 13.5px; margin-top: 12px; min-height: 18px; }
.msg-line.err { color: var(--err); }
.msg-line.ok { color: var(--ok); }
.notice { background: var(--accent-tint); border: 1px solid rgba(109,140,255,.3); color: var(--text-2); border-radius: 10px; padding: 11px 13px; font-size: 12.5px; margin-top: 18px; line-height: 1.5; }

/* ---------- chat layout ---------- */
.app { display: grid; grid-template-columns: 280px 1fr; height: 100%; }
.sidebar { background: var(--bg-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.sb-top { padding: 14px; }
.newchat { display: flex; align-items: center; gap: 8px; justify-content: center; width: 100%; border: 1px solid var(--line-2); background: var(--panel); color: var(--text); border-radius: 10px; padding: 11px; font-weight: 600; font-size: 14px; }
.newchat:hover { border-color: var(--accent); }
.convs { flex: 1; overflow-y: auto; padding: 4px 8px; min-height: 0; }
.conv { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 9px; color: var(--text-2); font-size: 13.5px; cursor: pointer; white-space: nowrap; overflow: hidden; }
.conv:hover { background: var(--panel); color: var(--text); }
.conv.on { background: var(--panel-2); color: var(--text); }
.conv .t { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.conv .x { opacity: 0; color: var(--text-3); font-size: 15px; border: 0; background: none; }
.conv:hover .x { opacity: 1; }
.conv .x:hover { color: var(--err); }
.sb-foot { border-top: 1px solid var(--line); padding: 10px; }
.who { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; cursor: pointer; }
.who:hover { background: var(--panel); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; flex: none; }
.who .n { font-size: 13.5px; font-weight: 600; }
.who .r { font-size: 11.5px; color: var(--text-3); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.topbar .title { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .links a { color: var(--text-2); font-size: 13px; margin-left: 16px; }
.stream { flex: 1; overflow-y: auto; min-height: 0; }
.stream-inner { max-width: 820px; margin: 0 auto; padding: 26px 20px 140px; }
.turn { display: flex; gap: 14px; margin-bottom: 26px; }
.turn .ava { width: 30px; height: 30px; border-radius: 8px; flex: none; display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.turn.user .ava { background: var(--user-bubble); color: var(--text); }
.turn.nova .ava { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.turn .body { flex: 1; min-width: 0; padding-top: 3px; }
.turn .name { font-size: 12.5px; color: var(--text-3); margin-bottom: 3px; }
.bubble { font-size: 15px; }
.bubble p { margin: 0 0 12px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3 { margin: 16px 0 8px; line-height: 1.3; }
.bubble h1 { font-size: 20px; } .bubble h2 { font-size: 18px; } .bubble h3 { font-size: 16px; }
.bubble ul, .bubble ol { margin: 0 0 12px; padding-left: 22px; }
.bubble li { margin: 3px 0; }
.bubble code { background: var(--bg-2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; font-family: var(--mono); font-size: 13px; }
.bubble pre { background: #0a0e18; border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; overflow-x: auto; margin: 0 0 12px; }
.bubble pre code { background: none; border: 0; padding: 0; font-size: 13px; line-height: 1.5; }
.bubble strong { color: #fff; }
.bubble table { border-collapse: collapse; margin: 0 0 12px; }
.bubble td, .bubble th { border: 1px solid var(--line-2); padding: 6px 10px; }
.bubble .katex-display { margin: 10px 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.bubble .katex { font-size: 1.04em; }
.rawtex { color: var(--text-2); }
.cursor::after { content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.think { margin: 0 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-2); overflow: hidden; }
.think summary { cursor: pointer; padding: 8px 12px; font-size: 12.5px; color: var(--text-3); user-select: none; list-style: none; }
.think summary::-webkit-details-marker { display: none; }
.think summary::before { content: "💭 "; }
.think .inner { padding: 4px 14px 12px; font-size: 13px; color: var(--text-2); white-space: pre-wrap; max-height: 260px; overflow-y: auto; }
.tool-chip { display: inline-block; font-size: 12px; color: var(--text-3); background: var(--bg-2); border: 1px solid var(--line); border-radius: 20px; padding: 3px 10px; margin: 0 0 10px; }

.composer { position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 10px 20px 18px; }
.composer-inner { max-width: 820px; margin: 0 auto; }
.inputwrap { display: flex; align-items: flex-end; gap: 8px; background: var(--panel); border: 1px solid var(--line-2); border-radius: 16px; padding: 10px 10px 10px 16px; }
.inputwrap:focus-within { border-color: var(--accent); }
#msg { flex: 1; background: none; border: 0; color: var(--text); resize: none; font-size: 15px; max-height: 200px; outline: none; font-family: inherit; }
.send { width: 36px; height: 36px; border-radius: 10px; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 17px; flex: none; }
.send:disabled { background: var(--line-2); color: var(--text-3); }
.disclaimer { text-align: center; color: var(--text-3); font-size: 11.5px; margin-top: 8px; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; border: 0; background: transparent; color: var(--text-2); font-size: 20px; display: grid; place-items: center; flex: none; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn.recording { color: var(--err); background: rgba(255,107,107,.12); animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.preview { position: relative; display: inline-block; margin-bottom: 8px; }
.preview img { max-height: 120px; max-width: 220px; border-radius: 10px; border: 1px solid var(--line-2); display: block; }
.preview #preview-x { position: absolute; top: -8px; right: -8px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--err); color: #fff; font-size: 14px; line-height: 1; }
.bubble img.photo { max-width: 320px; max-height: 320px; border-radius: 12px; border: 1px solid var(--line-2); margin-bottom: 8px; display: block; }
.turn.user .bubble img.photo { margin-left: auto; }
.hamburger { display: none; border: 0; background: transparent; color: var(--text-2); font-size: 20px; width: 34px; height: 34px; border-radius: 8px; margin-right: 6px; }
.hamburger:hover { background: var(--panel-2); color: var(--text); }
.sb-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 35; }
.sb-backdrop.on { display: block; }

/* ---------- admin ---------- */
.admin { max-width: 1100px; margin: 0 auto; padding: 24px 20px 80px; }
.admin h1 { font-size: 22px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 18px 0 26px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.stat .v { font-size: 26px; font-weight: 700; }
.stat .k { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.section { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 20px; }
.section h2 { font-size: 16px; margin: 0 0 14px; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.grid th { text-align: left; color: var(--text-3); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
table.grid td { padding: 10px; border-bottom: 1px solid var(--line); }
.pill { font-size: 11.5px; padding: 2px 9px; border-radius: 20px; font-weight: 600; }
.pill.active { background: rgba(62,207,142,.15); color: var(--ok); }
.pill.pending { background: rgba(240,167,66,.15); color: var(--warn); }
.pill.suspended { background: rgba(255,107,107,.15); color: var(--err); }
.pill.owner { background: var(--accent-tint); color: var(--accent); }
.rowbtns { display: flex; gap: 6px; flex-wrap: wrap; }
.codebox { font-family: var(--mono); background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 10px; font-size: 13px; }
.muted { color: var(--text-3); font-size: 12.5px; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; place-items: center; padding: 20px; z-index: 50; }
.modal-bg.on { display: grid; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; width: min(760px, 100%); max-height: 85vh; overflow-y: auto; padding: 22px; }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 82%; max-width: 300px; z-index: 40; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .sidebar.open { transform: none; }
  .hamburger { display: grid; }
  .stream-inner { padding: 18px 14px 150px; }
  .turn { gap: 10px; margin-bottom: 20px; }
  .composer { padding: 8px 12px 14px; }
  .bubble img.photo, .preview img { max-width: 100%; }
  .card { padding: 22px; }
}
/* iOS: keep the input above the on-screen keyboard and avoid zoom-on-focus */
@media (max-width: 820px) {
  #msg, .input, textarea { font-size: 16px; }
}
