:root,
[data-theme="dark"] {
  --bg: #08080a;
  --bg-soft: #0c0c10;
  --sidebar: #0b0b0e;
  --surface: #111115;
  --surface-2: #17171c;
  --surface-3: #1f1f26;
  --border: rgba(255, 255, 255, 0.075);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f4f4f5;
  --text-2: #b3b3bd;
  --text-3: #7a7a86;
  --accent: #a78bfa;
  --accent-2: #7c3aed;
  --accent-soft: rgba(167, 139, 250, 0.13);
  --ok: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;
  --info: #60a5fa;
  --code-bg: #0d0d11;
  --glow: rgba(124, 58, 237, 0.18);
  --glow-soft: rgba(124, 58, 237, 0.07);
  --brand-bg: #f4f4f5;
  --brand-fg: #08080a;
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, 0.55);
  --shadow-md: 0 10px 34px rgba(0, 0, 0, 0.32);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f6f6f3;
  --bg-soft: #ffffff;
  --sidebar: #efefeb;
  --surface: #ffffff;
  --surface-2: #f2f2ee;
  --surface-3: #e7e7e2;
  --border: rgba(20, 20, 24, 0.09);
  --border-strong: rgba(20, 20, 24, 0.17);
  --text: #151518;
  --text-2: #4b4b53;
  --text-3: #7f7f88;
  --accent: #6d28d9;
  --accent-2: #7c3aed;
  --accent-soft: rgba(109, 40, 217, 0.09);
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --info: #1d4ed8;
  --code-bg: #f2f2ed;
  --glow: rgba(124, 58, 237, 0.1);
  --glow-soft: rgba(124, 58, 237, 0.045);
  --brand-bg: #151518;
  --brand-fg: #ffffff;
  --shadow-lg: 0 24px 70px rgba(20, 20, 24, 0.16);
  --shadow-md: 0 10px 34px rgba(20, 20, 24, 0.1);
  color-scheme: light;
}

*,
*::before,
*::after { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, "Segoe UI Variable", "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14.5px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }
a { color: inherit; text-decoration: none; touch-action: manipulation; }
.chat-scroll, .view-body, .modal-body, .drawer-body, .history {
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
h1, h2, h3, h4, p { margin: 0; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
*:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
[hidden] { display: none !important; }

/* login */
.login {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(800px 500px at 50% 0%, var(--glow), transparent 70%),
    var(--bg);
}
.login-glow {
  position: absolute;
  top: 8%; left: 50%;
  width: 620px; height: 380px;
  transform: translateX(-50%);
  background: radial-gradient(closest-side, var(--glow), transparent 75%);
  filter: blur(40px);
  pointer-events: none;
}
.login-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  padding: 30px;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  background: color-mix(in srgb, var(--bg-soft) 92%, transparent);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-theme { position: absolute; top: 12px; right: 12px; }
.login-card h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; margin-top: 8px; }
.login-sub { font-size: 12.5px; color: var(--text-3); line-height: 1.7; }
.login-error { min-height: 18px; font-size: 12px; color: var(--danger); }
.login-hint { font-size: 11px; line-height: 1.7; color: var(--text-3); }
.login-hint code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 10.5px; }
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: linear-gradient(145deg, var(--brand-bg), color-mix(in srgb, var(--brand-bg) 72%, var(--bg)));
  color: var(--brand-fg);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
}
.brand-mark svg { width: 17px; height: 17px; }
.brand strong { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; }
.brand em { font-style: normal; color: var(--accent); font-weight: 500; margin-left: 3px; font-size: 15px; }
.brand.big .brand-mark { width: 36px; height: 36px; }
.brand.big strong { font-size: 21px; }

/* app shell */
.app { display: flex; height: var(--app-height, 100dvh); overflow: hidden; }
.sidebar {
  width: 256px;
  flex: none;
  height: var(--app-height, 100dvh);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 12px 12px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  z-index: 30;
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 8px; }
#closeSidebar { display: none; }
.new-chat {
  display: flex; align-items: center; gap: 9px;
  height: 38px; padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  font-size: 13px; font-weight: 500;
  transition: background 0.15s ease;
}
.new-chat:hover { background: var(--surface-2); }
.new-chat svg { width: 15px; height: 15px; color: var(--text-3); }

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text-2);
  font-size: 12.8px;
  text-align: left;
}
.nav-item svg { width: 16px; height: 16px; color: var(--text-3); }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--text); }
.nav-item.active svg { color: var(--accent); }
.nav-count { margin-left: auto; font-size: 10.5px; color: var(--text-3); background: var(--surface-3); border-radius: 99px; padding: 1px 6px; }

