:root {
  --bg: #f6f7f9; --surface: #fff; --text: #1d2330; --muted: #6b7385; --border: #e2e5eb;
  --accent: #c8341f; --accent-ink: #fff; --ok: #1f7a4a; --err: #b42318; --code-bg: #f1f3f6;
  --user-bg: #fdecea; --radius: 10px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14161b; --surface: #1c1f26; --text: #e6e8ee; --muted: #959cad; --border: #2c303a;
    --accent: #ef5b43; --code-bg: #12141a; --user-bg: #3a2220; --ok: #4cc38a; --err: #ff7b6e; color-scheme: dark; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: .2em 0 .6em; }
h2 { font-size: 1.1rem; margin: 0 0 .8em; }
code, pre { font-family: ui-monospace, "Cascadia Code", Menlo, Consolas, monospace; font-size: 13px; }
pre { white-space: pre-wrap; word-break: break-word; margin: 0; }
.muted { color: var(--muted); } .small { font-size: 13px; } .center { text-align: center; } .right { text-align: right; }
.hidden { display: none !important; }

header.top { display: flex; align-items: center; gap: 24px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; color: var(--text); }
header nav { display: flex; gap: 16px; flex: 1; }
header nav a { color: var(--text); }
.me { display: flex; gap: 10px; align-items: center; }
main { padding: 20px; max-width: 1500px; margin: 0 auto; }
main.narrow { max-width: 420px; padding-top: 10vh; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card.auth h1 { margin-top: 0; }
details > summary { cursor: pointer; }
details.card[open] > summary { margin-bottom: 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card.project { color: var(--text); display: block; margin: 0; }
.card.project:hover { border-color: var(--accent); text-decoration: none; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin: .4em 0; }
.two-col { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.w-sm { max-width: 360px; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.grid-form.one { grid-template-columns: 1fr; }
.grid-form .span2 { grid-column: span 2; }
@media (max-width: 700px) { .grid-form { grid-template-columns: 1fr; } .grid-form .span2 { grid-column: auto; } }
.inline-form { display: flex; gap: 8px; margin-bottom: 12px; }
form.inline { display: inline; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 7px; padding: 7px 9px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
textarea { resize: vertical; }
button { font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 7px; padding: 7px 14px; }
button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--err); border-color: var(--err); background: transparent; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button.link.danger { color: var(--err); }
button.full { width: 100%; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--code-bg); color: var(--muted); border: 1px solid var(--border); font-weight: 500; vertical-align: middle; }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.flash.ok { color: var(--ok); border-color: var(--ok); background: color-mix(in srgb, var(--ok) 8%, transparent); }
.flash.err { color: var(--err); border-color: var(--err); background: color-mix(in srgb, var(--err) 8%, transparent); white-space: pre-wrap; }
.danger-zone summary { color: var(--err); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
ul.list { list-style: none; padding: 0; margin: 10px 0; }
ul.list li { padding: 6px 0; border-bottom: 1px solid var(--border); }

/* project workbench */
.project-head h1 { margin-bottom: .1em; }
.project-head p { margin: 0 0 10px; }
.workbench { display: grid; grid-template-columns: 220px 1fr 280px; gap: 14px; height: calc(100vh - 170px); min-height: 480px; }
@media (max-width: 1100px) { .workbench { grid-template-columns: 1fr; height: auto; } .chat { height: 75vh; } }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; overflow: auto; min-height: 0; }
.convs li { display: flex; flex-direction: column; padding: 6px 8px; border-radius: 6px; border: 0; }
.convs li.active { background: var(--code-bg); }
.convs li a { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; }
.msg.user .bubble { background: var(--user-bg); }
.msg.assistant .bubble { background: var(--bg); border: 1px solid var(--border); }
.bubble pre.code { background: var(--code-bg); border: 1px solid var(--border); padding: 10px; border-radius: 8px; margin: 8px 0; overflow-x: auto; white-space: pre; }
.bubble code { background: var(--code-bg); padding: 1px 4px; border-radius: 4px; }
.tool { font-size: 13px; }
.tool.call code { color: var(--muted); }
.tool.call::before { content: "⚙ "; color: var(--muted); }
details.tool pre, details.thinking pre { background: var(--code-bg); padding: 8px; border-radius: 6px; max-height: 300px; overflow: auto; margin-top: 4px; }
details.tool summary, details.thinking summary { color: var(--muted); font-size: 12px; }
details.tool.err summary { color: var(--err); }
details.thinking pre { font-family: inherit; font-size: 13px; color: var(--muted); }
.composer { border-top: 1px solid var(--border); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.composer textarea { width: 100%; }
.composer-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.composer-actions #status { flex: 1; }
.empty { margin: auto; text-align: center; padding: 40px; }
.chat > .flash, .chat > p { margin: 0 12px 12px; }
ul.tree { list-style: none; padding: 0; margin: 8px 0; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
ul.tree li { padding: 1px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
ul.tree .dir { color: var(--muted); }
dialog { width: min(1000px, 92vw); max-height: 85vh; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 16px; }
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog pre.code { background: var(--code-bg); padding: 12px; border-radius: 8px; max-height: 65vh; overflow: auto; white-space: pre; margin: 10px 0; }
dialog form { text-align: right; }
