/* BOSON AI by STARK HELIX
   Palette: Deep Field, Track Cyan, Track Violet, Higgs Gold */
:root {
  --font-ui: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Syne", "Onest", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --side-w: 288px;
  --col-w: 780px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121533;
  --side: #0e1128;
  --panel: #181c42;
  --raised: #21265c;
  --line: #2e3472;
  --text: #e9ecff;
  --muted: #9aa2d6;
  --accent: #3de0d0;
  --accent-ink: #06142a;
  --violet: #8b7bff;
  --hot: #ffc24b;
  --danger: #ff7a8a;
  --code-bg: #0d1030;
  --tk-c: #7a82bd;
  --tk-s: #7ee0a8;
  --tk-n: #ffc24b;
  --tk-k: #a99cff;
  --shadow: 0 10px 40px rgba(2, 4, 20, 0.45);
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6fc;
  --side: #e9edfa;
  --panel: #ffffff;
  --raised: #e6ebfa;
  --line: #d2d9ee;
  --text: #141838;
  --muted: #5b6396;
  --accent: #0a8f8a;
  --accent-ink: #ffffff;
  --violet: #5b4be0;
  --hot: #d98a00;
  --danger: #c4283d;
  --code-bg: #eef1fb;
  --tk-c: #7480b3;
  --tk-s: #11805a;
  --tk-n: #b36b00;
  --tk-k: #5b4be0;
  --shadow: 0 10px 40px rgba(30, 40, 100, 0.14);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15.5px/1.6 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.spacer { flex: 1; }
.ic { display: block; flex: none; }

/* ---------- App grid ---------- */
.app {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr) 0;
  height: 100dvh;
  transition: grid-template-columns 0.25s ease;
}
.app.nav-collapsed { grid-template-columns: 0 minmax(0, 1fr) 0; }
.app.has-preview { grid-template-columns: var(--side-w) minmax(0, 1fr) minmax(360px, 44%); }
.app.nav-collapsed.has-preview { grid-template-columns: 0 minmax(0, 1fr) minmax(360px, 44%); }

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--side);
  border-right: 1px solid var(--line);
  overflow: hidden;
  min-width: 0;
  transition: visibility 0s;
}
.app.nav-collapsed .sidebar { visibility: hidden; transition: visibility 0s 0.25s; }
.side-inner {
  width: var(--side-w);
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 14px 12px 12px;
  gap: 10px;
}
.side-top { display: flex; align-items: center; padding: 2px 6px 6px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.wordmark { font: 800 19px/1 var(--font-display); letter-spacing: 0.04em; }
.new-chat {
  display: flex; align-items: center; gap: 10px;
  background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 12px; padding: 10px 14px; font-weight: 600;
}
.new-chat:hover { filter: brightness(1.08); }
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 0 12px; color: var(--muted);
}
.search:focus-within { border-color: var(--accent); }
.search input {
  flex: 1; min-width: 0; background: transparent; border: 0; color: var(--text);
  padding: 9px 0; font: inherit; font-size: 14px; outline: none;
}
.chat-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.group-label { padding: 12px 10px 4px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.chat-item { display: flex; align-items: center; border-radius: 10px; position: relative; }
.chat-item:hover, .chat-item.active { background: var(--raised); }
.chat-link {
  flex: 1; min-width: 0; text-align: left; background: none; border: 0;
  padding: 8px 10px; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item.active .chat-link { font-weight: 600; }
.chat-actions { display: none; padding-right: 4px; gap: 2px; }
.chat-item:hover .chat-actions, .chat-item:focus-within .chat-actions { display: flex; }
.mini {
  background: none; border: 0; color: var(--muted); padding: 5px; border-radius: 8px; line-height: 0;
}
.mini:hover { color: var(--text); background: var(--line); }
.list-empty { padding: 16px 10px; color: var(--muted); font-size: 14px; }
.side-bottom { border-top: 1px solid var(--line); padding-top: 10px; }
.side-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: 0; border-radius: 10px; padding: 9px 10px; font-size: 14px; color: var(--text);
}
.side-btn:hover { background: var(--raised); }
.byline { margin: 6px 10px 0; font-size: 12.5px; color: var(--muted); }
.scrim { display: none; }

/* ---------- Main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.topbar { display: flex; align-items: center; gap: 6px; padding: 10px 14px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px;
  background: none; border: 0; border-radius: 12px; color: var(--muted); flex: none;
}
.icon-btn:hover { background: var(--raised); color: var(--text); }
.icon-btn.on { background: var(--accent); color: var(--accent-ink); }
.model-picker { position: relative; }
.model-btn {
  display: flex; align-items: center; gap: 6px; background: none; border: 0;
  border-radius: 12px; padding: 8px 12px; font-weight: 600;
}
.model-btn:hover { background: var(--raised); }
.menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; min-width: 250px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 6px;
}
.menu-opt {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: none; border: 0; border-radius: 10px; padding: 9px 10px;
}
.menu-opt:hover { background: var(--raised); }
.menu-opt .t { flex: 1; display: flex; flex-direction: column; line-height: 1.3; }
.menu-opt .t small { color: var(--muted); font-size: 12.5px; }
.menu-opt .ck { color: var(--accent); width: 18px; }

.stage-wrap { position: relative; flex: 1; min-height: 0; }
#collider { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.stage { position: absolute; inset: 0; overflow-y: auto; scroll-behavior: auto; }

/* ---------- Empty state ---------- */
.empty {
  min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px 20px 40px; position: relative;
}
.mark-big { width: 64px; height: 64px; margin-bottom: 18px; }
.mark-big svg { width: 100%; height: 100%; }
.empty h1 {
  margin: 0; font: 800 clamp(28px, 5vw, 44px)/1.08 var(--font-display); letter-spacing: -0.01em;
  max-width: 16ch;
}
.empty-sub { margin: 12px 0 26px; color: var(--muted); max-width: 44ch; }
.suggest { display: flex; flex-direction: column; width: min(560px, 100%); text-align: left; }
.suggest-item {
  display: flex; align-items: center; gap: 12px; background: none; border: 0;
  border-top: 1px solid var(--line); padding: 13px 6px; color: var(--text); text-align: left;
}
.suggest-item:last-child { border-bottom: 1px solid var(--line); }
.suggest-item:hover { background: color-mix(in srgb, var(--raised) 70%, transparent); }
.suggest-item .ic { color: var(--accent); }

/* ---------- Thread ---------- */
.thread { padding: 8px 0 28px; }
.msg { max-width: var(--col-w); margin: 0 auto; padding: 14px 20px; display: flex; gap: 14px; }
.msg.user { flex-direction: column; align-items: flex-end; gap: 4px; }
.bubble {
  max-width: 86%; background: var(--raised); border-radius: 18px 18px 6px 18px;
  padding: 10px 15px; white-space: pre-wrap; word-break: break-word;
}
.bubble .utext:empty { display: none; }
.avatar { width: 28px; height: 28px; flex: none; margin-top: 2px; }
.avatar svg { width: 100%; height: 100%; }
.content { flex: 1; min-width: 0; }
.body { max-width: 72ch; word-break: break-word; }
.meta { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.msg-actions { display: flex; gap: 2px; margin-top: 6px; opacity: 0; transition: opacity 0.15s; }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { opacity: 1; }
.msg.bot:not(:last-child) [data-act="regen"] { display: none; }
@media (hover: none) { .msg-actions { opacity: 1; } }
.msg-actions .mini { padding: 6px; }

.att-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.att {
  display: inline-flex; align-items: center; gap: 8px; max-width: 220px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 4px 8px 4px 4px; font-size: 13px; white-space: normal;
}
.att img { width: 34px; height: 34px; object-fit: cover; border-radius: 7px; }
.att .ph { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 7px; background: var(--raised); color: var(--muted); }
.att .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.att .x { background: none; border: 0; color: var(--muted); line-height: 0; padding: 3px; border-radius: 6px; }
.att .x:hover { color: var(--text); background: var(--raised); }
.att.gone { opacity: 0.6; }

.edit-area {
  width: min(560px, 70vw); background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px; font: inherit; resize: vertical;
}
.edit-row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

.think {
  border-left: 2px solid var(--violet); padding: 2px 0 2px 12px; margin-bottom: 12px; color: var(--muted);
  font-size: 14px;
}
.think summary { cursor: pointer; font-weight: 500; }
.think-body { margin-top: 6px; }

.sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.src {
  font-size: 13px; text-decoration: none; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 11px; max-width: 220px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.src:hover { border-color: var(--accent); }
.err {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 8px;
  border: 1px solid var(--danger); color: var(--danger); border-radius: 12px; padding: 10px 14px; font-size: 14px;
}

/* Thinking indicator: a nucleus with one orbiting particle */
.orbit {
  display: inline-block; width: 22px; height: 22px; border-radius: 50%; position: relative;
  border: 1.5px solid var(--line); animation: spin 1.1s linear infinite; vertical-align: middle; margin: 4px 0;
}
.orbit::before {
  content: ""; position: absolute; width: 5px; height: 5px; border-radius: 50%;
  background: var(--hot); top: 50%; left: 50%; margin: -2.5px 0 0 -2.5px;
}
.orbit::after {
  content: ""; position: absolute; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 8px var(--accent); top: -4px; left: 50%; margin-left: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Markdown ---------- */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 0.9em; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.25; margin: 1.3em 0 0.5em; font-weight: 600; }
.md h1 { font-size: 1.45em; } .md h2 { font-size: 1.25em; } .md h3 { font-size: 1.1em; } .md h4, .md h5, .md h6 { font-size: 1em; }
.md ul, .md ol { margin: 0 0 0.9em; padding-left: 1.4em; }
.md li { margin: 0.25em 0; }
.md li > ul, .md li > ol { margin: 0.25em 0 0; }
.md a { color: var(--accent); text-underline-offset: 3px; }
.md blockquote { margin: 0 0 0.9em; padding: 2px 0 2px 14px; border-left: 3px solid var(--accent); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.4em 0; }
.md code { font-family: var(--font-mono); font-size: 0.88em; background: var(--raised); padding: 0.12em 0.4em; border-radius: 6px; }
.tbl { overflow-x: auto; margin: 0 0 1em; border: 1px solid var(--line); border-radius: 12px; }
.md table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
.md th, .md td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.md th { background: var(--raised); font-weight: 600; }
.md tr:last-child td { border-bottom: 0; }

.code { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin: 0 0 1em; background: var(--code-bg); max-width: 100%; }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 14px; border-bottom: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.code-actions { display: flex; gap: 2px; }
.code-actions button {
  display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; color: var(--muted);
  padding: 4px 8px; border-radius: 8px; font-size: 12.5px;
}
.code-actions button:hover { background: var(--raised); color: var(--text); }
.code pre { margin: 0; padding: 14px; overflow-x: auto; }
.md .code code { background: none; padding: 0; font-size: 13.5px; line-height: 1.6; border-radius: 0; }
.tk-c { color: var(--tk-c); font-style: italic; } .tk-s { color: var(--tk-s); } .tk-n { color: var(--tk-n); } .tk-k { color: var(--tk-k); }

/* ---------- Composer ---------- */
.composer-wrap { padding: 4px 16px calc(10px + env(safe-area-inset-bottom)); }
.composer {
  max-width: var(--col-w); margin: 0 auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 22px; padding: 10px 10px 8px 14px; box-shadow: var(--shadow);
}
.composer:focus-within { border-color: var(--accent); }
.composer.drop { border-color: var(--hot); border-style: dashed; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; }
.attachments:not(:empty) { margin-bottom: 8px; }
#input {
  display: block; width: 100%; background: transparent; border: 0; color: var(--text); resize: none;
  font: inherit; line-height: 1.5; padding: 4px 4px 6px 0; max-height: 200px; outline: none;
}
#input::placeholder { color: var(--muted); }
.composer-row { display: flex; align-items: center; gap: 4px; }
.modes { flex: 1; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.modes::-webkit-scrollbar { display: none; }
.mode {
  display: inline-flex; align-items: center; gap: 6px; flex: none; background: none;
  border: 1px solid transparent; border-radius: 999px; padding: 5px 11px; font-size: 13.5px; color: var(--muted);
}
.mode:hover { color: var(--text); background: var(--raised); }
.mode[aria-checked="true"] { color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.send {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; border: 0; flex: none;
  background: var(--accent); color: var(--accent-ink);
}
.send:disabled { background: var(--raised); color: var(--muted); cursor: default; }
.send:not(:disabled):hover { filter: brightness(1.1); }
.fine { text-align: center; color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }

/* ---------- Preview panel ---------- */
.preview { min-width: 0; overflow: hidden; border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; visibility: hidden; }
.app.has-preview .preview { visibility: visible; }
.preview-head { display: flex; align-items: center; gap: 4px; padding: 8px 10px 8px 16px; border-bottom: 1px solid var(--line); }
.preview iframe { flex: 1; width: 100%; border: 0; background: #fff; }

/* ---------- Buttons, dialog, toast ---------- */
.btn { border-radius: 10px; padding: 8px 14px; border: 1px solid var(--line); background: none; font-weight: 500; }
.btn:hover { background: var(--raised); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.ghost { padding: 5px 12px; font-size: 13.5px; }
dialog {
  border: 1px solid var(--line); border-radius: 20px; background: var(--panel); color: var(--text);
  width: min(520px, calc(100% - 32px)); padding: 0; box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(5, 7, 20, 0.6); backdrop-filter: blur(3px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 0 22px; }
.dlg-head h2 { margin: 0; font: 700 20px/1.2 var(--font-display); }
.dlg-body { padding: 14px 22px 22px; display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 14px; }
.field label { font-weight: 500; }
.field input[type="text"], .field input[type="password"], .field textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; font: inherit; font-weight: 400;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); outline: none; }
.field small { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.field output { color: var(--accent); margin-left: 6px; }
.field input[type="range"] { accent-color: var(--accent); }
.dlg-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 4px; }
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 60;
  background: var(--raised); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 16px; font-size: 14px; box-shadow: var(--shadow); max-width: calc(100% - 32px);
}

/* ---------- Responsive ---------- */
.key-row { display: flex; gap: 8px; }
.key-row input { flex: 1; min-width: 0; }
.btn-group { display: flex; gap: 8px; }
.dlg-actions { flex-wrap: wrap; }
.note { margin: 0; color: var(--muted); }
.steps { margin: 0; padding-left: 1.3em; color: var(--text); }
.steps a { color: var(--accent); }
.status { margin: 0; min-height: 1.4em; font-size: 14px; color: var(--accent); }
.warn { margin: 0; padding: 10px 12px; border: 1px solid var(--hot); border-radius: 12px; font-size: 14px; }
#admin-login, #admin-panel { display: flex; flex-direction: column; gap: 14px; }
#admin-login[hidden], #admin-panel[hidden] { display: none; }
.cont { margin-top: 10px; }
.msg.bot:not(:last-child) .cont { display: none; }
.to-bottom {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 5;
  background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 50%; color: var(--text);
}
.to-bottom:hover { background: var(--raised); }

@media (max-width: 880px) {
  .app, .app.nav-collapsed, .app.has-preview, .app.nav-collapsed.has-preview { grid-template-columns: minmax(0, 1fr); }
  .sidebar, .app.nav-collapsed .sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--side-w); z-index: 50; visibility: visible;
    transform: translateX(-100%); transition: transform 0.25s ease;
  }
  .app.nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .app.nav-collapsed .sidebar { visibility: visible; }
  .scrim { position: fixed; inset: 0; background: rgba(5, 7, 20, 0.55); z-index: 40; }
  .app.nav-open .scrim { display: block; }
  .preview { position: fixed; inset: 0; z-index: 45; }
  .msg { padding: 12px 14px; gap: 10px; }
  .bubble { max-width: 94%; }
  .chat-actions { display: flex; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
