/* ─────────────────────────────────────────────────────────────
   Salarium (расчёт ЗП) — дизайн-токены и стили.
   Референс: светлый лавандовый кабинет (GetCourse). Всё светлое,
   белый сайдбар, мягкие сиреневые заливки вместо рамок, лёгкие тени.
   Радиусы: панели 16, контролы 10, кнопки и чипы — pill.
   Акцент один: фиолетовый. Semantic-цвета (danger/warn) не трогать.
   ───────────────────────────────────────────────────────────── */

:root {
  color-scheme: light;

  --bg: #f0f1f8;             /* светлый перивинкл, фон страницы */
  --panel: #ffffff;
  --panel-2: #f7f6fc;        /* шапки таблиц, заливки инпутов, ховеры */
  --ink: #2a2438;
  --muted: #7b7691;
  --line: #edebf5;           /* разделители внутри панелей */
  --line-strong: #ddd8ec;

  --accent: #7c5ce0;          /* кнопки, ссылки, активные пункты */
  --accent-hover: #6a49d6;
  --accent-soft: #efeafc;     /* сиреневая подложка */
  --accent-soft-hover: #e5dcfa;
  --accent-soft-line: #d9cdf6;

  --danger: #c03a2e;
  --danger-bg: #fdf1f0;
  --danger-line: #f0c5c0;

  --warn-ink: #92540e;
  --warn-bg: #fdf5e0;
  --warn-line: #f0dfae;
  --warn-strong: #d99e06;

  --ok-ink: #5a3bc4;
  --ok-bg: #efeafc;
  --ok-line: #d9cdf6;

  --shadow-card: 0 2px 10px rgba(84, 60, 160, .06);
  --shadow-float: 0 8px 28px rgba(84, 60, 160, .1);
}

/* ── База ─────────────────────────────────────────────────── */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 "Segoe UI Variable Text", "Segoe UI", -apple-system, Roboto, Arial, sans-serif;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

code {
  background: var(--panel-2);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 12.5px;
  color: #5a3bc4;
}

.muted, .dim { color: var(--muted); }
.dim { font-size: 13px; }
.right { text-align: right; }

/* ── Каркас: белый сайдбар + контент ──────────────────────── */

.shell { display: flex; min-height: 100vh; }

