:root {
  --bg: #15100c; --bg-2: #1e1813; --bg-3: #271f18; --line: #3a2f24;
  --text: #f0e9e1; --muted: #a89684; --orange: #ff8c2b; --amber: #ffb454;
  --steel: #8fb7d6; --green: #4cd07a; --red: #ff6b5e; --radius: 12px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  display: flex; flex-direction: column; height: 100vh; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif; font-size: 14px;
}
.hidden { display: none !important; }
.accent { color: var(--orange); }
.welcome-logo { font-size: 40px; color: var(--orange); background: var(--bg-2); border: 1px solid var(--line); width: 84px; height: 84px; display: flex; align-items: center; justify-content: center; border-radius: 20px; margin: 0 auto 18px; }

/* ---- pairing screen ---- */
.pair { flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px; }
.pair-card { width: 460px; max-width: 100%; text-align: center; background: var(--bg-2); border: 1px solid var(--line); border-radius: 18px; padding: 34px 28px; }
.pair-card h1 { font-size: 26px; font-weight: 800; margin-bottom: 10px; }
.pair-status { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.pair-status.ok { color: var(--green); }
.pair-status.err { color: var(--red); }
.pair-card input { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; color: var(--text); font-size: 14px; outline: none; margin-bottom: 10px; }
.pair-card input:focus { border-color: var(--amber); }
.pair-btn { width: 100%; background: var(--orange); color: #1a0f04; border: none; border-radius: 10px; padding: 12px; font-weight: 700; font-size: 15px; cursor: pointer; }
.pair-btn:hover { background: var(--amber); }
.pair-hint { color: var(--muted); font-size: 12px; line-height: 1.5; margin-top: 16px; }

/* ---- layout: sidebar + main ---- */
#app { flex: 1; display: flex; min-height: 0; }
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#sidebar { width: 240px; flex-shrink: 0; background: #110d09; border-right: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden; }
.side-brand { display: flex; align-items: center; gap: 8px; padding: 14px 16px 6px; }
.side-brand .logo { color: var(--orange); font-size: 20px; }
.side-brand .name { font-weight: 800; font-size: 16px; }
.side-brand .badge { font-size: 10px; text-transform: uppercase; color: var(--amber); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; }
#newChatBtn { margin: 8px 12px; padding: 10px; background: var(--bg-3); color: var(--text); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-size: 13px; font-weight: 600; }
#newChatBtn:hover { border-color: var(--amber); }
.side-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; padding: 6px 16px 4px; }
#chatList { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.chat-item { display: flex; align-items: center; gap: 6px; padding: 9px 10px; margin-bottom: 4px; border-radius: 8px; cursor: pointer; color: var(--muted); font-size: 12.5px; }
.chat-item:hover { background: var(--bg-2); color: var(--text); }
.chat-item.active { background: var(--bg-3); color: var(--text); border-left: 2px solid var(--orange); }
.chat-item .ct { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-empty { color: var(--muted); font-size: 12px; text-align: center; padding: 16px 10px; opacity: .6; }
.side-conn { border-top: 1px solid var(--line); padding: 10px 12px; }
.conn-row { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.conn-btn { width: 100%; background: var(--bg-3); color: var(--text); border: 1px solid var(--line); border-radius: 9px; padding: 8px; font-size: 12.5px; cursor: pointer; }
.conn-btn:hover { border-color: var(--amber); }
.mode-badge { font-size: 11px; font-weight: 700; border-radius: 6px; padding: 2px 8px; }
.mode-badge.online { color: var(--green); border: 1px solid rgba(76,208,122,.4); }
.mode-badge.desktop { color: var(--steel); border: 1px solid rgba(143,183,214,.4); }
.gen-image { margin-top: 8px; max-width: 360px; width: 100%; border-radius: 8px; border: 1px solid var(--line); display: block; }

/* ---- modal ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal.hidden { display: none; }
.modal-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 24px; width: 440px; max-width: 92%; }
.modal-card h2 { margin-bottom: 14px; }
.modal-card label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
.modal-card input { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; color: var(--text); font-size: 13px; outline: none; }
.modal-card input:focus { border-color: var(--amber); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.btn-primary { background: var(--orange); color: #1a0f04; border: none; padding: 9px 18px; border-radius: 8px; font-weight: 700; cursor: pointer; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--line); padding: 9px 18px; border-radius: 8px; cursor: pointer; }

/* ---- topbar ---- */
#topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: var(--bg-2); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; }
.brand .logo { color: var(--orange); font-size: 20px; }
.brand .name { font-weight: 800; letter-spacing: .3px; }
.brand .badge { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--amber); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; }
.topbar-controls { display: flex; align-items: center; gap: 8px; }
.chip { font-size: 12px; color: var(--steel); background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { width: 32px; height: 32px; background: var(--bg-3); border: 1px solid var(--line); color: var(--text); border-radius: 8px; cursor: pointer; }
.icon-btn:hover { border-color: var(--amber); }

/* ---- messages ---- */
#messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; flex-direction: column; max-width: 760px; width: 100%; margin: 0 auto; }
.msg .role { font-size: 11px; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .5px; }
.bubble { padding: 12px 14px; border-radius: var(--radius); line-height: 1.55; word-wrap: break-word; }
.msg.user { align-items: flex-end; }
.msg.user .bubble { background: var(--bg-3); border: 1px solid var(--line); align-self: flex-end; max-width: 80%; }
.msg.assistant .bubble { background: var(--bg-2); border: 1px solid var(--line); border-left: 3px solid var(--orange); }
.msg.error .bubble { background: #2a1714; border: 1px solid var(--red); color: var(--red); }
.notice { max-width: 760px; width: 100%; margin: 0 auto; color: var(--amber); font-size: 12px; opacity: .85; text-align: center; }
.plan-box { max-width: 760px; width: 100%; margin: 0 auto; background: var(--bg-2); border: 1px solid var(--line); border-left: 3px solid var(--amber); border-radius: 10px; padding: 12px 14px; }
.plan-title { font-weight: 700; margin-bottom: 8px; }
.plan-step { font-size: 13px; padding: 3px 0; }
.plan-step .ps-ico { color: var(--muted); margin-right: 6px; }
.plan-step.done { color: var(--muted); text-decoration: line-through; }
.plan-step.in_progress .ps-ico { color: var(--amber); }

/* markdown */
.bubble p { margin: 6px 0; }
.bubble h1, .bubble h2, .bubble h3 { margin: 10px 0 6px; line-height: 1.3; }
.bubble ul { margin: 6px 0 6px 22px; }
.bubble li { margin: 3px 0; }
.bubble code.inline { background: var(--bg-3); color: var(--amber); padding: 1px 5px; border-radius: 5px; font-family: "Cascadia Code", Consolas, monospace; font-size: 12.5px; }
.bubble pre { background: #0f0b08; border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow-x: auto; margin: 8px 0; }
.bubble pre code { font-family: "Cascadia Code", Consolas, monospace; font-size: 12.5px; color: var(--steel); white-space: pre; }
.bubble strong { color: #fff; }

/* tool chips */
.tool { max-width: 760px; width: 100%; margin: 0 auto; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 12.5px; color: var(--muted); }
.tool .tool-head { display: flex; align-items: center; gap: 8px; }
.tool .tname { color: var(--text); font-weight: 600; }
.tool .targ { color: var(--steel); font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool.cmd .targ { color: var(--amber); }
.tool details { margin-top: 6px; }
.tool details summary { cursor: pointer; color: var(--muted); font-size: 11.5px; }
.tool pre.result { background: #0f0b08; border: 1px solid var(--line); border-radius: 6px; padding: 8px; margin-top: 6px; max-height: 240px; overflow: auto; color: var(--steel); font-family: "Cascadia Code", Consolas, monospace; font-size: 11.5px; white-space: pre-wrap; }
.tool .approve { margin-top: 8px; }
.tool .approve-row { display: flex; gap: 8px; margin-top: 8px; }
.tool .approve-row button { padding: 5px 14px; border-radius: 7px; border: 1px solid var(--line); cursor: pointer; font-weight: 600; }
.tool .approve-row .allow { background: var(--green); color: #08210f; border-color: var(--green); }
.tool .approve-row .deny { background: var(--bg-3); color: var(--text); }
.tool .approve-row button:disabled { opacity: .5; cursor: default; }
.tool .status { font-size: 11px; margin-left: 8px; }
.tool .status.ok { color: var(--green); }
.tool .status.no { color: var(--red); }

/* welcome */
.welcome { margin: auto; text-align: center; color: var(--muted); max-width: 640px; padding: 20px; }
.welcome h1 { margin: 8px 0; color: var(--text); font-size: 28px; font-weight: 800; }
.welcome p { margin-bottom: 24px; }
.sugg-chips { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; }
.chip-label { color: var(--muted); font-size: 13px; margin-right: 4px; }
.sugg-chips .chip { cursor: pointer; }
.sugg-chips .chip:hover { border-color: var(--amber); }

/* thinking */
.thinking { display: flex; align-items: center; gap: 8px; padding: 4px 22px 0; font-size: 12.5px; color: var(--amber); }
.th-logo { font-size: 15px; color: var(--orange); display: inline-block; transform-origin: 50% 70%; animation: cf-forge .85s ease-in-out infinite; }
.thinking.waiting { color: var(--orange); }
.thinking.waiting .th-logo { animation: cf-pulse 1s ease-in-out infinite; }
@keyframes cf-forge { 0% { transform: rotate(-14deg) scale(1); } 50% { transform: rotate(14deg) scale(1.14); } 100% { transform: rotate(-14deg) scale(1); } }
@keyframes cf-pulse { 0%,100% { opacity: .35; transform: scale(.9); } 50% { opacity: 1; transform: scale(1.18); } }

/* composer */
#composer { padding: 12px 20px 6px; background: var(--bg); }
.composer-box { max-width: 820px; margin: 0 auto; background: var(--bg-2); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px 10px; }
.composer-box:focus-within { border-color: var(--amber); }
#input { width: 100%; resize: none; max-height: 180px; background: transparent; color: var(--text); border: none; padding: 2px; font-size: 14px; font-family: inherit; line-height: 1.5; outline: none; }
.composer-foot { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.comp-spacer { flex: 1; }
.select-wrap.mini select { height: 30px; font-size: 12px; padding: 0 6px; background: var(--bg-3); color: var(--text); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.send-btn { width: 40px; height: 34px; border-radius: 9px; border: none; background: var(--orange); color: #1a0f04; font-size: 16px; cursor: pointer; }
.send-btn:hover { background: var(--amber); }
.send-btn:disabled { opacity: .5; cursor: default; }

/* status bar */
.statusbar { display: flex; align-items: center; gap: 16px; padding: 6px 20px 10px; background: var(--bg); font-size: 12px; color: var(--muted); }
.st-left { display: flex; align-items: center; gap: 6px; }
.st-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 6px var(--green); }
.capacity { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.cap-bar { width: 120px; height: 7px; border-radius: 4px; background: var(--bg-3); border: 1px solid var(--line); overflow: hidden; }
.cap-fill { display: block; height: 100%; width: 0%; background: var(--green); transition: width .3s, background .3s; }
.cap-fill.warn { background: var(--amber); }
.cap-fill.crit { background: var(--red); }
.cap-text { font-size: 11.5px; white-space: nowrap; }
