/* ErgoAI — workspace app */
:root {
  --bg: #08090c; --bg-2: #0d0f14; --panel: #12151c; --panel-2: #181c25; --panel-3: #1e2330;
  --line: #20242f; --line-2: #2b3140; --text: #e9ecf3; --muted: #9aa3b5; --dim: #687084;
  --accent: #5eead4; --accent-2: #a78bfa; --accent-ink: #04201c; --danger: #f87171; --warn: #fbbf24; --ok: #4ade80;
  --font: 'Geist', ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --side: 268px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.6 var(--font); -webkit-font-smoothing: antialiased; overflow: hidden; }
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }
.hidden { display: none !important; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #232836; border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

.layout { display: grid; grid-template-columns: var(--side) 1fr auto; height: 100vh; height: 100dvh; }

/* ── Sidebar ── */
.side { background: var(--bg-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-top { padding: 14px 14px 10px; display: grid; gap: 12px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -.02em; color: var(--text); font-size: 16.5px; }
.brand .mark { width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; background: conic-gradient(from 210deg, var(--accent), var(--accent-2), var(--accent)); color: #050608; font: 800 14px var(--mono); }
.new-btn { display: flex; align-items: center; gap: 8px; width: 100%; height: 38px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--panel); color: var(--text); font: 600 14px var(--font); cursor: pointer; }
.new-btn:hover { background: var(--panel-2); }
.new-btn kbd { margin-left: auto; font: 11px var(--mono); color: var(--dim); }
.search { height: 34px; width: 100%; border-radius: 9px; border: 1px solid var(--line); background: var(--bg); color: var(--text); padding: 0 10px; font: 13.5px var(--font); outline: none; }
.search:focus { border-color: var(--line-2); }
.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.conv-group { font: 600 11px var(--mono); color: var(--dim); text-transform: uppercase; letter-spacing: .08em; padding: 14px 8px 6px; }
.conv { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px; color: var(--muted); font-size: 13.5px; cursor: pointer; position: relative; }
.conv:hover { background: var(--panel); color: var(--text); }
.conv.on { background: var(--panel-2); color: var(--text); }
.conv .t { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .m { font: 10px var(--mono); color: var(--dim); border: 1px solid var(--line-2); border-radius: 4px; padding: 0 4px; text-transform: uppercase; }
.conv .del { opacity: 0; background: none; border: 0; color: var(--dim); cursor: pointer; padding: 0 2px; font-size: 15px; }
.conv:hover .del { opacity: 1; }
.conv .del:hover { color: var(--danger); }
.side-foot { border-top: 1px solid var(--line); padding: 12px 14px; display: grid; gap: 10px; }
.quota { font-size: 12px; color: var(--dim); }
.quota .bar { height: 4px; background: var(--panel-3); border-radius: 4px; margin-top: 6px; overflow: hidden; }
.quota .bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .3s; }
.me { display: flex; align-items: center; gap: 10px; font-size: 13.5px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-3); color: var(--text); font-weight: 700; font-size: 13px; flex: none; }
.me .who { flex: 1; min-width: 0; line-height: 1.3; }
.me .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.me .who span { color: var(--dim); font-size: 12px; }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 13px; padding: 4px 6px; border-radius: 6px; }
.link-btn:hover { color: var(--text); background: var(--panel); }

/* ── Main ── */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.topbar { height: 56px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.icon-btn { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; border: 1px solid transparent; background: none; color: var(--muted); cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--panel); color: var(--text); }
.icon-btn.on { color: var(--accent); background: rgba(94, 234, 212, .08); border-color: rgba(94, 234, 212, .2); }
.title { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 32vw; padding: 4px 8px; border-radius: 7px; cursor: text; outline: none; }
.title:hover { background: var(--panel); }
.title:focus { background: var(--panel); box-shadow: 0 0 0 1px var(--line-2); }
.spacer { flex: 1; }
.seg { display: flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { background: none; border: 0; color: var(--muted); font: 600 13px var(--font); padding: 5px 12px; border-radius: 7px; cursor: pointer; display: flex; align-items: center; gap: 6px; }
.seg button.on { background: var(--panel-3); color: var(--text); box-shadow: 0 1px 0 rgba(255, 255, 255, .04) inset; }
.seg button .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .6; }
.seg button.on[data-mode="build"] .dot { background: var(--accent); opacity: 1; }
.seg button.on[data-mode="work"] .dot { background: var(--accent-2); opacity: 1; }
.seg button.on[data-mode="chat"] .dot { background: var(--warn); opacity: 1; }

.model-pick { position: relative; }
.model-btn { display: flex; align-items: center; gap: 8px; white-space: nowrap; height: 34px; padding: 0 10px 0 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg-2); color: var(--text); font: 600 13px var(--font); cursor: pointer; }
.model-btn:hover { border-color: var(--line-2); }
.menu { position: absolute; right: 0; top: calc(100% + 6px); width: 290px; background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px; padding: 6px; z-index: 40; box-shadow: 0 20px 60px -10px rgba(0, 0, 0, .7); }
.menu button { width: 100%; text-align: left; background: none; border: 0; color: var(--text); padding: 9px 10px; border-radius: 8px; cursor: pointer; display: grid; gap: 1px; }
.menu button:hover { background: var(--panel-2); }
.menu button.on { background: var(--panel-3); }
.menu button b { font-size: 13.5px; display: flex; align-items: center; gap: 8px; }
.menu button span { font-size: 12px; color: var(--muted); }
.menu .badge { font: 600 10px var(--mono); color: var(--accent-2); border: 1px solid rgba(167, 139, 250, .4); border-radius: 4px; padding: 0 4px; }

