:root {
  --bg: #0b0d12;
  --bg-2: #10131a;
  --panel: #141822;
  --panel-2: #1a1f2b;
  --line: #232a38;
  --line-2: #2e3647;
  --text: #e8ebf2;
  --text-2: #b7bfcf;
  --muted: #7f899c;
  --accent: #d97757;
  --accent-2: #e8936f;
  --accent-soft: rgba(217, 119, 87, .14);
  --blue: #6aa6ff;
  --green: #3ecf8e;
  --red: #f26d6d;
  --amber: #f0b45a;
  --radius: 14px;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  --side-w: 290px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.55 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased; overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; flex: none; }
a { color: var(--accent-2); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.center { text-align: center; }
.b { font-weight: 600; }
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; }

/* boot */
.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line-2);
  background: var(--panel-2); font-weight: 600; font-size: 14px; transition: .15s;
}
.btn:hover { border-color: #3b4558; background: #202636; }
.btn.primary { background: linear-gradient(180deg, var(--accent-2), var(--accent)); border-color: transparent; color: #1a0f0a; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--red); }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.stop { height: 36px; background: rgba(242, 109, 109, .12); border-color: rgba(242, 109, 109, .35); color: #ffb3b3; }
.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px;
  background: transparent; border: 0; color: var(--text-2); transition: .15s;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

/* login */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; overflow: auto; }
.login-glow { position: absolute; inset: 0; background:
  radial-gradient(600px 400px at 20% 10%, rgba(217,119,87,.16), transparent 60%),
  radial-gradient(700px 500px at 90% 90%, rgba(106,166,255,.10), transparent 60%); pointer-events: none; }
.login-card {
  position: relative; width: 100%; max-width: 380px; padding: 34px 28px 24px;
  background: rgba(20, 24, 34, .82); backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
}
.login-card h1 { margin: 6px 0 0; font-size: 22px; text-align: center; }
.login-card > p { margin: -8px 0 6px; text-align: center; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent-2), #b8573a); color: #fff; box-shadow: 0 4px 14px rgba(217,119,87,.35); }
.brand-mark svg { width: 18px; height: 18px; }
.brand-mark.big { width: 54px; height: 54px; border-radius: 16px; margin: 0 auto; }
.brand-mark.big svg { width: 30px; height: 30px; }
.brand-mark.huge { width: 64px; height: 64px; border-radius: 20px; margin: 0 auto 6px; }
.brand-mark.huge svg { width: 34px; height: 34px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-2); font-weight: 500; }
.field input, .field select, .field textarea {
  height: 44px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line-2);
  background: var(--bg-2); outline: none; font-size: 15px; transition: .15s;
}
.field textarea { height: auto; padding: 10px 14px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field small { color: var(--muted); font-weight: 400; }
.form-err { background: rgba(242,109,109,.1); border: 1px solid rgba(242,109,109,.3); color: #ffb3b3; padding: 10px 12px; border-radius: 10px; font-size: 13px; }

/* layout */
.app { position: fixed; inset: 0; display: flex; }
.sidebar {
  width: var(--side-w); flex: none; background: var(--bg-2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: calc(12px + var(--safe-t)) 12px 12px; gap: 10px; z-index: 30;
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 2px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; }
.new-chat { height: 42px; }
.search { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); }
.search input { flex: 1; background: none; border: 0; outline: none; min-width: 0; color: var(--text); }
.chat-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.chat-list .group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 12px 10px 6px; font-weight: 600; }
.chat-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 10px;
  background: none; border: 0; text-align: left; 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-item .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.chat-item .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.chat-item .dot.unread { background: var(--accent); }
.chat-item .dot.run { border: 2px solid var(--accent); border-top-color: transparent; width: 12px; height: 12px; animation: spin .8s linear infinite; }
.chat-item .pin { color: var(--muted); width: 13px; height: 13px; }
.side-foot { position: relative; border-top: 1px solid var(--line); padding-top: 10px; }
.user-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border-radius: 10px; border: 0; background: none; text-align: left; }
.user-btn:hover { background: var(--panel); }
.user-meta { flex: 1; min-width: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px;
  background: linear-gradient(135deg, #3b4a6b, #273049); color: #cfe0ff; flex: none; }
.menu { position: absolute; bottom: calc(100% + 6px); left: 0; right: 0; background: var(--panel-2); border: 1px solid var(--line-2);
  border-radius: 12px; padding: 6px; box-shadow: var(--shadow); z-index: 40; }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border-radius: 8px; background: none; border: 0; text-align: left; font-size: 14px; }
.menu button:hover { background: #262d3d; }
.menu button.danger { color: var(--red); }
.scrim { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative;
  background: radial-gradient(900px 500px at 70% -10%, rgba(217,119,87,.06), transparent 60%), var(--bg); }
.topbar { display: flex; align-items: center; gap: 8px; padding: calc(10px + var(--safe-t)) 16px 10px; border-bottom: 1px solid var(--line);
  background: rgba(11,13,18,.75); backdrop-filter: blur(12px); z-index: 10; min-height: 60px; }
.top-title { flex: 1; min-width: 0; }
.chat-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: text; }
.chat-meta { display: flex; gap: 6px; flex-wrap: nowrap; overflow: hidden; margin-top: 2px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--text-2); background: var(--panel); border: 1px solid var(--line);
  padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.chip.accent { color: var(--accent-2); border-color: rgba(217,119,87,.35); background: var(--accent-soft); }
.top-actions { display: flex; align-items: center; gap: 4px; }
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; }
.conn.on { background: var(--green); box-shadow: 0 0 0 4px rgba(62,207,142,.12); }
.conn.off { background: var(--red); }

