:root {
  --bg: #1a1814;
  --panel: #23201b;
  --panel-2: #2c2822;
  --line: #3a352d;
  --text: #ece6da;
  --muted: #9a9284;
  --accent: #f0a34a;
  --ok: #6fcf86;
  --err: #ef6b6b;
  --badge: rgba(28, 26, 23, 0.92);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.4 var(--font); }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* вход */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(340px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; display: grid; gap: 12px; }
.login-title { font-size: 20px; font-weight: 700; }
.login-sub { color: var(--muted); }
.login-card input { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 11px 12px; color: var(--text); font: inherit; }
.login-card button { background: var(--accent); color: #1a1814; border: 0; border-radius: 8px; padding: 11px; font-weight: 700; }
.login-err { color: var(--err); min-height: 1.2em; }

/* каркас */
.app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--panel); flex: none; padding-top: max(8px, env(safe-area-inset-top)); }
.brand { font-weight: 800; letter-spacing: .3px; }
@media (max-width: 420px) { .brand { display: none; } }
.summary { color: var(--muted); font-size: 13px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.summary b { color: var(--text); font-weight: 600; }
.top-actions { display: flex; gap: 6px; }
.tab-btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; font-size: 13px; }
.tab-btn.active { border-color: var(--accent); color: var(--accent); }
.banner { padding: 8px 16px; background: #4a3417; color: #ffd9a8; font-size: 13px; border-bottom: 1px solid #6b4a1f; }
.main { flex: 1; display: flex; min-height: 0; }
.office { position: relative; flex: 1; overflow-x: hidden; overflow-y: auto; scrollbar-gutter: stable; background: #12110e; }
#canvas { display: block; image-rendering: pixelated; image-rendering: crisp-edges; margin: 0 auto; }
#badges { position: absolute; left: 0; top: 0; pointer-events: none; }

/* бейджи над агентами */
.badge {
  position: absolute; transform: translate(-50%, -100%); pointer-events: auto; cursor: pointer;
  display: flex; align-items: center; gap: 6px; padding: 4px 9px 4px 5px; border-radius: 999px;
  background: var(--badge); border: 1px solid rgba(255,255,255,.08); white-space: nowrap;
  font-size: 12.5px; box-shadow: 0 2px 6px rgba(0,0,0,.35); user-select: none;
  transition: border-color .2s;
}
.badge:hover { border-color: rgba(255,255,255,.3); }
.badge .tag { font: 700 11px/1 var(--font); padding: 2px 3px; border-radius: 5px; color: #15130f; }
/* за столом переговорки — только иконка профессии, иначе вся команда не помещается */
.badge.compact { padding: 2px; gap: 0; }
.badge.compact .nm, .badge.compact .st { display: none; }
.badge .nm { font-weight: 700; }
.badge .st { color: var(--muted); }
.badge.working .st { color: #d8cfbf; }
.badge.done .st { color: var(--ok); }
.badge.error .st { color: var(--err); }
.badge .dots::after { content: ''; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.badge.unread { border-color: var(--accent); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(240,163,74,.25); } }
.badge.selected { border-color: var(--text); }

/* боковая панель / шторка */
.panel { width: 420px; flex: none; display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); min-height: 0; }
@media (max-width: 860px) {
  .panel { position: fixed; inset: 0; width: auto; z-index: 20; border: 0; padding-bottom: env(safe-area-inset-bottom); }
}
.panel-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex: none; }
.back { background: none; border: 0; font-size: 18px; color: var(--muted); padding: 2px 6px; }
.panel-title { flex: 1; min-width: 0; }
.panel-title .t1 { font-weight: 700; display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.panel-title .t1 > span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.panel-title .t2 { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-tools { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; max-width: 55%; }
.tool-btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 4px 8px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.tool-btn:hover { color: var(--text); }
.tool-btn:disabled { opacity: .6; cursor: default; }
.panel-title .ctx.big { color: #e8a33d; }
.panel-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }

/* сообщения */
.msg { max-width: 88%; padding: 8px 11px; border-radius: 12px; background: var(--panel-2); word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: #3d3324; border-bottom-right-radius: 4px; }
.msg.agent { align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.task { align-self: flex-start; background: #2a2a1e; border: 1px solid #4a4526; }
.msg.error { border: 1px solid #6b2f2f; background: #2d1f1f; }
.msg.ack { padding: 5px 10px; font-size: 13px; color: #cfc6b6; }
.msg .who { font-size: 11.5px; color: var(--muted); margin-bottom: 3px; }
.msg .time { font-size: 10.5px; color: #6f685c; margin-top: 4px; text-align: right; }
.msg pre { background: #161511; padding: 8px; border-radius: 6px; overflow-x: auto; font: 12px/1.45 var(--mono); white-space: pre; }
.msg code { font: 12.5px var(--mono); background: #161511; padding: 1px 4px; border-radius: 4px; }
.msg pre code { background: none; padding: 0; }
.msg h4 { margin: 6px 0 2px; font-size: 14px; }
.tool { align-self: flex-start; font: 11.5px/1.35 var(--mono); color: #8d8676; padding: 0 4px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sys { align-self: center; font-size: 12px; color: var(--muted); text-align: center; padding: 2px 8px; }
.assign { margin-top: 8px; display: grid; gap: 5px; }
.assign-item { background: #1d1b17; border-radius: 8px; padding: 6px 8px; font-size: 13px; border-left: 3px solid var(--c, var(--accent)); }
.assign-item b { cursor: pointer; }
.empty { color: var(--muted); text-align: center; margin-top: 30px; }

/* лента */
.feed-item { display: grid; gap: 2px; padding: 8px 10px; border-radius: 10px; background: var(--panel-2); }
.feed-item .fh { font-size: 12px; color: var(--muted); }
.feed-item .fh b { color: var(--text); cursor: pointer; }
.feed-item .fb { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 7.2em; overflow: hidden; }
.job { padding: 9px 10px; border-radius: 10px; background: #26231d; border: 1px solid var(--line); display: grid; gap: 6px; }
.job-title { font-weight: 600; }
.job-subs { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { font-size: 11.5px; padding: 2px 7px; border-radius: 999px; background: #1a1814; border: 1px solid var(--line); }
.chip.done { border-color: #2f6b3d; color: var(--ok); }
.chip.error { border-color: #6b2f2f; color: var(--err); }
.chip.working { border-color: #6b5426; color: var(--accent); }
.section-h { font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 6px 2px 0; }

/* файлы */
.crumbs { font: 12px var(--mono); color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px; }
.crumbs a { color: var(--accent); cursor: pointer; text-decoration: none; }
.file-row { display: flex; gap: 8px; align-items: center; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.file-row:hover { background: var(--panel-2); }
.file-row .fn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .fs { color: var(--muted); font-size: 12px; }
.file-view { background: #161511; border-radius: 8px; padding: 10px; font: 12px/1.5 var(--mono); white-space: pre; overflow: auto; }
.file-actions { display: flex; gap: 8px; }
.file-actions a { color: var(--accent); font-size: 13px; }

/* ход работы агента */
.tool-item { align-self: stretch; font: 11.5px/1.35 var(--mono); color: #8d8676; }
.tool-line { display: flex; gap: 6px; align-items: center; cursor: pointer; padding: 1px 4px; border-radius: 6px; min-width: 0; }
.tool-line:hover { background: #2a2620; color: #b7af9f; }
.tool-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ts { flex: none; width: 12px; text-align: center; }
.ts.ok { color: var(--ok); }
.ts.err { color: var(--err); }
.ts.run::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--accent); border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.tool-detail { display: none; margin: 4px 0 6px 18px; }
.tool-item.open .tool-detail { display: block; }
.tool-detail pre { margin: 0; background: #161511; color: #cfc6b6; padding: 8px; border-radius: 6px; white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto; font: 11.5px/1.45 var(--mono); }
.tool-detail pre.err { color: #f2a0a0; }
.tool-res-h { color: var(--muted); font: 600 10.5px var(--font); text-transform: uppercase; letter-spacing: .5px; margin: 6px 0 3px; }
.note { align-self: flex-start; max-width: 92%; color: #b3ab9c; font-size: 13px; font-style: italic; padding: 0 4px; overflow-wrap: anywhere; }
.msg.live { border: 1px dashed #4a4336; }
.cursor { animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

/* вложения */
.atts { display: grid; gap: 6px; margin-top: 6px; }
.att-img { max-width: 100%; max-height: 260px; border-radius: 8px; display: block; }
.att-video { width: 100%; max-height: 300px; border-radius: 8px; background: #000; }
.att-audio audio { width: 100%; max-width: 280px; height: 36px; }
.att-tr { font-size: 12.5px; color: #e6dccb; margin-top: 3px; }
.att-media { display: grid; gap: 3px; }
.att-img-btn { background: none; border: 0; padding: 0; cursor: zoom-in; justify-self: start; max-width: 100%; }
.att-meta { display: flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--muted); min-width: 0; }
.att-meta .att-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.att-meta .att-dl { margin-left: auto; }
.att-dl { flex: none; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; width: 30px; height: 28px; padding: 0; font-size: 13px; color: var(--text); cursor: pointer; }
.att-dl:hover { border-color: var(--accent); color: var(--accent); }
.att-file { display: flex; align-items: center; gap: 6px; background: #1d1b17; border: 1px solid var(--line); border-radius: 10px; padding: 6px 6px 6px 8px; min-width: 0; }
.att-file-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; background: none; border: 0; padding: 0; color: var(--text); text-align: left; cursor: pointer; }
.att-ico { font-size: 22px; flex: none; }
.att-fn { display: grid; min-width: 0; }
.att-fn .att-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-sub { font-size: 11px; color: var(--muted); }
code.file-link { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 2px; }
code.file-link:hover { color: var(--accent); }

/* просмотр файла поверх всего */
.viewer { position: fixed; inset: 0; z-index: 50; background: rgba(10, 9, 8, .96); display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }
.viewer-top { display: flex; align-items: center; gap: 10px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); flex: none; }
.viewer-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; color: var(--text); font-size: 13px; white-space: nowrap; }
.viewer-body { flex: 1; min-height: 0; overflow: auto; padding: 12px; }
.viewer-body.center { display: flex; align-items: center; justify-content: center; }
.viewer-body img, .viewer-body video { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-body audio { width: 100%; margin-top: 30vh; }
.viewer-body iframe { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 6px; }
.viewer-text { margin: 0; white-space: pre-wrap; word-break: break-word; font: 12.5px/1.5 var(--mono); color: #d8d0c2; }
.viewer-md { max-width: 760px; margin: 0 auto; line-height: 1.55; overflow-wrap: anywhere; }
.viewer-md h2, .viewer-md h3, .viewer-md h4, .viewer-md h5, .viewer-md h6 { margin: 18px 0 6px; line-height: 1.3; }
.viewer-md h2 { font-size: 20px; } .viewer-md h3 { font-size: 17px; } .viewer-md h4, .viewer-md h5, .viewer-md h6 { font-size: 15px; }
.viewer-md p { margin: 6px 0; }
.viewer-md ul, .viewer-md ol { margin: 6px 0; padding-left: 22px; }
.viewer-md li { margin: 2px 0; }
.viewer-md blockquote { margin: 8px 0; padding: 4px 12px; border-left: 3px solid var(--accent); color: #cfc6b6; }
.viewer-md hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.viewer-md pre { background: #161511; padding: 10px; border-radius: 8px; overflow: auto; font: 12px/1.45 var(--mono); }
.viewer-md code { background: #2c2822; padding: 1px 4px; border-radius: 4px; font: 12.5px var(--mono); }
.md-table { overflow-x: auto; margin: 8px 0; }
.md-table table { border-collapse: collapse; font-size: 13px; min-width: 100%; }
.md-table th, .md-table td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
.md-table th { background: var(--panel-2); }

/* профиль агента */
.panel-title.clickable { cursor: pointer; }
.prof-card { display: grid; justify-items: center; gap: 2px; padding: 10px 0 4px; text-align: center; }
.prof-ava { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-size: 30px; color: #15130f; font-weight: 700; margin-bottom: 6px; }
.prof-name { font-size: 17px; font-weight: 700; }
.prof-title, .prof-stat { color: var(--muted); font-size: 12.5px; }
.prof-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; padding: 4px 0 6px; }
.prof-filters { display: flex; gap: 6px; overflow-x: auto; padding: 6px 0 2px; scrollbar-width: none; flex: none; }
.pf-chip { flex: none; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; font-size: 12.5px; color: var(--text); white-space: nowrap; }
.pf-chip span { color: var(--muted); margin-left: 2px; }
.pf-chip.active { background: var(--accent); border-color: var(--accent); color: #1a1814; }
.pf-chip.active span { color: #3a2a12; }
.prof-day { position: sticky; top: -12px; z-index: 1; background: var(--panel); font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 2px 4px; }
.prof-list { display: grid; gap: 2px; }
.prof-row { display: flex; align-items: center; gap: 10px; padding: 7px 6px; border-radius: 10px; cursor: pointer; min-width: 0; }
.prof-row:hover { background: var(--panel-2); }
.prof-row.missing { opacity: .5; cursor: default; }
.prof-ico { width: 42px; height: 42px; flex: none; border-radius: 8px; background: #1d1b17; display: grid; place-items: center; font-size: 22px; overflow: hidden; }
.prof-ico img { width: 100%; height: 100%; object-fit: cover; }
.prof-fn { flex: 1; min-width: 0; }
.prof-fname { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prof-meta { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prof-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.prof-tile { position: relative; aspect-ratio: 1; padding: 0; border: 0; border-radius: 4px; overflow: hidden; background: #1d1b17; cursor: pointer; color: var(--muted); font-size: 11px; }
.prof-tile img, .prof-tile video { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.prof-play { position: absolute; inset: auto auto 6px 6px; background: rgba(0, 0, 0, .6); color: #fff; border-radius: 999px; padding: 1px 7px; font-size: 11px; }

/* ввод */
.composer-wrap { flex: none; border-top: 1px solid var(--line); }
.busy-row { display: flex; align-items: center; gap: 8px; padding: 7px 12px; background: #2a2419; font-size: 12.5px; }
.busy-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse2 1.2s ease-in-out infinite; flex: none; }
@keyframes pulse2 { 50% { opacity: .3; } }
.busy-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #e6dccb; }
.queue-mode { color: var(--muted); display: flex; gap: 4px; align-items: center; white-space: nowrap; }
.stop-btn { background: #5a2323; border: 1px solid #7a3030; color: #ffd6d6; border-radius: 8px; padding: 4px 10px; font-size: 12.5px; font-weight: 600; }
.stop-btn:disabled { opacity: .6; }
/* озвучка */
.msg .time .say { float: left; background: none; border: 0; padding: 0; font-size: 11.5px; color: var(--muted); cursor: pointer; }
.msg .time .say:hover, .msg .time .say.on { color: var(--accent); }
.speech-bar { flex: none; display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-top: 1px solid var(--line); background: #1f2a26; font-size: 12.5px; }
.speech-who { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #d6eadf; }
.speech-btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; min-width: 32px; padding: 4px 8px; font-size: 12.5px; color: var(--text); }
.speech-rate { font-variant-numeric: tabular-nums; min-width: 48px; }
.att-strip { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px 0; }
.att-chip { display: flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px 4px 9px; font-size: 12px; max-width: 100%; }
.att-chip .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.att-chip .pr { color: var(--muted); }
.att-chip.err { border-color: #6b2f2f; color: var(--err); }
.att-chip button { background: none; border: 0; color: var(--muted); padding: 0 3px; }
.att-chip.rec { border-color: #7a3030; }
.att-chip.rec button:not(.x) { color: var(--accent); font-weight: 600; }
.rec-dot { width: 8px; height: 8px; border-radius: 50%; background: #ef4b4b; animation: pulse2 1s infinite; }
.icon-btn { flex: none; width: 38px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; font-size: 17px; padding: 0; }
.icon-btn.on { background: #5a2323; border-color: #ef4b4b; }
.composer { display: flex; gap: 8px; padding: 10px 12px; flex: none; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.composer textarea { flex: 1; resize: none; max-height: 160px; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; font: inherit; }
.composer textarea:focus { outline: none; border-color: var(--accent); }
.composer button { width: 42px; border: 0; border-radius: 10px; background: var(--accent); color: #1a1814; font-size: 16px; font-weight: 700; }
.composer button:disabled { opacity: .5; }