.thread { flex: 1; overflow-y: auto; scroll-behavior: auto; }
.thread-inner { width: min(820px, calc(100% - 32px)); margin: 0 auto; padding: 28px 0 40px; }

/* Empty state */
.empty { width: min(760px, calc(100% - 32px)); margin: 9vh auto 0; text-align: center; }
.empty h1 { font-size: clamp(28px, 4vw, 40px); letter-spacing: -.035em; margin: 0 0 8px; }
.empty p { color: var(--muted); margin: 0 0 28px; }
.sugs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: left; }
.sug { border: 1px solid var(--line); background: var(--bg-2); border-radius: 12px; padding: 14px 16px; cursor: pointer; color: var(--text); font-size: 14px; transition: border-color .15s, background .15s; }
.sug:hover { border-color: var(--line-2); background: var(--panel); }
.sug small { display: block; color: var(--dim); font: 11px var(--mono); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }
@media (max-width: 640px) { .sugs { grid-template-columns: 1fr; } }

/* Messages */
.msg { margin-bottom: 28px; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.bubble { background: var(--panel-2); border: 1px solid var(--line); border-radius: 16px 16px 4px 16px; padding: 10px 15px; max-width: 85%; white-space: pre-wrap; word-wrap: break-word; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; justify-content: flex-end; }
.chip { display: inline-flex; align-items: center; gap: 6px; font: 12px var(--mono); color: var(--muted); background: var(--bg-2); border: 1px solid var(--line); border-radius: 7px; padding: 3px 8px; }
.chip button { background: none; border: 0; color: var(--dim); cursor: pointer; padding: 0; font-size: 14px; line-height: 1; }
.msg.ai .who { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--dim); margin-bottom: 8px; font-family: var(--mono); }
.msg.ai .who .mark { width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center; background: conic-gradient(from 210deg, var(--accent), var(--accent-2), var(--accent)); color: #050608; font: 800 11px var(--mono); }

.reason { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 12px; background: rgba(255, 255, 255, .012); }
.reason summary { cursor: pointer; list-style: none; padding: 8px 12px; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; user-select: none; }
.reason summary::-webkit-details-marker { display: none; }
.reason summary::before { content: '›'; font: 600 15px var(--mono); transition: transform .15s; color: var(--dim); }
.reason[open] summary::before { transform: rotate(90deg); }
.reason .rt { padding: 0 14px 12px 28px; color: var(--muted); font-size: 13.5px; white-space: pre-wrap; max-height: 340px; overflow-y: auto; border-left: 2px solid rgba(167, 139, 250, .35); margin: 0 12px 12px; padding: 2px 12px; }
.shimmer { background: linear-gradient(90deg, var(--muted) 0%, var(--text) 40%, var(--muted) 80%); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: sh 1.6s linear infinite; }
@keyframes sh { to { background-position: -200% 0; } }

.steps { display: grid; gap: 6px; margin: 0 0 12px; }
.step { display: flex; align-items: center; gap: 10px; font: 12.5px var(--mono); color: var(--muted); padding: 6px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg-2); }
.step .tag { color: var(--accent); background: rgba(94, 234, 212, .08); border: 1px solid rgba(94, 234, 212, .2); padding: 0 7px; border-radius: 5px; flex: none; }
.step.err .tag { color: var(--danger); background: rgba(248, 113, 113, .08); border-color: rgba(248, 113, 113, .25); }
.step .s { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step.file { cursor: pointer; } .step.file:hover { border-color: var(--line-2); color: var(--text); }
.spin { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--accent); border-top-color: transparent; animation: rot .7s linear infinite; flex: none; }
@keyframes rot { to { transform: rotate(360deg); } }

