:root {
  --night-900: #0E2023;
  --night-950: #0D1F21;
  --surface-800: #182A2D;
  --line-600: #5B7D80;
  --sage-200: #D8E5E2;
  --white: #FFFFFF;
  --lime-500: #64E408;
  --teal-500: #04CE9B;
  --cyan-400: #00E7F7;
  --ink-900: #102427;
  --warn: #F2B84B;
  --danger: #FF7A6B;
  --radius: 8px;
  --radius-card: 16px;
  --font: TildaSans, Arial, "Helvetica Neue", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--night-900); color: var(--white); font: 17px/1.55 var(--font); }
body { min-height: 100vh; }
#net { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; opacity: 0.55; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.top { position: relative; z-index: 2; display: flex; align-items: center; gap: 16px; padding: 16px 32px; flex-wrap: wrap; }
.brand { display: flex; flex-direction: column; margin-right: auto; }
.brand-name { font-weight: 700; letter-spacing: 0.12em; font-size: 15px; color: var(--white); }
.brand-sub { color: var(--sage-200); font-size: 16px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line-600); border-radius: 999px; padding: 5px 14px; font-size: 15px; color: var(--sage-200); background: var(--night-950); }
.chip.warn { border-color: var(--warn); color: var(--warn); }
.chip.bad { border-color: var(--danger); color: var(--danger); }
.chip.ok { border-color: var(--teal-500); color: var(--teal-500); }
.sweep { position: relative; z-index: 2; height: 2px; background: linear-gradient(90deg, var(--lime-500), var(--teal-500)); transform-origin: left; animation: sweep 1.2s ease-out 1; }
@keyframes sweep { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.btn { font: inherit; cursor: pointer; border-radius: var(--radius); padding: 8px 16px; border: 1px solid var(--line-600); background: transparent; color: var(--white); }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, .desk:focus-visible { outline: 2px solid var(--cyan-400); outline-offset: 2px; }
.btn-primary { border: 0; color: var(--ink-900); font-weight: 700; background: linear-gradient(90deg, var(--lime-500), var(--teal-500)); }
.btn-ghost:hover { border-color: var(--sage-200); }
.btn-stop { border-color: var(--danger); color: var(--danger); font-weight: 700; }
.btn-stop.arm { background: var(--danger); color: var(--ink-900); }

main { position: relative; z-index: 1; display: grid; grid-template-columns: clamp(290px, 19vw, 400px) minmax(0, 1fr) clamp(340px, 23vw, 440px); gap: 20px; padding: 16px 24px 40px; max-width: none; margin: 0; align-items: start; }
@media (max-width: 1100px) { main { grid-template-columns: 1fr; padding: 16px 20px 48px; } }
.office { position: relative; background: color-mix(in srgb, var(--night-950) 85%, transparent); border: 1px solid var(--line-600); border-radius: var(--radius-card); padding: 16px; }
#floor { width: 100%; height: auto; display: block; }
.legend { list-style: none; display: flex; gap: 16px; flex-wrap: wrap; padding: 0 4px 12px; margin: 0; color: var(--sage-200); font-size: 15px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; background: var(--line-600); }

.st-working { background: var(--teal-500); }
.st-waiting_owner { background: var(--cyan-400); }
.st-idle { background: var(--line-600); }
.st-silent { background: var(--warn); }
.st-locked { background: #8A9A9C; }

.side { display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--surface-800); border: 1px solid var(--line-600); border-radius: var(--radius-card); padding: 16px 20px; }
.card h2 { margin: 0 0 12px; font-size: 20px; font-weight: 700; }
.muted { color: var(--sage-200); font-size: 15px; }
.empty { color: var(--sage-200); font-size: 15px; margin: 0; }
.prop { border-top: 1px solid var(--line-600); padding: 12px 0; }
.prop:first-child { border-top: 0; padding-top: 0; }
.prop h3 { margin: 0 0 4px; font-size: 18px; font-weight: 700; }
.prop ul { margin: 6px 0; padding-left: 18px; font-size: 15px; color: var(--sage-200); }
.tag { display: inline-block; border: 1px solid var(--line-600); border-radius: 999px; padding: 1px 10px; font-size: 13px; margin-right: 6px; color: var(--sage-200); }
.words { font-size: 15px; color: var(--sage-200); word-break: break-word; }
textarea { width: 100%; margin: 8px 0; border-radius: var(--radius); border: 1px solid var(--line-600); background: var(--night-950); color: var(--white); font: inherit; padding: 8px; min-height: 40px; resize: vertical; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.note { font-size: 14px; color: var(--sage-200); margin: 8px 0 0; }
.metric { display: flex; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line-600); padding: 8px 0; font-variant-numeric: tabular-nums; }
.metric:first-child { border-top: 0; }
.gap { height: 8px; }
.big { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }

.desk { cursor: pointer; }
.desk rect.body { fill: var(--surface-800); stroke: var(--line-600); stroke-width: 1.5; transition: stroke 180ms ease, fill 180ms ease; }
.desk:hover rect.body, .desk:focus-visible rect.body { stroke: var(--sage-200); }
.desk.sel rect.body { stroke: var(--lime-500); stroke-width: 2.5; }
.desk text { fill: var(--white); font-family: var(--font); }
.desk .t-title { font-weight: 700; }
.desk .t-dept, .desk .t-state, .desk .t-brain { fill: var(--sage-200); }
.desk .t-state { fill: var(--white); }
.glyph path { stroke: var(--sage-200); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.desk.working .glyph path, .desk.waiting_owner .glyph path { stroke: var(--teal-500); }
.desk.waiting_owner .glyph path { stroke: var(--cyan-400); }
.desk.replay rect.body { stroke: var(--lime-500); stroke-width: 3; fill: #1E3A38; }
.desk.working .pulse { animation: breathe 3.2s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes breathe { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
.flow.lit { stroke: var(--lime-500); stroke-width: 3.5; }
.desk.working rect.body { stroke: var(--teal-500); }
.desk.waiting_owner rect.body { stroke: var(--cyan-400); }
.desk.silent rect.body { stroke: var(--warn); }
.desk.locked rect.body { stroke-dasharray: 6 4; }
.desk.waiting_owner .pulse { animation: pulse 2.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.5; transform: scale(1.5); } }
.flow { fill: none; stroke: var(--line-600); stroke-width: 1.5; }
.flow.active { stroke: var(--teal-500); stroke-width: 2; stroke-dasharray: 6 8; animation: run 1.4s linear infinite; }
@keyframes run { to { stroke-dashoffset: -28; } }
.room-label { fill: var(--sage-200); letter-spacing: 0.08em; text-transform: uppercase; font-family: var(--font); }

.login { position: fixed; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; background: var(--night-900); padding: 20px; }
.login-box { background: var(--surface-800); border: 1px solid var(--line-600); border-radius: var(--radius-card); padding: 32px; width: min(420px, 100%); display: flex; flex-direction: column; gap: 8px; }
.login-box h1 { margin: 0 0 8px; font-size: 28px; }
.login-box input { height: 44px; border-radius: var(--radius); border: 1px solid var(--line-600); background: var(--night-950); color: var(--white); font: inherit; padding: 0 12px; }
.error { color: var(--danger); min-height: 24px; margin: 0; font-size: 15px; }

select { font: inherit; font-size: 15px; background: var(--night-950); color: var(--white); border: 1px solid var(--line-600); border-radius: var(--radius); padding: 6px 8px; }
.timeline { list-style: none; margin: 8px 0 0; padding: 0; max-height: 320px; overflow: auto; font-size: 15px; }
.timeline li { display: grid; grid-template-columns: 52px 1fr; column-gap: 8px; padding: 6px 4px; border-top: 1px solid var(--line-600); }
.timeline li .time { color: var(--sage-200); font-variant-numeric: tabular-nums; }
.timeline li .who { font-weight: 700; grid-column: 2; }
.timeline li span:last-child { grid-column: 2; color: var(--sage-200); }
.timeline li.now { background: color-mix(in srgb, var(--lime-500) 14%, transparent); }

@media (prefers-reduced-motion: reduce) {
  .sweep, .flow.active, .desk.waiting_owner .pulse, .desk.working .pulse { animation: none; }
  .desk rect.body { transition: none; }
}

.login-box a.btn { text-align: center; text-decoration: none; display: block; margin-top: 8px; }
#token-block { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }

.popover { position: absolute; z-index: 10; width: min(380px, calc(100% - 24px)); max-height: 78%; overflow: auto; transform: translate(-50%, -50%);
  background: var(--surface-800); border: 1.5px solid var(--lime-500); border-radius: var(--radius-card); padding: 16px 20px 18px; }
.popover h2 { margin: 0 36px 8px 0; font-size: 20px; font-weight: 700; }
.popover p { margin: 6px 0; }
.popover ul { margin: 6px 0; padding-left: 18px; }
.pop-close { position: absolute; top: 8px; right: 8px; width: 34px; height: 34px; padding: 0; font-size: 22px; line-height: 1; }

.popover.wide { width: min(520px, calc(100% - 24px)); }
.popover h3 { margin: 10px 0 4px; font-size: 18px; }
.progress { height: 6px; border-radius: 3px; background: var(--night-950); border: 1px solid var(--line-600); margin: 8px 0; overflow: hidden; }
.progress .bar { display: block; height: 100%; background: linear-gradient(90deg, var(--lime-500), var(--teal-500)); }
.popover a { color: var(--teal-500); }

.pipeline { margin: 6px 0 10px; padding-left: 20px; font-size: 15px; }
.pipeline li { margin: 4px 0; }
.pipeline .who { font-weight: 700; }
.pipeline li.st-closed .label { color: var(--teal-500); }
.pipeline li.st-in_progress .label { color: var(--lime-500); }
.pipeline li.st-in_progress::marker { color: var(--lime-500); }
.pipeline li.st-needs_review .label { color: var(--cyan-400); }

.ticker { border: 1px solid var(--line-600); border-radius: var(--radius); padding: 8px 12px; margin: 0 0 10px; background: color-mix(in srgb, var(--night-950) 80%, transparent); font-size: 15px; }
.tick { padding: 2px 0; color: var(--sage-200); }
.tick.now { color: var(--white); }
.tick .time { font-variant-numeric: tabular-nums; color: var(--sage-200); }
.tick.flash { animation: flash 1.6s ease-out 1; }
@keyframes flash { from { background: color-mix(in srgb, var(--lime-500) 28%, transparent); } to { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .tick.flash { animation: none; } }

.center { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.center #metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 28px; }
.center #metrics .gap { display: none; }
.center #metrics .note { grid-column: 1 / -1; }

/* Рабочий чат: современный мессенджер */
.chat { position: sticky; top: 12px; height: calc(100vh - 24px); display: flex; flex-direction: column; overflow: hidden;
  background: color-mix(in srgb, var(--surface-800) 94%, transparent); border: 1px solid var(--line-600); border-radius: var(--radius-card); }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line-600); }
.chat-head h2 { margin: 0; font-size: 18px; }
.chat-sub { margin: 0; font-size: 13px; color: var(--sage-200); }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--lime-500); flex: none; animation: breathe 2.4s ease-in-out infinite; }
.chat-log { flex: 1; overflow-y: auto; padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 3px; scrollbar-width: thin; }
.grp-head { display: flex; align-items: baseline; gap: 8px; margin: 12px 0 2px 44px; font-size: 13px; color: var(--sage-200); }
.grp-head strong { color: var(--white); font-size: 14px; }
.row { display: flex; align-items: flex-end; gap: 8px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center; background: var(--night-950); border: 1.5px solid var(--teal-500); }
.avatar svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.avatar.ghost { visibility: hidden; }
.bubble { position: relative; max-width: calc(100% - 46px); padding: 8px 12px 6px; border-radius: 18px 18px 18px 6px; background: #1F3538; font-size: 14.5px; line-height: 1.42; word-break: break-word; }
.bubble .t { display: block; margin-top: 2px; text-align: right; font-size: 11.5px; color: var(--sage-200); font-variant-numeric: tabular-nums; }
.row.mine { flex-direction: row-reverse; }
.row.mine .bubble { border-radius: 18px 18px 6px 18px; background: linear-gradient(135deg, color-mix(in srgb, var(--lime-500) 28%, #1F3538), color-mix(in srgb, var(--teal-500) 30%, #1F3538)); }
.sys { align-self: center; margin: 10px 0; padding: 3px 12px; border-radius: 999px; font-size: 12.5px; color: var(--sage-200); border: 1px solid var(--line-600); background: var(--night-950); }
.row.new .bubble { animation: pop 0.5s ease-out 1; }
@keyframes pop { from { transform: translateY(8px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }
.typing { min-height: 28px; padding: 4px 16px 10px; font-size: 13px; color: var(--sage-200); border-top: 1px solid transparent; }
.typing .dots span { display: inline-block; width: 4px; height: 4px; margin: 0 1px; border-radius: 50%; background: var(--sage-200); animation: blink 1.2s infinite ease-in-out; }
.typing .dots span:nth-child(2) { animation-delay: 0.2s; }
.typing .dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .live-dot, .row.new .bubble, .typing .dots span { animation: none; } }
@media (max-width: 1250px) {
  main { grid-template-columns: minmax(0, 1fr) clamp(320px, 34vw, 420px); }
  .chat { grid-column: 1 / -1; position: static; height: 300px; }
}
@media (max-width: 900px) { main { grid-template-columns: 1fr; } .center #metrics { grid-template-columns: 1fr; } }

.prop.postponed { opacity: 0.85; }
.sub { margin: 14px 0 6px; font-size: 16px; font-weight: 700; color: var(--sage-200); }
.tasks { list-style: none; margin: 6px 0 10px; padding: 0; }
.tasks li { padding: 5px 0; border-top: 1px solid var(--line-600); font-size: 14.5px; }
.tasks li:first-child { border-top: 0; }
.tasks li.st-in_progress .tag { border-color: var(--lime-500); color: var(--lime-500); }
.tasks li.st-needs_review .tag { border-color: var(--cyan-400); color: var(--cyan-400); }
.tasks li.st-closed .tag { border-color: var(--teal-500); color: var(--teal-500); }
