/* NEXUS_AI v2 — web chat */
body[data-page="chat"] { height: 100vh; height: 100dvh; overflow: hidden; }
body[data-page="chat"] .site-footer { display: none; }
body[data-page="chat"]::before { opacity: .35; }
.chat-app { height: calc(100dvh - var(--header-h)); display: grid; grid-template-columns: 288px minmax(0, 1fr); }

/* ---------- sidebar ---------- */
.chat-side { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border-subtle); background: color-mix(in srgb, var(--bg-surface) 70%, transparent); }
.side-top { padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 10px; }
.side-search { position: relative; }
.side-search input { width: 100%; height: 36px; padding: 0 12px 0 32px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-canvas); font-size: 13.5px; outline: none; }
.side-search input:focus { border-color: var(--border-focus); }
.side-search::before { content: '⌕'; position: absolute; left: 11px; top: 50%; transform: translateY(-52%); color: var(--text-muted); }
.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.conv-group { padding: 12px 8px 6px; font: 700 10.5px var(--font-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--text-muted); }
.conv-item { position: relative; display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border-radius: 9px; text-align: left; color: var(--text-secondary); font-size: 13.5px; }
.conv-item:hover { background: var(--bg-hover); color: var(--text-main); }
.conv-item.active { background: var(--bg-subtle); color: var(--text-main); box-shadow: inset 2px 0 0 var(--accent-violet); }
.conv-item .ci-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .ci-pin { font-size: 11px; color: var(--accent-warm); }
.conv-item .ci-actions { display: none; gap: 2px; }
.conv-item:hover .ci-actions, .conv-item.active .ci-actions { display: flex; }
.conv-item .ci-actions button { width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; font-size: 12px; color: var(--text-muted); }
.conv-item .ci-actions button:hover { background: var(--bg-active); color: var(--text-main); }
.conv-item input.ci-rename { flex: 1; min-width: 0; height: 26px; padding: 0 6px; border-radius: 6px; border: 1px solid var(--border-focus); background: var(--bg-canvas); font-size: 13.5px; outline: none; }
.side-empty { padding: 30px 14px; text-align: center; color: var(--text-muted); font-size: 13px; }
.side-foot { padding: 10px 12px 14px; border-top: 1px solid var(--border-subtle); display: flex; flex-direction: column; gap: 8px; }
.balance-pill { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 12px; border-radius: 10px; background: var(--bg-subtle); font-size: 13px; color: var(--text-secondary); }
.balance-pill b { color: var(--text-main); font-variant-numeric: tabular-nums; }
.side-links { display: flex; gap: 6px; flex-wrap: wrap; }
.side-links button, .side-links a { font-size: 12px; color: var(--text-muted); padding: 4px 6px; border-radius: 6px; }
.side-links button:hover, .side-links a:hover { color: var(--text-main); background: var(--bg-hover); }

/* ---------- main ---------- */
.chat-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.chat-top { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--border-subtle); min-height: 56px; }
.chat-title { flex: 1; min-width: 0; font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title small { font-weight: 500; color: var(--text-muted); margin-left: 8px; }
.side-toggle { display: none; }
.top-actions { display: flex; align-items: center; gap: 6px; }

/* model picker */
.model-btn { display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 10px 0 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-surface); font-size: 13.5px; font-weight: 650; max-width: 280px; }
.model-btn:hover { border-color: var(--border-strong); }
.model-btn .mb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-btn .caret { color: var(--text-muted); font-size: 10px; }
.model-menu { position: absolute; z-index: 40; top: 54px; right: 16px; width: min(420px, calc(100vw - 32px)); max-height: 70vh; display: none; flex-direction: column; border-radius: 14px; border: 1px solid var(--border); background: var(--bg-elevated); box-shadow: var(--shadow-xl); overflow: hidden; }
.model-menu.open { display: flex; animation: pop-in .15s var(--ease); }
.model-menu input { height: 46px; padding: 0 14px; border: 0; border-bottom: 1px solid var(--border-subtle); background: transparent; outline: none; font-size: 14px; }
.model-menu .mm-list { overflow-y: auto; padding: 6px; }
.mm-group { padding: 10px 10px 4px; font: 700 10.5px var(--font-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--text-muted); }
.mm-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 9px; text-align: left; font-size: 14px; }
.mm-item:hover, .mm-item.sel { background: var(--bg-hover); }
.mm-item .mm-id { margin-left: auto; font: 11.5px var(--font-mono); color: var(--text-muted); }
.mm-item.current { box-shadow: inset 2px 0 0 var(--accent-violet); }
.mm-note { padding: 10px 14px; font-size: 12px; color: var(--text-muted); border-top: 1px solid var(--border-subtle); }

