/* ClankaBox web UI. Same layout as the terminal UI: title bar, chat with the message box
   under it, a 40-column sidebar (vitals, or the sub-clanker boxes while any run), and a
   footer line for status and key hints. Everything else opens as a modal. */
:root {
  --bg: #121418;
  --bg-2: #171a1f;
  --panel: #1b1f25;
  --raise: #232831;
  --line: #2b313b;
  --line-soft: #22272f;
  --fg: #e6e8eb;
  --fg-2: #b6bdc6;
  --dim: #8d96a1;
  --accent: #5865f2;   /* Discord blurple */
  --accent-ink: #ffffff;
  --accent-soft: #1d2042;
  --accent-line: #3c4499;
  --think: #c3b5ff;
  --think-soft: #1d1a2b;
  --think-line: #3e3566;
  --tool: #5bb8d6;
  --ok: #5bc88a;
  --ok-line: #2f6046;
  --mid: #e8c75a;
  --warn: #f0b75a;
  --pace: #f0b75a;     /* the vitals' pace word at "cruising" */
  --err: #ff9e97;
  --err-soft: #3a1f1f;
  --err-line: #7a3434;
  --user: #8fc1ff;
  --code-bg: #0f1215;
  --font-ui: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --r: 6px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f5f7; --bg-2: #eceef1; --panel: #ffffff; --raise: #f0f2f5; --line: #d5dae1; --line-soft: #e4e7ec;
    --fg: #191c21; --fg-2: #3d444e; --dim: #5d6672; --accent: #4752c4; --accent-ink: #ffffff; --accent-soft: #eceefe;
    --accent-line: #b6bcf7; --think: #5a3fc0; --think-soft: #f1edff; --think-line: #cfc3f5; --tool: #0b6f8f;
    --ok: #1d7a4a; --ok-line: #9fd2b5; --mid: #8a6a00; --warn: #9a5c00; --pace: #9a5c00; --err: #b3261e; --err-soft: #fdecea;
    --err-line: #f0b4ae; --user: #1f5fb3; --code-bg: #f6f7f9; color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f4f5f7; --bg-2: #eceef1; --panel: #ffffff; --raise: #f0f2f5; --line: #d5dae1; --line-soft: #e4e7ec;
  --fg: #191c21; --fg-2: #3d444e; --dim: #5d6672; --accent: #4752c4; --accent-ink: #ffffff; --accent-soft: #eceefe;
  --accent-line: #b6bcf7; --think: #5a3fc0; --think-soft: #f1edff; --think-line: #cfc3f5; --tool: #0b6f8f;
  --ok: #1d7a4a; --ok-line: #9fd2b5; --mid: #8a6a00; --warn: #9a5c00; --pace: #9a5c00; --err: #b3261e; --err-soft: #fdecea;
  --err-line: #f0b4ae; --user: #1f5fb3; --code-bg: #f6f7f9; color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.5 var(--font-ui); }
button, input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: var(--font-mono); }
.dim { color: var(--dim); }
.spacer { flex: 1 1 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 11px;
  background: var(--raise); border: 1px solid var(--line); border-radius: var(--r);
  cursor: pointer; white-space: nowrap; font-size: 13px; font-weight: 500;
}
.btn:hover { border-color: var(--dim); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.sm { min-height: 26px; padding: 0 8px; font-size: 12px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { background: var(--err-soft); border-color: var(--err-line); color: var(--err); }
.btn.on { border-color: var(--accent-line); color: var(--accent); background: var(--accent-soft); }
.ibtn {
  display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px;
  background: transparent; border: 1px solid transparent; border-radius: var(--r); color: var(--dim); cursor: pointer;
}
.ibtn:hover { background: var(--raise); color: var(--fg); }
.ibtn svg, .btn svg, .attach svg { width: 15px; height: 15px; flex: none; }
.tag {
  font: 600 10.5px/1 var(--font-ui); letter-spacing: .05em; text-transform: uppercase;
  border: 1px solid var(--line); border-radius: 4px; padding: 3px 6px; white-space: nowrap; color: var(--dim);
}
.tag.ok { color: var(--ok); border-color: var(--ok-line); }
.tag.warn { color: var(--warn); border-color: var(--accent-line); }
.tag.pend { color: var(--warn); border-style: dashed; border-color: var(--accent-line); }
.tag.err { color: var(--err); border-color: var(--err-line); }
.tag.tool { color: var(--tool); border-color: var(--line); }

/* ── shell ── */
.app { display: flex; flex-direction: column; height: 100%; }
.titlebar {
  display: grid; grid-template-columns: 1fr auto 1fr auto; align-items: center; gap: 8px; flex: none;
  padding: 3px 12px; background: var(--accent); color: var(--accent-ink); font: 600 13px var(--font-mono);
  transition: background-color .35s, color .35s;
}
/* while the model works: the bar goes dark and a soft green glow sweeps across it,
   painted into the bar's own background (no overlay, no extra line) */
.titlebar.busy {
  background-color: #101317; color: #d7dde4;
  background-image: linear-gradient(90deg, rgba(91,200,138,0) 0%, rgba(91,200,138,.32) 50%, rgba(91,200,138,0) 100%);
  background-size: 35% 100%; background-repeat: no-repeat;
  animation: sweep 2.4s ease-in-out infinite;
}
.titlebar.busy .badge { background: #5bc88a; color: #0d1a12; }
@keyframes sweep { from { background-position: -60% 0; } to { background-position: 160% 0; } }
@media (prefers-reduced-motion: reduce) { .titlebar.busy { animation: none; background-image: none; } }
.titlebar .left { justify-self: start; background: none; border: 0; padding: 0; cursor: pointer; font: inherit; color: inherit; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.titlebar .badge { background: var(--accent-ink); color: var(--accent); padding: 0 8px; border-radius: 3px; }
.titlebar .right { justify-self: end; white-space: nowrap; }
.strip { flex: none; display: none; padding: 2px 12px; font: 12px var(--font-mono); color: var(--dim); border-bottom: 1px solid var(--line); overflow-x: auto; white-space: nowrap; }
.app.nodash .strip { display: block; }
.body { display: flex; flex: 1 1 auto; min-height: 0; }
.chatcol { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.side { flex: 0 0 360px; min-width: 0; overflow-y: auto; border-left: 1px solid var(--line); padding: 8px 14px 14px; font: 12.5px/1.55 var(--font-mono); }
.app.nodash .side { display: none; }
.footer { flex: none; display: flex; align-items: center; gap: 4px; padding: 3px 10px; border-top: 1px solid var(--line); font: 12px var(--font-mono); color: var(--dim); min-height: 28px; overflow-x: auto; white-space: nowrap; }
.footer .hint { background: none; border: 0; padding: 0 4px; cursor: pointer; color: var(--dim); font: inherit; }
.footer .hint b { color: var(--accent); font-weight: 500; }
.footer .hint:hover { color: var(--fg); }
@media (max-width: 900px) {
  .body { flex-direction: column; overflow-y: auto; }
  .chatcol { min-height: 75vh; }
  .side { flex: none; border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
}

/* ── sidebar (vitals, as in the terminal) ── */
.vt { color: var(--accent); font-weight: 600; letter-spacing: .3em; margin: 2px 0 4px; }
.vsec { color: var(--accent); margin: 10px 0 2px; border-bottom: 1px solid var(--line); }
.vrow { display: flex; gap: 6px; align-items: center; white-space: nowrap; overflow: hidden; }
.vk { flex: 0 0 52px; color: var(--dim); }
.bar { flex: 1 1 auto; height: 8px; background: var(--line); border-radius: 2px; overflow: hidden; display: flex; }
.bar > span { display: block; height: 100%; }
.c-ok { color: var(--ok); } .c-mid { color: var(--mid); } .c-hi { color: var(--err); } .c-acc { color: var(--accent); } .c-think { color: var(--think); } .c-warn { color: var(--warn); }
.bg-ok { background: var(--ok); } .bg-mid { background: var(--mid); } .bg-hi { background: var(--err); } .bg-acc { background: var(--accent); } .bg-think { background: var(--think); } .bg-ans { background: var(--user); }
.spark { width: 100%; height: 28px; display: block; }
.subbox { border-bottom: 1px solid var(--line); padding: 6px 0; cursor: pointer; }
.subbox .head { display: flex; gap: 6px; align-items: center; }
.subbox .body { font-size: 12px; max-height: 9.5em; overflow: hidden; white-space: pre-wrap; margin: 4px 0; display: block; }
.subbox .acts { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }

/* ── transcript ── */
.transcript { flex: 1 1 auto; overflow-y: auto; padding-block: 14px; padding-inline: 16px; }
.transcript-inner { max-width: 960px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }
.msg { position: relative; border-radius: var(--r); padding: 8px 12px; border: 1px solid transparent; }
.msg.user { background: var(--panel); border-color: var(--line); }
.msg.error { background: var(--err-soft); border-color: var(--err-line); color: var(--err); }
.msg.sel { border-color: var(--accent-line); box-shadow: 0 0 0 1px var(--accent-line); }
.msghead { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 2px; }
.who { font-weight: 600; font-size: 13px; }
.who.user { color: var(--user); }
.who.assistant { color: var(--accent); }
.meta { font: 11px var(--font-mono); color: var(--dim); }
.msgacts { display: flex; gap: 2px; margin-left: auto; opacity: 0; transition: opacity .12s; }
.msg:hover .msgacts, .msg:focus-within .msgacts, .msg.sel .msgacts { opacity: 1; }
@media (hover: none) { .msgacts { opacity: 1; } }
.content { font-size: 15px; line-height: 1.6; overflow-wrap: anywhere; }
.content p { margin: 0 0 8px; }
.content p:last-child { margin-bottom: 0; }
.content code { font: 13px var(--font-mono); background: var(--raise); padding: 1px 5px; border-radius: 4px; }
.codeblock { background: var(--code-bg); border: 1px solid var(--line); border-radius: var(--r); margin: 8px 0; overflow: hidden; }
.codeblock .bar2 { display: flex; align-items: center; gap: 8px; padding: 3px 6px 3px 10px; border-bottom: 1px solid var(--line); font: 12px var(--font-mono); color: var(--dim); }
.codeblock pre { margin: 0; padding: 10px 12px; font: 13px/1.55 var(--font-mono); overflow-x: auto; }
.cursor { display: inline-block; width: .55em; height: 1.1em; vertical-align: text-bottom; background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.think-toggle { color: var(--think); background: var(--think-soft); border-color: var(--think-line); }
.thinking { margin: 6px 0; padding: 4px 12px; border-left: 2px solid var(--think-line); color: var(--think); font-size: 14px; white-space: pre-wrap; }
.attach { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; padding: 6px 10px; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r); font-size: 13px; }
.editbox textarea { width: 100%; min-height: 90px; background: var(--code-bg); border: 1px solid var(--line); border-radius: var(--r); padding: 8px 10px; font: 14px/1.5 var(--font-ui); resize: vertical; }
.editbox .row { display: flex; gap: 6px; margin-top: 6px; justify-content: flex-end; }
.toolgroup { display: flex; flex-direction: column; gap: 6px; border-left: 2px solid var(--line); margin-left: 6px; padding-left: 12px; }
.toolcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 6px 10px; }
.toolcard.pend { background: var(--accent-soft); border: 1px dashed var(--accent-line); }
.toolhead { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.toolname { font: 13px var(--font-mono); color: var(--tool); }
.toolargs { font: 12px var(--font-mono); color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1 1 120px; }
.toolnote { font-size: 13px; color: var(--fg-2); margin-top: 3px; }
.toolcard.pend .toolnote { color: var(--warn); }
.toolout { margin-top: 6px; background: var(--code-bg); border: 1px solid var(--line-soft); border-radius: 5px; padding: 8px 10px; font: 12px/1.55 var(--font-mono); white-space: pre-wrap; max-height: 240px; overflow: auto; color: var(--fg-2); }

/* ── message box ── */
.compose { border-top: 1px solid var(--line); padding-block: 8px; padding-inline: 16px; }
.compose .boxhead, .compose textarea, .compose .compose-row { max-width: 960px; margin-left: auto; margin-right: auto; }
.boxhead { display: flex; gap: 8px; font: 12px var(--font-mono); color: var(--accent); margin-bottom: 4px; }
.compose textarea { display: block; width: 100%; min-height: 64px; max-height: 40vh; resize: vertical; padding: 8px 10px; background: var(--code-bg); border: 1px solid var(--accent-line); border-radius: var(--r); font: 15px/1.5 var(--font-ui); }
.compose-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }

/* ── modals (the terminal's pop-up windows) ── */
.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / .5); z-index: 10; }
.modal {
  position: fixed; z-index: 11; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(1100px, calc(100% - 24px)); max-height: calc(100% - 32px); display: flex; flex-direction: column;
  background: var(--bg); border: 1px solid var(--accent-line); border-radius: 8px; box-shadow: 0 16px 50px rgb(0 0 0 / .45);
}
.modal.narrow { width: min(760px, calc(100% - 24px)); }
.modalhead { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.modalhead h1 { margin: 0; font: 600 14px var(--font-mono); color: var(--accent); }
.modalbody { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.card > .cardhead { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.card > .cardhead h2 { margin: 0; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.card > .cardbody { padding: 8px 12px; }
.queue { background: var(--accent-soft); border: 1px dashed var(--accent-line); border-radius: 8px; padding: 8px 12px; }
.qrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; }
.split { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; }
.split > .grow { flex: 999 1 540px; min-width: 0; }
.split > .side2 { flex: 1 1 320px; min-width: 0; }
.tablewrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th { text-align: left; font-size: 10.5px; font-weight: 600; letter-spacing: .08em; color: var(--dim); padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; text-transform: uppercase; }
table.grid td { padding: 6px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.grid tr.selrow td { background: var(--raise); }
table.grid tr.clickable { cursor: pointer; }
table.grid .acts { text-align: right; white-space: nowrap; }
table.grid .acts .btn + .btn { margin-left: 4px; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.viewer { margin: 0; padding: 10px 12px; font: 12px/1.6 var(--font-mono); white-space: pre-wrap; max-height: 55vh; overflow: auto; color: var(--fg-2); }
.acts-row { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.form { display: flex; flex-direction: column; }
.frow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 6px 0; border-bottom: 1px solid var(--line-soft); }
.frow:last-child { border-bottom: none; }
.frow > label:first-child, .frow > .fl { flex: 0 0 180px; font-size: 13px; color: var(--fg-2); }
.ctl { min-height: 30px; padding: 0 8px; background: var(--code-bg); border: 1px solid var(--line); border-radius: var(--r); font-size: 13px; }
input[type="range"] { flex: 1 1 160px; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; min-height: 30px; }
.list { display: flex; flex-direction: column; gap: 6px; }
.listitem { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; cursor: pointer; }
.listitem.cur { border-color: var(--dim); background: var(--raise); }
.errbox { background: var(--err-soft); border: 1px solid var(--err-line); border-radius: var(--r); padding: 8px 10px; color: var(--err); font: 12px var(--font-mono); }
kbd { font: 12px var(--font-mono); color: var(--accent); white-space: nowrap; }
.confirm { position: fixed; z-index: 21; left: 50%; top: 30%; transform: translateX(-50%); width: min(420px, calc(100% - 32px)); background: var(--panel); border: 1px solid var(--accent-line); border-radius: 8px; padding: 14px; box-shadow: 0 10px 40px rgb(0 0 0 / .4); }
.confirm p { margin: 0 0 12px; }
.confirm .row { display: flex; gap: 8px; justify-content: flex-end; }

/* a random image from web/splash/ on an empty chat */
.splash { display: flex; justify-content: center; align-items: center; min-height: 50vh; }
.splash img { max-width: min(100%, 640px); max-height: 60vh; border-radius: 8px; box-shadow: 0 10px 40px rgb(0 0 0 / .35); }
.keyrow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; border-bottom: 1px solid var(--line); }
.keyrow input { flex: 1 1 240px; min-width: 0; }

/* files waiting to go with the next message, and the drop target */
.staged { display: flex; flex-wrap: wrap; gap: 6px; max-width: 960px; margin: 0 auto 6px; }
.staged:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 2px 2px 8px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); font-size: 12.5px; }
.chip svg { width: 14px; height: 14px; }
.dropzone { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; background: rgb(0 0 0 / .45); pointer-events: none; }
.dropzone[hidden] { display: none; }
.dropzone > div { padding: 28px 40px; border: 2px dashed var(--accent); border-radius: 12px; background: var(--bg); color: var(--accent); font: 600 16px var(--font-mono); }

/* account button (title bar) */
.titlebar .acct { background: none; border: 1px solid currentColor; border-radius: var(--r);
  color: inherit; font: 600 12px/1 var(--font-mono); padding: 3px 8px; cursor: pointer; max-width: 30ch; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.titlebar .acct:empty { display: none; }

/* gates: over the inert page while a chat isn't open to you */
.gate { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(3px); }
.gate[hidden] { display: none; }
.gatebox { display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: 560px; width: 100%; text-align: center; }
.gatebox h1 { margin: 0; font-size: 22px; }
.gatebox .row { display: flex; gap: 8px; width: 100%; max-width: 380px; }
.gatebox .row .ctl { flex: 1; min-width: 0; padding: 8px 10px; }
.gatebox .list { width: 100%; max-width: 380px; }
.gatebig { font-size: clamp(28px, 6vw, 46px); font-weight: 800; line-height: 1.15; }
.gateerr { min-height: 1.4em; color: var(--err); }
.btn.ghost { background: none; border-color: transparent; color: var(--dim); }

/* admin: Users screen */
.grantapi { border-left: 2px solid var(--line); padding-left: 10px; margin: 6px 0; }
.grantapi .frow { padding-left: 6px; }

/* profile pictures: hang off the left of each message, at its top corner; the column
   stays centered and keeps room on both sides for them */
.transcript-inner { width: min(960px, 100% - 104px); }
.msg .pfp { position: absolute; left: -50px; top: 0; width: 38px; height: 38px; border-radius: 8px;
  object-fit: cover; background: var(--raise); }
@media (max-width: 700px) {
  .transcript-inner { width: auto; margin-left: 50px; margin-right: 0; }
}
.pfprow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pfprow img { width: 48px; height: 48px; border-radius: 10px; object-fit: cover; background: var(--raise); }

/* vitals: the pace word, by speed - asleep, sloth, cruising, brisk, zooming, WARP */
.pace-0 { color: var(--dim); } .pace-1 { color: var(--err); } .pace-2 { color: var(--pace); }
.pace-3 { color: var(--ok); } .pace-4 { color: var(--user); }
.pace-5 { font-weight: 700; color: transparent; -webkit-background-clip: text; background-clip: text;
  background-image: linear-gradient(90deg, #ff5f5f, #ffb347, #ffe25f, #5fdc7a, #5fb8ff, #a77bff, #ff5fcf, #ff5f5f);
  background-size: 200% 100%; animation: warp 1.6s linear infinite; }
@keyframes warp { from { background-position: 0 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .pace-5 { animation: none; } }

/* status popups: anchored between the transcript and the message box, growing upward
   over the chat - they never change the size of anything */
.toastdock { position: relative; height: 0; z-index: 5; }
.toasts { position: absolute; left: 16px; right: 16px; bottom: 8px; display: flex; flex-direction: column;
  align-items: center; gap: 6px; pointer-events: none; }
.toast { pointer-events: auto; cursor: pointer; max-width: min(640px, 100%); padding: 6px 12px; border-radius: var(--r);
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent); color: var(--fg);
  font: 13px/1.4 var(--font-mono); box-shadow: 0 6px 22px rgb(0 0 0 / .35); overflow-wrap: anywhere;
  animation: toast-in .18s ease-out; transition: opacity .25s, transform .25s; }
.toast.ok { border-left-color: var(--ok); } .toast.warn { border-left-color: var(--warn); }
.toast.err { border-left-color: var(--err); color: var(--err); }
.toast.out { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; transition: none; } }
