:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --line: #e2e6ec;
  --text: #18202d;
  --muted: #5f6b7c;
  --accent: #1e3a8a;
  --accent-soft: #e6ecfa;
  --ok: #1a7f37;
  --warn: #9a6700;
  --crit: #c4232d;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 12px rgba(16,24,40,.05);
  --radius: 12px;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Source Serif 4', Georgia, serif;
  --x-docx: #2b579a; --x-pdf: #c4232d; --x-xlsx: #1d6f42; --x-pptx: #c43e1c; --x-other: #5f6b7c;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --panel: #161c25; --panel-2: #1b222d; --line: #2a3340; --text: #e7ebf1; --muted: #93a0b2;
    --accent: #8fb0ff; --accent-soft: #1f2a44; --ok: #3fb950; --warn: #d29922; --crit: #f85149;
    --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 8px 24px rgba(0,0,0,.25);
    --x-docx: #6f9be0; --x-pdf: #f0706a; --x-xlsx: #4cb878; --x-pptx: #ef8a61; --x-other: #93a0b2;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141b; --panel: #161c25; --panel-2: #1b222d; --line: #2a3340; --text: #e7ebf1; --muted: #93a0b2;
  --accent: #8fb0ff; --accent-soft: #1f2a44; --ok: #3fb950; --warn: #d29922; --crit: #f85149;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 8px 24px rgba(0,0,0,.25);
  --x-docx: #6f9be0; --x-pdf: #f0706a; --x-xlsx: #4cb878; --x-pptx: #ef8a61; --x-other: #93a0b2;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); }
h2 { font: 600 16px/1.3 var(--serif); margin: 0; }
h3 { margin: 0; }
code { font-family: var(--mono); font-size: 12px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.sm { font-size: 13px; } .xs { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.error-text { color: var(--crit); font-size: 13px; margin: 6px 0 0; min-height: 0; }
.error-text:empty { display: none; }
[hidden] { display: none !important; }

.btn { font: 500 14px var(--sans); border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; padding: 8px 14px; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #0f141b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #0f141b; } }
.btn.danger { color: var(--crit); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.icon-btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 16px; }
input, select, textarea { font: 14px var(--sans); color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { width: 100%; resize: vertical; line-height: 1.5; }
.field { display: grid; gap: 6px; margin: 16px 0 4px; }
.field span { font-weight: 500; font-size: 13px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.login-card p { margin: 8px 0 0; }
.login-card .btn { margin-top: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font: 600 16px var(--serif); white-space: nowrap; }
.brand b { color: var(--accent); }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font: 700 16px var(--serif); }
.brand.big { font-size: 20px; }
.brand.big .brand-mark { width: 38px; height: 38px; font-size: 20px; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 20px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tab { border: 0; background: none; color: var(--muted); font: 500 14px var(--sans); padding: 8px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--accent); }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--crit); }
.conn.on { background: var(--ok); }

.tab-panel { padding: 20px; max-width: 1500px; margin: 0 auto; display: grid; gap: 20px; }
.banner { padding: 12px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); }
.banner.warn { border-color: color-mix(in srgb, var(--warn) 45%, transparent); background: color-mix(in srgb, var(--warn) 9%, var(--panel)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.head-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: none; color: var(--muted); padding: 6px 10px; font: 500 13px var(--sans); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--accent-soft); color: var(--accent); }

.office-grid { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 20px; align-items: start; }
.canvas-wrap { border-radius: 10px; overflow: hidden; background: #1b2030; }
#office { display: block; width: 100%; image-rendering: pixelated; }
.agent-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-top: 12px; }
.agent { position: relative; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 10px 16px; background: var(--panel-2); cursor: pointer; }
.agent::before { content: ''; position: absolute; left: 0; top: 10px; bottom: 10px; width: 4px; border-radius: 0 3px 3px 0; background: var(--rc); }
.agent.sel { border-color: var(--rc); }
.agent .a-top { display: flex; align-items: center; gap: 6px; }
.agent .a-nick { font-weight: 600; }
.agent .a-role { font-size: 12px; color: var(--muted); }
.agent .a-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); margin-left: auto; }
.agent.working .a-dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.agent .a-detail { font-size: 12px; color: var(--muted); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.9em; }

