:root {
  --bg: #f6f7fb; --bg2: #ffffff; --bg3: #eef0f6; --line: #e2e5ee; --text: #161a24; --muted: #6b7386;
  --accent: #6a4dff; --accent2: #14a88f; --accent-soft: #ece8ff; --ok: #14a35c; --warn: #d98a00; --bad: #d64545;
  --user: #6a4dff; --user-text: #fff; --shadow: 0 6px 24px rgba(20, 24, 40, .08); --radius: 16px;
  --code: #f1f3f8; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --s-rgb: 255 255 255; --bg-rgb: 238 240 247; --surface: rgb(var(--s-rgb) / var(--glass, .8));
  --page: radial-gradient(1100px 700px at 100% -10%, #e4ddff, transparent 60%), radial-gradient(900px 600px at -10% 110%, #d6f3ec, transparent 60%), #f3f4f9;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f14; --bg2: #151821; --bg3: #1c202b; --line: #262b38; --text: #e8eaf1; --muted: #8b93a7;
    --accent: #8b74ff; --accent2: #2fd3b5; --accent-soft: #241f3f; --ok: #3ccf7f; --warn: #f0b03a; --bad: #ff6b6b;
    --user: #5b43e0; --shadow: 0 8px 30px rgba(0, 0, 0, .35); --code: #11141b; color-scheme: dark;
    --s-rgb: 22 25 35; --bg-rgb: 10 12 17; --surface: rgb(var(--s-rgb) / var(--glass, .8));
    --page: radial-gradient(1100px 700px at 100% -10%, #2a2160, transparent 60%), radial-gradient(900px 600px at -10% 110%, #0f3a37, transparent 60%), #0b0d12;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0f14; --bg2: #151821; --bg3: #1c202b; --line: #262b38; --text: #e8eaf1; --muted: #8b93a7;
  --accent: #8b74ff; --accent2: #2fd3b5; --accent-soft: #241f3f; --ok: #3ccf7f; --warn: #f0b03a; --bad: #ff6b6b;
  --user: #5b43e0; --shadow: 0 8px 30px rgba(0, 0, 0, .35); --code: #11141b; color-scheme: dark;
  --s-rgb: 22 25 35; --bg-rgb: 10 12 17; --surface: rgb(var(--s-rgb) / var(--glass, .8));
  --page: radial-gradient(1100px 700px at 100% -10%, #2a2160, transparent 60%), radial-gradient(900px 600px at -10% 110%, #0f3a37, transparent 60%), #0b0d12;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--page, var(--bg)); background-attachment: fixed; color: var(--text); font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; font-weight: 400; }
a { color: var(--accent); cursor: pointer; text-decoration: none; }
h2 { font-size: 15px; margin: 22px 0 10px; }
button { font: inherit; color: inherit; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 9px 14px; cursor: pointer; transition: .15s; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; border: 0; font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 9px; }
.btn.wide { width: 100%; }
.icon-btn { border: 0; background: transparent; font-size: 20px; cursor: pointer; padding: 6px 8px; border-radius: 10px; display: inline-flex; align-items: center; }
.icon-btn:hover { background: var(--bg3); }

/* login */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 20% 0%, var(--accent-soft), transparent), var(--bg); }
.login-card { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 32px 24px; text-align: center; box-shadow: var(--shadow); display: grid; gap: 12px; }
.login-card h1 { margin: 0; }
.login-card p { margin: 0; }
.login-logo { width: 64px; height: 64px; margin: 0 auto; }
input, textarea, select { font: inherit; color: var(--text); background: var(--bg3); border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
.err { color: var(--bad); min-height: 1em; }

/* layout */
.app { display: grid; grid-template-columns: 280px 1fr; height: 100dvh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px; gap: 12px; min-height: 0; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand img { width: 32px; height: 32px; }
.live { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-left: auto; }
.live.on { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 20%, transparent); }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 10px; color: var(--text); }
.nav a:hover { background: var(--bg3); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.badge { margin-left: auto; background: var(--accent); color: #fff; border-radius: 99px; font-size: 11px; padding: 1px 7px; }
.badge.warn { background: var(--warn); }
.convs-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.convs { overflow: auto; display: grid; gap: 2px; align-content: start; min-height: 0; flex: 1; }
.conv { padding: 8px 10px; border-radius: 10px; cursor: pointer; display: flex; gap: 6px; align-items: center; }
.conv:hover { background: var(--bg3); }
.conv.active { background: var(--bg3); }
.conv .t { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .x { opacity: 0; border: 0; background: none; cursor: pointer; color: var(--muted); }
.conv:hover .x { opacity: 1; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 5; }
.topbar .title { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#menuBtn { display: none; }
.status-pill { font-size: 12px; color: var(--muted); white-space: nowrap; }
.view { flex: 1; overflow: auto; padding: 16px; min-height: 0; }
#view-chat { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.scrim { display: none; }

/* chat */
.messages { flex: 1; overflow: auto; padding: 18px 16px 8px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: min(760px, 92%); }
.msg.user { align-self: flex-end; background: var(--user); color: var(--user-text); padding: 10px 14px; border-radius: 18px 18px 4px 18px; white-space: pre-wrap; word-wrap: break-word; }
.msg.bruce { align-self: flex-start; width: min(760px, 100%); }
.msg.bruce .who { font-size: 12px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 6px; align-items: center; }
.msg.bruce .who img { width: 18px; height: 18px; }
.md { word-wrap: break-word; }
.md p { margin: 0 0 8px; }
.md p:last-child { margin: 0; }
.md pre { background: var(--code); border: 1px solid var(--line); border-radius: 12px; padding: 12px; overflow: auto; position: relative; font: 13px/1.45 var(--mono); }
.md code { font-family: var(--mono); font-size: .9em; background: var(--code); padding: 1px 5px; border-radius: 6px; }
.md pre code { background: none; padding: 0; }
.md .copy { position: absolute; top: 6px; right: 6px; font-size: 12px; padding: 3px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; opacity: .8; }
.md ul, .md ol { margin: 4px 0 8px; padding-left: 22px; }
.md h3, .md h4 { margin: 10px 0 6px; }
.files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.file-chip { font-size: 12px; background: var(--bg3); border: 1px solid var(--line); padding: 3px 8px; border-radius: 99px; color: var(--text); }
.msg.user .file-chip { background: rgba(255,255,255,.18); border-color: transparent; color: #fff; }
.typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.empty-chat { margin: auto; text-align: center; max-width: 520px; padding: 20px; }
.empty-chat img { width: 72px; }
.empty-chat h2 { font-size: 22px; margin: 10px 0 4px; }
.suggest { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; margin-top: 18px; text-align: left; }
.suggest button { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; cursor: pointer; }
.suggest button:hover { border-color: var(--accent); }
.suggest b { display: block; font-size: 13px; }
.suggest span { font-size: 12px; color: var(--muted); }

/* task card inside chat */
.tcard { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 12px; margin-top: 8px; box-shadow: var(--shadow); }
.tcard .head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tcard .goal { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--bg3); color: var(--muted); white-space: nowrap; }
.pill.running { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.pill.completed { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.pill.failed, .pill.cancelled { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.pill.waiting, .pill.paused { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.steps { margin: 8px 0 0; padding: 0; list-style: none; font-size: 13px; color: var(--muted); display: grid; gap: 3px; }
.steps li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.steps li::before { content: "› "; color: var(--accent); }
.ask { margin-top: 10px; padding: 10px; border-radius: 12px; background: color-mix(in srgb, var(--warn) 12%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); }
.ask .row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.ask input { flex: 1; min-width: 140px; }
.result { margin-top: 10px; }
.media { display: grid; gap: 8px; margin-top: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.media img, .media video { width: 100%; border-radius: 12px; border: 1px solid var(--line); background: #000; }
.media audio { width: 100%; }
.progress-bar { height: 3px; border-radius: 3px; background: var(--bg3); overflow: hidden; margin-top: 10px; }
.progress-bar i { display: block; height: 100%; width: 40%; background: linear-gradient(90deg, var(--accent), var(--accent2)); animation: slide 1.4s infinite ease-in-out; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(260%); } }

/* composer */
.composer-wrap { padding: 8px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); position: relative; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.chips button { white-space: nowrap; font-size: 13px; border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 5px 11px; cursor: pointer; }
.chips button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.composer { display: flex; align-items: flex-end; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 6px; box-shadow: var(--shadow); }
.composer:focus-within { border-color: var(--accent); }
.composer textarea { flex: 1; resize: none; border: 0; background: transparent; padding: 8px 6px; max-height: 40vh; }
.send { width: 40px; height: 40px; border-radius: 50%; border: 0; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; font-size: 16px; cursor: pointer; flex: none; }
.send:disabled { opacity: .4; }
.palette { position: absolute; bottom: 100%; left: 16px; right: 16px; max-height: 300px; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 6px; z-index: 10; }
.palette div { padding: 8px 10px; border-radius: 9px; cursor: pointer; display: flex; gap: 10px; }
.palette div.sel, .palette div:hover { background: var(--accent-soft); }
.palette b { font-family: var(--mono); color: var(--accent); min-width: 90px; }
.attached { display: flex; flex-wrap: wrap; gap: 6px; }
.attached:not(:empty) { padding-bottom: 8px; }

/* lists, cards, grids */
.toolbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 12px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--bg3); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 9px; cursor: pointer; }
.seg button.on { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }
.list { display: grid; gap: 8px; }
.row-item { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; cursor: pointer; display: grid; gap: 4px; }
.row-item:hover { border-color: var(--accent); }
.row-item .top { display: flex; gap: 8px; align-items: center; min-width: 0; }
.row-item .top .g { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.row-item .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.grid { display: grid; gap: 10px; }
.stats { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.stat .v { font-size: 22px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); }
.meter { height: 5px; border-radius: 5px; background: var(--bg3); margin-top: 6px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent2); }
.machines { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.machine { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: grid; gap: 8px; align-content: start; }
.machine .h { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.machine img { width: 100%; border-radius: 10px; border: 1px solid var(--line); cursor: zoom-in; }
.caps { display: flex; flex-wrap: wrap; gap: 4px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.feed { max-height: 420px; overflow: auto; padding: 6px; display: grid; gap: 2px; align-content: start; }
.fe { display: grid; grid-template-columns: 52px 1fr; gap: 8px; padding: 6px 8px; border-radius: 9px; font-size: 13px; cursor: pointer; }
.fe:hover { background: var(--bg3); }
.fe .tm { color: var(--muted); font-family: var(--mono); font-size: 11px; padding-top: 2px; }
.fe .tx { min-width: 0; }
.fe .tx div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fe .tx .d { color: var(--muted); font-size: 12px; }
.fe.new { animation: flash 1.2s; }
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }
.table-wrap { overflow: auto; padding: 0; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 500; }
.models { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.mcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: grid; gap: 6px; cursor: pointer; }
.mcard:hover { border-color: var(--accent); }
.mcard .h { display: flex; gap: 8px; align-items: center; font-weight: 600; }
.mcard .h span:not(.dot):not(.pill) { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mcard .nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; font-size: 12px; color: var(--muted); }
.mcard .nums b { display: block; color: var(--text); font-size: 15px; }
.qual { height: 4px; border-radius: 4px; background: var(--bg3); overflow: hidden; }
.qual i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.agents { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.agent { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 12px; background: var(--bg3); }
.agent .n { font-weight: 600; } .agent .s { font-size: 12px; color: var(--muted); }
pre.block { background: var(--code); border: 1px solid var(--line); border-radius: 12px; padding: 12px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; font: 12.5px/1.5 var(--mono); max-height: 50vh; }

/* settings */
.settings { display: grid; gap: 14px; max-width: 760px; }
.set-group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.set-group h3 { margin: 0; padding: 12px 14px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--line); }
.set { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.set:last-child { border-bottom: 0; }
.set .lbl { flex: 1; min-width: 0; }
.set .lbl small { display: block; color: var(--muted); font-size: 12px; }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); }
.switch input:disabled + span { opacity: .4; cursor: not-allowed; }

/* modal & toast */
.modal { position: fixed; inset: 0; background: rgba(5, 7, 12, .55); display: grid; place-items: center; z-index: 50; padding: 16px; backdrop-filter: blur(3px); }
.modal-card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; width: min(900px, 100%); max-height: 90dvh; overflow: auto; padding: 18px; position: relative; box-shadow: var(--shadow); }
.modal-card .close { position: absolute; top: 10px; right: 10px; }
.modal-card h3 { margin: 0 36px 8px 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13px; margin: 10px 0; }
.kv span:nth-child(odd) { color: var(--muted); }
.timeline { display: grid; gap: 2px; font-size: 13px; margin: 8px 0; }
.timeline div { display: grid; grid-template-columns: 60px 110px 1fr; gap: 8px; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.timeline .tm { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 60; max-width: calc(100% - 32px); }

/* phone */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 30; transform: translateX(-105%); transition: transform .2s; box-shadow: var(--shadow); padding-top: calc(14px + env(safe-area-inset-top)); }
  .sidebar.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 25; }
  #menuBtn { display: inline-flex; }
  .topbar { padding-top: calc(10px + env(safe-area-inset-top)); }
  .app:has(#view-chat:not(.hidden))   .composer-wrap { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .two { grid-template-columns: 1fr; }
  .view { padding: 12px; }
  .messages { padding: 14px 12px 6px; }
  .composer-wrap { padding-left: 10px; padding-right: 10px; }
  .msg { max-width: 94%; }
  .timeline div { grid-template-columns: 50px 1fr; }
  .timeline div .ev { display: none; }
  .status-pill { display: none; }
}
.set select { max-width: 55%; }
@media (max-width: 860px) {
  .set:has(select) { flex-wrap: wrap; }
  .set:has(select) select { width: 100%; max-width: none; }
}

/* planner */
.plan-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.addform { display: grid; gap: 8px; margin-bottom: 10px; }
.addform textarea { resize: vertical; }
.addform .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.addform .row input:not([type=checkbox]) { flex: 1; min-width: 150px; }
.days label { display: inline-flex; gap: 4px; align-items: center; background: var(--bg3); padding: 4px 9px; border-radius: 99px; font-size: 13px; cursor: pointer; }
.hint { margin: 4px 2px 10px; }
.pitem { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: start; }
.pitem.dragging { opacity: .4; }
.pitem.over { border-color: var(--accent); box-shadow: 0 -3px 0 var(--accent); }
.pitem .handle { cursor: grab; color: var(--muted); user-select: none; font-size: 18px; line-height: 1; padding-top: 2px; }
.pitem .txt { min-width: 0; word-wrap: break-word; }
.pitem .meta { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 5px; }
.pitem .acts { display: flex; gap: 2px; }
.pitem .acts button { border: 0; background: none; cursor: pointer; padding: 4px 6px; border-radius: 8px; color: var(--muted); font-size: 15px; }
.pitem .acts button:hover { background: var(--bg3); color: var(--text); }
.pitem.working { border-color: var(--accent); }
.pill.bruce { background: color-mix(in srgb, var(--accent2) 18%, transparent); color: var(--accent2); }
.pill.high { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.hist summary { cursor: pointer; color: var(--muted); margin: 14px 0 8px; }
.sitem { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; display: grid; gap: 4px; }
.sitem .top { display: flex; gap: 8px; align-items: center; }
.sitem .top b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sitem.off { opacity: .6; }
@media (max-width: 1100px) { .plan-cols { grid-template-columns: 1fr; } }
#upStatus { margin-bottom: 10px; }
.pre { background: var(--code); border: 1px solid var(--line); border-radius: 12px; padding: 12px; overflow: auto; max-height: 65vh; white-space: pre-wrap; word-break: break-word; font: 12px/1.45 var(--mono); }

/* «Работа»: live model and agent cards */
.live-card .top, .card.model .top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
pre.stream { background: var(--code); border-radius: 10px; padding: 10px; font: 12px/1.45 var(--mono); max-height: 260px; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 6px 0; }
pre.stream.think { border-left: 3px solid var(--accent); color: var(--muted); }
.card.model.busy { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.dot.pulse { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.rate .icon-btn { font-size: 16px; padding: 2px 6px; opacity: .6; } .rate .icon-btn.on, .rate .icon-btn:hover { opacity: 1; background: var(--accent-soft); }

/* ===== theme «KARA»: a dark android interface (inspired by the mood of Detroit: Become Human; original art) ===== */
:root[data-theme="kara"] {
  --bg: #070b14; --bg2: rgba(13, 22, 38, .86); --bg3: rgba(26, 40, 64, .7); --line: rgba(88, 196, 255, .18);
  --text: #e6f1ff; --muted: #7f94b3; --accent: #3ad0ff; --accent2: #2a7dff; --accent-soft: rgba(58, 208, 255, .12);
  --ok: #3ad0ff; --warn: #ffc93a; --bad: #ff3b55; --user: rgba(42, 125, 255, .28); --user-text: #e6f1ff;
  --shadow: 0 0 0 1px rgba(58, 208, 255, .06), 0 10px 40px rgba(0, 0, 0, .55); --radius: 4px; --code: rgba(4, 8, 16, .8);
  --led-idle: #3ad0ff; --led-busy: #ffc93a; --led-alert: #ff3b55; color-scheme: dark;
  --s-rgb: 10 18 33; --bg-rgb: 5 9 17; --surface: rgb(var(--s-rgb) / var(--glass, .8));
}
[data-theme="kara"] body {
  font-family: "Rajdhani", "Exo 2", "Segoe UI", Inter, Roboto, sans-serif; letter-spacing: .01em;
  background:
    linear-gradient(rgba(58, 208, 255, .035) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(90deg, rgba(58, 208, 255, .035) 1px, transparent 1px) 0 0 / 32px 32px,
    radial-gradient(900px 500px at 85% -10%, rgba(42, 125, 255, .22), transparent 70%),
    radial-gradient(700px 500px at -10% 110%, rgba(58, 208, 255, .12), transparent 70%), #070b14;
}
[data-theme="kara"] h2, [data-theme="kara"] h3, [data-theme="kara"] .convs-title, [data-theme="kara"] .brand span:not(.led) { text-transform: uppercase; letter-spacing: .12em; }
[data-theme="kara"] h2, [data-theme="kara"] h3 { color: var(--accent); font-weight: 600; }
[data-theme="kara"] .brand { font-size: 20px; letter-spacing: .3em; }
[data-theme="kara"] .brand-icon:not(.own) { display: none; }
[data-theme="kara"] .brand-icon.own, [data-theme="kara"] .who img.own { border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 2px var(--accent); }
[data-theme="kara"] .who img.own { width: 26px; height: 26px; }
[data-theme="kara"] .card, [data-theme="kara"] .tcard, [data-theme="kara"] .login-card, [data-theme="kara"] .set-group {
  position: relative; border-radius: 3px; border-color: var(--line);
  background: linear-gradient(180deg, rgb(20 34 58 / var(--glass, .8)), rgb(10 18 32 / calc(var(--glass, .8) + .06))); }
/* corner brackets, like the in-world holographic panels */
[data-theme="kara"] .card::before, [data-theme="kara"] .tcard::before, [data-theme="kara"] .login-card::before {
  content: ""; position: absolute; inset: -1px; pointer-events: none; border-radius: 3px;
  background:
    linear-gradient(var(--accent), var(--accent)) 0 0 / 12px 2px no-repeat, linear-gradient(var(--accent), var(--accent)) 0 0 / 2px 12px no-repeat,
    linear-gradient(var(--accent), var(--accent)) 100% 100% / 12px 2px no-repeat, linear-gradient(var(--accent), var(--accent)) 100% 100% / 2px 12px no-repeat;
  opacity: .8; }
[data-theme="kara"] .tcard .goal::before { content: "МИССИЯ · "; color: var(--accent); font-size: 11px; letter-spacing: .18em; }
[data-theme="kara"] .btn { border-radius: 2px; text-transform: uppercase; letter-spacing: .08em; font-size: 13px; }
[data-theme="kara"] .btn.primary { background: linear-gradient(90deg, #1d6dff, #3ad0ff); color: #02101f; box-shadow: 0 0 18px rgba(58, 208, 255, .35); }
[data-theme="kara"] .msg.user { border: 1px solid rgba(58, 208, 255, .35); border-radius: 3px 3px 0 3px; }
[data-theme="kara"] input, [data-theme="kara"] textarea, [data-theme="kara"] select { border-radius: 2px !important; }
[data-theme="kara"] .nav a.active { box-shadow: inset 3px 0 0 var(--accent); }
[data-theme="kara"] .login { background: transparent; }
[data-theme="kara"] .login-logo { display: none; }
[data-theme="kara"] .login-card h1 { letter-spacing: .5em; font-weight: 500; }

/* LED ring: KARA's state, like an android's temple light — blue free, yellow working, red needs you */
.led, .k-boot, .stab { display: none; }
[data-theme="kara"] .led { display: inline-block; width: 18px; height: 18px; border-radius: 50%; flex: none;
  border: 3px solid var(--led-idle); box-shadow: 0 0 10px var(--led-idle), inset 0 0 6px var(--led-idle); transition: .4s; }
[data-theme="kara"] .led[data-state="busy"] { border-color: var(--led-busy); box-shadow: 0 0 12px var(--led-busy), inset 0 0 6px var(--led-busy);
  border-top-color: transparent; animation: led-spin 1.4s linear infinite; }
[data-theme="kara"] .led[data-state="alert"] { border-color: var(--led-alert); box-shadow: 0 0 14px var(--led-alert), inset 0 0 6px var(--led-alert); animation: led-pulse 1s ease-in-out infinite; }
[data-theme="kara"] .led[data-state="off"] { border-color: var(--muted); box-shadow: none; }
[data-theme="kara"] .login-led { width: 64px; height: 64px; border-width: 6px; margin: 0 auto 4px; animation: led-pulse 2.6s ease-in-out infinite; }
[data-theme="kara"] .k-boot { display: block; font-size: 11px; letter-spacing: .2em; }
[data-theme="kara"] .live { display: none; }
@keyframes led-spin { to { transform: rotate(360deg); } }
@keyframes led-pulse { 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { [data-theme="kara"] .led { animation: none !important; } }

/* stability meter */
[data-theme="kara"] .stab { display: flex; align-items: center; gap: 8px; font-size: 11px; letter-spacing: .16em; color: var(--muted); }
[data-theme="kara"] .stab.hidden { display: none; }
[data-theme="kara"] .stab i { width: 90px; height: 4px; background: rgba(58, 208, 255, .15); position: relative; }
[data-theme="kara"] .stab b { position: absolute; inset: 0 auto 0 0; background: var(--accent); box-shadow: 0 0 8px var(--accent); transition: width .6s; }
[data-theme="kara"] .stab[data-level="warn"] b { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
[data-theme="kara"] .stab[data-level="bad"] b { background: var(--bad); box-shadow: 0 0 8px var(--bad); }
[data-theme="kara"] .stab em { font-style: normal; color: var(--text); min-width: 34px; }
@media (max-width: 860px) { [data-theme="kara"] .stab { display: none; } }


/* ===================== design layer (Dec 2026): the owner's background shows through glass panels ===================== */
/* the picture: in every theme; --bg-dim (0 = as is) and --glass (panel opacity) come from Settings → «Внешний вид» */
html.has-bg body { background: rgb(var(--bg-rgb)); }
html.has-bg body::before { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(rgb(var(--bg-rgb) / var(--bg-dim, .25)), rgb(var(--bg-rgb) / calc(var(--bg-dim, .25) + .12))), var(--user-bg) center / cover no-repeat; }
.sidebar, .topbar, .composer-wrap, .card, .tcard, .row-item, .stat, .machine, .mcard, .set-group, .pitem, .sitem,
.modal-card, .login-card, .palette, .msg.bruce .bubble, .seg, .desk, .composer {
  -webkit-backdrop-filter: blur(16px) saturate(1.35); backdrop-filter: blur(16px) saturate(1.35); }
.topbar, .composer-wrap { background: rgb(var(--s-rgb) / calc(var(--glass, .8) * .75)); }
.sidebar { border-right-color: color-mix(in srgb, var(--line) 70%, transparent); }
.composer-wrap { border-top: 0; }
.seg { background: rgb(var(--s-rgb) / calc(var(--glass, .8) * .8)); border: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent); box-shadow: none; }
/* text that sits right on the picture stays readable */
html.has-bg .view > h2, html.has-bg .view > .muted, html.has-bg .view > div > h2, html.has-bg .plan-cols h2, html.has-bg .hint, html.has-bg .counts,
html.has-bg .msg.bruce .who, html.has-bg h2 .small, html.has-bg .list > .muted, html.has-bg .grid > .muted, html.has-bg #machines > .muted,
html.has-bg .toolbar .muted { text-shadow: 0 1px 2px rgb(var(--bg-rgb) / .95), 0 0 14px rgb(var(--bg-rgb) / .9); }
html.has-bg .view > .muted, html.has-bg h2 .small, html.has-bg .msg.bruce .who, html.has-bg .list > .muted, html.has-bg .grid > .muted,
html.has-bg #machines > .muted, html.has-bg .counts, html.has-bg .hint, html.has-bg .toolbar .muted { color: var(--text); opacity: .92; }

/* typography and rhythm */
body { font-size: 15px; letter-spacing: .005em; }
h2 { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 26px 2px 10px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
h2 .small { text-transform: none; letter-spacing: 0; }
.view { padding: 20px 24px 28px; }
.view > *:first-child { margin-top: 0; }
.card { padding: 16px; border-radius: var(--radius); box-shadow: var(--shadow); }
.btn { border-radius: 11px; font-weight: 500; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn.primary:hover { filter: brightness(1.08); }
input, textarea, select { background: rgb(var(--s-rgb) / .55); }
input[type=range] { padding: 0; accent-color: var(--accent); width: min(220px, 45vw); background: none; border: 0; }
.topbar { min-height: 56px; padding: 10px 20px; }
.topbar .title { font-size: 16px; }

/* sidebar */
.sidebar { padding: 18px 14px; gap: 14px; }
.brand { padding: 2px 6px 4px; }
.nav a { padding: 9px 12px; border-radius: 11px; transition: background .15s, color .15s; }
.nav a span { flex: 1; }
.conv { border-radius: 10px; }
.conv.active { background: var(--accent-soft); color: var(--accent); }
.convs-title { padding: 0 8px; }

/* chat: KARA's answers on a glass bubble, the owner's on the accent */
.messages { padding: 24px 24px 10px; gap: 18px; }
.msg.bruce .bubble { background: var(--surface); border: 1px solid var(--line); border-radius: 6px 18px 18px 18px; padding: 12px 15px; box-shadow: var(--shadow); }
.msg.bruce .bubble:empty { display: none; }
.msg.user { box-shadow: 0 6px 18px color-mix(in srgb, var(--user) 35%, transparent); }
.composer-wrap { padding: 10px 24px calc(14px + env(safe-area-inset-bottom)); }
.composer { border-radius: 22px; padding: 6px 6px 6px 10px; }
.chips button { background: rgb(var(--s-rgb) / calc(var(--glass, .8) * .85)); }
.empty-chat { background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 28px; box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }

/* lists and cards */
.row-item, .pitem, .sitem { border-radius: 14px; transition: border-color .15s, transform .15s; }
.row-item:hover { transform: translateY(-1px); }
.stats { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 12px; }
.stat { padding: 14px 16px; border-radius: var(--radius); box-shadow: var(--shadow); }
.stat .v { font-size: 24px; letter-spacing: -.01em; }
.mcard, .machine { box-shadow: var(--shadow); }
.table th { text-transform: uppercase; font-size: 11px; letter-spacing: .06em; }
.table tr:hover td { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.warnbox { border-color: color-mix(in srgb, var(--warn) 45%, transparent); margin: 12px 0; }
.warn-t { color: var(--warn); }

/* «Экраны»: remote desktops */
.desks { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; margin-top: 14px; }
.desk { display: flex; gap: 14px; align-items: flex-start; }
.desk-ico { font-size: 34px; line-height: 1; width: 56px; height: 56px; display: grid; place-items: center; border-radius: 16px; background: var(--accent-soft); flex: none; }
.desk-body { display: grid; gap: 6px; min-width: 0; flex: 1; }
.desk-body .h { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.desk-body .row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.desk-body code { font-size: 11px; display: inline-block; margin: 2px 4px 0 0; padding: 1px 6px; border-radius: 6px; background: var(--code); }
.desk-overlay { position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column; background: #000; }
.desk-bar { display: flex; gap: 10px; align-items: center; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); background: rgb(var(--s-rgb)); border-bottom: 1px solid var(--line); }
.desk-bar b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.desk-overlay iframe { flex: 1; border: 0; width: 100%; background: #000; }

/* phone */
@media (max-width: 860px) {
  .app { grid-template-rows: minmax(0, 1fr); }
  .view { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  .main { grid-row: 1; }
  .view { padding: 14px 12px 20px; }
  .messages { padding: 16px 12px 8px; }
  .composer-wrap { padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); }
  .topbar { min-height: 52px; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); }
  .desks { grid-template-columns: 1fr; }
  .desk-bar .muted { display: none; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* theme «KARA»: tidier — headings tracked, the rest in normal case; corners slightly rounder */
:root[data-theme="kara"] { --radius: 6px; }
[data-theme="kara"] .nav a { font-size: 14.5px; letter-spacing: .02em; }
[data-theme="kara"] .btn { border-radius: 4px; letter-spacing: .06em; font-size: 12.5px; }
[data-theme="kara"] .msg.bruce .bubble { border-radius: 3px 10px 10px 10px; border-color: rgba(58, 208, 255, .22); }
[data-theme="kara"] h2 { color: var(--accent); }
[data-theme="kara"] .desk-ico { border-radius: 6px; box-shadow: inset 0 0 0 1px var(--line); }
@media (prefers-reduced-transparency: reduce) { :root { --glass: .96 !important; } }

/* ---- mega-projects («Проекты») ---- */
.mega { display: flex; flex-direction: column; gap: 8px; }
.mega .h { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mega .bar { height: 6px; border-radius: 99px; background: rgb(var(--s-rgb) / .5); border: 1px solid var(--line); overflow: hidden; }
.mega .bar i { display: block; height: 100%; background: var(--accent); transition: width .4s; }
.mega .warnbox .pre { max-height: 40vh; background: transparent; border: 0; padding: 0; font: inherit; }
.mphases { margin: 0; padding-left: 0; list-style: none; display: grid; gap: 4px; }
.mph.later { opacity: .55; }
.mph.now b { color: var(--accent); }
.mms { display: inline-block; margin: 2px 6px 2px 0; }
.mms.later { opacity: .55; }
.mms.now { font-weight: 600; color: var(--accent); }
/* KARA's requests to the owner («Просьбы») */
.card.req { display: flex; flex-direction: column; gap: 8px; border-left: 3px solid var(--warn); }
.card.req .h { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: baseline; justify-content: space-between; }
.card.req input, .card.req textarea { width: 100%; }
.card.req .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* places in the rating instead of medal emoji (the owner, 06.12.2026: no emoji in the web app) */
.place { display: inline-grid; place-items: center; min-width: 26px; height: 26px; border-radius: 50%; font-weight: 700; font-size: 13px; background: var(--bg3); color: var(--muted); }
.place.p1 { background: #f5c542; color: #3a2a00; } .place.p2 { background: #c9ced8; color: #222; } .place.p3 { background: #d99a5b; color: #2a1500; }
.rate .icon-btn { width: auto; padding: 0 10px; font-size: 12px; }
.desk-ico { font-weight: 700; font-size: 14px; letter-spacing: .04em; color: var(--muted); }

/* «Лимиты»: what is left for every model, as cards */
.left-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.lcard { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--surface); display: grid; gap: 4px; min-width: 0; }
.lcard .lh { display: flex; justify-content: space-between; gap: 6px; min-width: 0; }
.lcard .lh b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.lcard .lnum { font-size: 13px; color: var(--muted); } .lcard .lnum b { font-size: 22px; color: var(--text); }
.lcard .lbar { height: 6px; border-radius: 3px; background: var(--bg3); overflow: hidden; }
.lcard .lbar i { display: block; height: 100%; background: var(--accent); }
.lcard.ok .lbar i { background: var(--ok); } .lcard.warn .lbar i { background: var(--warn); } .lcard.bad .lbar i { background: var(--bad); }
@media (max-width: 860px) { .left-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* grouped menu, «Сводка», «Файлы» */
.nav-sec { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 10px 12px 2px; }
.stat small { font-size: 12px; color: var(--muted); } .stat small.bad { color: var(--bad); }
.stat.warn .v { color: var(--warn); }
.file-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.fcard { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); display: grid; min-width: 0; }
.fcard img, .fcard video { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: #000; display: block; }
.fcard audio { width: 100%; margin: 10px 0 0; }
.fcard .fext { aspect-ratio: 16 / 9; display: grid; place-items: center; font-weight: 700; letter-spacing: .1em; color: var(--muted); background: var(--bg3); }
.fcard .fb { padding: 8px 10px 10px; min-width: 0; }
.fcard .fb b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.fcard .fb .muted { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
@media (max-width: 860px) { .file-grid { grid-template-columns: 1fr; } }
/* the menu grew (Сводка, Файлы, sections): the sidebar scrolls as a whole and the chats keep room */
.sidebar { overflow-y: auto; }
.nav a { padding: 7px 10px; }
.convs { flex: 1 0 auto; min-height: 180px; overflow: visible; }

/* models KARA does not use now (paid with budget 0, local switched off) */
.mcard.off, .lcard.off, tr.off { opacity: .5; }