/* messages */
.scroller { flex: 1; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: auto; }
.messages, .empty, .working { max-width: 820px; margin: 0 auto; padding: 0 20px; }
.messages { padding-top: 22px; display: flex; flex-direction: column; gap: 18px; }
.scroll-pad { height: 24px; }
.empty { text-align: center; padding-top: 12vh; }
.empty h2 { margin: 10px 0 6px; font-size: 26px; letter-spacing: -.01em; }
.empty p { max-width: 460px; margin: 0 auto; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 26px; text-align: left; }
.suggestions button { padding: 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); color: var(--text-2); font-size: 14px; transition: .15s; }
.suggestions button:hover { border-color: var(--line-2); color: var(--text); background: var(--panel-2); }

.msg { display: flex; gap: 12px; animation: rise .18s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }
.msg.user { justify-content: flex-end; }
.bubble-user { max-width: min(85%, 640px); background: linear-gradient(180deg, #232a3a, #1d2331); border: 1px solid var(--line-2);
  padding: 10px 14px; border-radius: 18px 18px 4px 18px; white-space: pre-wrap; word-wrap: break-word; }
.bubble-user .files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.bubble-user .files img { max-width: 220px; max-height: 180px; border-radius: 10px; display: block; border: 1px solid var(--line-2); }
.file-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 8px; background: rgba(0,0,0,.25); font-size: 12.5px; color: var(--text-2); text-decoration: none; }
.msg-time { font-size: 11px; color: var(--muted); margin-top: 4px; text-align: right; }
.bot-ava { width: 30px; height: 30px; border-radius: 9px; flex: none; display: grid; place-items: center; margin-top: 2px;
  background: linear-gradient(135deg, var(--accent-2), #b8573a); color: #fff; }
.bot-ava svg { width: 17px; height: 17px; }
.bot-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.bot-body.cont { padding-left: 42px; }

.md { word-wrap: break-word; overflow-wrap: anywhere; }
.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 { margin: 1.2em 0 .5em; line-height: 1.3; letter-spacing: -.01em; }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.2em; } .md h3 { font-size: 1.07em; }
.md ul, .md ol { margin: 0 0 .8em; padding-left: 1.4em; }
.md li { margin: .25em 0; }
.md code { font-family: "JetBrains Mono", monospace; font-size: .86em; background: #1c2230; border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; }
.md pre { position: relative; margin: .6em 0 1em; background: #0d1017; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.md pre code { display: block; padding: 14px 16px; overflow-x: auto; background: none; border: 0; font-size: 13px; line-height: 1.6; }
.md pre .copy { position: absolute; top: 6px; right: 6px; opacity: 0; transition: .15s; }
.md pre:hover .copy, .md pre .copy.done { opacity: 1; }
.md blockquote { margin: 0 0 .8em; padding: .2em 1em; border-left: 3px solid var(--accent); color: var(--text-2); background: rgba(255,255,255,.02); border-radius: 0 8px 8px 0; }
.md table { border-collapse: collapse; margin: .4em 0 1em; display: block; overflow-x: auto; max-width: 100%; font-size: 14px; }
.md th, .md td { border: 1px solid var(--line-2); padding: 6px 10px; text-align: left; }
.md th { background: var(--panel); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.md a { word-break: break-all; }
.md img { max-width: 100%; border-radius: 10px; }
.copy { height: 28px; padding: 0 9px; border-radius: 7px; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text-2); font-size: 12px; display: inline-flex; align-items: center; gap: 5px; }
.copy svg { width: 14px; height: 14px; }
.msg-actions { display: flex; gap: 6px; margin-top: 6px; opacity: 0; transition: .15s; }
.msg:hover .msg-actions { opacity: 1; }
.caret::after { content: ""; display: inline-block; width: 8px; height: 1em; margin-left: 2px; vertical-align: -2px; background: var(--accent); border-radius: 2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* tools */
.tools { display: flex; flex-direction: column; gap: 6px; margin: 2px 0; }
.tool { border: 1px solid var(--line); background: var(--bg-2); border-radius: 10px; overflow: hidden; }
.tool > summary { list-style: none; display: flex; align-items: center; gap: 9px; padding: 7px 11px; cursor: pointer; font-size: 13px; color: var(--text-2); }
.tool > summary::-webkit-details-marker { display: none; }
.tool > summary:hover { background: var(--panel); }
.tool .tname { font-weight: 600; color: var(--text); flex: none; }
.tool .tsum { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: "JetBrains Mono", monospace; font-size: 12px; color: var(--muted); }
.tool .tstate { flex: none; width: 16px; height: 16px; display: grid; place-items: center; }
.tool .tstate.ok { color: var(--green); }
.tool .tstate.err { color: var(--red); }
.tool .tstate.run::before { content: ""; width: 11px; height: 11px; border: 2px solid var(--accent); border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
.tool .tstate svg { width: 14px; height: 14px; }
.tool .ticon { color: var(--muted); width: 15px; height: 15px; }
.tool-body { border-top: 1px solid var(--line); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.tool-body .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; }
.tool-body pre { margin: 0; max-height: 360px; overflow: auto; font-family: "JetBrains Mono", monospace; font-size: 12px; line-height: 1.55;
  background: #0a0c11; border: 1px solid var(--line); border-radius: 8px; padding: 10px; white-space: pre-wrap; word-break: break-word; color: #cdd5e3; }
.tool-body pre.err { color: #ffb3b3; }
.tools-more { font-size: 12.5px; color: var(--muted); background: none; border: 0; padding: 2px 4px; text-align: left; }
.tools-more:hover { color: var(--text); }

.result-line { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); padding-left: 42px; margin-top: -8px; }
.result-line .ok { color: var(--green); }
.notice { align-self: center; font-size: 12.5px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); padding: 5px 12px; border-radius: 999px; }
.err-card { display: flex; gap: 10px; align-items: flex-start; border: 1px solid rgba(242,109,109,.3); background: rgba(242,109,109,.07); color: #ffc4c4; border-radius: 12px; padding: 10px 14px; font-size: 13.5px; white-space: pre-wrap; word-break: break-word; margin-left: 42px; }
.err-card svg { color: var(--red); margin-top: 2px; }

.working { display: flex; align-items: center; gap: 10px; padding-top: 16px; padding-left: 62px; color: var(--text-2); font-size: 13.5px; }
.working #workingText { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pulse { display: flex; gap: 4px; flex: none; }
.pulse i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: bounce 1.2s infinite ease-in-out; }
.pulse i:nth-child(2) { animation-delay: .15s; } .pulse i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { opacity: .3; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

.to-bottom { position: absolute; right: 50%; transform: translateX(50%); bottom: calc(150px + var(--safe-b)); width: 38px; height: 38px; border-radius: 50%;
  background: var(--panel-2); border: 1px solid var(--line-2); display: grid; place-items: center; box-shadow: var(--shadow); z-index: 5; color: var(--text); }

/* composer */
.composer-wrap { padding: 8px 16px calc(10px + var(--safe-b)); position: relative; }
.composer { max-width: 820px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line-2); border-radius: 18px; padding: 10px 10px 8px 14px;
  box-shadow: 0 6px 30px rgba(0,0,0,.3); transition: .15s; }
.composer:focus-within { border-color: #46506a; box-shadow: 0 0 0 3px rgba(217,119,87,.08), 0 6px 30px rgba(0,0,0,.3); }
.composer textarea { width: 100%; resize: none; border: 0; outline: none; background: none; max-height: 40vh; min-height: 24px; line-height: 1.5; padding: 2px 0; font-size: 15.5px; }
.composer-row { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.composer-row .left, .composer-row .right { display: flex; align-items: center; gap: 6px; }
.send-btn { width: 36px; height: 36px; border-radius: 10px; border: 0; display: grid; place-items: center; color: #1a0f0a;
  background: linear-gradient(180deg, var(--accent-2), var(--accent)); transition: .15s; }
.send-btn:disabled { background: var(--line-2); color: var(--muted); cursor: default; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; }
.attachments:not(:empty) { margin-bottom: 8px; }
.att { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 6px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); font-size: 12.5px; max-width: 240px; }
.att img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; }
.att .ficon { width: 34px; height: 34px; border-radius: 6px; display: grid; place-items: center; background: var(--panel-2); color: var(--muted); }
.att .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att .rm { background: none; border: 0; color: var(--muted); padding: 2px; }
.att.up { opacity: .6; }
.foot-note { margin-top: 6px; }
.drop-hint { position: absolute; inset: -400px 16px 0; border: 2px dashed var(--accent); border-radius: 18px; background: rgba(217,119,87,.08); display: grid; place-items: center; font-weight: 600; color: var(--accent-2); z-index: 20; pointer-events: none; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(4,6,10,.65); backdrop-filter: blur(4px); display: grid; place-items: center; z-index: 100; padding: 16px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal-card { width: 100%; max-width: 520px; max-height: 88vh; overflow: auto; background: var(--panel); border: 1px solid var(--line-2); border-radius: 18px; box-shadow: var(--shadow); }
.modal-card.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; padding: 0 18px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 12px 12px; color: var(--muted); font-weight: 600; font-size: 14px; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line-2); color: var(--text-2); }
.badge.accent { color: var(--accent-2); background: var(--accent-soft); border-color: rgba(217,119,87,.35); }
.badge.red { color: #ffb3b3; background: rgba(242,109,109,.1); border-color: rgba(242,109,109,.3); }
.badge.green { color: #8ff0c2; background: rgba(62,207,142,.1); border-color: rgba(62,207,142,.3); }
.creds { background: var(--bg-2); border: 1px solid rgba(217,119,87,.4); border-radius: 12px; padding: 14px; font-family: "JetBrains Mono", monospace; font-size: 14px; line-height: 1.9; }
.creds b { color: var(--accent-2); font-weight: 500; }
.audit { font-size: 12.5px; }
.audit .row { padding: 8px 12px; gap: 10px; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.stat .v { font-size: 22px; font-weight: 700; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text-2); }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* toasts */
.toasts { position: fixed; top: calc(14px + var(--safe-t)); left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--panel-2); border: 1px solid var(--line-2); padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px; animation: rise .2s; max-width: 90vw; }
.toast.err { border-color: rgba(242,109,109,.4); color: #ffc4c4; }
.toast.ok { border-color: rgba(62,207,142,.4); }

.only-mobile { display: none; }
@media (max-width: 860px) {
  .only-mobile { display: grid; }
  .hide-mobile { display: none; }
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: min(86vw, 320px); transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow); }
  .app.side-open .sidebar { transform: none; }
  .app.side-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 25; }
  .topbar { padding-left: 8px; padding-right: 8px; }
  .messages, .empty, .working { padding: 0 14px; }
  .messages { padding-top: 16px; }
  .working { padding-left: 56px; }
  .composer-wrap { padding: 6px 10px calc(8px + var(--safe-b)); }
  .suggestions { grid-template-columns: 1fr; }
  .empty { padding-top: 7vh; }
  .grid2, .stat-row { grid-template-columns: 1fr; }
  .msg-actions { opacity: 1; }
  .bubble-user { max-width: 88%; }
  .md pre .copy { opacity: 1; }
  .row { flex-wrap: wrap; }
  .modal { padding: 0; place-items: end center; }
  .modal-card { max-height: 92vh; border-radius: 18px 18px 0 0; padding-bottom: var(--safe-b); }
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #262d3b; border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* usage */
.usage-mini { display: flex; flex-direction: column; gap: 5px; width: 100%; padding: 10px 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); text-align: left; transition: .15s; }
.usage-mini:hover { border-color: var(--line-2); background: var(--panel-2); }
.um-head { width: 100%; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13px; }
.um-head .tiny { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.um-row { display: grid; grid-template-columns: 58px minmax(40px, 1fr) 40px; align-items: center; gap: 8px; width: 100%; }
.um-row .mono { text-align: right; color: var(--text-2); }
.bar { height: 6px; border-radius: 99px; background: #232a38; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: 99px; background: var(--green); transition: width .5s ease; }
.bar i.mid { background: var(--amber); }
.bar i.high { background: var(--red); }
.bar.big { height: 8px; }
.u-legend { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; font-size: 12.5px; color: var(--text-2); }
.u-legend .sp { flex: 1; }
.sdot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; vertical-align: 1px; }
.sdot.in_use { background: var(--green); box-shadow: 0 0 0 3px rgba(62,207,142,.15); }
.sdot.standby { background: var(--muted); }
.sdot.limit { background: var(--red); box-shadow: 0 0 0 3px rgba(242,109,109,.15); }
.sdot.logged_out { background: var(--amber); }
.u-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.u-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.u-card.cur { border-color: rgba(217,119,87,.45); box-shadow: 0 0 0 1px rgba(217,119,87,.15); }
.u-top { display: flex; align-items: center; gap: 10px; }
.u-top .grow { min-width: 0; flex: 1; }
.u-top .b, .u-top .tiny { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.u-status { font-size: 12px; color: var(--text-2); display: flex; align-items: center; }
.u-win { display: flex; flex-direction: column; gap: 5px; }
.u-win .l { display: flex; justify-content: space-between; font-size: 13px; }
.u-win .l b { font-weight: 600; }
.u-win .r { font-size: 11.5px; color: var(--muted); }
.u-warn { font-size: 12px; color: var(--amber); }
.spin-on svg { animation: spin .8s linear infinite; }
@media (max-width: 860px) { .u-grid { grid-template-columns: 1fr; } }

/* history */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.seg button { height: 30px; border: 0; border-radius: 7px; background: none; color: var(--muted); font-size: 13px; font-weight: 600; }
.seg button.on { background: var(--panel-2); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.04) inset; }
.hist-item { flex-direction: column; align-items: stretch; gap: 2px; }
.hist-item .t { display: flex; align-items: center; gap: 8px; }
.hist-item .t span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-item .sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-item .live { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(62,207,142,.15); flex: none; }
.hist-bar { max-width: 820px; margin: 0 auto; display: flex; align-items: center; gap: 14px; background: var(--panel); border: 1px solid var(--line-2); border-radius: 18px; padding: 12px 12px 12px 16px; box-shadow: 0 6px 30px rgba(0,0,0,.3); }
.hist-bar .grow { flex: 1; min-width: 0; }
.hist-bar .b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 860px) { .hist-bar { flex-direction: column; align-items: stretch; } .hist-bar .btn { width: 100%; } }