.history { flex: 1; min-height: 0; display: flex; flex-direction: column; margin-top: 8px; border-top: 1px solid var(--border); padding-top: 8px; }
.history-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 8px 6px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); }
.mini-btn { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 5px; color: var(--text-3); }
.mini-btn:hover { background: var(--surface-2); color: var(--text); }
.mini-btn svg { width: 13px; height: 13px; }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.conv-item { display: flex; align-items: center; gap: 7px; padding: 7px 9px; border-radius: 7px; color: var(--text-3); font-size: 12.3px; text-align: left; }
.conv-item:hover { background: var(--surface-2); color: var(--text-2); }
.conv-item.active { background: var(--surface-2); color: var(--text); }
.conv-item span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-empty { padding: 12px 9px; font-size: 11.5px; color: var(--text-3); line-height: 1.6; }

.side-foot { border-top: 1px solid var(--border); padding-top: 9px; display: flex; flex-direction: column; gap: 5px; }
.hub-status { display: flex; align-items: center; gap: 6px; padding: 0 6px; font-size: 10.5px; color: var(--text-3); }
.hub-status em { margin-left: auto; font-style: normal; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); display: inline-block; flex: none; }
.dot.online { background: var(--ok); box-shadow: 0 0 6px rgba(74, 222, 128, 0.55); }
.dot.warn { background: var(--warn); }
.dot.error { background: var(--danger); }
.logout-btn { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 7px; font-size: 12px; color: var(--text-3); }
.logout-btn:hover { background: var(--surface-2); color: var(--text); }
.logout-btn svg { width: 14px; height: 14px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: var(--app-height, 100dvh); position: relative; background: radial-gradient(900px 420px at 55% -10%, var(--glow-soft), transparent 70%), var(--bg); }
.topbar {
  flex: none;
  height: calc(62px + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 20px 0;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  z-index: 20;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar h1 { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.topbar p { font-size: 10.8px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topstats { display: flex; gap: 14px; }
.stat { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-3); }
.stat strong { color: var(--text-2); font-weight: 600; }
.stat svg { width: 13px; height: 13px; }
.mobile-menu { display: none; }
.icon-btn { width: 32px; height: 32px; display: inline-grid; place-items: center; border-radius: 8px; color: var(--text-3); }
.icon-btn.mobile-menu { display: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }

.view { display: none; flex: 1; min-height: 0; }
.view.active { display: flex; flex-direction: column; }
.view-body { flex: 1; overflow-y: auto; padding: 26px 30px 50px; }
.view-body.narrow { max-width: 820px; width: 100%; margin: 0 auto; }

/* chat */
.chat-layout { flex: 1; min-height: 0; display: flex; }
.chat-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-scroll { flex: 1; overflow-y: auto; }
.chat-empty {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100%;
  padding: 8vh 24px 30px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
}
.empty-mark { width: 52px; height: 52px; border-radius: 15px; border: 1px solid var(--border-strong); background: var(--surface); display: grid; place-items: center; color: var(--accent); margin-bottom: 18px; box-shadow: var(--shadow-md); }
.empty-mark svg { width: 25px; height: 25px; }
.eyebrow { font-size: 10.5px; font-weight: 600; letter-spacing: 0.16em; color: var(--text-3); }
.chat-empty h2 { margin: 12px 0 10px; font-size: clamp(26px, 3.4vw, 36px); line-height: 1.25; letter-spacing: -0.035em; font-weight: 600; }
.empty-sub { max-width: 480px; font-size: 12.8px; color: var(--text-3); line-height: 1.75; }
.suggestions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; width: 100%; margin-top: 30px; text-align: left; }
.suggestions button { padding: 13px; border: 1px solid var(--border); border-radius: 12px; background: color-mix(in srgb, var(--surface) 60%, transparent); display: flex; flex-direction: column; gap: 3px; transition: border-color 0.15s ease, background 0.15s ease; }
.suggestions button:hover { border-color: var(--border-strong); background: var(--surface); }
.suggestions strong { font-size: 12.2px; font-weight: 600; }
.suggestions span { font-size: 11px; color: var(--text-3); }

.messages { max-width: 760px; margin: 0 auto; padding: 24px 24px 10px; display: flex; flex-direction: column; gap: 24px; }
.msg-user { align-self: flex-end; max-width: 85%; }
.msg-user .bubble { background: var(--surface-2); border: 1px solid var(--border); border-radius: 16px 16px 5px 16px; padding: 10px 14px; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-assistant { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 12px; }
.msg-assistant.continued { grid-template-columns: minmax(0, 1fr); padding-left: 40px; }
.msg-assistant.continued .avatar { display: none; }
.avatar { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(145deg, var(--accent-2), #4c1d95); color: #fff; display: grid; place-items: center; margin-top: 2px; }
.avatar svg { width: 15px; height: 15px; }
.msg-body { min-width: 0; }
.md { font-size: 14.3px; line-height: 1.7; overflow-wrap: anywhere; }
.md p { margin: 0 0 12px; }
.md h1, .md h2, .md h3 { margin: 18px 0 8px; font-weight: 600; letter-spacing: -0.01em; }
.md h1 { font-size: 1.4em; } .md h2 { font-size: 1.2em; } .md h3 { font-size: 1.05em; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md code { font-family: "SF Mono", "Cascadia Code", Consolas, monospace; font-size: 0.86em; background: var(--surface-3); padding: 1.5px 5px; border-radius: 5px; }
.md pre { margin: 0 0 13px; padding: 11px 13px; background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; font-size: 12.2px; line-height: 1.6; white-space: pre; }
.md blockquote { margin: 0 0 12px; padding-left: 12px; border-left: 2px solid var(--border-strong); color: var(--text-2); }
.md a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.md table { width: 100%; border-collapse: collapse; margin: 0 0 12px; font-size: 12.8px; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; }
.md th { background: var(--surface-2); }
.md .stream-cursor::after { content: ""; display: inline-block; width: 6px; height: 1em; margin-left: 2px; vertical-align: -2px; background: var(--accent); animation: blink 1s steps(2) infinite; }
.msg-actions { display: flex; gap: 4px; margin-top: 5px; opacity: 0; transition: opacity 0.15s ease; }
.msg:hover .msg-actions { opacity: 1; }
.msg-actions .icon-btn { width: 26px; height: 26px; }
.msg-actions .icon-btn svg { width: 13px; height: 13px; }
.msg-error { border: 1px solid rgba(248, 113, 113, 0.3); background: rgba(248, 113, 113, 0.07); color: var(--danger); border-radius: 10px; padding: 9px 11px; font-size: 12.5px; }

/* tool trace */
.trace-group { margin-bottom: 10px; }
.trace-group > summary {
  list-style: none;
  cursor: pointer;
  width: fit-content;
  padding: 3px 0;
  font-size: 10.8px;
  color: var(--text-3);
  user-select: none;
}
.trace-group > summary::-webkit-details-marker { display: none; }
.trace-group > summary:hover { color: var(--text-2); }
.trace-group[open] > summary { margin-bottom: 8px; }
.trace { display: flex; flex-direction: column; gap: 7px; margin-bottom: 10px; }
.tool-card { border: 1px solid var(--border); border-radius: 10px; background: color-mix(in srgb, var(--surface) 70%, transparent); overflow: hidden; }
.tool-card.running { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.tool-card.error { border-color: rgba(248, 113, 113, 0.3); }
.tool-head { display: flex; align-items: center; gap: 8px; padding: 7px 10px; font-size: 11.5px; min-width: 0; }
.tool-icon { width: 22px; height: 22px; flex: none; border-radius: 6px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.tool-icon svg { width: 12px; height: 12px; }
.tool-name { font-weight: 600; font-size: 11.8px; flex: none; white-space: nowrap; }
.tool-sub { color: var(--text-3); font-size: 10.5px; margin-left: 2px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-status { margin-left: auto; flex: none; white-space: nowrap; font-size: 9.8px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); }
.tool-card.running .tool-status { color: var(--accent); }
.tool-card.done .tool-status { color: var(--ok); }
.tool-card.error .tool-status { color: var(--danger); }
.tool-details summary { list-style: none; cursor: pointer; padding: 0 10px 7px; font-size: 10.4px; color: var(--text-3); width: fit-content; }
.tool-details summary::-webkit-details-marker { display: none; }
.tool-details summary:hover { color: var(--text-2); }
.tool-body { padding: 0 10px 9px; }
.tool-args { margin: 0; padding: 6px 8px; background: var(--code-bg); border: 1px solid var(--border); border-radius: 7px; font-family: "SF Mono", Consolas, monospace; font-size: 10.6px; line-height: 1.55; color: var(--text-3); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 90px; overflow-y: auto; }
.tool-result { margin-top: 5px; }
.tool-result summary { cursor: pointer; font-size: 10.8px; color: var(--text-3); list-style: none; }
.tool-result summary::-webkit-details-marker { display: none; }
.tool-result pre { margin: 5px 0 0; max-height: 180px; overflow: auto; font-size: 10.6px; white-space: pre-wrap; color: var(--text-2); background: var(--code-bg); border: 1px solid var(--border); border-radius: 7px; padding: 7px 8px; }

/* composer */
.composer-wrap { flex: none; padding: 0 24px calc(14px + env(safe-area-inset-bottom, 0px)); background: linear-gradient(to top, var(--bg) 65%, transparent); }
.composer { max-width: 760px; margin: 0 auto; border: 1px solid var(--border-strong); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow-md); overflow: hidden; }
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 45%, var(--border-strong)); box-shadow: var(--shadow-md), 0 0 0 3px var(--accent-soft); }
.composer textarea { display: block; width: 100%; min-height: 44px; max-height: 200px; padding: 13px 15px 2px; border: 0; outline: none; resize: none; background: none; font-size: 14px; line-height: 1.6; }
.composer textarea::placeholder { color: var(--text-3); }
.composer-bar { display: flex; align-items: center; justify-content: flex-end; gap: 6px; padding: 3px 8px 8px; }
.composer-hint { margin-right: auto; padding-left: 7px; font-size: 10px; color: var(--text-3); }
.send-btn { width: 32px; height: 32px; border-radius: 50%; background: var(--text); color: var(--bg); display: grid; place-items: center; }
.send-btn svg { width: 16px; height: 16px; stroke-width: 2.1; }
.send-btn:disabled { opacity: 0.25; cursor: default; }
.send-btn.stop { background: var(--surface-3); color: var(--text); border: 1px solid var(--border-strong); }
.send-btn.stop svg { width: 13px; height: 13px; }
.disclaimer { max-width: 760px; margin: 8px auto 0; text-align: center; font-size: 10px; color: var(--text-3); }

/* fleet rail */
.fleet-rail {
  width: 272px; flex: none;
  border-left: 1px solid var(--border);
  padding: 18px 14px;
  overflow-y: auto;
  background: color-mix(in srgb, var(--sidebar) 55%, transparent);
}
.rail-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 2px 8px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--text-3); }
.rail-bots { display: flex; flex-direction: column; gap: 4px; margin-bottom: 22px; }
.rail-bot { display: flex; align-items: center; gap: 8px; padding: 8px 9px; border-radius: 8px; border: 1px solid transparent; }
.rail-bot:hover { background: var(--surface-2); }
.rail-bot .name { flex: 1; min-width: 0; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-bot .sub { font-size: 10px; color: var(--text-3); }
.rail-empty { padding: 10px 4px; font-size: 11px; color: var(--text-3); line-height: 1.6; }
.rail-pending { display: flex; flex-direction: column; gap: 6px; }
.pending-item { border: 1px solid var(--border); border-radius: 8px; padding: 8px 9px; background: var(--surface); }
.pending-item .title { font-size: 11.5px; color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pending-item .meta { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 10px; color: var(--text-3); }
.pending-item .meta button { margin-left: auto; }
.badge { font-size: 9.5px; background: var(--surface-3); color: var(--text-3); border-radius: 99px; padding: 1px 6px; }

/* buttons */
.primary-btn, .secondary-btn, .ghost-btn, .danger-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 33px; padding: 0 13px; border-radius: 8px;
  font-size: 12.2px; font-weight: 500; white-space: nowrap;
  transition: background 0.14s ease, opacity 0.14s ease, border-color 0.14s ease;
}
.primary-btn { background: var(--text); color: var(--bg); font-weight: 600; }
.primary-btn:hover { opacity: 0.88; }
.primary-btn.full { width: 100%; height: 38px; }
.primary-btn svg, .secondary-btn svg { width: 14px; height: 14px; }
.secondary-btn { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); }
.secondary-btn:hover { background: var(--surface-2); color: var(--text); }
.ghost-btn { color: var(--text-2); }
.ghost-btn:hover { background: var(--surface-2); color: var(--text); }
.danger-btn { background: var(--danger); color: #fff; font-weight: 600; }
.danger-btn:hover { filter: brightness(1.08); }
.link-btn { font-size: 11.5px; color: var(--accent); }
.link-btn:hover { text-decoration: underline; text-underline-offset: 3px; }
.icon-btn.small { width: 26px; height: 26px; }
.icon-btn.small svg { width: 13px; height: 13px; }

/* fleet view */
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.section-head h2 { font-size: 19px; font-weight: 600; letter-spacing: -0.02em; }
.section-head p { margin-top: 3px; font-size: 12px; color: var(--text-3); }
.section-actions { display: flex; gap: 7px; }
.bot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 12px; }
.bot-card { border: 1px solid var(--border); border-radius: 13px; background: var(--surface); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.bot-card.offline { opacity: 0.72; }
.bot-head { display: flex; align-items: center; gap: 8px; }
.bot-name { font-size: 13.5px; font-weight: 600; }
.status-pill { margin-left: auto; font-size: 9.8px; padding: 2px 7px; border-radius: 99px; border: 1px solid var(--border); color: var(--text-3); }
.status-pill.online { color: var(--ok); border-color: rgba(74, 222, 128, 0.28); background: rgba(74, 222, 128, 0.06); }
.status-pill.offline { color: var(--text-3); }
.bot-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 10.8px; color: var(--text-3); }
.bot-meta span { display: flex; align-items: center; gap: 4px; }
.bot-meta svg { width: 11px; height: 11px; }
.caps { display: flex; flex-wrap: wrap; gap: 4px; }
.cap { font-size: 9.5px; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--text-3); }
.cap.shell { color: var(--warn); background: rgba(251, 191, 36, 0.07); }
.cap.agent { color: var(--accent); background: var(--accent-soft); }
.bot-actions { display: flex; gap: 4px; margin-top: auto; padding-top: 4px; border-top: 1px solid var(--border); }
.bot-actions .icon-btn { margin-left: auto; }
.bot-actions .icon-btn + .icon-btn { margin-left: 0; }

/* tasks */
.filters { display: flex; gap: 4px; flex-wrap: wrap; }
.filter { font-size: 11.3px; padding: 5px 10px; border-radius: 7px; color: var(--text-3); border: 1px solid transparent; }
.filter:hover { color: var(--text-2); background: var(--surface-2); }
.filter.active { color: var(--text); background: var(--surface-2); border-color: var(--border); }
.task-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); }
.task-row { display: grid; grid-template-columns: 90px 1fr 110px 92px 74px; gap: 12px; align-items: center; padding: 11px 14px; border-bottom: 1px solid var(--border); text-align: left; }
.task-row:last-child { border-bottom: 0; }
.task-row:hover { background: var(--surface-2); }
.task-status { font-size: 9.8px; padding: 2px 7px; border-radius: 99px; width: fit-content; border: 1px solid var(--border); color: var(--text-3); }
.task-status.succeeded { color: var(--ok); border-color: rgba(74, 222, 128, 0.28); }
.task-status.running { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 32%, transparent); }
.task-status.pending_approval { color: var(--warn); border-color: rgba(251, 191, 36, 0.3); }
.task-status.failed, .task-status.cancelled, .task-status.timeout { color: var(--danger); border-color: rgba(248, 113, 113, 0.28); }
.task-bot { font-size: 11.8px; color: var(--text-2); }
.task-instruction { min-width: 0; font-size: 12.2px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-time { font-size: 10.5px; color: var(--text-3); text-align: right; }
.task-mode { font-size: 9.8px; color: var(--text-3); text-transform: uppercase; }
.empty-state { padding: 40px 20px; text-align: center; color: var(--text-3); font-size: 12.5px; border: 1px dashed var(--border); border-radius: 12px; }

/* settings */
.settings-card { border: 1px solid var(--border); border-radius: 13px; background: var(--surface); padding: 18px; display: flex; flex-direction: column; gap: 14px; margin-bottom: 16px; }
.settings-card h3 { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; }
.settings-card h3 svg { width: 14px; height: 14px; color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 11.2px; font-weight: 500; color: var(--text-2); }
.field input, .field select, .field textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12.5px; outline: none; transition: border-color 0.14s ease;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: vertical; line-height: 1.6; }
.field small { font-size: 10.5px; color: var(--text-3); line-height: 1.55; }
.field-row { display: grid; grid-template-columns: 1fr 120px; gap: 12px; }
.field.narrow { max-width: 130px; }
.form-actions { display: flex; align-items: center; gap: 9px; justify-content: flex-end; }
.test-status { margin-right: auto; font-size: 11px; color: var(--text-3); }
.test-status.ok { color: var(--ok); }
.test-status.err { color: var(--danger); }
.security-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; font-size: 11.8px; color: var(--text-3); line-height: 1.65; }
.audit-head { display: flex; align-items: center; justify-content: space-between; padding-top: 10px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; }
.audit-list { display: flex; flex-direction: column; gap: 1px; font-size: 11px; color: var(--text-3); }
.audit-row { display: flex; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.audit-row:last-child { border-bottom: 0; }
.audit-row time { color: var(--text-3); flex: none; }
.audit-row .action { color: var(--text-2); }

/* modals & drawer */
.modal, .drawer { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 20px; }
.modal-backdrop, .drawer-backdrop { position: absolute; inset: 0; background: rgba(4, 4, 6, 0.62); backdrop-filter: blur(7px); }
[data-theme="light"] .modal-backdrop,
[data-theme="light"] .drawer-backdrop { background: rgba(20, 20, 24, 0.28); }
.modal-card {
  position: relative; width: 100%; max-width: 480px; max-height: calc(100dvh - 40px);
  display: flex; flex-direction: column; background: var(--bg-soft);
  border: 1px solid var(--border-strong); border-radius: 17px; box-shadow: var(--shadow-lg); overflow: hidden;
}
.modal-card.wide { max-width: 640px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 14px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 15px; font-weight: 600; }
.modal-head p { margin-top: 3px; font-size: 11.5px; color: var(--text-3); line-height: 1.6; }
.modal-head .icon-btn { margin: -3px -4px 0 0; }
.modal-body { padding: 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 13px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); }
.copy-row { display: flex; gap: 7px; }
.copy-row input { flex: 1; font-family: "SF Mono", Consolas, monospace; font-size: 11px; }
.hint-block { font-size: 11px; color: var(--text-3); line-height: 1.65; }
.confirm-card { max-width: 390px; padding: 22px; }
.confirm-card h2 { font-size: 15px; font-weight: 600; }
.confirm-card p { margin-top: 6px; font-size: 12.5px; color: var(--text-3); line-height: 1.6; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 7px; margin-top: 20px; }

