/* 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); }
.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; }
.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 textarea { display: block; 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-bar { display: flex; align-items: center; gap: 6px; padding: 6px 8px 8px 10px; flex-wrap: wrap; }
.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-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; }
}