/* messages */
.msgs { flex: 1; overflow-y: auto; padding: 24px 0 16px; scroll-behavior: auto; }
.msgs-inner { max-width: 860px; margin: 0 auto; padding: 0 22px; display: flex; flex-direction: column; gap: 22px; }
.msg { position: relative; display: flex; flex-direction: column; gap: 8px; }
.msg-user { align-items: flex-end; }
.msg-user .bubble { max-width: min(680px, 88%); padding: 11px 15px; border-radius: 16px 16px 4px 16px; background: var(--bg-subtle); border: 1px solid var(--border-subtle); white-space: pre-wrap; word-wrap: break-word; line-height: 1.55; }
.msg-ai .md { line-height: 1.68; font-size: 15px; color: var(--text-main); word-wrap: break-word; }
.msg-head { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-muted); }
.msg-head .ai-av { width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; color: var(--on-brand); font-size: 10px; background: var(--brand); }
.msg-head b { color: var(--text-secondary); font-weight: 650; }
.msg-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { opacity: 1; }
.msg-actions button { height: 26px; padding: 0 8px; border-radius: 7px; font-size: 12px; color: var(--text-muted); display: inline-flex; align-items: center; gap: 4px; }
.msg-actions button:hover { background: var(--bg-hover); color: var(--text-main); }
.msg-meta { font: 500 11.5px var(--font-mono); color: var(--text-muted); }
.msg-error { padding: 10px 14px; border-radius: 10px; background: var(--accent-red-subtle); color: var(--accent-red); font-size: 14px; }
.att-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.att-img { width: 120px; height: 90px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); cursor: zoom-in; }
.att-file { display: inline-flex; align-items: center; gap: 8px; max-width: 260px; padding: 7px 10px; border-radius: 10px; background: var(--bg-surface); border: 1px solid var(--border); font-size: 12.5px; }
.att-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-file small { color: var(--text-muted); white-space: nowrap; }