.drawer { place-items: stretch; padding: 0; justify-content: flex-end; }
.drawer-card { position: relative; width: 100%; max-width: 560px; height: 100%; display: flex; flex-direction: column; background: var(--bg-soft); border-left: 1px solid var(--border-strong); box-shadow: var(--shadow-lg); }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: calc(18px + env(safe-area-inset-top, 0px)) 20px 14px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { font-size: 15px; font-weight: 600; }
.drawer-head p { margin-top: 3px; font-size: 11px; color: var(--text-3); }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.drawer-foot { padding: 12px 20px calc(12px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--border); display: flex; gap: 7px; justify-content: flex-end; }
.detail-grid { display: grid; grid-template-columns: 90px 1fr; gap: 6px 12px; font-size: 11.8px; }
.detail-grid dt { color: var(--text-3); }
.detail-grid dd { margin: 0; color: var(--text-2); overflow-wrap: anywhere; }
.detail-block { border: 1px solid var(--border); border-radius: 9px; background: var(--surface); padding: 10px 12px; }
.detail-block h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-3); margin-bottom: 6px; }
.detail-block pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 11.2px; line-height: 1.6; color: var(--text-2); max-height: 260px; overflow-y: auto; }
.event-list { display: flex; flex-direction: column; gap: 6px; }
.event { border-left: 2px solid var(--border-strong); padding: 2px 0 2px 9px; font-size: 11px; color: var(--text-3); }
.event strong { color: var(--text-2); font-weight: 500; }
.event pre { margin: 3px 0 0; font-size: 10.5px; white-space: pre-wrap; color: var(--text-3); max-height: 100px; overflow-y: auto; }

