:root {
  --bg: #0E1014; --side: #12151B; --panel: #161A21; --raised: #1C212A; --hover: #1A1E26;
  --line: #232833; --line2: #2C3340;
  --text: #E6E8EB; --soft: #C9CED6; --muted: #AEB5BF; --dim: #8B939E; --off: #4A5260;
  --accent: #8AB4F8; --accent-hi: #B3CEFB; --accent-bg: #151B26; --accent-line: #3A4A66;
  --amber: #E5B567; --amber-bg: #1D1A14; --amber-line: #5C4A2A; --amber-chip: #3A3020;
  --green: #7FD18B;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 14px; line-height: 1.5; }
a { color: var(--accent); } a:hover { color: var(--accent-hi); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--mono); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.loading { margin: auto; color: var(--muted); }

.app { height: 100vh; display: flex; flex-wrap: wrap; overflow: hidden; }
.side { flex: 1 1 248px; max-width: 280px; height: 100%; overflow-y: auto; padding: 16px 12px;
  display: flex; flex-direction: column; gap: 20px; background: var(--side); border-right: 1px solid var(--line); }
.main { flex: 999 1 560px; min-width: 0; height: 100%; display: flex; flex-direction: column; overflow: hidden; }
@media (max-width: 820px) {
  .app { height: auto; overflow: visible; }
  .side { max-width: none; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .main { height: auto; min-height: 100vh; }
}

/* sidebar */
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; font-weight: 600; font-size: 15px; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--bg);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 11px; flex-shrink: 0; }
.newtask { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; border-radius: 8px;
  border: 1px solid var(--line2); background: transparent; font-weight: 500; }
.newtask:hover { background: var(--hover); }
.navlist { display: flex; flex-direction: column; gap: 2px; }
.nav { display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 4px 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); text-align: left; width: 100%; }
.nav:hover { background: var(--hover); }
.nav.on { background: var(--raised); color: var(--text); }
.nav .grow { flex-grow: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--amber); color: var(--bg);
  font-size: 12px; font-weight: 600; text-align: center; }
.label { padding: 0 10px 4px; font-size: 12px; font-weight: 600; letter-spacing: .6px; text-transform: uppercase; color: var(--dim); }
.mate { min-height: 44px; }
.mate .who { display: flex; flex-direction: column; min-width: 0; flex-grow: 1; }
.mate .who b { font-weight: 500; color: var(--text); }
.mate .who span { font-family: var(--mono); font-size: 12px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 4px; background: var(--off); flex-shrink: 0; }
.dot.blue { background: var(--accent); } .dot.green { background: var(--green); } .dot.amber { background: var(--amber); }
.dot.pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.foot { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px;
  background: var(--panel); font-size: 12px; color: var(--muted); }
.switch { margin-left: auto; position: relative; width: 36px; height: 20px; border-radius: 10px; border: 0;
  background: var(--off); flex-shrink: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 7px;
  background: var(--text); transition: left .15s; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { left: 19px; background: var(--bg); }

/* common */
.btn { min-height: 40px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line2); background: transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.primary { border: 0; background: var(--accent); color: var(--bg); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hi); }
.btn.warn { border: 0; background: var(--amber); color: var(--bg); font-weight: 600; }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .45; cursor: default; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input { min-height: 40px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line2);
  background: var(--panel); color: var(--text); font-size: 14px; }