/* thinking box */
.think { border: 1px solid var(--border); border-radius: 12px; background: var(--bg-surface); overflow: hidden; }
.think summary { list-style: none; cursor: pointer; padding: 9px 12px; font-size: 13px; color: var(--text-secondary); display: flex; align-items: center; gap: 8px; }
.think summary::-webkit-details-marker { display: none; }
.think[open] summary { border-bottom: 1px solid var(--border-subtle); }
.wait-note { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); padding: 2px 0; }
.wait-note .wait-s { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.think .think-body { padding: 10px 14px; font-size: 13px; color: var(--text-muted); white-space: pre-wrap; max-height: 280px; overflow-y: auto; }

/* markdown */
.md > :first-child { margin-top: 0; }
.md p, .md ul, .md ol, .md blockquote, .md table, .md pre { margin: 0 0 12px; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 20px 0 10px; line-height: 1.3; letter-spacing: -.01em; }
.md h1 { font-size: 22px; } .md h2 { font-size: 19px; } .md h3 { font-size: 17px; } .md h4, .md h5, .md h6 { font-size: 15px; }
.md ul, .md ol { padding-left: 22px; }
.md li { margin: 3px 0; }
.md li > ul, .md li > ol { margin: 4px 0 0; }
.md a { color: var(--accent-violet); text-decoration: underline; text-underline-offset: 2px; }
.md code.ic { padding: 1px 6px; border-radius: 6px; background: var(--bg-subtle); border: 1px solid var(--border-subtle); font-size: .88em; }
.md blockquote { padding: 4px 0 4px 14px; border-left: 3px solid var(--accent-violet); color: var(--text-secondary); }
.md hr { margin: 18px 0; }
.md .tbl { overflow-x: auto; margin: 0 0 12px; border: 1px solid var(--border); border-radius: 10px; }
.md table { border-collapse: collapse; width: 100%; font-size: 14px; margin: 0; }
.md th, .md td { padding: 8px 12px; border-bottom: 1px solid var(--border-subtle); text-align: left; }
.md th { background: var(--bg-subtle); font-weight: 650; }
.md tr:last-child td { border-bottom: 0; }
.md .codewin { margin: 6px 0 14px; }
.md del { color: var(--text-muted); }
.caret-blink::after { content: '▍'; margin-left: 2px; color: var(--accent-violet); animation: pulse 1s infinite; }

/* code window extras */
.codewin-actions button span { display: inline; }
.codewin-gutter { position: absolute; left: 0; top: 0; padding: 14px 0; width: 42px; text-align: right; font: 13px/1.6 var(--font-mono); color: #4A5068; user-select: none; pointer-events: none; }
.codewin.lines pre { padding-left: 54px; }
.codewin.wrap .codewin-gutter { display: none; }
.codewin.wrap.lines pre { padding-left: 16px; }

/* empty state */
.welcome { max-width: 720px; margin: 6vh auto 0; padding: 0 22px; text-align: center; }
.welcome .logo-mark { width: 52px; height: 52px; border-radius: 16px; font-size: 22px; margin: 0 auto 18px; }
.welcome h2 { font-size: clamp(24px, 3vw, 32px); }
.welcome p { margin-top: 10px; }
.mode-switch { display: inline-flex; gap: 2px; margin-top: 16px; padding: 3px; border-radius: 999px; background: var(--bg-subtle); border: 1px solid var(--border-subtle); }
.mode-switch button { height: 36px; padding: 0 18px; border-radius: 999px; font-size: 14px; font-weight: 650; color: var(--text-secondary); }
.mode-switch button.on { background: var(--text-main); color: var(--bg-canvas); box-shadow: var(--shadow-sm); }
.suggest { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 26px; text-align: left; }
.suggest button { padding: 14px 16px; border-radius: 14px; border: 1px solid var(--border); background: var(--bg-surface); font-size: 14px; color: var(--text-secondary); transition: border-color .15s, transform .15s; }
.suggest button b { display: block; color: var(--text-main); margin-bottom: 2px; }
.suggest button:hover { border-color: var(--border-strong); transform: translateY(-2px); }

/* composer */
.composer-wrap { padding: 8px 22px 16px; }
.composer { max-width: 860px; margin: 0 auto; border-radius: 18px; border: 1px solid var(--border); background: var(--bg-surface); box-shadow: var(--shadow-md); transition: border-color .15s, box-shadow .15s; }
.composer:focus-within { border-color: var(--border-strong); box-shadow: var(--shadow-lg); }
.composer-row { display: flex; align-items: flex-end; gap: 6px; padding: 0 8px 0 0; }
.composer textarea { display: block; flex: 1; min-width: 0; width: 100%; min-height: 54px; max-height: 260px; padding: 15px 16px 6px; border: 0; background: transparent; resize: none; outline: none; font-size: 15px; line-height: 1.5; }
.composer-row .send-btn { margin: 0 0 8px; flex: 0 0 auto; }
.plus-btn { display: none; }
.composer-bar { display: flex; align-items: center; gap: 6px; padding: 6px 8px 8px 10px; flex-wrap: wrap; }
.composer-bar .sheet-head { display: none; }
.tool-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px 0; }
.tool-chips[hidden] { display: none; }
@media (min-width: 701px) { .tool-chips { display: none; } }  /* desktop: the toolbar itself shows what is on */
.tool-chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 999px; background: var(--accent-violet-subtle); color: var(--accent-violet); font-size: 12.5px; font-weight: 650; }
.tool-chip i { font-style: normal; opacity: .7; }
.side-nav { display: none; }
.side-backdrop, .sheet-backdrop { display: none; }
.top-new { display: none; }
.tool-select { display: contents; }
.tool-select[hidden] { display: none; }
.tool-select .ts-label { display: none; }
.composer-bar .tool { height: 32px; padding: 0 10px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--text-secondary); display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent; }
.composer-bar .tool:hover { background: var(--bg-hover); color: var(--text-main); }
.composer-bar .tool.on { color: var(--accent-violet); background: var(--accent-violet-subtle); }
.composer-bar select.tool { -webkit-appearance: none; appearance: none; background: var(--bg-subtle); cursor: pointer; padding-right: 10px; }
.send-btn { margin-left: auto; width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; color: var(--on-brand); background: var(--brand); font-size: 16px; box-shadow: 0 4px 12px var(--brand-shadow); }
.send-btn:disabled { opacity: .45; box-shadow: none; }
.send-btn.stop { background: var(--text-main); color: var(--bg-canvas); box-shadow: none; }
.pending { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 12px 0; }
.chip-att { position: relative; display: inline-flex; align-items: center; gap: 8px; max-width: 240px; padding: 6px 30px 6px 6px; border-radius: 12px; background: var(--bg-subtle); border: 1px solid var(--border-subtle); font-size: 12.5px; }
.chip-att img { width: 36px; height: 36px; object-fit: cover; border-radius: 8px; }
.chip-att .ca-ico { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; background: var(--bg-surface); font-size: 16px; }
.chip-att .ca-name { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.chip-att .ca-sub { display: block; color: var(--text-muted); font-size: 11px; }
.chip-att .ca-del { position: absolute; top: 6px; right: 6px; width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center; font-size: 11px; color: var(--text-muted); }
.chip-att .ca-del:hover { background: var(--bg-active); color: var(--text-main); }
.chip-att.loading { opacity: .7; }
.estimate { max-width: 860px; margin: 8px auto 0; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); }
.estimate b { color: var(--text-secondary); font-weight: 650; }
.estimate .warn { color: var(--accent-warm); }
.drop-overlay { position: absolute; inset: 0; z-index: 30; display: none; align-items: center; justify-content: center; background: color-mix(in srgb, var(--bg-canvas) 80%, transparent); border: 2px dashed var(--accent-violet); border-radius: 16px; margin: 10px; font-size: 18px; font-weight: 700; color: var(--accent-violet); pointer-events: none; }
.chat-main.dragging .drop-overlay { display: flex; }