/* toasts */
.toast-stack { position: fixed; z-index: 120; top: calc(72px + env(safe-area-inset-top, 0px)); right: 20px; display: flex; flex-direction: column; gap: 7px; pointer-events: none; }
.toast { max-width: 360px; padding: 9px 13px; border-radius: 9px; border: 1px solid var(--border-strong); background: var(--bg-soft); color: var(--text-2); font-size: 12px; box-shadow: var(--shadow-md); animation: toast-in 0.18s ease; }
.toast.error { border-color: rgba(248, 113, 113, 0.35); color: var(--text); }
.toast.ok { border-color: rgba(74, 222, 128, 0.3); }

.scrim { position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, 0.5); opacity: 0; pointer-events: none; transition: opacity 0.2s ease; }
[data-theme="light"] .scrim { background: rgba(20, 20, 24, 0.28); }
::selection { background: var(--accent-soft); color: var(--text); }
.mobile-tabbar { display: none; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

@media (max-width: 1080px) {
  .fleet-rail { display: none; }
}
@media (max-width: 820px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; height: var(--app-height, 100dvh); transform: translateX(-102%); transition: transform 0.26s cubic-bezier(0.16, 1, 0.3, 1); width: 272px; padding-top: calc(14px + env(safe-area-inset-top, 0px)); padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
  .app.nav-open .sidebar { transform: translateX(0); }
  .app.nav-open .scrim { opacity: 1; pointer-events: auto; }
  #closeSidebar { display: inline-grid; }
  .mobile-menu { display: inline-grid; }
  .icon-btn.mobile-menu { display: inline-grid; }
  .topbar { padding-left: 10px; padding-right: 12px; }
  .topstats .stat:first-child { display: none; }
  .view-body { padding: 18px 14px 28px; }
  .chat-empty { padding: 5vh 16px 20px; }
  .suggestions { grid-template-columns: 1fr; }
  .messages { padding: 16px 14px 6px; }
  .composer-wrap { padding: 0 12px 8px; }
  .msg-user { max-width: 92%; }
  .task-list { border-radius: 10px; }
  .task-row { grid-template-columns: 82px minmax(0, 1fr); gap: 5px 10px; }
  .task-bot, .task-mode { display: none; }
  .task-instruction { grid-column: 2; }
  .task-time { grid-column: 2; text-align: left; }
  .section-head { flex-direction: column; }
  .field-row { grid-template-columns: 1fr; }
  .field.narrow { max-width: none; }
  .modal { padding: 12px; }
  .drawer-card { max-width: none; }
  .toast-stack { right: 12px; left: 12px; top: calc(66px + env(safe-area-inset-top, 0px)); }
  .toast { max-width: none; }

  .mobile-tabbar {
    display: flex;
    flex: none;
    height: calc(54px + env(safe-area-inset-bottom, 0px));
    padding: 0 6px env(safe-area-inset-bottom, 0px);
    border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--sidebar) 92%, transparent);
    backdrop-filter: blur(14px);
  }
  .mobile-tab {
    flex: 1;
    min-height: 50px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-3);
    font-size: 9.8px;
    border-radius: 8px;
  }
  .mobile-tab svg { width: 18px; height: 18px; }
  .mobile-tab.active { color: var(--accent); }
  .mobile-tab:active { background: var(--surface-2); }

  .icon-btn { width: 44px; height: 44px; }
  .icon-btn svg { width: 18px; height: 18px; }
  .send-btn { width: 44px; height: 44px; }
  .send-btn svg { width: 18px; height: 18px; }
  .nav-item { min-height: 46px; padding: 10px 10px; }
  .new-chat { height: 44px; }
  .primary-btn, .secondary-btn, .ghost-btn, .danger-btn { min-height: 40px; }
  .primary-btn.full { height: 46px; }
  .filter { min-height: 38px; padding: 8px 12px; }
  .composer textarea { font-size: 16px; }
  .field input, .field select, .field textarea, .field input[type="number"] { font-size: 16px; }
  .login-card input { font-size: 16px; }
  .field select { padding-right: 32px; }
}

