:root {
  --bg: #0b0a10;
  --bg-2: #110f18;
  --panel: #15131e;
  --panel-2: #1c1928;
  --line: #2a2638;
  --line-2: #3a3550;
  --text: #ece9f5;
  --text-2: #b9b3cc;
  --muted: #847d99;
  --accent: #b69cff;
  --accent-2: #8f6dff;
  --accent-ink: #120d22;
  --gold: #e9c46a;
  --danger: #ff7a8a;
  --ok: #6fdcaa;
  --p-claudexia: #e9a26a;
  --p-featherless: #6fc3ff;
  --p-tokenator: #6fdcaa;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(1200px 600px at 70% -10%, rgba(143, 109, 255, .10), transparent 60%), var(--bg);
  color: var(--text); font: 15px/1.6 var(--sans); -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
kbd { font: 11px var(--mono); color: var(--muted); border: 1px solid var(--line-2); border-radius: 5px; padding: 1px 5px; margin-left: auto; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* sigil / brand */
.sigil {
  width: 26px; height: 26px; border-radius: 50%; display: inline-block; flex: none;
  background:
    conic-gradient(from 45deg, transparent 0 10%, var(--gold) 10% 15%, transparent 15% 35%, var(--gold) 35% 40%, transparent 40% 60%, var(--gold) 60% 65%, transparent 65% 85%, var(--gold) 85% 90%, transparent 90%),
    radial-gradient(circle, var(--gold) 0 18%, transparent 19%), #191527;
  box-shadow: inset 0 0 0 2px var(--accent), 0 0 18px rgba(182, 156, 255, .35);
  -webkit-mask: radial-gradient(circle, #000 69%, transparent 70%);
}
.sigil-lg { width: 54px; height: 54px; }
.sigil-xl { width: 72px; height: 72px; opacity: .9; }
.wordmark { font-family: var(--serif); font-weight: 600; letter-spacing: .06em; }

/* buttons */
.btn { border: 1px solid var(--line-2); background: var(--panel-2); border-radius: 10px; padding: 9px 14px; display: inline-flex; gap: 8px; align-items: center; justify-content: center; transition: background .15s, border-color .15s; }
.btn:hover { background: #241f33; border-color: #4a4365; }
.btn.primary { background: linear-gradient(180deg, var(--accent), var(--accent-2)); color: var(--accent-ink); border: 0; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid transparent; background: transparent; display: inline-grid; place-items: center; color: var(--text-2); }
.icon-btn:hover { background: var(--panel-2); border-color: var(--line); color: var(--text); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 34px 28px; display: grid; gap: 12px; justify-items: center; text-align: center; box-shadow: var(--shadow); }
.login-card h1 { margin: 6px 0 0; font-size: 30px; }
.login-card p { margin: 0 0 6px; }
.login-card input { width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--bg-2); outline: none; }
.login-card input:focus { border-color: var(--accent); }
.login-card .btn { width: 100%; padding: 11px; }
.error-text { color: var(--danger); min-height: 1.2em; font-size: 13px; }

/* layout */
.app { display: grid; grid-template-columns: 280px 1fr; height: 100dvh; }
.sidebar { background: var(--bg-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; padding: 14px 10px 10px; gap: 10px; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; }
.new-chat { width: 100%; justify-content: flex-start; }
.search-wrap { position: relative; display: flex; align-items: center; }
.search-wrap svg { position: absolute; left: 11px; color: var(--muted); width: 16px; height: 16px; }
.search-wrap input { width: 100%; padding: 8px 10px 8px 34px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); outline: none; }
.search-wrap input:focus { border-color: var(--line-2); }
.chat-list { flex: 1; overflow-y: auto; min-height: 0; margin: 0 -4px; padding: 0 4px; }
.group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 14px 8px 4px; }
.chat-item { display: flex; align-items: center; gap: 9px; padding: 7px 8px; border-radius: 9px; cursor: pointer; color: var(--text-2); position: relative; }
.chat-item:hover { background: var(--panel); color: var(--text); }
.chat-item.active { background: var(--panel-2); color: var(--text); }
.chat-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.chat-actions { display: none; gap: 2px; }
.chat-item:hover .chat-actions, .chat-item.active .chat-actions { display: flex; }
.chat-actions button { border: 0; background: transparent; color: var(--muted); width: 24px; height: 24px; border-radius: 6px; font-size: 12px; }
.chat-actions button:hover { background: var(--line); color: var(--text); }
.chat-empty { padding: 14px 8px; font-size: 13px; }
.side-foot { border-top: 1px solid var(--line); padding-top: 8px; display: grid; gap: 2px; }
.side-link { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; color: var(--text-2); padding: 8px; border-radius: 9px; text-align: left; }
.side-link:hover { background: var(--panel); color: var(--text); }
.scrim { display: none; }
.only-mobile { display: none; }

.prov-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.p-claudexia { --pc: var(--p-claudexia); }
.p-featherless { --pc: var(--p-featherless); }
.p-tokenator { --pc: var(--p-tokenator); }
.prov-dot.p-claudexia, .prov-dot.p-featherless, .prov-dot.p-tokenator { background: var(--pc); box-shadow: 0 0 8px var(--pc); }

/* main */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: rgba(11, 10, 16, .7); backdrop-filter: blur(10px); }
.topbar-spacer { flex: 1; }
.model-chip { display: inline-flex; align-items: center; gap: 9px; max-width: min(520px, 70vw); padding: 7px 12px; border-radius: 11px; border: 1px solid var(--line); background: var(--panel); font-weight: 600; }
.model-chip:hover { border-color: var(--line-2); background: var(--panel-2); }
.model-chip #modelName { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-chip svg { width: 15px; height: 15px; color: var(--muted); }

.messages { flex: 1; overflow-y: auto; min-height: 0; scroll-behavior: auto; }
.empty { min-height: 100%; display: grid; place-content: center; justify-items: center; text-align: center; gap: 6px; padding: 40px 16px; }
.empty h2 { font-family: var(--serif); font-weight: 500; font-size: 30px; margin: 16px 0 0; letter-spacing: .01em; }
.empty p { margin: 0; max-width: 460px; }
.thread { max-width: 820px; margin: 0 auto; padding: 24px 20px 40px; display: grid; gap: 22px; }

.msg { display: grid; gap: 6px; min-width: 0; }
.msg.user { justify-items: end; }
.bubble { background: var(--panel-2); border: 1px solid var(--line); padding: 10px 14px; border-radius: 16px 16px 4px 16px; max-width: min(640px, 92%); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-atts { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.att-img { max-width: 220px; max-height: 180px; border-radius: 10px; border: 1px solid var(--line); cursor: zoom-in; object-fit: cover; }
.att-file { background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 5px 10px; font-size: 13px; color: var(--text-2); }
.msg-meta { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); font-weight: 600; letter-spacing: .01em; }
.msg-actions { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions, .msg:focus-within .msg-actions, .error-msg .msg-actions { opacity: 1; }
.msg-actions button { border: 1px solid transparent; background: transparent; color: var(--muted); font-size: 12.5px; padding: 3px 8px; border-radius: 7px; }
.msg-actions button:hover { background: var(--panel); border-color: var(--line); color: var(--text); }
.msg.streaming .msg-actions { display: none; }
.err-box { border: 1px solid rgba(255, 122, 138, .35); background: rgba(255, 122, 138, .08); color: #ffc2ca; padding: 10px 14px; border-radius: 12px; overflow-wrap: anywhere; font-size: 14px; }

.thoughts { border: 1px solid var(--line); border-radius: 12px; background: var(--bg-2); }
.thoughts summary { cursor: pointer; padding: 7px 12px; color: var(--muted); font-size: 13px; list-style: none; display: flex; align-items: center; gap: 6px; }
.thoughts summary::before { content: "✦"; color: var(--accent); }
.thoughts summary::-webkit-details-marker { display: none; }
.thought-body { padding: 0 14px 12px; color: var(--text-2); font-size: 13.5px; white-space: pre-wrap; max-height: 360px; overflow-y: auto; }

/* markdown */
.md { overflow-wrap: anywhere; min-width: 0; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .8em; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.3; margin: 1.2em 0 .5em; }
.md h1 { font-size: 1.45em; } .md h2 { font-size: 1.25em; } .md h3 { font-size: 1.1em; }
.md ul, .md ol { padding-left: 1.4em; margin: 0 0 .8em; }
.md li { margin: .2em 0; }
.md a { color: var(--accent); text-underline-offset: 3px; }
.md blockquote { margin: 0 0 .8em; padding: 2px 14px; border-left: 3px solid var(--line-2); color: var(--text-2); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.md code { font: .88em var(--mono); background: var(--panel-2); border: 1px solid var(--line); padding: .1em .35em; border-radius: 6px; }
.md .code { margin: 0 0 .9em; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #0e0d14; }
.md .code-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px 6px 14px; background: var(--panel); border-bottom: 1px solid var(--line); font: 12px var(--mono); color: var(--muted); }
.md .copy-code { border: 1px solid var(--line); background: transparent; color: var(--text-2); font-size: 12px; padding: 2px 9px; border-radius: 6px; }
.md .copy-code:hover { color: var(--text); border-color: var(--line-2); }
.md pre { margin: 0; padding: 14px; overflow-x: auto; }
.md pre code { background: none; border: 0; padding: 0; font-size: 13px; line-height: 1.55; white-space: pre; }
.md .table-wrap { overflow-x: auto; margin: 0 0 .9em; border: 1px solid var(--line); border-radius: 10px; }
.md table { border-collapse: collapse; width: 100%; font-size: 14px; }
.md th, .md td { padding: 7px 12px; border-bottom: 1px solid var(--line); text-align: left; }
.md th { background: var(--panel); font-weight: 600; }
.md tr:last-child td { border-bottom: 0; }
.caret { display: inline-block; width: 8px; height: 1.05em; vertical-align: text-bottom; background: var(--accent); margin-left: 2px; animation: blink 1s steps(2) infinite; border-radius: 2px; }
@keyframes blink { 50% { opacity: 0; } }
.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); opacity: .4; animation: bob 1.1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bob { 30% { opacity: 1; transform: translateY(-3px); } }

/* composer */
.composer-wrap { padding: 8px 16px 12px; max-width: 860px; width: 100%; margin: 0 auto; }
.composer { display: flex; align-items: flex-end; gap: 6px; background: var(--panel); border: 1px solid var(--line-2); border-radius: 18px; padding: 8px; box-shadow: 0 10px 30px rgba(0, 0, 0, .3); }
.composer:focus-within { border-color: #574e78; }
.composer textarea { flex: 1; resize: none; border: 0; outline: none; background: transparent; padding: 8px 4px; max-height: 260px; min-height: 22px; line-height: 1.5; }
.send { width: 38px; height: 38px; border-radius: 12px; border: 0; background: linear-gradient(180deg, var(--accent), var(--accent-2)); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.send svg { stroke-width: 2.3; }
.send .i-stop { display: none; fill: currentColor; stroke: none; }
.send.stop { background: var(--text); }
.send.stop .i-send { display: none; } .send.stop .i-stop { display: block; }
.pill { display: inline-flex; align-items: center; gap: 5px; height: 36px; padding: 0 11px; border-radius: 10px; border: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 13px; }
.pill:hover { color: var(--text); border-color: var(--line-2); }
.pill.on { color: var(--gold); border-color: rgba(233, 196, 106, .5); background: rgba(233, 196, 106, .08); }
.pill svg { width: 16px; height: 16px; }
.fine { font-size: 11.5px; color: var(--muted); text-align: center; margin: 7px 0 0; }
.attach-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.attach-row:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 7px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px 6px 4px 4px; font-size: 13px; max-width: 240px; }
.chip img { width: 30px; height: 30px; object-fit: cover; border-radius: 7px; }
.chip > span:first-child:not(.chip-name) { padding-left: 4px; }
.chip-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip button { border: 0; background: transparent; color: var(--muted); border-radius: 6px; width: 22px; height: 22px; }
.chip button:hover { background: var(--line); color: var(--text); }

/* modals */
.modal { position: fixed; inset: 0; background: rgba(5, 4, 9, .66); backdrop-filter: blur(4px); display: grid; place-items: start center; padding: 9vh 16px 16px; z-index: 50; }
.modal-card { width: min(760px, 100%); background: var(--panel); border: 1px solid var(--line-2); border-radius: 18px; box-shadow: var(--shadow); }
.picker { display: flex; flex-direction: column; max-height: 78vh; }
.picker-head { flex: none; display: flex; gap: 6px; align-items: center; padding: 12px; border-bottom: 1px solid var(--line); }
.picker-head .search-wrap { flex: 1; }
.search-wrap.big input { padding: 11px 12px 11px 38px; font-size: 15px; background: var(--bg-2); }
.search-wrap.big svg { left: 13px; }
.tabs { flex: none; display: flex; gap: 6px; padding: 10px 12px 4px; overflow-x: auto; scrollbar-width: none; }
.tab { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--text-2); font-size: 13px; }
.tab:hover { border-color: var(--line-2); color: var(--text); }
.tab.active { background: var(--panel-2); border-color: var(--accent); color: var(--text); }
.tab .count { color: var(--muted); font-size: 11.5px; }
.notes { flex: none; padding: 0 12px; display: grid; gap: 4px; }
.note { font-size: 12.5px; color: #ffc2ca; background: rgba(255, 122, 138, .07); border: 1px solid rgba(255, 122, 138, .25); border-radius: 9px; padding: 6px 10px; margin-top: 6px; overflow-wrap: anywhere; }
.model-list { overflow-y: auto; padding: 8px; min-height: 120px; }
.model-row { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; }
.model-row.focus { background: var(--panel-2); }
.model-row.selected { border-color: rgba(182, 156, 255, .45); }
.model-main { flex: 1; min-width: 0; }
.model-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-id { font: 12px var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badges { display: flex; gap: 5px; flex: none; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--text-2); }
.badge.warm { color: var(--gold); border-color: rgba(233, 196, 106, .4); }
.badge.prov { color: var(--pc); border-color: color-mix(in srgb, var(--pc) 45%, transparent); }
.star { border: 0; background: transparent; color: var(--muted); font-size: 17px; width: 30px; height: 30px; border-radius: 8px; flex: none; }
.star:hover { background: var(--line); color: var(--gold); }
.star.on { color: var(--gold); }
.model-empty { padding: 30px; text-align: center; }
.picker-foot { flex: none; padding: 8px 16px 12px; font-size: 12.5px; border-top: 1px solid var(--line); }

.form-card { padding: 18px 20px 20px; display: grid; gap: 14px; width: min(560px, 100%); }
.form-head { display: flex; justify-content: space-between; align-items: center; }
.form-head h3 { margin: 0; font-size: 17px; }
.form-card label { display: grid; gap: 6px; font-size: 13.5px; color: var(--text-2); }
.form-card textarea, .form-card input { width: 100%; background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 10px 12px; outline: none; resize: vertical; }
.form-card textarea:focus, .form-card input:focus { border-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; justify-content: flex-end; }
.provider-status { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; gap: 6px; font-size: 13.5px; }
.ps-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.ps-row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.ps-err { flex-basis: 100%; color: #ffc2ca; font-size: 12.5px; padding-left: 17px; overflow-wrap: anywhere; }

.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .85); display: grid; place-items: center; padding: 20px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--panel-2); border: 1px solid var(--line-2); padding: 9px 16px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 70; font-size: 14px; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: rgba(255, 122, 138, .5); color: #ffc2ca; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2a2638; border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* mobile */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 40; transform: translateX(-100%); transition: transform .22s ease; }
  .app.side-open .sidebar { transform: none; }
  .app.side-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 30; }
  .only-mobile { display: inline-grid; }
  .topbar { padding: 8px 10px; }
  .thread { padding: 18px 16px 30px; }
  .composer-wrap { padding: 6px 10px calc(10px + env(safe-area-inset-bottom)); }
  .fine { display: none; }
  .new-chat kbd { display: none; }
  .modal { padding: 0; place-items: stretch; }
  .modal-card { border-radius: 0; width: 100%; }
  .picker { max-height: none; height: 100dvh; }
  .form-card { align-self: start; border-radius: 0 0 18px 18px; }
  .badges .badge:not(.prov):not(.warm) { display: none; }
  .msg-actions { opacity: 1; }
  .row2 { grid-template-columns: 1fr; }
}

/* accounts */
.auth-tabs { display: flex; gap: 4px; padding: 4px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; width: 100%; margin: 4px 0 2px; }
.auth-tab { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 7px 10px; border-radius: 9px; font-size: 14px; }
.auth-tab.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.whoami { font-size: 12.5px; color: var(--muted); padding: 2px 8px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pw-box { border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.pw-box summary { cursor: pointer; font-size: 13.5px; color: var(--text-2); }
.pw-box[open] summary { margin-bottom: 10px; }

/* file attachments */
.chip { max-width: 280px; }
.chip-icon { width: 30px; height: 30px; display: grid; place-items: center; font-size: 17px; background: var(--bg-2); border-radius: 7px; flex: none; }
.chip-text { display: grid; min-width: 0; line-height: 1.25; }
.chip-note { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip.loading { opacity: .8; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--accent); animation: spin .7s linear infinite; display: block; }
.dropzone { position: fixed; inset: 0; z-index: 80; display: none; place-items: center; background: rgba(11, 10, 16, .78); backdrop-filter: blur(3px); pointer-events: none; padding: 16px; }
.dropzone.show { display: grid; }
.drop-card { border: 2px dashed var(--accent); border-radius: 22px; padding: 38px 40px; display: grid; justify-items: center; gap: 8px; text-align: center; background: rgba(182, 156, 255, .06); max-width: 520px; }
.drop-card svg { width: 38px; height: 38px; color: var(--accent); }
.drop-card b { font-size: 18px; }
.drop-card span { color: var(--text-2); font-size: 13.5px; }
