/* Веб-интерфейс учёта рабочих чатов. Светлая тема, приглушённые цвета, без внешних шрифтов. */

:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef1f5;
  --border: #e3e7ed;
  --border-strong: #cdd4de;
  --text: #1c2230;
  --text-2: #4d5667;
  --muted: #7a8394;
  --accent: #3563c9;
  --accent-hover: #2a52ab;
  --accent-soft: #eaf0fb;
  --accent-ring: rgba(53, 99, 201, .30);
  --danger: #c2413b;
  --danger-text: #a2322d;
  --danger-soft: #fbedeb;
  --danger-line: #f0c9c5;
  --warn: #a8660a;
  --warn-line: #d08a12;
  --warn-soft: #fdf4e3;
  --warn-border: #f1dcb2;
  --ok: #2b7f51;
  --ok-soft: #e8f4ed;
  --violet: #5f48b8;
  --violet-soft: #f0edfa;
  --teal: #1d7279;
  --teal-soft: #e4f2f3;
  --slate: #566173;
  --slate-soft: #eef0f4;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 16px 40px rgba(16, 24, 40, .16), 0 2px 8px rgba(16, 24, 40, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
  --sidebar-w: 236px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: .92em; }
code { background: var(--surface-3); padding: 1px 5px; border-radius: 5px; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.noscript { padding: 24px; }

/* --- каркас ------------------------------------------------------------------------------ */

.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
  padding: 18px 12px 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px; }
.brand-mark {
  width: 32px; height: 32px; flex: none; border-radius: 9px;
  background: var(--accent) url("/static/favicon.svg") center / cover no-repeat;
}
.brand-title { font-weight: 700; font-size: 15px; line-height: 1.2; }
.brand-sub { color: var(--muted); font-size: 12px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 520;
}
.nav-link:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav-link svg { flex: none; }
.nav-label { flex: 1; min-width: 0; }
.nav-badge {
  min-width: 22px; padding: 0 7px; border-radius: 999px;
  font-size: 12px; font-weight: 650; line-height: 20px; text-align: center;
  background: var(--surface-3); color: var(--text-2);
}
.nav-badge.danger { background: var(--danger); color: #fff; }
.nav-badge.warn { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn-border); line-height: 18px; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 8px; }
.fresh { color: var(--muted); font-size: 12px; line-height: 1.45; }
.whoami { font-size: 12px; line-height: 1.4; padding-top: 8px; border-top: 1px solid var(--border); }
.whoami:empty { display: none; }
.who-email { color: var(--text-2); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-role { color: var(--muted); }

.main { min-width: 0; padding: 22px 28px 48px; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.topbar h1 { font-size: 22px; }
.page-sub { color: var(--muted); margin-top: 2px; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.view { display: flex; flex-direction: column; gap: 18px; }

/* --- кнопки и поля ----------------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 13px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 560; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: #bcc4cf; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #a8352f; border-color: #a8352f; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-xs { height: 24px; padding: 0 8px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; }
.btn-link { border: 0; background: none; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-align: left; }
.btn-link:hover { text-decoration: underline; }
.icon-btn {
  display: inline-grid; place-items: center; width: 28px; height: 28px; flex: none;
  border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

.input, .select, .textarea {
  width: 100%; height: 34px; padding: 0 11px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit;
}
.textarea { height: auto; min-height: 76px; padding: 8px 11px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field-hint { font-size: 12px; color: var(--muted); }
.search { position: relative; display: block; width: 100%; max-width: 380px; }
.toolbar .search { flex: 1 1 260px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .input { padding-left: 34px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.toolbar .spacer { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 11px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  font: inherit; font-size: 13px; font-weight: 540; cursor: pointer;
}
.chip-btn:hover { border-color: var(--border-strong); color: var(--text); }
.chip-btn[aria-pressed="true"] { background: var(--accent-soft); border-color: #c5d4f2; color: var(--accent); }
.chip-count { color: var(--muted); font-weight: 600; }
.chip-btn[aria-pressed="true"] .chip-count { color: var(--accent); }

/* --- карточки, плитки -------------------------------------------------------------------- */

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 14px 18px 0; }
.card-head h2 { font-size: 15px; }
.card-body { padding: 14px 18px 16px; }
.card-foot { padding: 0 18px 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }

.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.kpi {
  position: relative; display: flex; flex-direction: column; gap: 4px;
  padding: 14px 16px 13px; min-height: 108px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); color: var(--text);
}
a.kpi:hover { text-decoration: none; border-color: var(--border-strong); }
.kpi::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 0 3px 3px 0; background: transparent; }
.kpi-label { font-size: 12.5px; color: var(--text-2); font-weight: 560; line-height: 1.3; }
.kpi-value { font-size: 30px; font-weight: 700; line-height: 1.1; letter-spacing: -.02em; }
.kpi-caption { font-size: 12px; color: var(--muted); margin-top: auto; display: flex; align-items: center; gap: 5px; }
.kpi.tone-danger { background: var(--danger-soft); border-color: var(--danger-line); }
.kpi.tone-danger::before { background: var(--danger); }
.kpi.tone-danger .kpi-value { color: var(--danger-text); }
.kpi.tone-warn { background: var(--warn-soft); border-color: var(--warn-border); }
.kpi.tone-warn::before { background: var(--warn-line); }
.kpi.tone-warn .kpi-value { color: var(--warn); }
.kpi.tone-ok .kpi-caption { color: var(--ok); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--muted); }
.tone-danger .status-dot { background: var(--danger); }
.tone-warn .status-dot { background: var(--warn-line); }
.tone-ok .status-dot { background: var(--ok); }