/* preview & fullscreen */
.preview-modal { max-width: 1100px; height: 82vh; display: flex; flex-direction: column; }
.preview-modal .modal-body { flex: 1; padding: 0; background: #fff; display: flex; justify-content: center; overflow: auto; }
.preview-modal iframe { width: 100%; height: 100%; border: 0; background: #fff; transition: width .2s; }
.run-console { max-height: 160px; overflow: auto; padding: 10px 14px; font: 12.5px/1.5 var(--font-mono); background: #0B0D14; color: #D8DCEA; border-top: 1px solid #1E2232; white-space: pre-wrap; }
.run-console .err { color: #FF6066; }
.code-full { max-width: 1200px; height: 86vh; display: flex; flex-direction: column; }
.code-full .codewin { margin: 0; flex: 1; display: flex; flex-direction: column; border-radius: 0; border: 0; }
.code-full .codewin-body { flex: 1; max-height: none; }

/* ---------- projects (chat/project.js) ---------- */
.proj-btn { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-surface); font-size: 13.5px; font-weight: 650; }
.proj-btn:hover { border-color: var(--border-strong); }
.proj-btn b { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent-violet-subtle); color: var(--accent-violet); font: 700 11.5px/20px var(--font-mono); text-align: center; }
.att-proj { cursor: pointer; text-align: left; }
.att-proj:hover { border-color: var(--border-strong); }
.chip-proj { cursor: pointer; }
.chip-proj:hover { border-color: var(--border-strong); }
.proj-card { display: grid; gap: 10px; padding: 12px 14px; border-radius: 14px; border: 1px solid color-mix(in srgb, var(--accent-violet) 30%, var(--border)); background: color-mix(in srgb, var(--accent-violet) 6%, var(--bg-surface)); }
.pc-head { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.pc-head small { display: block; color: var(--text-muted); font-size: 12px; }
.pc-ico { font-size: 22px; }
.pc-files { display: flex; flex-wrap: wrap; gap: 6px; }
.pc-file, .pc-more { padding: 3px 8px; border-radius: 7px; background: var(--bg-surface); border: 1px solid var(--border-subtle); font: 12px var(--font-mono); color: var(--text-secondary); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-file.cut { border-color: color-mix(in srgb, var(--accent-warm) 50%, transparent); color: var(--accent-warm); }
.pc-file.cut::before { content: '✂ '; }
.pc-acts { display: flex; gap: 8px; flex-wrap: wrap; }
.cut-note { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 10px 14px; border-radius: 12px; background: var(--accent-warm-subtle); border: 1px solid color-mix(in srgb, var(--accent-warm) 35%, transparent); font-size: 13px; color: var(--text-secondary); }
.cut-note span { flex: 1 1 260px; }

.proj-modal { max-width: 1240px; height: 88vh; display: flex; flex-direction: column; }
.proj-modal .modal-head h3 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 290px minmax(0, 1fr); }
.pv-tree { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border-subtle); background: var(--bg-canvas); }
.pv-tree input { margin: 10px; height: 34px; padding: 0 10px; border-radius: 9px; border: 1px solid var(--border); background: var(--bg-surface); font-size: 13px; outline: none; }
.pv-tree input:focus { border-color: var(--border-focus); }
.pv-list { flex: 1; overflow-y: auto; padding: 0 6px 10px; }
.pv-dir { padding: 10px 8px 4px; font: 600 11.5px var(--font-mono); color: var(--text-muted); overflow-wrap: anywhere; }
.pv-item { display: flex; align-items: center; gap: 6px; width: 100%; padding: 6px 8px; border-radius: 7px; text-align: left; font: 13px var(--font-mono); color: var(--text-secondary); }
.pv-item.in { padding-left: 20px; }
.pv-item span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-item:hover { background: var(--bg-hover); color: var(--text-main); }
.pv-item.on { background: var(--accent-violet-subtle); color: var(--text-main); }
.pv-badge { flex: 0 0 auto; padding: 1px 6px; border-radius: 6px; font: 600 10.5px var(--font-sans); }
.pv-badge.new { background: var(--accent-green-subtle); color: var(--accent-green); }
.pv-badge.chg { background: var(--accent-blue-subtle); color: var(--accent-blue); }
.pv-badge.cut { background: var(--accent-warm-subtle); color: var(--accent-warm); }
.pv-file { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; padding: 12px 14px 14px; gap: 10px; }
.pv-file-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; }
.pv-file-head code { font: 600 13.5px var(--font-mono); overflow-wrap: anywhere; }
.pv-warn { padding: 8px 12px; border-radius: 10px; background: var(--accent-warm-subtle); font-size: 13px; color: var(--text-secondary); }
.pv-file .codewin { flex: 1; min-height: 0; margin: 0; display: flex; flex-direction: column; }
.pv-file .codewin-body { flex: 1; max-height: none; overflow: auto; }

.pick-modal { max-width: 720px; }
.pick-modal .modal-body { display: grid; gap: 10px; }
.pick-hint { font-size: 13.5px; }
.pick-tools { display: flex; gap: 8px; }
.pick-tools .input { flex: 1; height: 36px; }
.pick-list { max-height: min(48vh, 460px); overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; padding: 4px; }
.pick-row { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.pick-row:hover { background: var(--bg-hover); }
.pick-row .pp { flex: 1; min-width: 0; font-family: var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-row small { color: var(--text-muted); font: 11.5px var(--font-mono); }
.pick-skipped { font-size: 12px; color: var(--text-muted); overflow-wrap: anywhere; }
.pick-modal .modal-foot { justify-content: space-between; align-items: center; flex-wrap: wrap; }
.pick-sum { font-size: 12.5px; color: var(--text-secondary); }

@media (max-width: 900px) {
  .proj-btn span { display: none; }
  .pv-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(120px, 34%) minmax(0, 1fr); }
  .pv-tree { border-right: 0; border-bottom: 1px solid var(--border-subtle); }
  .proj-modal { height: 92vh; }
}

@media (max-width: 900px) {
  .chat-app { grid-template-columns: minmax(0, 1fr); }
  .chat-side { position: fixed; z-index: 60; top: var(--header-h); bottom: 0; left: 0; width: min(320px, 86vw); transform: translateX(-102%); transition: transform .22s var(--ease); background: var(--bg-surface); box-shadow: var(--shadow-xl); }
  .chat-side.open { transform: none; }
  .side-backdrop { display: block; position: fixed; inset: 0; z-index: 59; background: rgba(0, 0, 0, .45); opacity: 0; pointer-events: none; transition: opacity .22s var(--ease); }
  .chat-side.open + .side-backdrop { opacity: 1; pointer-events: auto; }
  .side-toggle { display: inline-grid; }
  .msgs-inner, .composer-wrap { padding-left: 14px; padding-right: 14px; }
  .suggest { grid-template-columns: 1fr; }
  .model-btn { max-width: 170px; }
  .codewin-actions button span { display: none; }
  .msg-actions { opacity: 1; }
}

/* ---------- phones: one app bar, pill composer, bottom sheets (ChatGPT / Gemini pattern) ---------- */
@media (max-width: 700px) {
  body[data-page="chat"] { --header-h: 0px; }
  body[data-page="chat"] [data-shell="header"], body[data-page="chat"] .site-header { display: none !important; }
  .chat-app { height: 100dvh; }

  /* app bar: menu | model (centre) | new chat | more */
  .chat-top { position: relative; gap: 4px; min-height: 52px; padding: 6px 8px; padding-top: calc(6px + env(safe-area-inset-top)); border-bottom-color: transparent; }
  .chat-top .icon-btn { width: 40px; height: 40px; border-radius: 12px; font-size: 18px; }
  .chat-title { display: none; }
  .top-actions { flex: 1; min-width: 0; justify-content: flex-end; gap: 2px; }
  .model-btn { margin-right: auto; margin-left: auto; max-width: min(240px, calc(100vw - 190px)); height: 40px; border: 0; background: transparent; font-size: 16px; padding: 0 8px; }
  .model-btn .rate { display: none; }  /* the rate is in the line under the input and in the model sheet */
  .chat-top .icon-btn { border: 0; background: transparent; }
  .top-new { display: inline-grid; }
  .proj-btn { height: 40px; padding: 0 10px; }

  /* drawer: full height, with site links instead of the hidden site header */
  .chat-side { top: 0; width: min(320px, 84vw); padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); border-right: 0; }
  .side-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .side-install { grid-column: 1 / -1; padding: 11px 12px; border-radius: 10px; background: var(--brand); color: var(--on-brand); font-size: 14px; font-weight: 700; }
  .side-install[hidden] { display: none; }
  .side-nav a { padding: 10px 12px; border-radius: 10px; background: var(--bg-subtle); font-size: 13.5px; font-weight: 600; color: var(--text-secondary); text-align: center; }
  .conv-item { min-height: 44px; font-size: 15px; }
  .conv-item .ci-actions { display: flex; }

  /* messages: assistant full width, user bubble on the right */
  .msgs { padding: 8px 0 12px; }
  .msgs-inner { gap: 18px; padding: 0 16px; }
  .msg-user .bubble { max-width: 86%; padding: 10px 14px; border-radius: 20px 20px 6px 20px; font-size: 16px; }
  .msg-ai .md { font-size: 16px; line-height: 1.6; }
  .msg-actions button { height: 32px; padding: 0 9px; font-size: 13px; }
  .md pre, .md .codewin-body { max-width: 100%; overflow-x: auto; }
  .welcome { margin-top: 10vh; padding: 0 18px; }
  .welcome .logo-mark { width: 44px; height: 44px; border-radius: 14px; margin-bottom: 14px; }
  .welcome h2 { font-size: 24px; }
  .welcome p { font-size: 14px; }
  .suggest { grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 20px; }
  .suggest button { padding: 12px; font-size: 12.5px; border-radius: 16px; }
  .suggest button { text-align: left; }
  .suggest button b { font-size: 13.5px; }
  .tool-select { display: flex; flex-direction: column; gap: 6px; padding: 6px 14px; }
  .tool-select .ts-label { display: block; font-size: 13px; color: var(--text-muted); }
  .mm-item .mm-id { display: none; }

  /* composer: [+] [text] [send] pill */
  .composer-wrap { padding: 6px 10px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .composer { border-radius: 26px; box-shadow: none; background: var(--bg-subtle); }
  .composer-row { align-items: flex-end; padding: 4px 5px; gap: 2px; }
  .plus-btn { display: grid; place-items: center; flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; font-size: 22px; color: var(--text-secondary); position: relative; }
  .plus-btn.has-on::after { content: ''; position: absolute; top: 7px; right: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-violet); }
  .composer textarea { font-size: 16px; min-height: 40px; max-height: 40dvh; padding: 9px 6px; }  /* 16px: iOS does not zoom in */
  .composer-row .send-btn { width: 40px; height: 40px; border-radius: 50%; margin: 0; box-shadow: none; }
  .estimate { margin-top: 6px; padding: 0 6px; font-size: 11.5px; justify-content: center; }
  .estimate > span:first-child:not(.warn) { display: none; }

  /* tools: bottom sheet */
  .composer-bar { position: fixed; z-index: 70; left: 0; right: 0; bottom: 0; flex-direction: column; align-items: stretch; flex-wrap: nowrap; gap: 4px; padding: 8px 12px calc(14px + env(safe-area-inset-bottom)); border-radius: 22px 22px 0 0; background: var(--bg-elevated); box-shadow: var(--shadow-xl); transform: translateY(105%); transition: transform .22s var(--ease); }
  .composer.tools-open .composer-bar { transform: none; }
  .composer-bar .sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 4px 8px; font-weight: 700; }
  .composer-bar .sheet-head::before { content: ''; position: absolute; top: 7px; left: 50%; width: 38px; height: 4px; margin-left: -19px; border-radius: 2px; background: var(--border-strong); }
  .composer-bar .tool { height: 50px; padding: 0 14px; border-radius: 14px; font-size: 15px; justify-content: flex-start; gap: 12px; background: transparent; }
  .composer-bar .tool span:first-child { font-size: 19px; width: 24px; text-align: center; }
  .composer-bar .tool.on { background: var(--accent-violet-subtle); }
  .composer-bar select.tool { width: 100%; background: var(--bg-subtle); }
  .sheet-backdrop { display: block; position: fixed; inset: 0; z-index: 69; background: rgba(0, 0, 0, .45); opacity: 0; pointer-events: none; transition: opacity .22s var(--ease); }
  .chat-main.tools-open .sheet-backdrop { opacity: 1; pointer-events: auto; }

  /* model picker and the "more" menu: bottom sheets */
  .model-menu { position: fixed; top: auto; left: 0; right: 0; bottom: 0; width: 100% !important; max-height: 78dvh; border-radius: 22px 22px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .model-menu input { height: 52px; font-size: 16px; }
  .mm-item { min-height: 48px; font-size: 15px; }
}
@media (max-width: 700px) and (pointer: coarse) {
  #folder-btn { display: none; }  /* phones cannot pick a whole folder */
}

/* Media creation uses its own scrollable workspace without changing the text composer. */
.chat-kind-tabs { display:flex; gap:4px; padding:8px 20px; border-bottom:1px solid var(--border-subtle); flex:0 0 auto; }
.chat-kind-tabs button { padding:7px 14px; border-radius:8px; color:var(--text-muted); font-size:13px; }
.chat-kind-tabs button:hover { color:var(--text-main); background:var(--bg-hover); }
.chat-kind-tabs button.on { color:var(--text-main); background:var(--bg-subtle); box-shadow:inset 0 -2px var(--brand); }
.media-active > .msgs, .media-active > .composer-wrap { display:none; }
.media-active #model-btn { display:none; }
.media-root { flex:1; min-height:0; overflow-y:auto; }
.media-root[hidden], .media-workspace[hidden] { display:none; }
.media-workspace { max-width:1000px; margin:0 auto; padding:24px 22px 40px; display:flex; flex-direction:column; gap:18px; }
.media-intro { display:flex; gap:16px; align-items:flex-start; justify-content:space-between; }
.media-intro h2 { font-size:23px; margin:0 0 5px; }
.media-intro p { color:var(--text-muted); font-size:14px; margin:0; }
.media-notice { color:var(--text-secondary); font-size:13px; padding:10px 12px; background:var(--bg-subtle); border-radius:9px; }
.media-notice[hidden] { display:none; }
.media-notice.bad { color:var(--accent-red); background:var(--accent-red-subtle); }
.media-form { padding:18px; border:1px solid var(--border); border-radius:16px; background:var(--bg-surface); display:flex; flex-direction:column; gap:16px; }
.media-fields { display:flex; flex-wrap:wrap; gap:12px; align-items:end; }
.media-field { display:flex; flex-direction:column; gap:6px; min-width:0; }
.media-field > span { color:var(--text-secondary); font-size:12.5px; }
.media-model-field { flex:1 1 220px; }
.media-settings { display:flex; flex-wrap:wrap; gap:12px; flex:2 1 280px; }
.media-settings .media-field { flex:1 1 110px; }
.media-settings select, .media-model-field select { width:100%; min-width:0; }
.media-form textarea { width:100%; min-height:100px; max-height:260px; resize:vertical; }
.media-reference { border:1px dashed var(--border); border-radius:12px; padding:12px; display:flex; flex-direction:column; gap:10px; background:var(--bg-subtle); }
.media-reference[hidden] { display:none; }
.media-reference-head { display:flex; align-items:center; justify-content:space-between; gap:10px; flex-wrap:wrap; }
.media-reference-head > span { font-size:12.5px; color:var(--text-secondary); }
.media-reference-preview { display:flex; align-items:center; gap:12px; }
.media-reference-preview[hidden] { display:none; }
.media-reference-preview img { width:96px; height:96px; object-fit:cover; border-radius:9px; border:1px solid var(--border); background:var(--bg-canvas); }
.media-reference-preview > div { display:flex; flex-direction:column; gap:8px; min-width:0; }
.media-reference-preview > div > span { font-size:12px; color:var(--text-muted); overflow-wrap:anywhere; }
.media-cost-row { display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:12px; }
.media-price { color:var(--text-main); font-size:13px; font-variant-numeric:tabular-nums; }
.media-form-actions { display:flex; flex-wrap:wrap; gap:8px; }
.media-form-actions .btn:disabled { opacity:.45; cursor:not-allowed; }
.media-fine { margin:0; color:var(--text-muted); font-size:12px; line-height:1.55; }
.media-recovery { padding:14px; border:1px solid var(--border); background:var(--bg-subtle); border-radius:10px; }
.media-recovery[hidden] { display:none; }
.media-recovery p { margin:0 0 10px; color:var(--text-secondary); font-size:13px; }
.media-history-head { display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap; gap:10px; margin-top:8px; }
.media-history-head h3 { margin:0; font-size:17px; }
.media-history-actions { display:flex; align-items:center; flex-wrap:wrap; gap:12px; }
.media-library-toggle { font-size:12.5px; color:var(--text-secondary); display:flex; align-items:center; gap:6px; }
.media-gallery { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:16px; }
.media-card { min-width:0; border:1px solid var(--border); border-radius:14px; padding:14px; background:var(--bg-surface); display:flex; flex-direction:column; gap:10px; }
.media-card-top { display:flex; justify-content:space-between; flex-wrap:wrap; gap:8px; font-size:12px; }
.media-card-top b { color:var(--text-secondary); }
.media-job-status { color:var(--text-muted); }
.media-job-status.good { color:var(--accent-green); }
.media-job-status.failed { color:var(--accent-red); }
.media-job-status.pending { color:var(--accent-warm); }
.media-job-prompt { margin:0; font-size:13.5px; line-height:1.5; white-space:pre-wrap; overflow-wrap:anywhere; max-height:115px; overflow:auto; }
.media-job-settings { color:var(--text-muted); font-size:12px; }
.media-assets { display:flex; flex-direction:column; gap:10px; }
.media-asset { min-width:0; display:flex; flex-direction:column; gap:8px; }
.media-asset img, .media-asset video { width:100%; max-height:460px; object-fit:contain; border-radius:8px; background:var(--bg-canvas); }
.media-asset audio { width:100%; }
.media-asset-placeholder, .media-job-note { min-height:100px; display:grid; place-items:center; padding:14px; border-radius:8px; background:var(--bg-canvas); color:var(--text-muted); font-size:13px; text-align:center; line-height:1.6; }
.media-download { color:var(--text-secondary); font-size:12.5px; width:fit-content; padding:4px 0; }
.media-download:hover { color:var(--text-main); }
.media-card-foot { display:flex; flex-direction:column; gap:8px; margin-top:auto; }
.media-card-foot > span { color:var(--text-muted); font-size:11.5px; }
.media-card-foot > div { display:flex; flex-wrap:wrap; gap:6px; }
.media-empty { grid-column:1/-1; min-height:220px; display:flex; flex-direction:column; justify-content:center; align-items:center; gap:10px; text-align:center; color:var(--text-secondary); }
.media-empty > span { color:var(--accent-warm); font-size:36px; }
.media-empty p { max-width:420px; margin:0; color:var(--text-muted); font-size:13px; line-height:1.6; }
.media-more { align-self:center; }
@media(max-width:700px) {
  .chat-kind-tabs { padding:7px 12px; }
  .chat-kind-tabs button { flex:1; min-height:38px; }
  .media-workspace { padding:18px 12px 30px; gap:14px; }
  .media-intro { flex-wrap:wrap; gap:10px; }
  .media-intro h2 { font-size:21px; }
  .media-form { padding:14px; }
  .media-gallery { grid-template-columns:1fr; }
  .media-cost-row, .media-form-actions { align-items:stretch; flex-direction:column; width:100%; }
  .media-form-actions .btn { min-height:42px; width:100%; }
  .media-history-actions { width:100%; justify-content:space-between; }
}