.plan-card { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin: 0 0 12px; background: rgba(255, 255, 255, .012); }
.plan-card h6 { margin: 0 0 6px; font: 600 11px var(--mono); color: var(--dim); text-transform: uppercase; letter-spacing: .08em; display: flex; justify-content: space-between; }
.plan-card ul { margin: 0; padding: 0; list-style: none; }
.plan-card li { display: flex; gap: 10px; align-items: center; padding: 3px 0; font-size: 14px; }
.plan-card li.done { color: var(--muted); }
.plan-card li.done span:last-child { text-decoration: line-through; text-decoration-color: var(--dim); }
.chk { width: 15px; height: 15px; border-radius: 5px; border: 1.5px solid var(--line-2); flex: none; display: grid; place-items: center; }
.chk.done { background: var(--accent); border-color: var(--accent); }
.chk.done::after { content: ''; width: 7px; height: 4px; border-left: 2px solid #042; border-bottom: 2px solid #042; transform: rotate(-45deg) translate(1px, -1px); }
.chk.in_progress { border-color: var(--accent); border-top-color: transparent; border-radius: 50%; animation: rot .8s linear infinite; }

.md { word-wrap: break-word; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 14px; }
.md h1, .md h2, .md h3, .md h4 { letter-spacing: -.02em; line-height: 1.25; margin: 24px 0 10px; }
.md h1 { font-size: 24px; } .md h2 { font-size: 20px; } .md h3 { font-size: 17px; }
.md ul, .md ol { padding-left: 22px; margin: 0 0 14px; }
.md li { margin: 3px 0; }
.md a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; text-decoration-color: rgba(94, 234, 212, .4); }
.md blockquote { margin: 0 0 14px; padding: 2px 14px; border-left: 3px solid var(--line-2); color: var(--muted); }
.md code:not(pre code) { font: .88em var(--mono); background: var(--panel-2); border: 1px solid var(--line); padding: 1px 5px; border-radius: 5px; }
.md table { border-collapse: collapse; width: 100%; margin: 0 0 14px; font-size: 14px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; }
.md th { background: var(--panel); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
.codeblock { position: relative; margin: 0 0 14px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #0a0c10; }
.codeblock .cb-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 14px; border-bottom: 1px solid var(--line); font: 12px var(--mono); color: var(--dim); }
.codeblock .cb-head button { background: none; border: 0; color: var(--dim); font: 12px var(--mono); cursor: pointer; padding: 3px 8px; border-radius: 6px; }
.codeblock .cb-head button:hover { color: var(--text); background: var(--panel); }
.md pre { margin: 0; padding: 14px 16px; overflow-x: auto; font: 13px/1.6 var(--mono); }
.md pre code.hljs { background: transparent; padding: 0; }

.meta { display: flex; align-items: center; gap: 12px; margin-top: 10px; font: 12px var(--mono); color: var(--dim); }
.meta button { background: none; border: 0; color: var(--dim); cursor: pointer; font: 12px var(--mono); padding: 2px 6px; border-radius: 5px; }
.meta button:hover { color: var(--text); background: var(--panel); }
.meta .tps { color: var(--accent); }
.error-box { border: 1px solid rgba(248, 113, 113, .35); background: rgba(248, 113, 113, .07); color: #fecaca; border-radius: 12px; padding: 10px 14px; font-size: 14px; margin-top: 8px; }
.error-box a { color: #fff; text-decoration: underline; }
.cursor::after { content: '▍'; color: var(--accent); animation: bl 1s steps(1) infinite; margin-left: 1px; }
@keyframes bl { 50% { opacity: 0; } }

/* Composer */
.composer-wrap { flex: none; padding: 0 16px 16px; }
.composer { width: min(820px, 100%); margin: 0 auto; border: 1px solid var(--line-2); background: var(--panel); border-radius: 16px; padding: 10px 10px 8px 14px; transition: border-color .15s, box-shadow .15s; }
.composer:focus-within { border-color: #3a4256; box-shadow: 0 0 0 4px rgba(94, 234, 212, .06); }
.composer.drag { border-color: var(--accent); }
.composer textarea { width: 100%; resize: none; border: 0; outline: none; background: transparent; color: var(--text); font: 15px/1.55 var(--font); max-height: 260px; min-height: 26px; padding: 4px 0; }
.composer textarea::placeholder { color: var(--dim); }
.comp-row { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.comp-row .chips { justify-content: flex-start; margin: 0 0 6px; }
.toggle { display: flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: none; color: var(--muted); font: 500 12.5px var(--font); cursor: pointer; }
.toggle:hover { color: var(--text); }
.toggle.on { color: var(--accent); border-color: rgba(94, 234, 212, .35); background: rgba(94, 234, 212, .07); }
.send { margin-left: auto; width: 36px; height: 36px; border-radius: 10px; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; cursor: pointer; transition: opacity .15s, transform .1s; }
.send:disabled { opacity: .35; cursor: default; }
.send:not(:disabled):active { transform: scale(.95); }
.send.stop { background: var(--text); }
.foot-note { text-align: center; font-size: 11.5px; color: var(--dim); margin-top: 8px; }

/* ── Workspace panel ── */
.ws { width: 0; overflow: hidden; border-left: 1px solid var(--line); background: var(--bg-2); display: flex; flex-direction: column; min-height: 0; transition: width .2s ease; }
.ws.open { width: min(44vw, 720px); }
.ws-head { height: 56px; flex: none; display: flex; align-items: center; gap: 8px; padding: 0 12px; border-bottom: 1px solid var(--line); }
.ws-tabs { display: flex; gap: 2px; }
.ws-tabs button { background: none; border: 0; color: var(--muted); font: 600 13px var(--font); padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.ws-tabs button.on { background: var(--panel-2); color: var(--text); }
.ws-body { flex: 1; min-height: 0; display: flex; }
.files { width: 200px; flex: none; border-right: 1px solid var(--line); overflow-y: auto; padding: 8px 6px; }
.file { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 7px; font: 12.5px var(--mono); color: var(--muted); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file:hover { background: var(--panel); color: var(--text); }
.file.on { background: var(--panel-2); color: var(--text); }
.file.flash { animation: flash 1.2s ease; }
@keyframes flash { 0% { background: rgba(94, 234, 212, .25); } 100% { background: transparent; } }
.file .ext { font-size: 10px; width: 26px; text-align: center; border-radius: 4px; padding: 1px 0; background: var(--panel-3); color: var(--dim); flex: none; }
.editor { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.editor-head { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line); font: 12px var(--mono); color: var(--dim); min-height: 40px; }
.editor-head .path { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.mini { background: var(--panel); border: 1px solid var(--line); color: var(--muted); font: 600 12px var(--font); padding: 4px 10px; border-radius: 7px; cursor: pointer; }
.mini:hover { color: var(--text); border-color: var(--line-2); }
.mini.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.editor textarea { flex: 1; width: 100%; resize: none; border: 0; outline: none; background: #0a0c10; color: #d6dbe5; font: 12.5px/1.65 var(--mono); padding: 14px 16px; tab-size: 2; white-space: pre; overflow: auto; }
.preview { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.preview-bar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.preview-bar .url { flex: 1; font: 12px var(--mono); color: var(--dim); background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 4px 10px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.preview iframe { flex: 1; width: 100%; border: 0; background: #fff; }
.ws-empty { flex: 1; display: grid; place-items: center; text-align: center; color: var(--dim); font-size: 14px; padding: 30px; }
.ws-plan { border-bottom: 1px solid var(--line); padding: 10px 14px; max-height: 32%; overflow-y: auto; }
.ws-plan .plan-card { margin: 0; border: 0; padding: 0; background: none; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: grid; place-items: center; z-index: 100; backdrop-filter: blur(4px); }
.modal { width: min(400px, calc(100% - 32px)); background: var(--panel); border: 1px solid var(--line-2); border-radius: 16px; padding: 26px; }
.modal h3 { margin: 0 0 6px; font-size: 20px; }
.modal p { color: var(--muted); margin: 0 0 20px; font-size: 14.5px; }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; }
.btn { display: inline-flex; align-items: center; justify-content: center; height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text); font: 600 14px var(--font); cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--panel-3); border: 1px solid var(--line-2); padding: 9px 16px; border-radius: 10px; font-size: 13.5px; z-index: 120; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); }

/* Mobile */
.only-mobile { display: none; }
@media (max-width: 1100px) {
  .ws.open { position: fixed; right: 0; top: 0; bottom: 0; width: min(100vw, 680px); z-index: 60; box-shadow: -20px 0 60px rgba(0, 0, 0, .6); }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr auto; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 280px; z-index: 70; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 20px 0 60px rgba(0, 0, 0, .6); }
  .only-mobile { display: grid; }
  .title { max-width: 30vw; }
  .seg button { padding: 5px 8px; }
  .seg button .lbl { display: none; }
  .files { width: 140px; }
}
