:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1e222b; --line: #2a2f3a; --text: #e6e8ee; --muted: #8b93a7;
  --accent: #7c9cff; --accent-dim: #3b4a7a; --ok: #5bc48a; --warn: #e0b45a; --bad: #e07a7a; --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; cursor: pointer; }
button:active { filter: brightness(1.2); }
button.primary { background: var(--accent); color: #0b0e16; border-color: transparent; font-weight: 600; }
button.stop { background: #3a2226; border-color: #5a2f35; color: #ffb4b4; }
button.small { padding: 8px 10px; }
button.wide { width: calc(100% - 24px); margin: 8px 12px 12px; }
button.icon { background: none; border: none; font-size: 28px; padding: 0 12px; line-height: 1; }
input, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
textarea { resize: none; max-height: 40vh; }
.muted { color: var(--muted); } .err { color: var(--bad); min-height: 1.4em; }

#login { display: flex; align-items: center; justify-content: center; min-height: 100%; padding: 24px; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 28px; text-align: center; display: grid; gap: 12px; }
.login-card h1 { margin: 0; font-size: 22px; font-weight: 600; } .logo { font-size: 44px; }

#app { display: flex; flex-direction: column; height: 100dvh; }
#topbar { display: flex; align-items: center; gap: 4px; padding: calc(10px + env(safe-area-inset-top)) 12px 10px; border-bottom: 1px solid var(--line); background: var(--bg); }
#title { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); } .dot.off { background: var(--bad); }
.view { flex: 1; overflow-y: auto; padding: 12px; -webkit-overflow-scrolling: touch; }
#view-chat { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
#view-screen { padding: 0; display: flex; flex-direction: column; }
#tabs { display: flex; border-top: 1px solid var(--line); background: var(--bg); padding-bottom: env(safe-area-inset-bottom); }
#tabs button { flex: 1; border: none; border-radius: 0; background: none; color: var(--muted); padding: 14px 4px; }
#tabs button.active { color: var(--text); box-shadow: inset 0 2px 0 var(--accent); }
#badge { background: var(--bad); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 12px; margin-left: 4px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.bot-row { display: flex; gap: 12px; align-items: center; cursor: pointer; }
.bot-row .emoji { font-size: 26px; width: 40px; height: 40px; display: grid; place-items: center; background: var(--panel2); border-radius: 12px; }
.bot-row .meta { flex: 1; min-width: 0; } .bot-row .name { font-weight: 600; }
.bot-row .job { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--panel2); color: var(--muted); }
.pill.work { background: #1f2d4f; color: var(--accent); } .pill.wait { background: #43361a; color: var(--warn); }
h3.section { margin: 18px 4px 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }

#messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 92%; padding: 10px 13px; border-radius: 16px; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent-dim); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg p { margin: 0 0 8px; } .msg p:last-child { margin: 0; } .msg ul, .msg ol { margin: 4px 0 8px 18px; padding: 0; }
.msg pre { background: #0b0d12; border: 1px solid var(--line); border-radius: 8px; padding: 8px; overflow-x: auto; font-size: 13px; }
.msg code { background: #0b0d12; padding: 1px 5px; border-radius: 5px; font-size: .92em; }
.msg pre code { background: none; padding: 0; }
.msg a { color: var(--accent); } .msg img { max-width: 100%; border-radius: 10px; margin-top: 6px; }
.tool { align-self: flex-start; font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: baseline; padding: 2px 6px; max-width: 95%; }
.tool .ic { width: 14px; text-align: center; } .tool.running .ic { color: var(--accent); } .tool.error .ic, .tool.denied .ic, .tool.blocked .ic { color: var(--bad); } .tool.ok .ic { color: var(--ok); }
.tool img { display: block; max-width: 220px; border-radius: 8px; margin-top: 4px; border: 1px solid var(--line); }
.notice { align-self: center; font-size: 13px; color: var(--muted); background: var(--panel); border-radius: 10px; padding: 6px 12px; text-align: center; }
.notice.warn { color: var(--warn); } .notice.error { color: var(--bad); }
.notice.cmd { align-self: stretch; text-align: left; font-size: 14px; color: var(--text); border-left: 3px solid var(--accent); border-radius: 8px; padding: 8px 12px; }
.notice.cmd p { margin: 2px 0; } .notice.cmd ul, .notice.cmd ol { margin: 4px 0; padding-left: 20px; }
#cmdlist { margin: 0 12px 6px; background: var(--panel2, var(--panel)); border: 1px solid var(--line); border-radius: 12px; overflow: auto; max-height: 38vh; }
#cmdlist button { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); color: var(--text); padding: 10px 12px; font: inherit; font-size: 14px; }
#cmdlist button:last-child { border-bottom: 0; } #cmdlist button:active, #cmdlist button.sel { background: var(--accent-soft, rgba(124,156,255,.15)); }
#cmdlist b { display: block; } #cmdlist span { color: var(--muted); font-size: 13px; }
.chat-status { padding: 6px 14px; font-size: 13px; color: var(--accent); background: #141a2b; border-bottom: 1px solid var(--line); }
#composer { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); align-items: flex-end; background: var(--bg); }
#chat-approvals { padding: 0 12px; }
.approval { border-color: #54421c; background: #1d1910; }
.approval.q { border-color: #28406e; background: #111a2c; }
.approval h4 { margin: 0 0 6px; font-size: 15px; } .approval .row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.approval pre { white-space: pre-wrap; background: #0b0d12; border-radius: 8px; padding: 8px; font-size: 13px; max-height: 160px; overflow: auto; }
.screen-bar { display: flex; gap: 6px; padding: 8px 10px; } .screen-bar input { flex: 1; min-width: 0; }
.screen-wrap { flex: 1; overflow: auto; background: #000; display: grid; place-items: start center; touch-action: manipulation; }
.screen-wrap img { width: 100%; height: auto; display: block; }
#toast { position: fixed; top: calc(10px + env(safe-area-inset-top)); left: 12px; right: 12px; z-index: 50; display: grid; gap: 8px; pointer-events: none; }
#toast .t { pointer-events: auto; background: #202534; border: 1px solid var(--accent-dim); border-radius: 12px; padding: 10px 14px; box-shadow: 0 6px 24px #0008; }
#toast .t b { display: block; }