.side {
  flex: 0 0 236px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 14px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 650;
  text-decoration: none;
  padding: 2px 10px 18px;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: linear-gradient(135deg, #8f6ff0, #6a49d6);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.side-nav { display: flex; flex-direction: column; gap: 28px; flex: 1; }
.nav-group { display: flex; flex-direction: column; gap: 3px; }
.nav-title {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #b3aecb;
  padding: 0 12px 8px;
  white-space: nowrap;
}
.nav-link {
  display: block;
  padding: 8px 12px;
  border-radius: 12px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
}
.nav-link:hover { background: var(--panel-2); color: var(--ink); text-decoration: none; }
.nav-link.on {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
}

.side-foot {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.badge {
  align-self: flex-start;
  margin: 0 12px;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 11.5px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  border: 1px solid var(--warn-line);
}
a.badge, a.badge:hover { text-decoration: none; }
a.badge:hover { border-color: var(--accent); }
/* ok = ставки подтверждены: спокойная сиреневая расцветка вместо «предупреждения» */
.badge.ok {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-soft-line);
}
.who {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 0 12px;
  font-size: 13px;
}
.who a { color: var(--ink); font-weight: 550; }
.who a.dim { color: var(--muted); font-weight: 400; font-size: 12.5px; }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
main { width: 100%; max-width: 1240px; margin: 0 auto; padding: 32px 40px 12px; flex: 1; }

h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; margin: 0 0 20px; }
h1 .dim { font-size: 15px; font-weight: 400; }
h2 { font-size: 15.5px; font-weight: 650; margin: 32px 0 14px; }
h2 .dim { font-weight: 400; font-size: 13px; }
section { margin-bottom: 8px; }

footer {
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 40px 32px;
  color: var(--muted);
  font-size: 12.5px;
}

/* ── Метрики ──────────────────────────────────────────────── */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.card {
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  padding: 14px 18px 15px;
  display: flex;
  flex-direction: column-reverse;
  gap: 2px;
  justify-content: flex-end;
}
.card .num {
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.card .lbl { color: var(--muted); font-size: 12.5px; }

/* ── Таблицы ──────────────────────────────────────────────── */

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  font-variant-numeric: tabular-nums;
}
th, td { padding: 10px 16px; border-bottom: 1px solid var(--line); text-align: left; }
th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel-2);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .02em;
  color: var(--muted);
  white-space: nowrap;
  border-bottom: none;
}
thead th:first-child { border-top-left-radius: 16px; }
thead th:last-child { border-top-right-radius: 16px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:last-child td:first-child { border-bottom-left-radius: 16px; }
tbody tr:last-child td:last-child { border-bottom-right-radius: 16px; }
tbody tr:hover td { background: #faf9fe; }
/* Строка-ссылка: кликается целиком (реестр недель ЗП и т.п.) */
tr.rowlink { cursor: pointer; }
tr.rowlink:hover td { background: var(--accent-soft); }
td a { color: var(--accent); font-weight: 550; }
.total { font-weight: 650; }
.cnt { color: var(--muted); font-size: 11px; margin-left: 5px; font-weight: 400; }
tr.sum td { font-weight: 650; background: var(--panel-2); }
tr.sum:hover td { background: var(--panel-2); }
/* В длинных таблицах «Итого» прилипает к низу окна - итог виден без скролла.
   Фон ячеек непрозрачный (panel-2), поэтому строки проезжают под ним. */
tr.sum td { position: sticky; bottom: 0; z-index: 1; }
/* Строка-ссылка, выбранная с клавиатуры */
tr.rowlink:focus-visible { outline-offset: -2px; }
tr.rowlink:focus-visible td { background: var(--accent-soft); }

table.narrow { max-width: 560px; }
table.narrow th {
  width: 170px; position: static; background: transparent;
  border-bottom: 1px solid var(--line);
}
table.narrow tbody tr:last-child th { border-bottom: none; }

/* ── Фильтры и формы ──────────────────────────────────────── */

.filters {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  flex-wrap: wrap;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  padding: 16px 18px;
  margin-bottom: 22px;
}
.filters label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); font-weight: 500; }