textarea.input { resize: vertical; }
.chip { padding: 2px 8px; border-radius: 6px; background: var(--raised); color: var(--soft); font-size: 12px; }
.chip.sub { background: #24324A; color: var(--accent-hi); }
.chip.api { background: #2A2F38; color: var(--soft); }
.chip.local { background: #203528; color: #A6E0AE; }
.chip.tool { background: var(--amber-chip); color: var(--amber); font-family: var(--mono); }
.page { flex-grow: 1; overflow-y: auto; padding: 32px 40px; display: flex; flex-direction: column; gap: 22px; }
@media (max-width: 820px) { .page { padding: 24px 16px; } }
.page h1 { margin: 0; font-size: 22px; font-weight: 600; }
.page .sub { margin: 4px 0 0; color: var(--muted); }
.pagehead { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; }
.pagehead .end { margin-left: auto; display: flex; gap: 8px; }
.h2 { margin: 6px 0 0; font-size: 12px; font-weight: 600; letter-spacing: .6px; text-transform: uppercase; color: var(--dim); }
.card { border: 1px solid var(--line); background: var(--side); border-radius: 12px; padding: 16px;
  display: flex; flex-direction: column; gap: 10px; }
.empty { color: var(--dim); padding: 24px; text-align: center; border: 1px dashed var(--line2); border-radius: 12px; }
pre.code { margin: 0; padding: 12px; border-radius: 8px; background: var(--bg); color: var(--soft);
  font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.row .end { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* chat */
.chathead { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 24px; border-bottom: 1px solid var(--line); }
.chathead h1 { margin: 0; font-size: 15px; font-weight: 600; max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slash { color: var(--off); }
.agentsel { min-height: 36px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--line2); background: var(--panel); }
.picker { position: relative; }
.modelbtn { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 10px 0 12px; border-radius: 8px;
  border: 1px solid var(--line2); background: var(--panel); }
.modelbtn .mono { font-size: 13px; }
.menu { position: absolute; top: 44px; left: 0; z-index: 20; width: 400px; max-width: 86vw; max-height: 70vh; overflow-y: auto;
  padding: 8px; border-radius: 12px; border: 1px solid var(--line2); background: var(--panel); box-shadow: 0 16px 40px rgba(0,0,0,.5); }
.menu .label { padding: 10px 10px 4px; display: flex; align-items: center; }
.opt { width: 100%; display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 10px; border: 0;
  border-radius: 8px; background: transparent; text-align: left; }
.opt:hover { background: #1E232C; } .opt.on { background: #1F2735; }
.opt .who { display: flex; flex-direction: column; flex-grow: 1; min-width: 0; }
.opt .who .mono { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opt .who span:last-child { font-size: 12px; color: var(--dim); }
.opt .st { font-size: 12px; } .ok { color: var(--green); } .no { color: var(--amber); }
.custom { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); margin-top: 6px; }
.custom .input { flex-grow: 1; min-height: 36px; font-family: var(--mono); font-size: 13px; }
.headend { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }

.thread { flex-grow: 1; overflow-y: auto; padding: 32px 24px; }
.thread .inner { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }
.you { align-self: flex-end; max-width: 80%; padding: 12px 16px; border-radius: 14px 14px 4px 14px; background: var(--raised);
  white-space: pre-wrap; word-break: break-word; }
.turn { display: flex; gap: 12px; }
.turn .body { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.turn .who { font-size: 12px; color: var(--dim); }
.reply { word-break: break-word; }
.reply p { margin: 0 0 10px; } .reply p:last-child { margin: 0; }
.reply code { font-family: var(--mono); font-size: 12.5px; background: var(--raised); padding: 1px 5px; border-radius: 4px; }
.reply pre { margin: 0 0 10px; padding: 12px; border-radius: 8px; background: var(--side); overflow-x: auto; }
.reply pre code { background: none; padding: 0; }
.thought { color: var(--muted); white-space: pre-wrap; }
.steps { margin: 0; padding: 0; list-style: none; border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  font-family: var(--mono); font-size: 13px; }
.steps li + li { border-top: 1px solid var(--line); }
.steps details { background: var(--side); }
.steps summary { display: flex; align-items: center; gap: 10px; padding: 9px 12px; cursor: pointer; list-style: none; }
.steps summary::-webkit-details-marker { display: none; }
.steps .name { color: var(--text); flex-shrink: 0; }
.steps .det { color: var(--dim); flex-grow: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.steps pre { margin: 0; padding: 10px 12px 12px 36px; color: var(--muted); white-space: pre-wrap; word-break: break-word;
  max-height: 260px; overflow: auto; font-size: 12px; }
.ask { border: 1px solid var(--amber-line); background: var(--amber-bg); border-radius: 12px; padding: 16px;
  display: flex; flex-direction: column; gap: 12px; }
.ask .title { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--amber); }
.ask .path { font-family: var(--mono); font-size: 13px; color: var(--muted); word-break: break-all; }
.decided { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.err { border: 1px solid var(--amber-line); background: var(--amber-bg); color: var(--amber); border-radius: 10px;
  padding: 12px 14px; white-space: pre-wrap; word-break: break-word; }
.working { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.hello { margin: 12vh auto 0; max-width: 560px; text-align: center; display: flex; flex-direction: column; gap: 16px; align-items: center; }
.hello h2 { margin: 0; font-size: 22px; font-weight: 600; }
.hello .ideas { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.composer { padding: 12px 24px 20px; }
.composer .box { max-width: 780px; margin: 0 auto; border: 1px solid var(--line2); border-radius: 14px; background: var(--panel);
  padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.composer textarea { resize: none; border: 0; background: transparent; outline: none; min-height: 44px; max-height: 240px; }
.composer .hint { font-size: 12px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1 1 200px; }

/* routines */
.split { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.split > .left { flex: 1 1 340px; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.split > .right { flex: 2 1 460px; min-width: 0; }
.rcard { cursor: pointer; text-align: left; }
.rcard.on { border-color: var(--accent-line); background: var(--accent-bg); }
.rcard h2 { margin: 0; font-size: 15px; font-weight: 600; flex-grow: 1; }
.runs { display: flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 12px; background: var(--side); }
.runs .head { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.runs .head h2 { margin: 0; font-size: 15px; }
.runs ol { flex: 1 1 190px; margin: 0; padding: 8px; list-style: none; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 2px; max-height: 60vh; overflow-y: auto; }
.runs .doc { flex: 3 1 300px; min-width: 0; padding: 18px 22px; max-height: 60vh; overflow-y: auto; }
.runitem { width: 100%; display: flex; justify-content: space-between; gap: 8px; min-height: 40px; align-items: center;
  padding: 0 10px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); }
.runitem.on { background: var(--raised); color: var(--text); }

/* table */
.tablebox { border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }
table { width: 100%; min-width: 560px; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 16px; font-weight: 500; color: var(--dim); }
td { padding: 12px 16px; border-top: 1px solid var(--line); }

/* settings */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tab { min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line2); background: transparent; color: var(--muted); }
.tab.on { background: var(--raised); color: var(--text); border-color: var(--accent-line); }
.kinds { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 560px) { .kinds { grid-template-columns: 1fr; } }
.kind { display: flex; flex-direction: column; gap: 2px; padding: 12px; border-radius: 10px; border: 1px solid var(--line2);
  background: var(--side); cursor: pointer; }
.kind.on { border-color: var(--accent); background: var(--accent-bg); }
.kind b { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.kind span { font-size: 12px; color: var(--muted); }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); cursor: pointer; }
.choice.on { border-color: var(--accent-line); background: var(--accent-bg); }
.choice span span { color: var(--muted); }
input[type=radio], input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }
.conn { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; min-height: 36px; }
.conn .grow { flex-grow: 1; }
.conn form { flex-basis: 100%; display: flex; gap: 6px; }
.conn form .input { flex-grow: 1; min-height: 36px; }

/* modal + toast */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 50; }
.dialog { width: 520px; max-width: 100%; max-height: 90vh; overflow-y: auto; border-radius: 14px; border: 1px solid var(--line2);
  background: var(--panel); padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.dialog h2 { margin: 0; font-size: 17px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); max-width: 80vw; padding: 10px 16px;
  border-radius: 10px; background: var(--raised); border: 1px solid var(--line2); box-shadow: 0 8px 30px rgba(0,0,0,.4);
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60; white-space: pre-wrap; }
.toast.show { opacity: 1; }
.spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line2); border-top-color: var(--accent);
  animation: spin .8s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* live text, history, skills, MCP */
.caret { display: inline-block; width: 7px; height: 15px; margin-left: 2px; vertical-align: -2px; background: var(--accent);
  animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.live .reply p:last-of-type { display: inline; }
.working .tail { flex: 1 1 200px; min-width: 0; color: var(--dim); font-style: italic; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
.hist { cursor: pointer; }
.hist:hover { border-color: var(--line2); background: var(--panel); }
.hist h2 { margin: 0; font-size: 15px; font-weight: 600; flex-grow: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview { margin: 0; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.dialog.wide { width: 680px; }
input[type=search].input { max-width: 520px; }
.stack { display: flex; flex-direction: column; gap: 22px; }
.stack:empty { display: none; }

/* import dialog */
.implist { display: flex; flex-direction: column; gap: 10px; max-height: 52vh; overflow-y: auto; padding-right: 4px; }
.implist > * { flex: none; }
.imphead { margin: 6px 0 0; font-size: 12px; font-weight: 600; letter-spacing: .6px; text-transform: uppercase; color: var(--dim); }
.impgroup { margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.impgroup legend { display: block; float: left; width: 100%; box-sizing: border-box; padding: 10px 12px; background: var(--side); font-weight: 600; font-size: 13px; }
.impgroup legend label { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.imp { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-top: 1px solid var(--line); cursor: pointer; clear: both; }
.imp:hover { background: var(--raised); }
.imp input, .impgroup legend input { margin-top: 3px; accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.impbody { display: flex; flex-direction: column; gap: 3px; min-width: 0; font-size: 13px; }
.impbody .mono { font-size: 13px; }
.impdesc { color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
