:root {
  --bg: #f6f6f4; --panel: #ffffff; --side: #efeeea; --line: #e2e0da; --text: #1d1d1b; --dim: #6f6e69;
  --accent: #3b5bdb; --accent-ink: #ffffff; --me: #e7ecff; --warn: #b7791f; --bad: #c92a2a; --good: #2b8a3e;
  --radius: 12px; --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #161615; --panel: #1f1f1d; --side: #1a1a18; --line: #32312d; --text: #ecebe6; --dim: #9a9892;
          --accent: #748ffc; --accent-ink: #10121c; --me: #2a3154; --warn: #e0a84a; --bad: #ff8787; --good: #69db7c; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
[hidden] { display: none !important; }
.dim { color: var(--dim); }
.spacer { flex: 1; }
.error { color: var(--bad); margin: 0; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 18px; } h3 { font-size: 14px; margin-top: 18px; }

/* controls */
.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 8px 14px;
       border-radius: 9px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--dim); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.link { font: inherit; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }
.icon-btn { font: inherit; background: none; border: 0; color: var(--dim); cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--line); }
input, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 9px;
                  padding: 9px 11px; width: 100%; }
input:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: grid; gap: 5px; font-size: 13px; color: var(--dim); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* auth */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
             padding: 28px; display: grid; gap: 14px; }
.brand { font-weight: 700; letter-spacing: -.01em; font-size: 17px; }
.auth-card .brand { font-size: 24px; }
.auth-sub { margin: -8px 0 4px; color: var(--dim); }
.tabs { display: flex; gap: 4px; background: var(--side); padding: 3px; border-radius: 10px; }
.tab { flex: 1; font: inherit; border: 0; background: none; color: var(--dim); padding: 6px; border-radius: 8px; cursor: pointer; }
.tab.is-on { background: var(--panel); color: var(--text); font-weight: 600; }

/* layout */
.app { height: 100%; display: grid; grid-template-columns: 260px minmax(0, 1fr); }
.app.with-computer { grid-template-columns: 260px minmax(320px, 1fr) minmax(360px, 46%); }
.sidebar { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px; }
.bots { flex: 1; overflow-y: auto; padding: 4px 8px; display: grid; gap: 2px; align-content: start; }
.bot { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; cursor: pointer; border: 0;
       background: none; color: inherit; font: inherit; text-align: left; width: 100%; }
.bot:hover { background: var(--line); }
.bot.is-on { background: var(--panel); box-shadow: 0 0 0 1px var(--line); }
.bot-text { min-width: 0; flex: 1; display: grid; }
.bot-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bot-sub { font-size: 12px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); flex: none; }
.badge.needs { background: var(--warn); }
.avatar { --c: var(--accent); width: 34px; height: 34px; border-radius: 10px; background: var(--c); color: #fff; flex: none;
          display: grid; place-items: center; font-weight: 700; position: relative; }
.avatar.working::after { content: ""; position: absolute; inset: -3px; border-radius: 13px; border: 2px solid var(--c);
                         opacity: .6; animation: ring 1.4s ease-out infinite; }
.avatar.needs::before { content: "!"; position: absolute; right: -5px; top: -5px; width: 16px; height: 16px; border-radius: 50%;
                        background: var(--warn); color: #fff; font-size: 11px; display: grid; place-items: center; }
@keyframes ring { from { transform: scale(.9); opacity: .7; } to { transform: scale(1.15); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .avatar.working::after, .pulse { animation: none !important; } }
.sidebar-foot { border-top: 1px solid var(--line); padding: 12px 14px; display: grid; gap: 10px; font-size: 13px; }
.usage-row { display: flex; justify-content: space-between; }
.meter { height: 5px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 4px 0; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); }
.account { display: flex; justify-content: space-between; gap: 8px; }
.account span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* chat */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.head-text { display: grid; min-width: 0; flex: 1; line-height: 1.25; overflow: hidden; }
.head-text strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-text span { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--dim); margin-right: 6px; }
.dot.on { background: var(--good); }
.timeline { flex: 1; overflow-y: auto; padding: 18px 16px 8px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: min(720px, 86%); padding: 9px 13px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line);
       overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--me); border-color: transparent; }
