body.app { height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
.shell { flex: 1; min-height: 0; display: grid; grid-template-columns: 264px 1fr; }

/* ---------- sidebar ---------- */
.side { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--bg2); }
.side-top { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.btn.new { justify-content: space-between; width: 100%; }
.side-search { width: 100%; background: none; border: 1px solid var(--line); border-radius: 4px; padding: 6px 10px; color: var(--fg); font: inherit; font-size: 12px; outline: 0; }
.side-search:focus { border-color: var(--line2); }
.side-search::placeholder { color: var(--faint); }
.chats { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.chats .grp { font-size: 11px; color: var(--faint); padding: 12px 8px 4px; text-transform: uppercase; letter-spacing: .08em; }
.chat-it { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 4px; cursor: pointer; color: var(--fg2); font-size: 12.5px; }
.chat-it:hover { background: var(--hover); }
.chat-it.on { background: var(--hover); color: var(--fg); }
.chat-it.on::before { content: '>'; color: var(--acc); margin-right: 2px; }
.chat-it span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-it .del { visibility: hidden; background: none; border: 0; color: var(--dim); cursor: pointer; padding: 0 4px; }
.chat-it:hover .del { visibility: visible; }
.chat-it .del:hover { color: var(--err); }
.chats .none { color: var(--faint); font-size: 12px; padding: 12px 8px; }
.side-bot { border-top: 1px solid var(--line); padding: 14px; display: flex; flex-direction: column; gap: 12px; font-size: 12px; }
.energy-row { display: flex; justify-content: space-between; gap: 8px; }
.energy-row b { color: var(--acc); font-weight: 500; }
.energy-row a { text-decoration: none; }
.energy-row a:hover { color: var(--fg); }
.energy-bar { height: 4px; background: var(--line); border-radius: 2px; margin: 7px 0; overflow: hidden; }
.energy-bar i { display: block; height: 100%; width: 100%; background: var(--acc); border-radius: 2px; transition: width .3s; }
.energy.low .energy-row b { color: var(--warn); }
.energy.low .energy-bar i { background: var(--warn); }
.side-stats { color: var(--dim); }
.scrim { display: none; }

/* ---------- main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.main-head { display: flex; align-items: center; gap: 8px; padding: 10px 16px; min-height: 52px; }
.head-r { margin-left: auto; display: flex; gap: 6px; }
.icon-btn { background: none; border: 1px solid transparent; border-radius: 4px; padding: 4px 9px; cursor: pointer; color: var(--dim); font-size: 14px; }
.icon-btn:hover { color: var(--fg); border-color: var(--line); }
.side-toggle { display: none; }
.pick-wrap { position: relative; }
.model-btn { display: flex; align-items: center; gap: 9px; background: none; border: 1px solid transparent; border-radius: 4px; padding: 6px 10px; cursor: pointer; font-weight: 500; }
.model-btn:hover, .model-btn[aria-expanded="true"] { border-color: var(--line); background: var(--bg2); }
.caret-d { color: var(--dim); font-size: 11px; }

.pop { position: absolute; top: calc(100% + 6px); left: 0; z-index: 40; background: var(--panel); border: 1px solid var(--line2); border-radius: 6px; box-shadow: 0 18px 50px rgba(0,0,0,.55); }
.models-pop { width: min(460px, calc(100vw - 24px)); display: flex; flex-direction: column; max-height: min(70vh, 560px); }
.pop-search { background: none; border: 0; border-bottom: 1px solid var(--line); padding: 11px 14px; color: var(--fg); font: inherit; outline: 0; }
.pop-search::placeholder { color: var(--faint); }
.pop-list { overflow-y: auto; padding: 6px; }
.pop-grp { display: flex; justify-content: space-between; font-size: 11px; color: var(--dim); padding: 10px 8px 4px; text-transform: uppercase; letter-spacing: .08em; }
.m-it { display: grid; grid-template-columns: 14px 1fr auto; gap: 2px 10px; align-items: center; padding: 8px; border-radius: 4px; cursor: pointer; }
.m-it:hover, .m-it.kb { background: var(--hover); }
.m-it .ck { color: var(--acc); grid-row: span 2; }
.m-it .nm { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-it .sub { grid-column: 2 / 4; font-size: 11px; color: var(--dim); }
.m-it .caps { display: flex; gap: 6px; font-size: 11px; color: var(--dim); }
.m-it.off { opacity: .4; cursor: not-allowed; }
.pop-foot { display: block; border-top: 1px solid var(--line); padding: 9px 14px; color: var(--dim); text-decoration: none; font-size: 12px; }
.pop-foot:hover { color: var(--fg); }
.set-pop { right: 0; left: auto; width: min(340px, calc(100vw - 24px)); padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.set-pop .lbl { font-size: 12px; }
.set-pop textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; color: var(--fg); font: inherit; font-size: 12.5px; padding: 8px; resize: vertical; outline: 0; }
.set-pop input[type=range] { accent-color: var(--acc); }
.set-row { display: flex; align-items: center; gap: 10px; font-size: 11px; margin-top: 6px; }

/* ---------- thread ---------- */
.thread { flex: 1; overflow-y: auto; padding: 8px 20px 24px; scroll-behavior: auto; }
.msgs, .hello { max-width: 780px; margin: 0 auto; }
.hello { padding: 7vh 0 20px; }
.hello-logo { display: block; width: 96px; height: 96px; margin: 0 0 26px -10px; animation: spin 60s linear infinite; }
.hello h1 { font-size: clamp(26px, 4.4vw, 40px); line-height: 1.1; letter-spacing: -.04em; margin: 0 0 12px; }
.hello-sub { color: var(--fg2); margin: 0 0 22px; }
.hello-sub a { color: var(--fg2); }
.hello-stats { display: flex; gap: 22px; flex-wrap: wrap; font-size: 12px; color: var(--dim); margin-bottom: 30px; }
.hello-stats b { color: var(--fg); font-weight: 500; }
.sugs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sug { text-align: left; background: var(--bg2); border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; cursor: pointer; color: var(--fg2); }
.sug:hover { border-color: var(--line2); color: var(--fg); background: var(--hover); }
.sug b { display: block; color: var(--fg); font-weight: 500; margin-bottom: 2px; }
.sug span { font-size: 12px; color: var(--dim); }

.m { margin: 0 0 26px; }
.m.user { display: flex; flex-direction: column; align-items: flex-end; }
.m.user .bubble { max-width: 85%; background: var(--panel); border: 1px solid var(--line); border-radius: 8px 8px 2px 8px; padding: 10px 14px; white-space: pre-wrap; word-wrap: break-word; }
.m.user .imgs { display: flex; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; justify-content: flex-end; }
.m.user .imgs img { height: 110px; border-radius: 6px; border: 1px solid var(--line); }
.m.user .u-acts { display: flex; gap: 4px; margin-top: 4px; opacity: 0; transition: opacity .15s; }
.m.user:hover .u-acts { opacity: 1; }
.m.ai .who { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--dim); margin-bottom: 6px; }
.m.ai .who::before { content: '◆'; color: var(--acc); }
.body { word-wrap: break-word; }
.body > :first-child { margin-top: 0; }
.body > :last-child { margin-bottom: 0; }
.body p, .body ul, .body ol, .body blockquote, .body table { margin: 0 0 12px; }
.body ul, .body ol { padding-left: 22px; }
.body li { margin: 3px 0; }
.body li::marker { color: var(--dim); }
.body h1, .body h2, .body h3, .body h4 { font-size: 14px; margin: 20px 0 8px; letter-spacing: -.01em; }
.body h1::before, .body h2::before { content: '# '; color: var(--acc); }
.body h3::before, .body h4::before { content: '## '; color: var(--faint); }
.body a { color: var(--acc); text-decoration: none; border-bottom: 1px solid rgba(201,255,52,.35); }
.body strong { color: #fff; }
.body em { color: var(--fg2); }
.body blockquote { border-left: 2px solid var(--line2); padding-left: 12px; color: var(--fg2); }
.body hr { border: 0; border-top: 1px dashed var(--line2); margin: 18px 0; }
.body code { background: var(--panel); border: 1px solid var(--line); padding: 1px 5px; border-radius: 3px; font-size: 12.5px; }
.body table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 12.5px; }
.body th, .body td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.body th { background: var(--panel); font-weight: 500; }
.code { margin: 0 0 12px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: #0d0d0c; }
.code-h { display: flex; justify-content: space-between; align-items: center; padding: 5px 10px; border-bottom: 1px solid var(--line); font-size: 11px; color: var(--dim); }
.code-h button { background: none; border: 0; color: var(--dim); cursor: pointer; font-size: 11px; }
.code-h button:hover { color: var(--fg); }
.code pre { margin: 0; padding: 12px 14px; overflow-x: auto; }
.code pre code { background: none; border: 0; padding: 0; font-size: 12.5px; line-height: 1.55; }
.hljs { background: transparent !important; }
.cur { display: inline-block; width: 7px; height: 1.05em; vertical-align: text-bottom; background: var(--acc); animation: blink 1s steps(1) infinite; margin-left: 1px; }
.think { margin: 0 0 10px; font-size: 12px; color: var(--dim); }
.think summary { cursor: pointer; list-style: none; user-select: none; }
.think summary::before { content: '▸ '; }
.think[open] summary::before { content: '▾ '; }
.think .tx { white-space: pre-wrap; border-left: 1px solid var(--line2); padding: 6px 0 6px 12px; margin-top: 6px; max-height: 280px; overflow-y: auto; color: var(--faint); }
.srcs { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.srcs a { font-size: 11px; color: var(--fg2); text-decoration: none; border: 1px solid var(--line); border-radius: 3px; padding: 2px 7px; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.srcs a:hover { border-color: var(--line2); color: var(--fg); }
.acts { display: flex; align-items: center; gap: 2px; margin-top: 8px; font-size: 11px; color: var(--faint); flex-wrap: wrap; }
.act { background: none; border: 0; color: var(--dim); cursor: pointer; padding: 3px 7px; border-radius: 3px; font-size: 11px; }
.act:hover { color: var(--fg); background: var(--hover); }
.meta { margin-left: 8px; }
.meta .paid { color: var(--acc); opacity: .8; }
.m.err .body { color: var(--err); font-size: 12.5px; }
.m.err .who::before { color: var(--err); content: '!'; }

/* ---------- composer ---------- */
.composer-wrap { padding: 0 20px 14px; }
.composer { max-width: 780px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line2); border-radius: 8px; padding: 12px 12px 8px 14px; transition: border-color .15s; }
.composer:focus-within { border-color: #4b4943; }
.composer.drag { border-color: var(--acc); border-style: dashed; }
.composer textarea { width: 100%; resize: none; background: none; border: 0; outline: 0; color: var(--fg); font: inherit; font-size: 14px; max-height: 220px; padding: 0; line-height: 1.55; }
.composer textarea::placeholder { color: var(--faint); }
.atts { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.att { position: relative; }
.att img { height: 56px; border-radius: 4px; border: 1px solid var(--line); display: block; }
.att button { position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--line2); background: var(--bg); color: var(--fg); font-size: 10px; cursor: pointer; line-height: 1; padding: 0; }
.comp-row { display: flex; align-items: center; gap: 4px; margin-top: 8px; }
.tool { background: none; border: 1px solid transparent; border-radius: 4px; padding: 3px 8px; font-size: 12px; color: var(--dim); cursor: pointer; white-space: nowrap; }
.tool:hover { color: var(--fg); border-color: var(--line); }
.tool[aria-pressed="true"] { color: var(--acc); border-color: rgba(201,255,52,.35); background: var(--acc-dim); }
.tool.na { opacity: .35; pointer-events: none; }
.cost { margin-left: auto; font-size: 11px; color: var(--dim); padding: 0 8px; white-space: nowrap; }
.send { width: 34px; height: 30px; border-radius: 4px; border: 0; background: var(--acc); color: var(--acc-ink); font-weight: 700; cursor: pointer; }
.send:disabled { background: var(--line2); color: var(--dim); cursor: default; }
.send.stop { background: var(--fg); }
.comp-note { max-width: 780px; margin: 8px auto 0; font-size: 11px; color: var(--faint); display: flex; justify-content: space-between; gap: 10px; }
.comp-note kbd { font-size: 10px; }
.comp-note .priv { color: var(--dim); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; top: var(--top); bottom: 0; left: 0; width: 280px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .scrim.on { display: block; position: fixed; inset: var(--top) 0 0 0; background: rgba(0,0,0,.5); z-index: 45; }
  .side-toggle { display: block; }
  .thread { padding: 8px 14px 20px; }
  .composer-wrap { padding: 0 10px 10px; }
  .sugs { grid-template-columns: 1fr; }
  .sug:nth-child(n+3) { display: none; }
  .hello { padding-top: 3vh; }
  .hello-logo { width: 72px; height: 72px; }
  .comp-note .kb { display: none; }
  .m.user .bubble { max-width: 92%; }
}
#model-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
.side-toggle { font-size: 12px; }

/* ---------- key in sidebar ---------- */
.key-box { font-size: 12px; }
.key-box b { color: var(--fg); font-weight: 500; }
.key-box code { display: block; color: var(--dim); margin-top: 2px; font-size: 11.5px; }
.key-box .act { padding: 1px 5px; }

/* ---------- access gate ---------- */
body.gated .shell { filter: blur(3px); pointer-events: none; }
.gate { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 16px; background: rgba(6,6,5,.72); backdrop-filter: blur(2px); animation: fade .2s ease-out; }
@keyframes fade { from { opacity: 0; } }
.gate-card { width: min(480px, 100%); background: var(--panel); border: 1px solid var(--line2); border-radius: 8px; box-shadow: 0 30px 80px rgba(0,0,0,.6); overflow: hidden; animation: rise .25s ease-out; }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } }
.gate-top { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 11.5px; color: var(--dim); }
.gate-top .dots { display: flex; gap: 6px; }
.gate-top .dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); }
.gate-body { padding: 26px 26px 24px; }
.kick { color: var(--dim); font-size: 12px; margin-bottom: 12px; }
.gate-logo { display: block; width: 64px; height: 64px; margin: -6px 0 14px -6px; animation: spin 40s linear infinite; }
.m.ai .who img { width: 16px; height: 16px; }
.m.ai.wait .who::before { display: none; }
.gate h2 { font-size: 26px; letter-spacing: -.035em; line-height: 1.1; margin: 0 0 10px; }
.gate-sub { color: var(--fg2); margin: 0 0 20px; font-size: 13px; }
.gate-sub b { color: var(--fg); font-weight: 500; }
.gate-sub b.acc { color: var(--acc); }
.supply { margin-bottom: 22px; font-size: 12px; }
.supply-row { display: flex; justify-content: space-between; }
.supply-row b { color: var(--fg); font-weight: 500; }
.supply-bar { height: 6px; background: var(--line); border-radius: 3px; margin-top: 7px; overflow: hidden; }
.supply-bar i { display: block; height: 100%; width: 0; background: var(--acc); border-radius: 3px; transition: width .6s; }
.gate-tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.gate-tabs button { background: none; border: 0; border-bottom: 1px solid transparent; margin-bottom: -1px; color: var(--dim); padding: 6px 2px; margin-right: 14px; cursor: pointer; font-size: 12.5px; }
.gate-tabs button.on { color: var(--fg); border-bottom-color: var(--acc); }
.btn.big { width: 100%; justify-content: center; padding: 11px 14px; font-size: 14px; }
.btn.pri:disabled { opacity: .5; cursor: default; filter: none; }
.fine { color: var(--dim); font-size: 11.5px; margin: 10px 0 0; text-align: center; }
.key-in { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line2); border-radius: 4px; padding: 10px 12px; margin-bottom: 10px; background: var(--bg); }
.key-in:focus-within { border-color: var(--acc); }
.key-in .ps { color: var(--acc); }
.key-in input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: var(--fg); font: inherit; }
.minted { border: 1px dashed rgba(201,255,52,.45); background: var(--acc-dim); border-radius: 6px; padding: 14px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.minted-h { display: flex; justify-content: space-between; width: 100%; font-size: 12px; color: var(--dim); }
.minted-h b { color: var(--acc); }
.minted code { font-size: 14px; word-break: break-all; color: var(--fg); }
#gate-ok .btn.big { margin-top: 16px; }
.g-err { color: var(--err); font-size: 12px; margin-top: 10px; min-height: 1em; text-align: center; }
.waiting { color: var(--faint); font-variant-numeric: tabular-nums; }
