/* TG Hub — интерфейс в духе ChatGPT: нейтральные поверхности, чат в центре, тихое движение. */

:root, [data-theme="dark"] {
  color-scheme: dark;
  --bg: #212121;
  --side: #171717;
  --surface: #2f2f2f;
  --surface-2: #3a3a3a;
  --hover: #262626;
  --active: #2f2f2f;
  --line: rgba(255, 255, 255, .09);
  --line-2: rgba(255, 255, 255, .16);
  --fg: #ececec;
  --fg-2: #c5c5c5;
  --muted: #9b9b9b;
  --dim: #7a7a7a;
  --inv-bg: #ececec;
  --inv-fg: #0d0d0d;
  --ok: #19c37d;
  --warn: #f2a93b;
  --bad: #f87171;
  --bad-bg: rgba(248, 113, 113, .1);
  --select: rgba(255, 255, 255, .2);
  --shadow: 0 12px 40px rgba(0, 0, 0, .45), 0 2px 8px rgba(0, 0, 0, .3);
  --scroll: rgba(255, 255, 255, .14);
}
[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --side: #f9f9f9;
  --surface: #f4f4f4;
  --surface-2: #e9e9e9;
  --hover: #efefef;
  --active: #e8e8e8;
  --line: rgba(0, 0, 0, .08);
  --line-2: rgba(0, 0, 0, .15);
  --fg: #0d0d0d;
  --fg-2: #3c3c3c;
  --muted: #676767;
  --dim: #8a8a8a;
  --inv-bg: #0d0d0d;
  --inv-fg: #ffffff;
  --ok: #0c8a63;
  --warn: #b4690e;
  --bad: #d92d20;
  --bad-bg: rgba(217, 45, 32, .07);
  --select: rgba(0, 0, 0, .12);
  --shadow: 0 12px 40px rgba(0, 0, 0, .12), 0 2px 8px rgba(0, 0, 0, .06);
  --scroll: rgba(0, 0, 0, .16);
}
:root {
  --font: ui-sans-serif, -apple-system, system-ui, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  --side-w: 288px;
  --col: 768px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
::selection { background: var(--select); }
* { scrollbar-width: thin; scrollbar-color: var(--scroll) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--scroll); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }
a { color: var(--fg); text-underline-offset: 3px; text-decoration-color: var(--line-2); }
a:hover { text-decoration-color: currentColor; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--fg-2); outline-offset: 2px; border-radius: 6px; }
h1 { font-size: 22px; font-weight: 600; margin: 0; letter-spacing: -0.015em; }
h2 { font-size: 18px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
h3 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
p { margin: 0; }
code { font-family: var(--mono); font-size: 12.5px; background: var(--surface); padding: 1px 5px; border-radius: 5px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.sm { font-size: 12.5px; }
.strong { font-weight: 600; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }
.wrap { white-space: normal; overflow-wrap: anywhere; }
.num { font-variant-numeric: tabular-nums; }
.ico { width: 18px; height: 18px; flex: none; }
.ico.sm { width: 16px; height: 16px; }

/* ---------- controls */
.input {
  width: 100%; background: var(--bg); color: var(--fg); border: 1px solid var(--line-2);
  border-radius: 12px; padding: 10px 14px; font: inherit; outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.input::placeholder { color: var(--dim); }
.input:focus { border-color: var(--fg-2); box-shadow: 0 0 0 3px var(--select); }
select.input { appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
textarea.input { resize: vertical; min-height: 110px; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; white-space: nowrap;
  background: var(--inv-bg); color: var(--inv-fg); border: 1px solid transparent; border-radius: 999px;
  padding: 8px 16px; font-weight: 500; cursor: pointer; line-height: 1.3;
  transition: transform 160ms var(--ease-out), opacity 150ms ease, background-color 150ms ease;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.ghost { background: transparent; color: var(--fg); border-color: var(--line-2); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.ghost.danger { background: transparent; color: var(--bad); }
.btn.sm { padding: 5px 12px; font-size: 13px; }
.btn.wide { width: 100%; padding: 11px 16px; }
.icon-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center; flex: none;
  border: 0; background: transparent; color: var(--muted); border-radius: 10px; cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease, transform 160ms var(--ease-out);
}
.icon-btn:active { transform: scale(0.94); }
@media (hover: hover) and (pointer: fine) {
  .btn.ghost:hover { background: var(--hover); }
  .btn:not(.ghost):hover:not(:disabled) { opacity: .88; }
  .icon-btn:hover { background: var(--hover); color: var(--fg); }
}

/* ---------- login */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login { width: 100%; max-width: 360px; display: grid; gap: 14px; }
.login .mark { width: 44px; height: 44px; margin: 0 auto 6px; }
.login h1 { text-align: center; font-size: 28px; margin-bottom: 10px; }
.login label, .form label { display: grid; gap: 7px; color: var(--fg-2); font-size: 13px; }
.form-err { color: var(--bad); font-size: 13px; }
.form-err:empty { display: none; }

/* ---------- shell */
.app { display: flex; height: 100dvh; overflow: hidden; }
.side { width: var(--side-w); flex: none; background: var(--side); display: flex; flex-direction: column; min-height: 0; }
.app[data-side="closed"] .side { display: none; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 6px 14px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 15px; text-decoration: none; color: var(--fg); }
.demo-tag { font-size: 11px; font-weight: 500; color: var(--warn); border: 1px solid currentColor; border-radius: 999px; padding: 0 7px; line-height: 17px; }
.mark { width: 26px; height: 26px; flex: none; display: block; }
.side-nav { padding: 2px 8px 8px; display: grid; gap: 1px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 10px; color: var(--fg-2); text-decoration: none; }
.nav-item span { flex: 1; }
.nav-item.on { background: var(--active); color: var(--fg); }
@media (hover: hover) and (pointer: fine) { .nav-item:hover { background: var(--hover); color: var(--fg); } }
.badge { font-size: 11px; font-weight: 600; background: var(--inv-bg); color: var(--inv-fg); border-radius: 999px; padding: 0 6px; min-width: 18px; text-align: center; line-height: 18px; font-variant-numeric: tabular-nums; }
.badge.bad { background: var(--bad); color: #fff; }
.badge:empty { display: none; }
.side-tools { padding: 6px 10px 4px; display: grid; gap: 8px; border-top: 1px solid var(--line); }
.search { position: relative; }
.search .ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--dim); pointer-events: none; }
.search input { padding-left: 36px; border-radius: 10px; background: transparent; border-color: var(--line); padding-top: 8px; padding-bottom: 8px; }
.chips { display: flex; gap: 4px; }
.chip { flex: 1; display: inline-flex; gap: 5px; justify-content: center; align-items: center; border: 0; background: transparent; color: var(--muted); padding: 5px 6px; border-radius: 8px; font-size: 12.5px; cursor: pointer; transition: background-color 150ms ease, color 150ms ease; }
.chip.on { background: var(--active); color: var(--fg); }
.chip i { font-style: normal; color: var(--dim); font-variant-numeric: tabular-nums; }
.chip i:empty { display: none; }
@media (hover: hover) and (pointer: fine) { .chip:hover { color: var(--fg); } }
.side-head { display: flex; align-items: center; gap: 8px; padding: 2px 0 4px; margin-left: -6px; }
.side-head .icon-btn { width: 30px; height: 30px; }
.sh-body { min-width: 0; display: grid; }
.sh-body b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sh-body span { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search .search-x { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); border: 0; background: none; color: var(--dim); width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; cursor: pointer; }
.search .search-x .ico { position: static; transform: none; }
.search .search-x:hover { color: var(--fg); background: var(--hover); }
.acc-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 12px; cursor: pointer; position: relative; }
@media (hover: hover) and (pointer: fine) { .acc-item:hover { background: var(--hover); } }
.acc-item .ava { width: 34px; height: 34px; font-size: 12.5px; }
.acc-item > .acc-dot { position: absolute; left: 36px; top: 34px; width: 10px; height: 10px; border: 2px solid var(--side); box-sizing: content-box; }
.acc-item.off .ava { opacity: .55; }
.ai-body { flex: 1; min-width: 0; }
.ai-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-empty a { color: var(--fg); text-decoration: underline; }
.side-tools select.input { padding: 6px 30px 6px 10px; border-radius: 10px; font-size: 13px; background-color: transparent; border-color: var(--line); color: var(--fg-2); }
.side-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; min-height: 0; }
.grp { font-size: 12px; color: var(--dim); padding: 14px 10px 4px; font-weight: 500; }
.dlg { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: 10px; cursor: pointer; position: relative; }
.dlg.on { background: var(--active); }
@media (hover: hover) and (pointer: fine) { .dlg:hover:not(.on) { background: var(--hover); } }
.dlg-top, .dlg-bot { display: flex; align-items: center; gap: 8px; min-width: 0; }
.dlg-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg); }
.dlg.unread .dlg-name { font-weight: 600; }
.dlg-time { font-size: 11.5px; color: var(--dim); flex: none; font-variant-numeric: tabular-nums; }
.dlg-bot { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.dlg-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlg-acc { color: var(--dim); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); flex: none; }
.cnt { flex: none; font-size: 11px; font-weight: 600; background: var(--inv-bg); color: var(--inv-fg); border-radius: 999px; padding: 0 6px; line-height: 17px; min-width: 17px; text-align: center; font-variant-numeric: tabular-nums; }
.side-empty { color: var(--muted); font-size: 13px; padding: 18px 12px; }
.side-foot { border-top: 1px solid var(--line); padding: 8px; display: flex; align-items: center; gap: 4px; }
.me { flex: 1; display: flex; align-items: center; gap: 9px; min-width: 0; padding: 4px 6px; }
.me b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ava { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 12px; color: #fff; flex: none; }
.ava.lg { width: 34px; height: 34px; font-size: 13px; }
.scrim { display: none; }

/* ---------- main */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.topbar { height: 56px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 14px; }
.topbar .open-side { display: none; }
.app[data-side="closed"] .topbar .open-side { display: inline-grid; }
.tb-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.tb-name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-sub { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-text { min-width: 0; }
#view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.health { text-decoration: none; display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line); }
.health .dot { background: var(--ok); }
.health.badish .dot { background: var(--bad); }

/* ---------- home: сводка */
.home { max-width: 1080px; padding-top: 18px; }
.home-hero { margin: 10px 0 24px; }
.home-hero h1 { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.home-hero > p { padding-left: 26px; }
.pulse { width: 12px; height: 12px; border-radius: 50%; background: var(--dim); flex: none; position: relative; }
.tone-ok .pulse { background: var(--ok); }
.tone-warn .pulse, .tone-wait .pulse { background: var(--warn); }
.tone-bad .pulse { background: var(--bad); }
.pulse::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: inherit; opacity: .5; animation: ring 2.4s var(--ease-out) infinite; }
@keyframes ring { from { transform: scale(1); opacity: .5; } to { transform: scale(2.6); opacity: 0; } }
.setup { list-style: none; padding: 0; margin: 0; max-width: 640px; border-top: 1px solid var(--line); }
.setup li { display: flex; align-items: center; gap: 16px; padding: 18px 0; border-bottom: 1px solid var(--line); }
.setup li > div { flex: 1; display: grid; gap: 2px; }
.setup li span { color: var(--muted); }
.metrics { display: grid; grid-template-columns: repeat(var(--cols, 5), 1fr); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; margin-bottom: 30px; }
.metric { display: grid; gap: 2px; padding: 16px 20px; text-align: left; border: 0; border-right: 1px solid var(--line); background: transparent; cursor: pointer; text-decoration: none; color: var(--fg); transition: background-color 150ms ease; }
.metric:last-child { border-right: 0; }
.metric b { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; }
.metric b small { font-size: 15px; color: var(--muted); font-weight: 500; }
.metric span { color: var(--muted); font-size: 13px; }
@media (hover: hover) and (pointer: fine) { .metric:hover { background: var(--hover); } }
.home-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 36px; align-items: start; }
.home-side { display: grid; gap: 30px; }
.sec-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; min-height: 26px; }
.sec-head h3 { margin: 0; flex: 1; }
.sec-link { background: none; border: 0; padding: 0; color: var(--muted); font-size: 13px; cursor: pointer; text-decoration: none; }
.sec-link:hover { color: var(--fg); }
.acc-list { display: grid; gap: 2px; }
.acc-row { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; border: 0; background: none; padding: 12px 14px; border-radius: 14px; cursor: pointer; }
@media (hover: hover) and (pointer: fine) { .acc-row:hover { background: var(--hover); } }
.acc-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dim); flex: none; }
.acc-dot.ok { background: var(--ok); }
.acc-dot.wait, .acc-dot.warn { background: var(--warn); }
.acc-dot.bad { background: var(--bad); }
.acc-main { flex: 1; min-width: 0; }
.acc-name { font-weight: 500; }
.acc-sub { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-nums { display: flex; gap: 16px; color: var(--muted); font-size: 12.5px; flex: none; }
.acc-nums b { color: var(--fg); font-weight: 600; }
.acc-nums .warn b, .acc-nums .warn { color: var(--warn); }
.attn { display: grid; gap: 8px; }
.attn-item { display: flex; align-items: flex-start; gap: 10px; padding: 12px 12px 12px 14px; border-radius: 14px; background: var(--surface); }
.attn-item > .ico { margin-top: 2px; color: var(--warn); }
.attn-item.t-bad > .ico { color: var(--bad); }
.attn-body { flex: 1; min-width: 0; display: grid; gap: 2px; font-size: 13.5px; }
.attn-body span { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.attn-item .btn { flex: none; }
.all-good { display: flex; align-items: center; gap: 10px; padding: 14px; border-radius: 14px; background: var(--surface); color: var(--fg-2); }
.all-good .ico { color: var(--ok); }
.events { list-style: none; margin: 0; padding: 0; display: grid; }
.events li { display: flex; gap: 12px; padding: 9px 2px; border-bottom: 1px solid var(--line); font-size: 13px; }
.events li:last-child { border-bottom: 0; }
.events li > div { flex: 1; min-width: 0; display: grid; gap: 1px; }
.events li b { font-weight: 500; }
.events li span { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.events time { color: var(--dim); font-size: 12px; white-space: nowrap; }
.ev-dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--dim); }
.ev-dot.ok { background: var(--ok); }
.ev-dot.warn { background: var(--warn); }
.ev-dot.bad { background: var(--bad); }
.home-wait { margin-top: 34px; }
.row-link { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: none; border: 0; padding: 10px 14px; border-radius: 14px; cursor: pointer; }
@media (hover: hover) and (pointer: fine) { .row-link:hover { background: var(--hover); } }
.row-link .rl-body { flex: 1; min-width: 0; }
.row-link .rl-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-link .rl-text { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-link .rl-meta { color: var(--dim); font-size: 12px; text-align: right; flex: none; }
@media (max-width: 1100px) { .home-grid { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metric { border-bottom: 1px solid var(--line); }
  .metric:nth-child(2n) { border-right: 0; }
  .metric:last-child { grid-column: span 2; border-bottom: 0; }
  .home-hero h1 { font-size: 22px; }
  .acc-row { flex-wrap: wrap; }
  .acc-nums { width: 100%; padding-left: 23px; }
}

/* ---------- thread */
.thread { flex: 1; overflow-y: auto; overflow-anchor: none; }
.thread-inner { max-width: var(--col); margin: 0 auto; padding: 12px 24px 24px; display: flex; flex-direction: column; }
.sep { align-self: center; color: var(--dim); font-size: 12px; padding: 18px 0 10px; }
.svc { align-self: center; display: inline-flex; gap: 6px; align-items: center; color: var(--muted); font-size: 12.5px; padding: 4px 12px; margin: 8px 0; border: 1px solid var(--line); border-radius: 999px; }
.m { max-width: 82%; margin-top: 14px; overflow-wrap: anywhere; }
.m.cont { margin-top: 4px; }
.m.in { align-self: flex-start; }
.m.out { align-self: flex-end; display: flex; flex-direction: column; align-items: flex-end; }
.m-who { font-size: 12.5px; font-weight: 600; color: var(--fg-2); margin-bottom: 2px; }
.m-text { white-space: pre-wrap; font-size: 15px; line-height: 1.6; }
.m-text a { text-decoration: underline; }
.m.out .m-body { background: var(--surface); padding: 9px 16px; border-radius: 20px; }
.m.out.cont .m-body { border-top-right-radius: 8px; }
.m.in .m-body { padding: 2px 0; }
.m-meta { font-size: 11.5px; color: var(--dim); margin-top: 3px; display: flex; gap: 8px; align-items: center; font-variant-numeric: tabular-nums; }
.m.out .m-meta { padding-right: 6px; }
.m.in .m-meta { opacity: 0; transition: opacity 150ms ease; }
.m.in:hover .m-meta, .m.in:last-child .m-meta, .m.in.last .m-meta { opacity: 1; }
.hub-tag { color: var(--fg-2); }
.m.pending .m-body { opacity: .55; }
.m.failed .m-body { background: var(--bad-bg); box-shadow: inset 0 0 0 1px var(--bad); }
.m.failed .m-meta { color: var(--bad); }
.m.failed .m-meta button { background: none; border: 0; padding: 0; color: var(--fg); text-decoration: underline; cursor: pointer; font-size: inherit; }
.att { display: inline-flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; margin: 2px 0 4px; cursor: pointer; color: var(--fg); font-size: 13.5px; text-decoration: none; }
.m.out .att { background: var(--bg); }
.att .ico { color: var(--muted); }
.m-img { max-width: 100%; max-height: 380px; border-radius: 14px; display: block; margin: 2px 0 4px; cursor: zoom-in; }
.skel { display: grid; gap: 22px; padding-top: 24px; }
.skel i { display: block; height: 14px; border-radius: 7px; background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
.skel i:nth-child(2n) { justify-self: end; width: 46%; height: 38px; border-radius: 18px; }
.skel i:nth-child(2n+1) { width: 62%; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.thread-note { text-align: center; color: var(--muted); padding: 60px 20px; }

/* ---------- composer */
.dock { flex: none; padding: 0 24px 10px; }
.composer { max-width: var(--col); margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 26px; padding: 8px 8px 8px 20px; box-shadow: 0 1px 3px rgba(0, 0, 0, .08); transition: border-color 150ms ease; }
.composer:focus-within { border-color: var(--line-2); }
.composer textarea { flex: 1; resize: none; background: transparent; color: var(--fg); border: 0; padding: 8px 0; font: inherit; font-size: 15px; line-height: 1.5; max-height: 220px; outline: none; }
.composer textarea::placeholder { color: var(--dim); }
.send { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--inv-bg); color: var(--inv-fg); display: grid; place-items: center; cursor: pointer; flex: none; transition: transform 160ms var(--ease-out), opacity 150ms ease; }
.send:disabled { opacity: .25; cursor: default; }
.send:active:not(:disabled) { transform: scale(0.92); }
.dock-hint { max-width: var(--col); margin: 8px auto 0; text-align: center; font-size: 12px; color: var(--dim); }
.offline { flex: 1; color: var(--muted); padding: 8px 0; }

/* ---------- chat: вложения, цитаты, действия, шаблоны */
.chat-area { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.chat-area.drop::after { content: "Отпустите, чтобы прикрепить файл"; position: absolute; inset: 12px; z-index: 20; display: grid; place-items: center;
  border: 2px dashed var(--line-2); border-radius: 20px; background: color-mix(in srgb, var(--bg) 88%, transparent); color: var(--fg-2); font-size: 15px; pointer-events: none; }
.cmp-wrap { max-width: var(--col); margin: 0 auto; position: relative; }
.cmp-wrap .composer { padding: 6px 6px 6px 6px; gap: 2px; }
.cmp-wrap .composer textarea { margin-left: 4px; }
.cmp-btn { width: 34px; height: 34px; border-radius: 50%; align-self: flex-end; margin-bottom: 1px; }
.cmp-bar { display: grid; gap: 6px; margin-bottom: 8px; }
.cmp-chip { display: flex; align-items: center; gap: 10px; background: var(--surface); border-radius: 16px; padding: 7px 7px 7px 12px; }
.cmp-chip > .ico { color: var(--muted); }
.cmp-chip img { width: 42px; height: 42px; object-fit: cover; border-radius: 10px; flex: none; }
.cc-ico { width: 42px; height: 42px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; flex: none; color: var(--muted); }
.cc-body { flex: 1; min-width: 0; display: grid; }
.cc-body b { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cc-body span { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmp-chip .icon-btn { width: 30px; height: 30px; }
.tpl-pop { position: absolute; left: 0; right: 0; bottom: 100%; margin-bottom: 8px; z-index: 15; background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow); padding: 6px; max-height: 340px; overflow-y: auto; transform-origin: bottom left; }
.tpl-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px 4px; font-size: 12px; color: var(--dim); }
.tpl-item { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 12px; cursor: pointer; }
.tpl-item b { display: block; font-weight: 500; }
.tpl-item span { display: block; color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpl-item.on { background: var(--surface-2); }
@media (hover: hover) and (pointer: fine) { .tpl-item:hover { background: var(--surface-2); } }
.tpl-empty { padding: 12px 10px; color: var(--muted); font-size: 13px; }
.tpl-empty a { color: var(--fg); }
.m { position: relative; }
.m-acts { position: absolute; top: -4px; display: flex; gap: 1px; padding: 2px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .12); opacity: 0; pointer-events: none; transition: opacity 120ms ease; z-index: 2; }
.m.in .m-acts { left: 100%; margin-left: 6px; }
.m.out .m-acts { right: 100%; margin-right: 6px; }
.m-acts .icon-btn { width: 28px; height: 28px; border-radius: 9px; }
.m-acts .icon-btn.danger:hover { color: var(--bad); }
@media (hover: hover) and (pointer: fine) { .m:hover .m-acts { opacity: 1; pointer-events: auto; } }
.m.acts-on .m-acts { opacity: 1; pointer-events: auto; }
@media (max-width: 860px) { .m.in .m-acts { left: auto; right: 0; top: -36px; margin: 0; } .m.out .m-acts { right: 0; top: -36px; margin: 0; } }
.m.editing .m-body { box-shadow: 0 0 0 2px var(--fg-2); }
.m-quote { display: grid; width: 100%; text-align: left; border: 0; cursor: pointer; background: rgba(127, 127, 127, .13); border-radius: 12px; padding: 6px 10px; margin: 2px 0 6px; font-size: 13px; color: var(--fg); }
.m-quote b { font-weight: 600; font-size: 12.5px; color: var(--fg-2); }
.m-quote span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 420px; }
.m.in .m-body:has(.m-quote) { padding-top: 0; }
.att-media { display: grid; gap: 4px; margin: 2px 0 4px; justify-items: start; }
.m-audio { width: min(320px, 100%); height: 40px; }
.m-video { max-width: min(420px, 100%); max-height: 360px; border-radius: 14px; background: #000; }
.m-video.round { width: 240px; height: 240px; border-radius: 50%; object-fit: cover; }
.att-dl, .att-name { font-size: 12px; color: var(--muted); }
.att-dl { text-decoration: underline; }
.ico.inline { width: 15px; height: 15px; vertical-align: -2px; }
textarea.input.plain { font-family: var(--font); font-size: 14px; line-height: 1.55; }
.tpl-list { display: grid; gap: 2px; }
.tpl-row { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border-radius: 14px; border-bottom: 1px solid var(--line); }
.tpl-row:last-child { border-bottom: 0; }
@media (hover: hover) and (pointer: fine) { .tpl-row:hover { background: var(--hover); } }
.tpl-row-body { flex: 1; min-width: 0; }
.tpl-row-body b { font-weight: 600; }
.tpl-row-body p { color: var(--muted); white-space: pre-wrap; margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- pages */
.page { flex: 1; overflow-y: auto; }
.page-in { max-width: 1120px; margin: 0 auto; padding: 8px 28px 48px; }
.page-head { display: flex; align-items: center; gap: 10px; margin: 6px 0 6px; flex-wrap: wrap; min-height: 40px; }
.page-head .grow { flex: 1; }
.lead { color: var(--muted); margin: 0 0 22px; max-width: 720px; }
.stats { display: flex; gap: 28px; flex-wrap: wrap; margin: 18px 0 22px; }
.stat b { display: block; font-size: 26px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 13px; }
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; }
.tbl th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12.5px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 13px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
@media (hover: hover) and (pointer: fine) { .tbl tbody tr:hover td { background: var(--hover); } }
.tbl tbody tr td:first-child { border-radius: 12px 0 0 12px; }
.tbl tbody tr td:last-child { border-radius: 0 12px 12px 0; }
.row-actions { white-space: nowrap; text-align: right; width: 1%; }
.row-actions > * { vertical-align: middle; }
.row-actions .btn { margin-left: 4px; }
.status { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; font-size: 13.5px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.status.ok::before { background: var(--ok); }
.status.wait::before { background: var(--warn); animation: blink 1.2s ease-in-out infinite; }
.status.warn::before { background: var(--warn); }
.status.bad { color: var(--bad); }
.status.bad::before { background: var(--bad); }
.status.ok, .status.wait, .status.warn, .status.off { color: var(--fg); }
@keyframes blink { 50% { opacity: .35; } }
.note-line { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.note-line.warn { color: var(--warn); display: flex; gap: 6px; }
.note-line.warn .ico { width: 14px; height: 14px; margin-top: 2px; }
.empty-state { text-align: center; padding: 70px 20px; }
.empty-state h2 { margin-bottom: 8px; }
.empty-state p { color: var(--muted); max-width: 460px; margin: 0 auto; }
.empty-state .btn { margin-top: 20px; }
.settings { display: grid; gap: 4px; max-width: 720px; }
.set-sec { padding: 22px 0; border-bottom: 1px solid var(--line); }
.set-sec:last-child { border-bottom: 0; }
.set-sec p { color: var(--muted); margin-bottom: 14px; }
.set-sec .form { max-width: 380px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 10px 28px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.more { text-align: center; margin-top: 18px; }

/* ---------- users */
.row-off td { opacity: .55; }
.acc-chips { display: flex; flex-wrap: wrap; gap: 5px; max-width: 420px; }
.acc-chip { font-size: 12.5px; padding: 2px 9px; border-radius: 999px; background: var(--surface); color: var(--fg-2); white-space: nowrap; }
.field-label { color: var(--fg-2); font-size: 13px; margin-bottom: 7px; }
.checklist { display: grid; max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 14px; padding: 4px; }
.check-row { display: flex !important; flex-direction: row !important; align-items: center; gap: 10px !important; padding: 8px 10px; border-radius: 10px; cursor: pointer; color: var(--fg) !important; font-size: 14px !important; }
.check-row input { accent-color: var(--fg); width: 16px; height: 16px; margin: 0; }
.check-row .cl-name { flex: 1; }
@media (hover: hover) and (pointer: fine) { .check-row:hover { background: var(--hover); } }
.cl-tools { display: flex; gap: 16px; margin-top: 8px; }
.form:has(input[name=role][value=owner]:checked) .access-field { display: none; }
.form:has(input[name=role][value=owner]:checked) .role-hint::before { content: "Владелец видит все аккаунты, прокси, журнал и управляет пользователями."; }
.form:has(input[name=role][value=operator]:checked) .role-hint::before { content: "Сотрудник видит только выданные аккаунты и может в них отвечать. Прокси, журнал и настройки ему недоступны."; }
.cred { display: grid; grid-template-columns: max-content 1fr; gap: 10px 20px; margin: 18px 0; font-size: 14px; }
.cred dt { color: var(--muted); }
.cred dd { margin: 0; overflow-wrap: anywhere; }
.cred .pw { font-size: 15px; letter-spacing: .03em; }

/* ---------- профиль аккаунта */
img.ava { object-fit: cover; background: var(--surface); }
.ava.sm { width: 24px; height: 24px; font-size: 10px; }
.acc-cell { display: flex; gap: 12px; align-items: flex-start; }
.acc-cell .ava { margin-top: 1px; }
.prof-top { display: flex; gap: 18px; align-items: center; }
.prof-img { width: 88px; height: 88px; border-radius: 50%; object-fit: cover; display: block; background: var(--surface); }
.prof-img.empty { display: grid; place-items: center; color: var(--dim); }
.prof-photo-acts { display: grid; gap: 8px; }
.row-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.lbl-row { display: flex; justify-content: space-between; }
.un-field { position: relative; }
.un-field span { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.un-field input { padding-left: 30px; }
.un-status.ok { color: var(--ok); }
.un-status.bad { color: var(--bad); }
.bulk-about, .bulk-last { display: none; margin-top: -8px; }
.form:has(input[name=set_about]:checked) .bulk-about, .form:has(input[name=set_last]:checked) .bulk-last { display: block; }
.bulk-bar { height: 6px; border-radius: 3px; background: var(--surface); overflow: hidden; }
.bulk-bar i { display: block; height: 100%; background: var(--fg); border-radius: 3px; transition: width 400ms var(--ease-out); }
.bulk-list { display: grid; gap: 2px; max-height: 320px; overflow-y: auto; }
.bulk-row { display: flex; align-items: center; gap: 12px; padding: 7px 4px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.bulk-row .cl-name { flex: 1; }
@media (max-width: 600px) { .grid2 { grid-template-columns: 1fr; } .prof-top { flex-direction: column; align-items: flex-start; } }

/* ---------- menu (popover) */
.menu { position: fixed; z-index: 60; min-width: 200px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 6px; box-shadow: var(--shadow);
  transition: opacity 150ms var(--ease-out), transform 150ms var(--ease-out); }
@starting-style { .menu { opacity: 0; transform: scale(0.95); } }
.menu.closing { opacity: 0; transform: scale(0.95); transition-duration: 100ms; }
.menu button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 8px 10px; border: 0; background: none; border-radius: 9px; cursor: pointer; text-align: left; }
.menu button .ico { color: var(--muted); }
.menu button.danger, .menu button.danger .ico { color: var(--bad); }
@media (hover: hover) and (pointer: fine) { .menu button:hover { background: var(--surface-2); } }

/* ---------- modal */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); display: grid; place-items: center; padding: 20px; z-index: 50;
  transition: opacity 220ms var(--ease-out); }
@starting-style { .overlay { opacity: 0; } }
.modal { background: var(--bg); border: 1px solid var(--line); border-radius: 18px; width: 100%; max-width: 460px; max-height: 92dvh; overflow: auto; box-shadow: var(--shadow);
  transition: opacity 220ms var(--ease-out), transform 220ms var(--ease-out); }
@starting-style { .modal { opacity: 0; transform: scale(0.96); } }
.overlay.closing { opacity: 0; transition-duration: 160ms; }
.overlay.closing .modal { opacity: 0; transform: scale(0.96); transition-duration: 160ms; }
.modal.wide { max-width: 640px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 18px 0 24px; }
.modal-body { padding: 16px 24px 24px; }
.modal-body > p { color: var(--muted); }
.form { display: grid; gap: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--surface); padding: 4px; border-radius: 14px; }
.seg label { display: block !important; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 8px 6px; border-radius: 10px; color: var(--muted); font-size: 13.5px; transition: background-color 150ms ease, color 150ms ease; }
.seg input:checked + span { background: var(--bg); color: var(--fg); box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }
.seg input:focus-visible + span { outline: 2px solid var(--fg-2); }
.form:has(input[name=method][value=qr]:checked) .phone-field { display: none; }
.check { display: flex !important; flex-direction: row !important; align-items: flex-start; gap: 10px; color: var(--fg) !important; font-size: 14px !important; cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--fg); }
.qr-box { background: #fff; border-radius: 16px; padding: 12px; width: 232px; height: 232px; margin: 4px auto 18px; }
.qr-box svg { width: 100%; height: 100%; display: block; }
.steps { margin: 0 0 14px; padding-left: 20px; color: var(--fg-2); }
.steps li { margin: 4px 0; }
.note { background: var(--surface); border-radius: 12px; padding: 11px 14px; font-size: 13px; color: var(--fg-2); }
.note.warn { color: var(--warn); }
.center { text-align: center; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line-2); border-top-color: var(--fg); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.done-mark { width: 48px; height: 48px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; margin: 4px auto 14px; color: var(--ok); }

/* ---------- toasts */
#toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); display: grid; gap: 8px; justify-items: center; z-index: 100; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 9px; background: var(--inv-bg); color: var(--inv-fg); padding: 10px 16px; border-radius: 14px; max-width: min(460px, calc(100vw - 32px)); box-shadow: var(--shadow); font-size: 13.5px;
  opacity: 1; transform: translateY(0); transition: opacity 400ms ease, transform 400ms ease; }
@starting-style { .toast { opacity: 0; transform: translateY(100%); } }
.toast.leaving { opacity: 0; transform: translateY(100%); }
.toast i { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--inv-fg); opacity: .5; }
.toast.ok i { background: var(--ok); opacity: 1; }
.toast.bad i { background: var(--bad); opacity: 1; }
.toast.warn i { background: var(--warn); opacity: 1; }

/* ---------- смена темы: круг от кнопки */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }

/* ---------- mobile: панель становится выезжающей */
@media (max-width: 860px) {
  .side { position: fixed; inset: 0 auto 0 0; z-index: 40; width: min(86vw, 320px); transform: translateX(-100%); transition: transform 400ms var(--ease-drawer); box-shadow: var(--shadow); display: flex !important; }
  .app[data-drawer="open"] .side { transform: translateX(0); }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 35; opacity: 0; pointer-events: none; transition: opacity 300ms var(--ease-out); }
  .app[data-drawer="open"] .scrim { opacity: 1; pointer-events: auto; }
  .topbar .open-side { display: inline-grid !important; }
    .thread-inner, .dock { padding-left: 14px; padding-right: 14px; }
  .page-in { padding: 4px 16px 40px; }
  .hello h1 { font-size: 24px; }
  .tbl thead { display: none; }
  .tbl tr { display: grid; grid-template-columns: 1fr auto; border-bottom: 1px solid var(--line); padding: 6px 0; }
  .tbl td { border: 0; padding: 6px 8px; }
  .m { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  .side, .modal, .overlay, .menu, .toast { transition-property: opacity; }
  @starting-style { .modal { transform: none; } .menu { transform: none; } .toast { transform: none; } }
  .toast.leaving, .overlay.closing .modal, .menu.closing { transform: none; }
  .status.wait::before, .skel i, .pulse::after { animation: none; }
}