.msg p { margin: 0 0 .6em; } .msg p:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: 0 0 .6em 1.2em; padding: 0; }
.msg code { font: 13px var(--mono); background: var(--side); padding: 1px 5px; border-radius: 5px; }
.msg pre { font: 13px/1.45 var(--mono); background: var(--side); padding: 10px; border-radius: 8px; overflow-x: auto; margin: 0 0 .6em; }
.msg pre code { background: none; padding: 0; }
.msg a { color: var(--accent); }
.msg.streaming { opacity: .85; }
.msg.streaming > :last-child::after { content: "▍"; color: var(--dim); animation: pulse 1s steps(2) infinite; margin-left: 2px; }
.msg.typing { display: flex; gap: 5px; align-items: center; padding: 13px 14px; }
.msg.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--dim); animation: bounce 1.2s ease-in-out infinite; }
.msg.typing i:nth-child(2) { animation-delay: .15s; } .msg.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-5px); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .msg.typing i, .msg.streaming > :last-child::after { animation: none; } }
.line { align-self: center; font-size: 13px; color: var(--dim); text-align: center; max-width: 80%; }
.line.warn { color: var(--warn); } .line.error { color: var(--bad); }
.handoff { align-self: flex-start; font-size: 13px; color: var(--dim); border-left: 3px solid var(--line); padding: 2px 10px; max-width: min(720px, 86%); }
.handoff b { color: var(--text); font-weight: 600; }
.card { align-self: flex-start; max-width: min(620px, 92%); border: 1px solid var(--line); border-left: 4px solid var(--warn);
        background: var(--panel); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 8px; }
.card.settled { border-left-color: var(--line); }
.card-title { font-weight: 600; }
.card-detail { font: 13px var(--mono); background: var(--side); border-radius: 8px; padding: 8px; overflow-wrap: anywhere; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--side); color: var(--dim); }
.pill.good { color: var(--good); } .pill.bad { color: var(--bad); } .pill.warn { color: var(--warn); }
details.steps { align-self: flex-start; font-size: 13px; color: var(--dim); }
details.steps summary { cursor: pointer; }
details.steps ol { margin: 6px 0 0 1.4em; padding: 0; }
details.steps li.failed { color: var(--bad); }
.statusline { display: flex; align-items: center; gap: 10px; padding: 6px 16px; font-size: 13px; color: var(--dim); }
.statusline #status-text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s ease-in-out infinite; flex: none; }
@keyframes pulse { 50% { opacity: .25; } }
.composer { display: flex; gap: 10px; padding: 10px 16px 16px; align-items: flex-end; }
.composer textarea { resize: none; max-height: 200px; }

/* computer panel */
.computer { border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.computer-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.screen { flex: 1; min-height: 0; background: #101010; display: grid; place-items: center; color: #bbb; overflow: hidden; position: relative; }
.screen.controlled { outline: 3px solid var(--warn); outline-offset: -3px; }
.screen > div { position: absolute; inset: 0; }
.screen .placeholder { display: grid; gap: 12px; place-items: center; align-content: center; text-align: center; padding: 24px; }
.computer-note { margin: 0; padding: 8px 12px; font-size: 12px; }

.field { display: grid; gap: 6px; font-size: 13px; }
.icons { display: grid; grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 4px; }
.icons button { font-size: 19px; line-height: 1; padding: 7px 0; border: 1px solid transparent; border-radius: 9px; background: var(--side); cursor: pointer; color: var(--text); }
.icons button.is-on { border-color: var(--accent); background: var(--me); }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatches button { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; background: var(--c); }
.swatches button.is-on { border-color: var(--text); box-shadow: 0 0 0 2px var(--panel) inset; }
.avatar.has-icon { font-size: 18px; font-weight: 400; }

/* dialogs */
.dialog { border: 1px solid var(--line); border-radius: 16px; padding: 0; background: var(--panel); color: var(--text);
          width: min(560px, calc(100% - 32px)); max-height: calc(100% - 48px); }
.dialog::backdrop { background: rgba(0, 0, 0, .35); }
.dialog-body { padding: 20px; display: grid; gap: 10px; }
.dialog-body header { display: flex; justify-content: space-between; align-items: center; }
.dialog-body p { margin: 0; font-size: 13px; }
.routines { display: grid; gap: 8px; }
.routine { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; display: grid; gap: 4px; font-size: 13px; }
.routine .row { justify-content: space-between; }

.only-narrow { display: none; }
@media (max-width: 860px) {
  .app, .app.with-computer { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 30% 0 0; z-index: 5; transform: translateX(-100%); transition: transform .15s; }
  .app.show-bots .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .3); }
  .computer { position: fixed; inset: 0; z-index: 6; }
  .only-narrow { display: inline-block; }
}