/* attachments + voice */
.attachment-preview { display: flex; gap: 8px; padding: 10px 12px 0; overflow-x: auto; }
.attachment-chip { position: relative; width: 62px; height: 62px; flex: none; border-radius: 9px; overflow: hidden; border: 1px solid var(--border-strong); background: var(--surface-2); }
.attachment-chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attachment-remove { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%; background: rgba(0,0,0,.62); color: #fff; display: grid; place-items: center; }
.attachment-remove svg { width: 12px; height: 12px; }
.voice-bar { display: flex; align-items: center; gap: 8px; padding: 9px 12px 0; font-size: 11.5px; color: var(--text-2); }
.voice-pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); animation: voicepulse 1.1s ease-in-out infinite; }
@keyframes voicepulse { 50% { opacity: 0.25; transform: scale(0.8); } }
.voice-cancel { margin-left: auto; color: var(--text-3); font-size: 11px; }
.composer-tools { display: flex; align-items: center; gap: 1px; margin-right: auto; padding-left: 2px; }
.composer-icon { width: 30px; height: 30px; border-radius: 8px; color: var(--text-3); display: grid; place-items: center; }
.composer-icon:hover { color: var(--text); background: var(--surface-2); }
.composer-icon svg { width: 16px; height: 16px; }
.composer-icon.recording { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); animation: voicepulse 1.2s ease-in-out infinite; }
.composer-hint { margin-right: 0; }
.composer-bar { justify-content: flex-end; }
.msg-images { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.msg-images img { max-width: 220px; max-height: 180px; border-radius: 10px; border: 1px solid var(--border); object-fit: cover; display: block; }
.md img { max-width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--border); margin: 4px 0 12px; display: block; }
.md-image-link { display: inline-block; font-size: 12px; color: var(--accent); margin-top: 4px; }
.speaker-btn { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; color: var(--text-3); margin-top: 6px; }
.speaker-btn:hover { color: var(--text); background: var(--surface-2); }
.speaker-btn svg { width: 14px; height: 14px; }
.speaker-btn.speaking { color: var(--accent); background: var(--accent-soft); }

