:root {
  --bg: #0b0e14;
  --panel: #111622;
  --panel-2: #171d2c;
  --border: #252e42;
  --text: #eef2ff;
  --muted: #9aa7c4;
  --cobalt: #1e40ff;
  --cobalt-h: #2d50ff;
  --neon: #7c3aed;
  --amber: #f5a524;
  --green: #10b981;
  --red: #ef4444;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100dvh; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 15px; overflow: hidden; }
.hidden { display: none !important; }
.ml-auto { margin-left: auto; }

/* Login */
.login-wrap { height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin: 0; font-size: 22px; }
.eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--amber); }
.err { color: var(--red); font-size: 13px; min-height: 18px; }

/* Inputs & Buttons */
input, select, textarea { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; font-family: inherit; font-size: 15px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--cobalt); }
button { cursor: pointer; font-family: inherit; font-weight: 600; border-radius: 6px; border: 1px solid transparent; padding: 10px 14px; font-size: 14px; color: var(--text); }
.btn-primary { background: var(--cobalt); }
.btn-primary:hover { background: var(--cobalt-h); }
.btn-neon { background: var(--neon); }
.btn-neon:hover { filter: brightness(1.12); }
.btn-danger { background: var(--red); }
.btn-ghost { background: var(--panel-2); border-color: var(--border); }
.btn-ghost:hover { border-color: #3b4969; }
.btn-sm { padding: 7px 11px; font-size: 13px; }
.btn-xs { padding: 4px 8px; font-size: 12px; }
.icon-btn { background: var(--panel-2); border: 1px solid var(--border); padding: 7px 10px; font-size: 15px; line-height: 1; }

/* App Shell */
.app { display: flex; height: 100dvh; width: 100vw; overflow: hidden; }
.sidebar { width: 272px; min-width: 272px; background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; z-index: 30; }
.sb-top { padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 12px; font-weight: 700; letter-spacing: 0.06em; }
.dot-live { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.tag-vm { background: var(--panel-2); border: 1px solid var(--border); padding: 2px 6px; border-radius: 4px; font-size: 10px; color: var(--amber); }
.sb-filters { display: flex; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.chip { flex: 1; padding: 5px 6px; font-size: 12px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
.chip.active { background: var(--panel-2); color: var(--text); border-color: var(--cobalt); }
.chat-list { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.chat-item { padding: 10px 11px; border-radius: 8px; border: 1px solid transparent; background: transparent; cursor: pointer; display: flex; flex-direction: column; gap: 4px; position: relative; }
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: var(--panel-2); border-color: var(--cobalt); }
.ci-top { display: flex; align-items: center; gap: 6px; }
.ci-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.ci-del { opacity: 0.45; background: none; border: none; padding: 2px 5px; font-size: 12px; }
.ci-del:hover { opacity: 1; color: var(--red); }
.ci-meta { display: flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.badge { padding: 1px 6px; border-radius: 4px; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.badge.claude { background: rgba(16,185,129,0.18); color: #34d399; }
.badge.agy { background: rgba(124,58,237,0.22); color: #c4b5fd; }
.badge.codex { background: rgba(245,165,36,0.2); color: var(--amber); }
.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); animation: pulse 1.1s infinite; flex-shrink: 0; }
.err-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); flex-shrink: 0; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }
.sb-foot { padding: 10px 12px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; font-size: 12px; }
.foot-link { color: #93c5fd; text-decoration: none; font-weight: 600; }
.foot-btn { background: none; border: none; color: var(--muted); padding: 4px 6px; font-size: 12px; }

/* Main Chat */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100dvh; }
.topbar { padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--panel); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tb-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.chat-meta { min-width: 0; flex: 1; }
.title-input { width: 100%; background: transparent; border: 1px solid transparent; padding: 3px 6px; font-size: 15px; font-weight: 700; }
.title-input:focus { background: var(--bg); border-color: var(--border); }
.sub-meta { display: flex; align-items: center; gap: 8px; padding-left: 6px; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.pill-branch { color: #93c5fd; }
.cwd-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.model-select { max-width: 210px; padding: 7px 10px; font-size: 13px; background: var(--panel-2); font-weight: 600; }

.messages { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 16px; }
.empty-state { margin: auto; max-width: 520px; text-align: center; display: flex; flex-direction: column; gap: 14px; align-items: center; }
.empty-state h2 { margin: 0; font-size: 24px; }
.empty-state p { margin: 0; color: var(--muted); line-height: 1.5; }
.quick-starts { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 6px; }

.msg { max-width: 880px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; }
.msg.user { align-items: flex-end; }
.msg.user .bubble { background: #192544; border: 1px solid #2b3f75; border-radius: 10px; padding: 12px 15px; max-width: 85%; white-space: pre-wrap; word-break: break-word; line-height: 1.5; }
.msg.assistant .bubble { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px 18px; line-height: 1.6; overflow-x: auto; }
.msg-head { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.msg-body p:first-child { margin-top: 0; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body pre { background: #07090e; border: 1px solid var(--border); border-radius: 6px; padding: 12px; overflow-x: auto; position: relative; font-size: 13px; }
.msg-body code { font-family: var(--mono); font-size: 13px; }
.msg-body :not(pre) > code { background: var(--panel-2); padding: 2px 5px; border-radius: 4px; }
.msg-body a { color: #93c5fd; }
.msg-body table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 14px; }
.msg-body th, .msg-body td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
.msg-body th { background: var(--panel-2); }
.msg-err { background: rgba(239,68,68,0.14); border: 1px solid rgba(239,68,68,0.45); color: #fecaca; padding: 10px 12px; border-radius: 6px; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; }

/* Tools */
.tools-wrap { display: flex; flex-direction: column; gap: 5px; margin-bottom: 8px; }
.tool-pill { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; font-family: var(--mono); font-size: 12px; }
.tool-pill summary { cursor: pointer; display: flex; align-items: center; gap: 8px; list-style: none; }
.tool-pill summary::-webkit-details-marker { display: none; }
.tool-st { font-size: 11px; }
.tool-st.running { color: var(--amber); }
.tool-st.done { color: var(--green); }
.tool-st.error { color: var(--red); }
.tool-name { font-weight: 700; color: #cbd5f5; }
.tool-sum { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.tool-out { margin: 8px 0 0; padding-top: 8px; border-top: 1px solid var(--border); color: var(--muted); white-space: pre-wrap; max-height: 200px; overflow-y: auto; font-size: 11px; }

/* Attachments */
.att-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.att-thumb { max-height: 140px; max-width: 220px; border-radius: 6px; border: 1px solid var(--border); }
.attach-preview { padding: 8px 16px; background: var(--panel); border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 8px; }
.att-chip { background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; font-size: 12px; display: flex; align-items: center; gap: 6px; }

/* Composer */
.composer { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--border); display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { flex: 1; resize: none; max-height: 180px; line-height: 1.45; }

/* IDE Drawer */
.ide-drawer { width: 460px; min-width: 340px; max-width: 55vw; background: var(--panel); border-left: 1px solid var(--border); display: flex; flex-direction: column; z-index: 25; }
.ide-tabs { display: flex; align-items: center; gap: 4px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.ide-tab { background: transparent; border: 1px solid transparent; padding: 6px 10px; font-size: 13px; color: var(--muted); }
.ide-tab.active { background: var(--panel-2); border-color: var(--border); color: var(--text); }
.ide-pane { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.pane-bar { padding: 8px 10px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; background: var(--bg); }
.mono-path { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-tree { flex: 1; overflow-y: auto; padding: 6px; }
.ft-row { padding: 7px 10px; border-radius: 6px; cursor: pointer; font-family: var(--mono); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.ft-row:hover { background: var(--panel-2); }
.file-editor { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.file-editor textarea { flex: 1; border: none; border-radius: 0; font-family: var(--mono); font-size: 13px; line-height: 1.5; resize: none; }
.diff-status { padding: 8px 10px; font-family: var(--mono); font-size: 12px; border-bottom: 1px solid var(--border); max-height: 140px; overflow-y: auto; color: var(--amber); }
.diff-body { flex: 1; margin: 0; padding: 10px; overflow: auto; font-family: var(--mono); font-size: 12px; line-height: 1.45; }
.diff-add { color: #4ade80; }
.diff-del { color: #f87171; }
.diff-hunk { color: #60a5fa; }
.term-box { flex: 1; padding: 6px; background: #000; overflow: hidden; }
.vm-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; font-size: 13px; }
.vm-card { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.vm-card h4 { margin: 0 0 8px; font-family: var(--mono); font-size: 12px; text-transform: uppercase; color: var(--amber); }
.bar-bg { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; margin: 6px 0; }
.bar-fill { height: 100%; background: var(--cobalt); }
.vm-pre { margin: 6px 0 0; font-family: var(--mono); font-size: 11px; color: var(--muted); white-space: pre-wrap; max-height: 180px; overflow-y: auto; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.68); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal-card { width: 100%; max-width: 440px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.modal-card h3 { margin: 0; }
.modal-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.row-check { flex-direction: row !important; align-items: center; gap: 8px !important; color: var(--text) !important; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.mobile-only { display: none; }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 20; }

@media (max-width: 900px) {
  .mobile-only { display: inline-flex; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform 0.2s ease; }
  .sidebar.open { transform: translateX(0); }
  .ide-drawer { position: fixed; inset: 0; width: 100vw; max-width: 100vw; z-index: 40; }
  .model-select { max-width: 130px; font-size: 12px; }
  .messages { padding: 12px; }
  .cwd-text { display: none; }
}