.side { display: grid; gap: 20px; min-width: 0; }
.composer { display: grid; gap: 10px; }
.composer-row { display: flex; gap: 8px; align-items: center; }
.composer-row select { flex: 1; }
.composer p { margin: 0; }
.kinds { display: flex; flex-wrap: wrap; gap: 6px; }
.kind { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 999px; padding: 4px 10px; font: 500 12px var(--sans); cursor: pointer; }
.kind[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.attach-row { position: relative; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.attach-row .btn { display: inline-flex; align-items: center; gap: 6px; }
.pick summary { list-style: none; display: inline-block; }
.pick summary::-webkit-details-marker { display: none; }
.pick-pop { position: absolute; z-index: 10; top: calc(100% + 4px); left: 0; right: 0; max-height: 260px; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; }
.pick-pop ul { list-style: none; margin: 0; padding: 0; }
.pick-pop label { display: flex; gap: 8px; align-items: center; padding: 6px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.pick-pop label:hover { background: var(--panel-2); }
.pick-pop label span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-pop .empty { color: var(--muted); font-size: 13px; padding: 6px; }
.attach-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.attach-list:empty { display: none; }
.attach-list li { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 3px 4px 3px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel-2); font-size: 12px; }
.attach-list li.busy { color: var(--muted); }
.attach-list li.bad { color: var(--crit); border-color: var(--crit); }
.attach-list li span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.attach-list li .ext { width: auto; padding: 1px 5px; font-size: 9px; }
.attach-list button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; padding: 0 4px; }
#taskPrompt.over { outline: 2px dashed var(--accent); }
.chip-resume { display: flex; gap: 6px; align-items: center; font-size: 12px; background: var(--accent-soft); color: var(--accent); padding: 6px 10px; border-radius: 8px; }
.chip-resume span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.chip-resume button { border: 0; background: none; color: inherit; cursor: pointer; font-size: 16px; }
.running { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 8px; }
.running .r-row { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.running .r-prompt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.feed-card { display: flex; flex-direction: column; }
.feed { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow: auto; display: grid; gap: 2px; }
.feed li { display: grid; grid-template-columns: 44px 18px minmax(0, 1fr); gap: 6px; padding: 5px 4px; border-radius: 6px; font-size: 13px; }
.feed li:hover { background: var(--panel-2); }
.feed .f-time { color: var(--muted); font: 11px var(--mono); padding-top: 2px; }
.feed .f-role { font-weight: 600; color: var(--rc); margin-right: 4px; }
.feed .f-text { overflow-wrap: anywhere; }
.feed li.warn .f-text, .feed li.error .f-text { color: var(--crit); }
.feed .empty { display: block; color: var(--muted); padding: 12px 4px; }

.docs-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; align-items: start; }
.doc-groups { display: grid; gap: 14px; }
.doc-group { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.doc-group > header { display: flex; gap: 10px; align-items: baseline; padding: 10px 12px; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.doc-group > header b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.doc-group > header button { flex: none; }
.doc-list { list-style: none; margin: 0; padding: 0; }
.doc-list li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--line); }
.doc-list li:first-child { border-top: 0; }
.doc-list .empty { color: var(--muted); display: block; }
.ext { flex: none; width: 42px; text-align: center; font: 700 10px var(--mono); color: #fff; background: var(--x); border-radius: 5px; padding: 4px 0; text-transform: uppercase; }
.d-name { flex: 1; min-width: 0; }
.d-name b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d-name span { font-size: 12px; color: var(--muted); }
.d-act { display: flex; gap: 6px; flex: none; }
.d-act a, .d-act button { font-size: 12px; }
.linkbtn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px; font: 12px var(--sans); }
.linkbtn:hover { color: var(--crit); }
.drop { display: grid; gap: 4px; text-align: center; padding: 22px 12px; border: 2px dashed var(--line); border-radius: 10px; cursor: pointer; margin-bottom: 12px; }
.drop.over, .drop:hover, .drop:focus-visible { border-color: var(--accent); background: var(--accent-soft); outline: none; }
.uploads { list-style: none; margin: 0 0 8px; padding: 0; font-size: 12px; display: grid; gap: 4px; }
.uploads .bad { color: var(--crit); }
.empty-state { color: var(--muted); padding: 24px 8px; text-align: center; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr.click { cursor: pointer; }
.table tbody tr:hover { background: var(--panel-2); }
.table .clip { max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--panel-2); border: 1px solid var(--line); white-space: nowrap; }
.pill.ok { color: var(--ok); } .pill.warn { color: var(--warn); } .pill.crit { color: var(--crit); } .pill.info { color: var(--accent); }

.dialog { width: min(820px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.dialog::backdrop { background: rgba(10,15,25,.5); }
.dialog-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.dialog-head h2 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog-body { padding: 16px 18px; display: grid; gap: 10px; }
.sub-h { font: 600 13px var(--sans); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 6px; }
.prompt-box { white-space: pre-wrap; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; max-height: 200px; overflow: auto; }
.result { line-height: 1.6; overflow-wrap: anywhere; }
.result p { margin: 0 0 8px; }
.result ul { margin: 0 0 8px; padding-left: 20px; }
.result h4 { margin: 10px 0 4px; font: 600 14px var(--serif); }
.result code { background: var(--panel-2); padding: 1px 4px; border-radius: 4px; }
.dialog .doc-list { border: 1px solid var(--line); border-radius: 8px; }
.log summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.log .feed { margin-top: 8px; max-height: 320px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

@media (max-width: 1100px) {
  .office-grid, .docs-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 16px; }
  .tabs { order: 3; width: 100%; }
  .tab-panel { padding: 16px; gap: 16px; }
  .brand > span:last-child { font-size: 15px; }
  .doc-list li { flex-wrap: wrap; }
  .d-act { width: 100%; justify-content: flex-end; }
  .agent-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