/* settings: media + memory */
.settings-note { margin: 0 0 4px; font-size: 11.5px; line-height: 1.55; color: var(--text-3); }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.setting-row strong { display: block; font-size: 12.5px; font-weight: 550; }
.setting-row small { display: block; margin-top: 2px; font-size: 11px; color: var(--text-3); }
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border-strong); transition: background .16s ease; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; border-radius: 50%; background: var(--text-3); transition: transform .16s ease, background .16s ease; }
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); background: var(--bg); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.memory-add { display: grid; grid-template-columns: minmax(0,1fr) 104px auto; gap: 7px; margin-top: 12px; }
.memory-add input, .memory-add select { height: 34px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); padding: 0 10px; font-size: 12px; }
.memory-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; max-height: 280px; overflow-y: auto; }
.memory-row { display: flex; align-items: flex-start; gap: 8px; padding: 8px 9px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg-soft); }
.memory-row .mem-cat { flex: none; font-size: 9px; padding: 2px 6px; border-radius: 5px; background: var(--accent-soft); color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }
.memory-row .mem-text { flex: 1; min-width: 0; font-size: 12px; line-height: 1.5; color: var(--text-2); overflow-wrap: anywhere; }
.memory-row .mem-del { flex: none; color: var(--text-3); width: 24px; height: 24px; display: grid; place-items: center; border-radius: 6px; }
.memory-row .mem-del:hover { color: var(--danger); background: var(--surface-2); }
.memory-row .mem-del svg { width: 13px; height: 13px; }
.memory-empty { padding: 12px; text-align: center; font-size: 11.5px; color: var(--text-3); border: 1px dashed var(--border); border-radius: 9px; }
.inline-actions { display: flex; align-items: center; gap: 7px; }
.inline-actions.end { justify-content: flex-end; margin-top: 8px; }
.inline-actions .secondary-btn, .inline-actions .primary-btn { min-height: 34px; }
.field input[type="range"] { padding: 0; accent-color: var(--accent); }
.field .inline-actions { min-height: 34px; }

@media (max-width: 820px) {
  .composer-tools { padding-left: 0; }
  .composer-icon { width: 40px; height: 40px; }
  .composer-hint { display: none; }
  .msg-images img { max-width: 150px; max-height: 130px; }
  .memory-add { grid-template-columns: 1fr 88px; }
  .memory-add .primary-btn { grid-column: 1 / -1; }
}

.settings-jump { display: flex; gap: 7px; margin: 0 0 12px; }
.settings-jump .filter { display: inline-flex; align-items: center; gap: 5px; }
.settings-jump svg { width: 13px; height: 13px; }
#mediaCard .field-row { grid-template-columns: minmax(0, 1fr) 170px; }
@media (max-width: 820px) {
  #mediaCard .field-row { grid-template-columns: 1fr; }
}