input[type=date], input[type=text], input[type=email], input[type=password],
input[type=search], select, input[type=file] {
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 13.5px;
  font-family: inherit;
  background: var(--panel-2);
  color: var(--ink);
}
input::placeholder { color: #a9a4bf; }
input:focus, select:focus {
  outline: none;
  background: var(--panel);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

button, .btn {
  padding: 8px 20px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: background-color .12s ease;
}
button:hover, .btn:hover { background: var(--accent-hover); text-decoration: none; }
button:active, .btn:active { transform: translateY(1px); }

.btn.ghost {
  background: var(--accent-soft);
  color: var(--accent);
}
.btn.ghost:hover { background: var(--accent-soft-hover); }

button.link {
  background: none; border: none; padding: 0; border-radius: 4px;
  color: var(--accent); cursor: pointer; font-size: 13px; font-weight: 550;
}
button.link:hover { background: none; text-decoration: underline; }
button.link:active { transform: none; }
button.link.danger { color: var(--danger); }

.upload { display: flex; gap: 12px; align-items: center; }
form.filters button { align-self: flex-end; }

/* ── Чипы, плашки, пустые состояния ───────────────────────── */

.chips { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; padding: 0; margin: 0; }
.chips li {
  background: var(--accent-soft);
  color: #5a3bc4;
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 13px;
}

.chip-warn {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 10px;
  border-radius: 20px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  border: 1px solid var(--warn-line);
  font-size: 11px;
  white-space: nowrap;
}

.empty {
  background: var(--panel);
  border: 1.5px dashed var(--accent-soft-line);
  border-radius: 16px;
  padding: 36px 28px;
  text-align: center;
  color: var(--muted);
}

.alert {
  background: var(--danger-bg); border: 1px solid var(--danger-line); color: var(--danger);
  border-radius: 12px; padding: 11px 16px; margin-bottom: 16px; font-size: 13.5px;
}
.notice {
  background: var(--ok-bg); color: var(--ok-ink);
  border-radius: 12px; padding: 13px 16px; margin-bottom: 18px; font-size: 13.5px;
}

/* Плашка-источник над заголовком: цифры берутся из загружаемых выгрузок,
   и видно, насколько они свежие. Желтеет, когда данные устарели. */
.data-note {
  background: var(--panel);
  border-radius: 12px;
  box-shadow: var(--shadow-card);
  padding: 8px 16px;
  margin-bottom: 16px;
  font-size: 12.5px;
  color: var(--muted);
}
.data-note.warn {
  background: var(--warn-bg);
  color: var(--warn-ink);
  border: 1px solid var(--warn-line);
  box-shadow: none;
}
.copyable {
  display: block; width: 100%; margin-top: 8px; padding: 9px 12px;
  border: 1px solid var(--ok-line); border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  font-family: ui-monospace, Consolas, monospace; font-size: 12.5px;
}
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row .copyable { flex: 1; }
.copy-row button { margin-top: 8px; flex: none; white-space: nowrap; }

/* Мигание свежесозданного приглашения — видно, что ссылка новая */
.notice.flash { animation: notice-flash 1.2s ease 2; }
@keyframes notice-flash {
  50% { background: var(--accent-soft-hover); box-shadow: 0 0 0 3px var(--accent-soft-line); }
}

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 980px) { .two-col { grid-template-columns: 1fr; } }

/* ── Графики на сводке (CSS-бары, без библиотек) ───────────── */

.chart-panel {
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  padding: 26px 16px 12px;   /* сверху место под подпись пика */
}
.chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;                  /* зазор между барами — фон панели */
  height: 132px;
}
.chart .bar-wrap {
  flex: 1;
  min-width: 2px;
  height: 100%;
  display: flex;
  align-items: flex-end;
  position: relative;
  cursor: default;
}
.chart .bar {
  width: 100%;
  min-height: 2px;
  background: var(--accent);
  border-radius: 4px 4px 0 0;  /* скруглён только «конец данных» */
}
.chart .bar.zero { background: var(--accent-soft); }
.chart .bar-wrap:hover .bar { background: var(--accent-hover); }
.chart .bar-wrap.peak::after {
  content: attr(data-v);
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 650;
  color: var(--ink);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.chart-x {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ── Вход, приглашения ────────────────────────────────────── */

body.auth {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
  background:
    radial-gradient(600px 400px at 15% 10%, #e7e0fa 0%, transparent 60%),
    radial-gradient(500px 400px at 90% 90%, #e2ddf7 0%, transparent 60%),
    var(--bg);
}
.auth-box {
  width: 100%;
  max-width: 388px;
  background: var(--panel);
  border-radius: 20px;
  box-shadow: var(--shadow-float);
  padding: 32px;
}
.auth-logo {
  display: flex; align-items: center; gap: 10px;
  font-weight: 650; font-size: 15px; margin-bottom: 20px;
}
.auth-box h1 { font-size: 19px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.stack input { padding: 10px 12px; font-size: 14px; }
.stack button { padding: 11px; font-size: 14px; margin-top: 4px; }

/* ── Сотрудники и роли ────────────────────────────────────── */

.row-form { display: inline; }
td input[type=text], td select {
  padding: 6px 10px; border-radius: 8px; font-size: 13px; max-width: 190px;
}
.nowrap { white-space: nowrap; }
.nowrap .link { margin-left: 10px; }
label.inline {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--ink);
}
input[type=checkbox] { accent-color: var(--accent); }

.perms { display: flex; flex-wrap: wrap; gap: 12px 18px; width: 100%; }
.role-card {
  background: var(--panel); border-radius: 16px;
  box-shadow: var(--shadow-card);
  padding: 18px 20px; margin-bottom: 6px;
}
.role-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.role-head input { font-size: 14px; font-weight: 600; }
.role-actions { margin-top: 12px; }
.role-delete { margin: 0 0 22px 20px; }

/* ── Недели ЗП и квитанции ────────────────────────────────── */

.payslip {
  background: var(--panel); border-radius: 16px;
  box-shadow: var(--shadow-card);
  padding: 24px 28px; max-width: 640px;
}
.payslip-head { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.payslip h2 { font-size: 15px; margin: 20px 0 8px; }
.payslip h3 { font-size: 13.5px; margin: 14px 0 6px; }
.payslip-total { font-size: 16px; font-weight: 700; margin: 16px 0 10px; }
.run-actions { display: flex; align-items: center; gap: 16px; margin-top: 18px; flex-wrap: wrap; }

@media print {
  .no-print { display: none !important; }
  .payslip { box-shadow: none; max-width: none; padding: 0; }
}

/* ── Таблица мотивации (отчёты и карточка сотрудника) ─────── */

details.motivation { margin: 14px 0 6px; }
details.motivation > summary {
  cursor: pointer; list-style: none;
  color: var(--accent); font-size: 13px; font-weight: 600;
}
details.motivation > summary::-webkit-details-marker { display: none; }
details.motivation > summary:hover { text-decoration: underline; }
.motivation-body { margin-top: 10px; max-width: 480px; }
.motivation-body h3 { font-size: 13.5px; margin: 14px 0 6px; }

/* ── Группы и роли ────────────────────────────────────────── */

/* Якоря возврата после сохранения: не прижимать блок вплотную к верху окна */
.group-card, details.role-row, tr[id] { scroll-margin-top: 24px; }

/* details без штатного треугольника */
.creators summary, .group-edit summary, .role-row summary { cursor: pointer; list-style: none; }
.creators summary::-webkit-details-marker,
.group-edit summary::-webkit-details-marker,
.role-row summary::-webkit-details-marker { display: none; }

.creators { display: flex; gap: 14px; margin: 18px 0 4px; flex-wrap: wrap; }
.creators > details {
  flex: 1 1 320px;
  background: var(--panel); border-radius: 16px;
  box-shadow: var(--shadow-card); padding: 0 20px;
}
.creators > details > summary { padding: 13px 0; font-weight: 600; color: var(--accent); }
.creators > details[open] > summary { border-bottom: 1px solid var(--line); }

.creator-form { padding: 14px 0 18px; }
.role-fields { display: flex; gap: 14px; flex-wrap: wrap; }
.role-fields label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 12.5px; color: var(--muted); font-weight: 500;
}
.creator-form .perms, .role-edit .perms { margin: 12px 0 14px; }
.creator-form .dim { margin: 10px 0 12px; }

.group-card {
  position: relative;   /* якорь для «настроить группу» в правом верхнем углу */
  background: var(--panel); border-radius: 16px;
  box-shadow: var(--shadow-card);
  padding: 18px 22px 20px; margin-top: 20px;
}
.group-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; }
.group-info { display: flex; align-items: baseline; gap: 10px 12px; flex-wrap: wrap; }
.group-info h2 { margin: 0; }
.mask-chip {
  background: var(--accent-soft); color: var(--ok-ink);
  border-radius: 999px; padding: 2px 10px; font-size: 12px; white-space: nowrap;
}
.mask-preview {
  margin-top: 5px; font-weight: 400; font-size: 12.5px;
  max-width: 460px; line-height: 1.45;
}

.group-edit > summary {
  position: absolute; top: 18px; right: 22px;
  color: var(--accent); font-size: 13px;
}
.group-edit > summary:hover { text-decoration: underline; }
.group-edit-body {
  margin-top: 10px; padding: 2px 16px;
  background: var(--panel-2); border-radius: 12px;
}
/* заголовку карточки — запас справа, чтобы не заезжать под ссылку настройки */
.group-top { padding-right: 130px; }

.role-list { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
details.role-row { background: var(--panel-2); border-radius: 12px; }
details.role-row > summary {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-radius: 12px;
}
details.role-row > summary:hover { background: var(--accent-soft); }
details.role-row[open] > summary {
  border-bottom: 1px solid var(--line-strong);
  border-radius: 12px 12px 0 0;
}
.role-name { font-weight: 600; flex: 0 1 220px; }
.role-tags { display: flex; gap: 6px; flex-wrap: wrap; flex: 1 1 auto; }
.perm-chip {
  background: var(--accent-soft); color: var(--ok-ink);
  border-radius: 999px; padding: 1px 9px; font-size: 12px; white-space: nowrap;
}
.perm-chip.none { background: var(--panel); color: var(--muted); }
.role-count { white-space: nowrap; }
details.role-row > summary::after {
  content: ""; flex: none; width: 7px; height: 7px; margin-left: 2px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg) translateY(-2px); transition: transform .15s;
}
details.role-row[open] > summary::after { transform: rotate(225deg) translateY(-2px); }
.role-edit { padding: 14px 16px 16px; }

/* Ряд действий формы: Сохранить + код слева, удаление прижато вправо */
.role-edit .role-actions, .group-edit-body .role-actions {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin-top: 0;
}
.role-actions .danger { margin-left: auto; }

/* Раскрытые формы лежат на подложке --panel-2 — стандартная заливка инпутов
   с ней сливается, поэтому здесь поля белые и с видимой рамкой. */
.role-edit input[type=text], .role-edit select,
.group-edit-body input[type=text], .group-edit-body select {
  background: var(--panel);
  border-color: var(--line-strong);
}
.role-edit input[type=text]:focus, .role-edit select:focus,
.group-edit-body input[type=text]:focus, .group-edit-body select:focus {
  border-color: var(--accent);
}

/* ── Регламент ────────────────────────────────────────────── */

.hb { display: grid; grid-template-columns: 256px 1fr; gap: 28px; align-items: start; }
@media (max-width: 900px) { .hb { grid-template-columns: 1fr; } .hb-side { position: static; } }

.hb-side { position: sticky; top: 24px; }
.hb-search input { width: 100%; background: var(--panel); box-shadow: var(--shadow-card); }
.hb-nav { margin: 14px 0; display: flex; flex-direction: column; gap: 2px; }
.hb-sec {
  padding: 8px 12px; border-radius: 12px; text-decoration: none;
  color: var(--muted); font-size: 13.5px; font-weight: 550;
}
.hb-sec:hover { background: #e9e7f3; color: var(--ink); text-decoration: none; }
.hb-sec.on { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.hb-anchors {
  display: flex; flex-direction: column;
  margin: 4px 0 8px 16px; padding-left: 12px; border-left: 2px solid var(--line-strong);
}
.hb-anchors a { padding: 4px 0; font-size: 12.5px; color: var(--muted); }
.hb-anchors a:hover { color: var(--accent); text-decoration: none; }
.hb-body {
  background: var(--panel); border-radius: 20px;
  box-shadow: var(--shadow-card);
  padding: 30px 34px;
}
.hb-body h1 { margin-bottom: 18px; }

/* Иллюстрация раздела обтекается текстом; таблицы её «сбрасывают»
   (clear) и всегда занимают полную ширину. */
.hb-art {
  float: right;
  width: 200px;
  max-width: 40%;
  margin: 4px 0 18px 26px;
}
@media (max-width: 600px) { .hb-art { width: 130px; } }

/* Основной текст — по ширине, с переносами: легче читать плотные абзацы */
.hb-p, .hb-text p, .hb-answer, .hb-warn, .hb-aside li, .hb-note li,
.hb-aside strong, .hb-sub, .hb-line, .hb-table td {
  text-align: justify;
  hyphens: auto;
}
.hb-h {
  font-size: 16.5px; font-weight: 650; margin: 34px 0 14px; padding-bottom: 8px;
  border-bottom: 1px solid var(--line); scroll-margin-top: 20px;
}
.hb-h:first-of-type { margin-top: 8px; }
.hb-p { white-space: pre-line; margin: 12px 0; }

.hb-item { display: flex; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); scroll-margin-top: 18px; }
.hb-item:last-child { border-bottom: none; }
.hb-item:target {
  background: var(--accent-soft);
  border-radius: 12px;
  padding-inline: 12px;
  margin-inline: -12px;
  border-bottom-color: transparent;
}
.hb-num {
  flex: none; width: 27px; height: 27px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 12.5px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-decoration: none;
}
a.hb-num:hover { background: var(--accent); color: #fff; text-decoration: none; }
.hb-text { flex: 1; }
.hb-text p { margin: 2px 0; white-space: pre-line; }

.hb-warn {
  background: var(--warn-bg); border-left: 4px solid var(--warn-strong);
  border-radius: 12px; padding: 13px 16px; margin: 16px 0;
  white-space: pre-line; font-size: 13.5px;
}
.hb-aside {
  background: var(--panel-2); border-radius: 12px;
  padding: 13px 16px; margin: 14px 0; font-size: 13.5px;
}
.hb-aside ul, .hb-note ul { margin: 6px 0 0; padding-left: 18px; }
.hb-aside li, .hb-note li { margin: 3px 0; white-space: pre-line; }
.hb-sub { font-weight: 650; margin: 12px 0 0; }
.hb-sub:first-child, strong + .hb-sub { margin-top: 8px; }
.hb-line { margin: 6px 0 0; white-space: pre-line; }

.hb-note { margin-top: 10px; }
.hb-note summary, .hb-faq summary {
  cursor: pointer; color: var(--accent); font-size: 13.5px; font-weight: 600;
  padding: 6px 0; list-style: none;
}
.hb-note summary::before, .hb-faq summary::before { content: "▸ "; }
.hb-note[open] summary::before, .hb-faq[open] summary::before { content: "▾ "; }
.hb-note[open] {
  background: var(--panel-2);
  border-radius: 12px; padding: 4px 14px 10px;
}

.hb-faq { border-bottom: 1px solid var(--line); }
.hb-faq summary { font-weight: 600; color: var(--ink); }
.hb-faq[open] summary { color: var(--accent); }
.hb-answer { padding: 4px 0 14px 18px; white-space: pre-line; color: var(--ink); }

mark { background: #ffe071; color: inherit; border-radius: 3px; padding: 0 1px; }

.hb-hit {
  display: block; padding: 12px 14px;
  border-radius: 12px;
  text-decoration: none; color: var(--ink);
}
.hb-hit:hover { background: var(--panel-2); text-decoration: none; }
.hb-hit + .hb-hit { border-top: 1px solid var(--line); }
.hb-hit-sec { display: block; font-size: 12px; color: var(--accent); font-weight: 650; margin-bottom: 3px; }
.hb-hit-text { font-size: 13.5px; }

.hb-img { margin: 16px 0; }
.hb-img img { max-width: 100%; border-radius: 12px; box-shadow: var(--shadow-card); }

.hb-toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--ink); color: #fff;
  font-size: 13px; padding: 8px 18px; border-radius: 999px;
  z-index: 50; box-shadow: var(--shadow-float);
}

.hb-table { overflow-x: auto; margin: 14px 0; clear: both; }
.hb-table table { box-shadow: none; border: 1px solid var(--line); border-radius: 12px; }
.hb-table td { white-space: pre-line; vertical-align: top; }
.hb-table th { position: static; }
.hb-chips { margin: 12px 0; }

/* ── Система (здоровье и логи) ────────────────────────────── */

.card .num.bad { color: var(--danger); }

.seg-row { display: flex; gap: 8px; align-items: center; margin: 0 0 14px; flex-wrap: wrap; }
.seg {
  padding: 6px 16px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  font-weight: 550;
  text-decoration: none;
  box-shadow: var(--shadow-card);
}
.seg:hover { color: var(--ink); text-decoration: none; }
.seg.on { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.seg-refresh { margin-left: auto; }

.lvl {
  display: inline-block;
  padding: 1px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .02em;
}
.lvl-info, .lvl-debug { background: var(--panel-2); color: var(--muted); }
.lvl-warning { background: var(--warn-bg); color: var(--warn-ink); }
.lvl-error, .lvl-critical { background: var(--danger-bg); color: var(--danger); }

.log-table td { font-size: 12.5px; padding: 7px 12px; }
.log-msg {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}
.log-scroll { max-height: 340px; overflow-y: auto; border-radius: 16px; }
.log-scroll table { box-shadow: var(--shadow-card); }

/* ── Адаптив ──────────────────────────────────────────────── */

@media (max-width: 960px) {
  .shell { flex-direction: column; }
  .side {
    position: static;
    height: auto;
    flex: none;
    padding: 12px 16px;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .brand { padding-bottom: 10px; }
  .side-nav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .nav-group { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .nav-title { display: none; }
  .side-foot {
    margin-top: 10px; padding-top: 10px;
    flex-direction: row; align-items: center; justify-content: space-between;
  }
  main { padding: 20px 16px 8px; }
  footer { padding: 8px 16px 24px; }
  th { position: static; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ── Удобства таблиц и фильтров ───────────────────────────── */

/* Обёртка вокруг таблиц (ставит app.js). Активна только на телефоне:
   на десктопе overflow остаётся видимым, и липкие th работают как раньше. */
@media (max-width: 960px) {
  .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-scroll > table { min-width: 640px; }
}

/* Сортировка кликом по заголовку */
table.sortable thead th { cursor: pointer; user-select: none; }
table.sortable thead th:hover { color: var(--accent); }
table.sortable thead th.sort-asc::after { content: " ↑"; color: var(--accent); }
table.sortable thead th.sort-desc::after { content: " ↓"; color: var(--accent); }

/* Пресеты периодов и чипы-фильтры строк */
.preset {
  display: inline-block;
  padding: 5px 14px;
  border: none;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #5a3bc4;
  font-size: 12.5px;
  font-weight: 550;
  cursor: pointer;
}
.preset:hover { background: var(--accent-soft-hover); text-decoration: none; }
.preset.on { background: var(--accent); color: #fff; }
.preset-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.filters .preset-row { margin: 0 0 3px; align-self: flex-end; }

/* Живой поиск по таблице */
.table-search {
  width: 280px;
  max-width: 100%;
  margin: 0 0 12px;
}

/* ── Подсказки «?» (всплывающие пояснения) ─────────────────── */

.hint {
  /* top+middle вместо выравнивания по базовой линии: у inline-flex базовая
     линия зависит от глифа «?» внутри — кружок «плавал» между контекстами */
  position: relative;
  top: -1px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  margin-left: 2px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  vertical-align: middle;
  cursor: help;
  user-select: none;
}
.hint:hover, .hint:focus-visible, .hint.on { background: var(--accent); color: #fff; }
.hint:focus-visible { border-radius: 50%; }
.perms .hint { margin-left: 0; }

/* стрелка облачка */
.hint::before {
  content: "";
  position: absolute;
  bottom: calc(100% - 1px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--ink);
}
/* само облачко: текст берётся из data-tip */
.hint::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 260px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: normal;
  white-space: normal;
  text-align: left;
  text-transform: none;
  box-shadow: var(--shadow-float);
  z-index: 40;
}
.hint::before, .hint::after {
  opacity: 0;
  visibility: hidden;
  transition: opacity .12s ease;
  pointer-events: none;
}
.hint:hover::before, .hint:hover::after,
.hint:focus::before, .hint:focus::after,
.hint.on::before, .hint.on::after {
  opacity: 1;
  visibility: visible;
}

/* У краёв экрана облачко прижимается к иконке (классы ставит app.js) */
.hint.tip-l::after { left: -6px; transform: none; }
.hint.tip-r::after { left: auto; right: -6px; transform: none; }

/* Открытая подсказка в липкой шапке таблицы: поднять её th над соседними,
   иначе непрозрачный фон соседнего заголовка закрашивает угол облачка */
th:has(.hint:hover), th:has(.hint:focus), th:has(.hint.on) { z-index: 2; }

/* На телефоне таблицы живут в .table-scroll (overflow) — облачко из шапки
   таблицы откидывается вниз, иначе его обрежет краем прокрутки. */
@media (max-width: 960px) {
  .table-scroll th .hint::before {
    bottom: auto;
    top: calc(100% - 1px);
    border-top-color: transparent;
    border-bottom-color: var(--ink);
  }
  .table-scroll th .hint::after {
    bottom: auto;
    top: calc(100% + 8px);
  }
}

/* ── «Рейтинг»: подиум топ-3 и своя строка ─────────────────── */

.podium { display: flex; gap: 12px; align-items: stretch; margin-bottom: 22px; }
.p-card {
  flex: 1;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  text-align: center;
}
.p-card.p-1 { order: 2; background: var(--accent-soft); }
.p-card.p-2 { order: 1; margin-top: 16px; }
.p-card.p-3 { order: 3; margin-top: 26px; }
.p-place {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-weight: 700; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 4px;
}
.p-2 .p-place, .p-3 .p-place { background: var(--accent-soft-line); color: var(--ok-ink); }
.p-login { font-weight: 650; overflow-wrap: anywhere; }
.p-approvals { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
tr.me td { background: var(--accent-soft); }
@media (max-width: 700px) {
  .podium { flex-direction: column; }
  .p-card { order: 0 !important; margin-top: 0 !important; }
}

/* ── Печать ───────────────────────────────────────────────── */

@media print {
  .side, footer, .hb-side, .filters, .preset-row, .table-search, .hint, .data-note { display: none; }
  .hb { grid-template-columns: 1fr; }
  .hb-body { padding: 0; box-shadow: none; }
  .hb-note, .hb-faq { display: block; }
  .hb-note ul, .hb-answer { display: block !important; }
  body { background: #fff; }
  table, .card, .role-card { box-shadow: none; border: 1px solid #ddd; }
}