/* --- графики ------------------------------------------------------------------------------- */

.charts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.chart { position: relative; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.chart-title { font-size: 13px; font-weight: 600; color: var(--text-2); }
.chart-now { font-size: 20px; font-weight: 700; }
.chart-delta { font-size: 12px; color: var(--muted); }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-svg .grid { stroke: var(--border); stroke-width: 1; }
.chart-svg .axis-label { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.chart-svg .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-svg .area { stroke: none; opacity: .09; }
.chart-svg .guide { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-svg .dot { stroke: var(--surface); stroke-width: 2; }
.chart-svg .hit { fill: transparent; cursor: crosshair; }
.series-danger { color: var(--danger); }
.series-warn { color: var(--warn-line); }
.series-accent { color: var(--accent); }
.chart-svg .line, .chart-svg .dot, .chart-svg .area { stroke: currentColor; }
.chart-svg .dot, .chart-svg .area { fill: currentColor; }
.chart-svg .dot { stroke: var(--surface); }
.chart-tip {
  position: absolute; top: 26px; z-index: 2; pointer-events: none;
  padding: 5px 9px; border-radius: 7px; background: var(--text); color: #fff;
  font-size: 12px; line-height: 1.35; white-space: nowrap; transform: translateX(-50%);
  box-shadow: var(--shadow);
}
.chart-tip b { font-weight: 700; }
.chart-empty { color: var(--muted); font-size: 12px; padding: 8px 0; }

/* --- списки и таблицы -------------------------------------------------------------------- */

.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.list-row:first-child { border-top: 0; padding-top: 2px; }
.list-main { min-width: 0; flex: 1; }
.list-title { font-weight: 600; overflow-wrap: anywhere; }
.list-sub { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.list-side { flex: none; text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }

.table-wrap { overflow-x: auto; border-radius: var(--radius); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th, .table td { padding: 9px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.table th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2);
  font-size: 12px; font-weight: 600; color: var(--text-2); white-space: nowrap;
}
.table tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; white-space: nowrap; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover td { background: var(--surface-2); }
.table tbody tr.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.th-sort { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; }
.th-sort:hover { color: var(--text); }
.th-sort .arrow { color: var(--muted); font-size: 10px; }
.cell-title { font-weight: 600; overflow-wrap: break-word; }
/* Название чата и ФИО не сжимаются до слова в строке: числа уступают место */
.table td.col-main { min-width: 190px; }
.table td.col-person { min-width: 170px; }
.table td.col-when { width: 1%; min-width: 84px; }
.cell-sub { color: var(--muted); font-size: 12px; }
.n-danger { color: var(--danger-text); font-weight: 700; }
.n-warn { color: var(--warn); font-weight: 700; }
.n-zero { color: var(--muted); }
.more-row { display: flex; justify-content: center; align-items: center; gap: 12px; padding: 12px; color: var(--muted); font-size: 12.5px; }

/* --- чипы и метки ------------------------------------------------------------------------ */

.tag, .kind {
  display: inline-flex; align-items: center; gap: 5px; max-width: 100%;
  padding: 1px 8px; border-radius: 999px; border: 1px solid transparent;
  font-size: 12px; font-weight: 560; line-height: 18px; white-space: nowrap;
  background: var(--surface-3); color: var(--text-2);
}
.kind::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.kind-employee { background: var(--ok-soft); color: var(--ok); }
.kind-departed { background: var(--danger-soft); color: var(--danger-text); border-color: var(--danger-line); }
.kind-outsider { background: var(--warn-soft); color: var(--warn); }
.kind-personal { background: var(--violet-soft); color: var(--violet); }
.kind-old { background: var(--slate-soft); color: var(--slate); }
.kind-bot { background: var(--teal-soft); color: var(--teal); }
.kind-deleted { background: var(--surface-3); color: var(--muted); }
.kind-other { background: var(--surface-3); color: var(--text-2); }
.tag-danger { background: var(--danger-soft); color: var(--danger-text); }
.tag-warn { background: var(--warn-soft); color: var(--warn); }
.tag-ok { background: var(--ok-soft); color: var(--ok); }
.tag-accent { background: var(--accent-soft); color: var(--accent); }
.tag-muted { background: var(--surface-3); color: var(--muted); }
.tag-auto { background: var(--accent-soft); color: var(--accent); cursor: help; }
.action-pill { display: inline-block; padding: 2px 9px; border-radius: 6px; font-size: 12.5px; font-weight: 600; background: var(--danger-soft); color: var(--danger-text); white-space: nowrap; }
.action-pill.check { background: var(--warn-soft); color: var(--warn); }

/* --- структура ------------------------------------------------------------------------------ */

.structure { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 18px; align-items: start; }
.unassigned-col { position: sticky; top: 16px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.unassigned-col .zone { display: flex; flex-direction: column; min-height: 160px; max-height: calc(100vh - 32px); }
.unassigned-col .zone-body { overflow-y: auto; }
.zone { transition: border-color .12s, background-color .12s, box-shadow .12s; }
.zone-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px 8px; }
.zone-title { font-weight: 650; min-width: 0; flex: 1; overflow-wrap: anywhere; }
.zone-count { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.zone-sub { color: var(--muted); font-size: 12px; padding: 0 14px 6px; margin-top: -6px; overflow-wrap: anywhere; }
.zone-body { display: flex; flex-direction: column; gap: 6px; padding: 4px 10px 10px; }
.zone-empty { padding: 14px 10px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); color: var(--muted); font-size: 12.5px; text-align: center; }
body.is-dragging .zone { border-style: dashed; border-color: var(--border-strong); }
.zone.drop-over { border-color: var(--accent) !important; border-style: solid !important; background: var(--accent-soft); box-shadow: 0 0 0 3px var(--accent-ring); }

.deps { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.dep { padding: 0; }
.dep-head {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 12px 16px; border: 0; background: none; text-align: left; font: inherit; color: inherit; cursor: pointer;
  border-radius: var(--radius);
}
.dep-head:hover { background: var(--surface-2); }
.dep-head .chev { transition: transform .15s; color: var(--muted); flex: none; }
.dep[data-open="true"] .dep-head .chev { transform: rotate(90deg); }
.dep-name { font-weight: 650; font-size: 15px; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.dep-stats { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.units-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; padding: 0 14px 14px; }
.unit { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.unit .zone-head { padding: 10px 10px 6px 12px; }

.ccard {
  display: flex; align-items: flex-start; gap: 6px;
  padding: 8px 6px 8px 10px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: 0 1px 1px rgba(16, 24, 40, .03);
  cursor: grab;
}
.ccard:hover { border-color: var(--border-strong); }
.ccard:active { cursor: grabbing; }
.ccard.dragging { opacity: .45; }
.ccard.removed { opacity: .7; }
.ccard-main { min-width: 0; flex: 1; }
.ccard-title { display: block; width: 100%; font-weight: 600; font-size: 13px; line-height: 1.35; overflow-wrap: anywhere; }
.ccard-title:hover { color: var(--accent); }
.ccard-meta { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; align-items: center; }
.ccard-meta .tag { font-size: 11.5px; line-height: 16px; padding: 0 6px; }
.ccard .icon-btn { width: 26px; height: 26px; margin-top: -2px; }

/* --- выдвижная панель чата ------------------------------------------------------------------ */

.drawer-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(20, 26, 38, .28); }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 41;
  width: min(720px, 100vw); display: flex; flex-direction: column;
  background: var(--surface); box-shadow: var(--shadow-lg);
  animation: slide-in .16s ease-out;
}
@keyframes slide-in { from { transform: translateX(24px); } to { transform: none; } }
.drawer-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px 12px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { font-size: 18px; overflow-wrap: anywhere; }
.drawer-head .head-main { flex: 1; min-width: 0; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 20px 28px; display: flex; flex-direction: column; gap: 20px; }
.section-title { font-size: 13px; font-weight: 650; color: var(--text-2); text-transform: none; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.stat { padding: 9px 11px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); }
.stat-value { font-size: 19px; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 11.5px; color: var(--muted); }
.stat.danger { background: var(--danger-soft); border-color: var(--danger-line); }
.stat.danger .stat-value { color: var(--danger-text); }
.stat.warn { background: var(--warn-soft); border-color: var(--warn-border); }
.stat.warn .stat-value { color: var(--warn); }
.unit-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); }
.unit-line .grow { flex: 1; min-width: 0; }
.person { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.person:first-child { border-top: 0; }
.avatar {
  width: 32px; height: 32px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
  background: var(--surface-3); color: var(--text-2);
}
.avatar.kind-employee { background: var(--ok-soft); color: var(--ok); }
.avatar.kind-departed { background: var(--danger-soft); color: var(--danger-text); }
.avatar.kind-outsider { background: var(--warn-soft); color: var(--warn); }
.avatar.kind-personal { background: var(--violet-soft); color: var(--violet); }
.avatar.kind-old { background: var(--slate-soft); color: var(--slate); }
.avatar.kind-bot { background: var(--teal-soft); color: var(--teal); }
.avatar::before { display: none; }
.person-main { min-width: 0; flex: 1; }
.person-name { font-weight: 600; overflow-wrap: anywhere; }
.person-sub { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.person-side { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.event { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 10px; padding: 7px 0; border-top: 1px solid var(--border); font-size: 13px; }
.event:first-child { border-top: 0; }
.event-when { color: var(--muted); font-size: 12px; }
.event-label { font-weight: 600; }
.event-text { color: var(--text-2); font-size: 12.5px; overflow-wrap: anywhere; }

/* --- посторонние ------------------------------------------------------------------------- */

.pgroup { padding: 14px 16px; }
.pgroup-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.pgroup-head .person-main { min-width: 220px; }
.pgroup-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.pgroup-chats { margin-top: 10px; border-top: 1px solid var(--border); }
.pchat { display: flex; align-items: center; gap: 10px; padding: 8px 0 8px 42px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.pchat:last-child { border-bottom: 0; padding-bottom: 0; }
.pchat-main { min-width: 0; flex: 1 1 260px; }
.pchat-side { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.allowed-note { font-size: 12px; color: var(--ok); overflow-wrap: anywhere; }
.pchat-more { justify-content: flex-start; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.sub-head { font-size: 14px; font-weight: 650; margin-top: 6px; }
.plain-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.plain-list li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; }
.access-add { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 12px; align-items: end; }

/* --- состояния: загрузка, пусто, ошибка --------------------------------------------------- */

.skeleton { display: flex; flex-direction: column; gap: 12px; }
.sk { border-radius: var(--radius); background: linear-gradient(90deg, #eceff3 0%, #f6f7f9 50%, #eceff3 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
.sk-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 36px 20px; color: var(--muted); }
.empty svg { color: var(--border-strong); }
.empty.ok svg { color: var(--ok); }
.empty-title { color: var(--text); font-weight: 650; font-size: 15px; }
.error-box { padding: 18px; border-radius: var(--radius); background: var(--danger-soft); color: var(--danger-text); border: 1px solid var(--danger-line); display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.note { padding: 12px 16px; border-radius: var(--radius); background: var(--accent-soft); color: #2b3f6b; border: 1px solid #d3def5; font-size: 13px; }

/* --- диалоги, меню, уведомления ------------------------------------------------------------- */

.dlg {
  width: min(520px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 14px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.dlg.wide { width: min(680px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(20, 26, 38, .35); }
.dlg form { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.dlg-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 6px; }
.dlg-head h2 { font-size: 17px; }
.dlg-body { padding: 8px 20px 4px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px 18px; }
.dlg-error { color: var(--danger-text); background: var(--danger-soft); border-radius: var(--radius-sm); padding: 8px 11px; font-size: 13px; }
.radio-row { display: flex; align-items: flex-start; gap: 9px; padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; }
.radio-row:has(input:checked) { border-color: #c5d4f2; background: var(--accent-soft); }
.radio-row input { margin-top: 3px; }
.pick-list { display: flex; flex-direction: column; max-height: 300px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.pick-group { padding: 8px 12px 4px; font-size: 11.5px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
.pick-item { display: flex; justify-content: space-between; gap: 8px; width: 100%; padding: 8px 12px; border: 0; border-top: 1px solid var(--border); background: var(--surface); text-align: left; font: inherit; color: inherit; cursor: pointer; }
.pick-item:hover, .pick-item:focus-visible { background: var(--accent-soft); outline: none; }
.pick-item[aria-current="true"] { color: var(--muted); cursor: default; background: var(--surface-2); }
.selected-chip { display: flex; align-items: center; gap: 8px; padding: 7px 8px 7px 11px; border-radius: var(--radius-sm); background: var(--accent-soft); border: 1px solid #c5d4f2; }
.selected-chip .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }

.menu {
  position: fixed; z-index: 60; min-width: 190px; padding: 5px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg);
}
.menu-item { display: flex; width: 100%; padding: 7px 10px; border: 0; border-radius: 6px; background: none; font: inherit; color: var(--text); text-align: left; cursor: pointer; }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-3); outline: none; }
.menu-item.danger { color: var(--danger-text); }

.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 70; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast {
  display: flex; align-items: center; gap: 12px; max-width: min(460px, calc(100vw - 40px));
  padding: 10px 12px 10px 14px; border-radius: 10px;
  background: #222a38; color: #fff; box-shadow: var(--shadow-lg); font-size: 13.5px;
  animation: toast-in .18s ease-out;
}
.toast.error { background: #8f2b26; }
.toast-text { flex: 1; overflow-wrap: anywhere; }
.toast .btn-link { color: #bcd0ff; font-weight: 650; }
.toast .icon-btn { color: rgba(255, 255, 255, .7); width: 24px; height: 24px; }
.toast .icon-btn:hover { background: rgba(255, 255, 255, .12); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

details.fold > summary { cursor: pointer; color: var(--text-2); font-weight: 600; padding: 4px 0; }
details.fold[open] > summary { margin-bottom: 8px; }

/* --- вход ---------------------------------------------------------------------------------- */

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(440px, 100%); display: flex; flex-direction: column; gap: 14px;
  padding: 28px 28px 24px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow-lg);
}
.login-card h1 { font-size: 20px; }
.brand-login { padding: 0; margin-bottom: 6px; }
.login-form { display: flex; flex-direction: column; gap: 8px; }
.login-or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12.5px; }
.login-or::before, .login-or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.login-block { display: flex; flex-direction: column; gap: 10px; }
.login-block[hidden] { display: none; }
.login-error { color: var(--danger-text); background: var(--danger-soft); border: 1px solid var(--danger-line); border-radius: var(--radius-sm); padding: 9px 12px; font-size: 13px; }

/* --- адаптивность -------------------------------------------------------------------------- */

@media (max-width: 1280px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1080px) {
  .charts { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .structure { grid-template-columns: 1fr; }
  .unassigned-col { position: static; max-height: none; }
  .unassigned-col .zone { max-height: 420px; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky; top: 0; z-index: 30; height: auto; flex-direction: row; align-items: center;
    gap: 10px; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--border);
  }
  .brand-text, .sidebar-foot .fresh, .whoami { display: none; }
  .access-add { grid-template-columns: 1fr; }
  .brand { padding: 0; }
  .nav { flex-direction: row; overflow-x: auto; flex: 1; scrollbar-width: none; }
  .nav-link { padding: 6px 9px; white-space: nowrap; }
  .sidebar-foot { margin: 0; padding: 0; }
  .main { padding: 16px 16px 40px; }
  .topbar { flex-direction: column; align-items: stretch; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search { max-width: none; }
  .event { grid-template-columns: 1fr; gap: 2px; }
  /* Таблица на телефоне прокручивается вбок, а не сжимает имена по буквам */
  .table { min-width: 760px; }
  .pchat { padding-left: 0; }
}
@media (max-width: 520px) {
  .kpi-value { font-size: 24px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav-label { display: none; }
  .nav-link[aria-current="page"] .nav-label { display: inline; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* --- настройки и ручные запуски -------------------------------------------------------------- */

.ctl-status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13.5px; }
.ctl-status .status-dot { flex: none; }
.status-dot.tone-danger { background: var(--danger); }
.status-dot.tone-warn { background: var(--warn-line); }
.status-dot.tone-ok { background: var(--ok); }
.dlg .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 12px; }
.dlg .section-title { margin-top: 14px; }

/* --- бэк-офис и креаторы ---------------------------------------------------------------------- */

.group-box { display: flex; flex-direction: column; gap: 10px; }
.group-title { font-weight: 650; font-size: 14px; }
.stats.stats-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.drawer .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.btn-danger-soft { color: var(--danger-text); border-color: var(--danger-line); background: var(--danger-soft); }
.btn-danger-soft:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
