/* ХИМИЯ — панель учёта. Оформление: «лаборатория» — светлый холст,
   тонкие линии-мензурки, один яркий реагент-акцент. */

:root {
  --canvas: #eeecf2;
  --surface: #ffffff;
  --surface-2: #f7f6fa;
  --line: #e0dde8;
  --line-strong: #cdc8db;
  --ink: #17151f;
  --ink-2: #4b4757;
  --muted: #7d798c;

  --accent: #ff3d6e;
  --accent-ink: #ffffff;
  --accent-soft: #ffe7ee;

  --sever: #6c4cf0;
  --centr: #00a2a0;
  --plus: #0f9d63;
  --minus: #d8484d;
  --warn: #c07a05;
  --warn-soft: #fdf1dc;
  --plus-soft: #e2f5ec;
  --minus-soft: #fdeaea;

  --shadow-sm: 0 1px 2px rgba(23, 21, 31, .06);
  --shadow-md: 0 12px 32px -18px rgba(23, 21, 31, .5);
  --shadow-lg: 0 40px 80px -40px rgba(23, 21, 31, .55);

  --radius: 14px;
  --radius-sm: 9px;
  --rail: 232px;

  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, system-ui, sans-serif;
  --display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Inter, system-ui, sans-serif;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, monospace;
}

[data-theme="dark"] {
  --canvas: #101019;
  --surface: #191922;
  --surface-2: #20202b;
  --line: #2b2b38;
  --line-strong: #3a3a4a;
  --ink: #f3f1f8;
  --ink-2: #c9c5d6;
  --muted: #918da2;

  --accent: #ff5680;
  --accent-ink: #1a0710;
  --accent-soft: #3a1524;

  --sever: #937cff;
  --centr: #2fd0c6;
  --plus: #3ecf8e;
  --minus: #ff6b6b;
  --warn: #f0b429;
  --warn-soft: #3a2d10;
  --plus-soft: #11322a;
  --minus-soft: #38191c;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 14px 34px -18px rgba(0, 0, 0, .9);
  --shadow-lg: 0 40px 80px -36px rgba(0, 0, 0, .95);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--display); margin: 0; letter-spacing: -.02em; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
p { margin: 0; }

button, input, select, textarea { font: inherit; color: inherit; }

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

.eyebrow {
  font-size: 10.5px;
  font-weight: 620;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}

.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

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

.app { display: grid; grid-template-columns: var(--rail) 1fr; min-height: 100vh; }

.rail {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 26px;
  height: 100vh;
  padding: 22px 16px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 11px; padding: 0 6px; }
.brand__mark { color: var(--accent); display: flex; }
.brand__text b { display: block; font-family: var(--display); font-size: 16px; letter-spacing: .16em; }
.brand__text small { display: block; font-size: 11px; color: var(--muted); letter-spacing: .04em; }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 520;
  text-align: left;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.nav__item:hover { background: var(--surface-2); color: var(--ink); }
.nav__item.is-active { background: var(--ink); color: var(--surface); }
.nav__dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--line-strong);
  transition: background .15s ease, box-shadow .15s ease;
}
.nav__item.is-active .nav__dot { background: var(--accent); box-shadow: 0 0 0 3px rgba(255, 61, 110, .25); }

.rail__foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.file-note { font-size: 11px; color: var(--muted); line-height: 1.4; padding: 0 6px; }

/* --- кто сейчас в панели ------------------------------------------------ */

.who {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.who__name { font-size: 13px; font-weight: 600; color: var(--ink); }
.who__role { font-size: 11px; color: var(--muted); }
.who__links { display: flex; gap: 10px; margin-top: 5px; }
.link-btn {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 11.5px;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.link-btn:hover { color: var(--accent); }

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

.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--canvas);
}
.gate__card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(340px, 100%);
  padding: 30px 28px 26px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}
.gate__mark { color: var(--accent); display: flex; }
.gate__card h1 { font-size: 25px; letter-spacing: .06em; margin-top: 2px; }
.gate__sub { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.gate__card .btn { margin-top: 6px; height: 38px; }
.gate__error {
  font-size: 12.5px;
  color: var(--minus);
  background: var(--minus-soft);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

/* --- напоминание сменить пароль ----------------------------------------- */

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 16px;
  font-size: 13px;
  color: var(--warn);
  background: var(--warn-soft);
  border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  border-radius: var(--radius-sm);
}

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 30px 16px;
  background: color-mix(in srgb, var(--canvas) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar__tools { display: flex; align-items: center; gap: 10px; }

.view { padding: 24px 30px 60px; display: flex; flex-direction: column; gap: 18px; }

/* --- элементы управления ------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 560;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.btn:hover { border-color: var(--ink-2); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { filter: brightness(1.05); border-color: var(--accent); }
.btn--danger { color: var(--minus); border-color: color-mix(in srgb, var(--minus) 40%, var(--line)); }
.btn--danger:hover { background: var(--minus-soft); border-color: var(--minus); }
.btn--sm { height: 28px; padding: 0 11px; font-size: 12.5px; }

.ghost-btn {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  padding: 7px 10px;
  cursor: pointer;
  text-align: left;
}
.ghost-btn:hover { color: var(--ink); border-color: var(--line-strong); }

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.segmented button {
  border: 0;
  border-radius: 999px;
  background: transparent;
  padding: 5px 13px;
  font-size: 13px;
  font-weight: 540;
  color: var(--muted);
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.segmented button:hover { color: var(--ink); }
.segmented button.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 11.5px; color: var(--muted); font-weight: 540; }
.field__hint { font-size: 11.5px; color: var(--muted); line-height: 1.35; }

input[type="text"], input[type="number"], input[type="search"], input[type="date"], input[type="password"], select, textarea {
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { height: auto; padding: 9px 11px; resize: vertical; min-height: 68px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
select { appearance: none; padding-right: 28px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

/* --- карточки ----------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
}
.card__body { padding: 18px; }

.grid { display: grid; gap: 14px; }
.grid--kpi { grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); }
.grid--split { grid-template-columns: 1.35fr 1fr; align-items: start; }
.grid--halves { grid-template-columns: 1fr 1fr; align-items: start; }

.kpi { padding: 16px 18px 15px; position: relative; overflow: hidden; }
.kpi__label { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.kpi__value {
  font-family: var(--display);
  font-size: 30px;
  font-weight: 680;
  letter-spacing: -.03em;
  margin-top: 8px;
  line-height: 1.05;
}
.kpi__value small { font-size: 15px; font-weight: 560; color: var(--muted); margin-left: 3px; letter-spacing: 0; }
.kpi__foot { margin-top: 7px; font-size: 12px; color: var(--muted); }
.kpi--plus .kpi__value { color: var(--plus); }
.kpi--minus .kpi__value { color: var(--minus); }

/* Подпись-«пробирка» слева у KPI прибыли */
.kpi--accent::before {
  content: "";
  position: absolute;
  inset: 12px auto 12px 0;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

/* --- «реакция»: доход → расходы → прибыль ------------------------------ */

.reaction { display: flex; flex-direction: column; gap: 12px; }
.reaction__bar {
  display: flex;
  height: 42px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.reaction__seg {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 2px;
  color: #fff;
  font-size: 11.5px;
  font-weight: 600;
  transition: flex-basis .5s cubic-bezier(.2, .8, .2, 1);
}
.reaction__legend { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-2); }
.legend-item i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.legend-item b { font-weight: 620; color: var(--ink); }

/* --- таблицы ------------------------------------------------------------ */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  font-size: 11px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 620;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--ink); }
thead th .arrow { opacity: .45; margin-left: 3px; }
tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.right, th.right { text-align: right; }
.cell-strong { font-weight: 600; }
.cell-sub { display: block; font-size: 11.5px; color: var(--muted); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; opacity: 0; transition: opacity .12s ease; }
tbody tr:hover .row-actions, tbody tr:focus-within .row-actions { opacity: 1; }

.icon-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 7px;
  width: 27px; height: 27px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
}
.icon-btn:hover { color: var(--ink); border-color: var(--line-strong); }
.icon-btn--danger:hover { color: var(--minus); border-color: var(--minus); background: var(--minus-soft); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.pill i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill--active { background: var(--plus-soft); color: var(--plus); }
.pill--renew { background: color-mix(in srgb, var(--sever) 14%, transparent); color: var(--sever); }
.pill--left { background: var(--minus-soft); color: var(--minus); }
.pill--warn { background: var(--warn-soft); color: var(--warn); }
.pill--muted { background: var(--surface-2); color: var(--muted); }

.branch-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 560; }
.branch-tag i { width: 8px; height: 8px; border-radius: 50%; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.toolbar__search { flex: 1 1 220px; min-width: 180px; max-width: 340px; }
.toolbar__count { margin-left: auto; font-size: 12.5px; color: var(--muted); }

.empty { padding: 46px 18px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 5px; font-family: var(--display); }

/* --- финансы: редактируемая сетка -------------------------------------- */

.fin-input {
  width: 100%;
  height: 30px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  text-align: right;
  font-variant-numeric: tabular-nums;
  transition: background .12s ease, border-color .12s ease;
}
.fin-input:hover { background: var(--surface-2); border-color: var(--line); }
.fin-input:focus { background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent); outline: none; }
.fin-input::placeholder { color: color-mix(in srgb, var(--muted) 55%, transparent); }
.fin-input.is-saved { animation: flash .8s ease; }
@keyframes flash {
  0% { background: color-mix(in srgb, var(--plus) 30%, transparent); }
  100% { background: transparent; }
}
.fin-fact {
  display: block;
  text-align: right;
  font-size: 10.5px;
  color: var(--warn);
  padding: 1px 8px 0 0;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

tr.total-row td { background: var(--surface-2); font-weight: 650; border-top: 2px solid var(--line-strong); }
tr.is-current td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.col-group-in { background: color-mix(in srgb, var(--plus) 5%, transparent); }
.col-group-out { background: color-mix(in srgb, var(--minus) 5%, transparent); }

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

.chart { width: 100%; display: block; overflow: visible; }
.chart text { font-family: var(--sans); font-size: 10.5px; fill: var(--muted); }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .zero-line { stroke: var(--line-strong); stroke-width: 1; }
.chart .bar { transition: opacity .15s ease; }
.chart .bar:hover { opacity: .78; }

.bars { display: flex; flex-direction: column; gap: 11px; }
.bars__row { display: grid; grid-template-columns: 116px 1fr 52px; align-items: center; gap: 11px; font-size: 12.5px; }
.bars__track { height: 9px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bars__fill { height: 100%; border-radius: 999px; transition: width .5s cubic-bezier(.2, .8, .2, 1); }
.bars__value { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

.expiring { display: flex; flex-direction: column; }
.expiring__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
}
.expiring__row:last-child { border-bottom: 0; }
.expiring__who b { display: block; font-weight: 600; }
.expiring__who span { font-size: 12px; color: var(--muted); }

/* --- посещаемость -------------------------------------------------------- */

.attend { display: flex; flex-direction: column; gap: 2px; padding: 6px 18px 16px; }
.attend__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 0;
  border-bottom: 1px dashed var(--line);
}
.attend__row:last-of-type { border-bottom: 0; }
.attend__who { display: flex; flex-direction: column; }
.attend__who b { font-weight: 600; }
.attend__who span { font-size: 11.5px; color: var(--muted); }
.attend__toggle { display: inline-flex; gap: 6px; flex: 0 0 auto; }

/* Индивидуальное занятие: кто провёл и почём */
.attend__ind { display: inline-flex; gap: 6px; margin-left: auto; flex: 0 0 auto; }
.attend__ind select { width: 168px; height: 30px; font-size: 12.5px; }
.attend__ind input { width: 96px; height: 30px; font-size: 12.5px; text-align: right; }
.attend__ind select:invalid, .attend__ind select[data-empty="1"] { color: var(--muted); }
.seg-btn {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 560;
  cursor: pointer;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.seg-btn:hover { border-color: var(--ink-2); color: var(--ink); }
.seg-btn.is-present { background: var(--plus-soft); border-color: var(--plus); color: var(--plus); }
.seg-btn.is-absent { background: var(--minus-soft); border-color: var(--minus); color: var(--minus); }
.attend__add { width: 100%; margin-top: 10px; }

.attend__chevron { color: var(--muted); font-size: 12px; width: 14px; text-align: center; }
.card__head[data-toggle-group]:hover { background: var(--surface-2); border-radius: var(--radius) var(--radius) 0 0; }

.attend-col { display: flex; flex-direction: column; gap: 14px; }
.attend-col__title {
  font-size: 11px;
  font-weight: 640;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 2px;
}

/* --- модальное окно ----------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 46px 20px;
  overflow-y: auto;
  background: color-mix(in srgb, #0d0c14 55%, transparent);
  backdrop-filter: blur(3px);
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } }

.modal {
  width: min(660px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  animation: rise .22s cubic-bezier(.2, .8, .2, 1);
}
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.99); } }

.modal__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 20px 22px 14px;
  border-bottom: 1px solid var(--line);
}
.modal__body { padding: 20px 22px; display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.modal__body .span-2 { grid-column: 1 / -1; }
.modal__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 22px 20px;
  border-top: 1px solid var(--line);
}
.modal__foot-right { display: flex; gap: 9px; margin-left: auto; }

.modal--narrow { width: min(430px, 100%); }
.confirm { width: min(430px, 100%); }
.confirm .modal__body { grid-template-columns: 1fr; color: var(--ink-2); }

/* --- уведомления -------------------------------------------------------- */

.toasts {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 9px;
  align-items: flex-end;
}
.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 15px;
  border-radius: 11px;
  background: var(--ink);
  color: var(--canvas);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: rise .2s ease;
}
.toast--error { background: var(--minus); color: #fff; }

.saving {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 15px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--canvas);
  font-size: 12.5px;
  box-shadow: var(--shadow-md);
}
.saving__pulse {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s infinite ease-in-out;
}
@keyframes pulse { 50% { opacity: .25; transform: scale(.7); } }

/* --- адаптив ------------------------------------------------------------ */

/* --- кнопка меню (видна только на узком экране) -------------------------- */

.burger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 40px;
  height: 40px;
  padding: 0 9px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--surface);
  cursor: pointer;
  flex: 0 0 auto;
}
.burger span { display: block; height: 2px; border-radius: 2px; background: var(--ink); transition: transform .2s ease, opacity .2s ease; }
body.nav-open .burger span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
body.nav-open .burger span:nth-child(2) { opacity: 0; }
body.nav-open .burger span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.nav-scrim {
  position: fixed;
  inset: 0;
  z-index: 65;
  background: color-mix(in srgb, #0d0c14 45%, transparent);
  animation: fade .18s ease;
}

/* --- планшет ------------------------------------------------------------- */

@media (max-width: 1080px) {
  .grid--split, .grid--halves { grid-template-columns: 1fr; }
}

/* --- телефон и узкий планшет --------------------------------------------- */

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }

  /* Боковая панель уезжает в выдвижное меню — на телефоне разделы
     переключают редко, а место под содержимое нужно всё. */
  .rail {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 70;
    width: min(280px, 84vw);
    height: 100dvh;
    padding: 18px 14px calc(18px + env(safe-area-inset-bottom));
    overflow-y: auto;
    border-right: 1px solid var(--line);
    transform: translateX(-100%);
    transition: transform .24s cubic-bezier(.2, .8, .2, 1);
    box-shadow: var(--shadow-lg);
  }
  body.nav-open .rail { transform: none; }
  body.nav-open { overflow: hidden; }
  .burger { display: flex; }

  /* Шапка: бургер и заголовок в строку, главное действие — справа от них,
     переключатель филиалов — отдельной прокручиваемой строкой под ними. */
  .topbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px 12px;
    padding: 12px 14px;
  }
  .topbar__title { min-width: 0; }
  .topbar__title h1 { font-size: 21px; }
  .topbar__title .eyebrow { font-size: 10px; }
  .topbar__tools {
    display: contents;
  }
  .segmented {
    grid-column: 1 / -1;
    grid-row: 2;
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    justify-content: flex-start;
  }
  .segmented::-webkit-scrollbar { display: none; }
  .segmented button { flex: 0 0 auto; }
  #primaryAction { grid-column: 3; grid-row: 1; }

  .view { padding: 16px 12px calc(40px + env(safe-area-inset-bottom)); gap: 14px; }
  .card__head { padding: 15px 15px 12px; flex-wrap: wrap; gap: 10px; }
  .card__head h2 { font-size: 16px; }

  /* На телефоне палец крупнее курсора: увеличиваем всё, что нажимают,
     и держим шрифт полей от 16px — иначе iOS зумит страницу при фокусе. */
  .btn { height: 40px; padding: 0 16px; }
  .btn--sm { height: 34px; padding: 0 13px; }
  .icon-btn { width: 34px; height: 34px; font-size: 15px; }
  .seg-btn { height: 38px; padding: 0 14px; }
  .row-actions { opacity: 1; }
  input[type="text"], input[type="number"], input[type="search"], input[type="date"],
  input[type="password"], select, textarea { height: 42px; font-size: 16px; }
  select { background-position: calc(100% - 15px) 19px, calc(100% - 10px) 19px; }
  .toolbar { padding: 12px 14px; gap: 8px; }
  .toolbar__search { flex: 1 1 100%; max-width: none; }
  .toolbar select { flex: 1 1 46%; }
  .toolbar__count { margin-left: 0; width: 100%; }

  /* Таблицы разворачиваются в карточки: строка — карточка, ячейка — «подпись: значение» */
  table.stacked thead { display: none; }
  table.stacked, table.stacked tbody, table.stacked tfoot { display: block; }
  table.stacked tbody tr, table.stacked tfoot tr {
    display: block;
    padding: 13px 15px;
    border-bottom: 1px solid var(--line);
  }
  table.stacked tbody tr:last-child { border-bottom: 0; }
  table.stacked tbody td, table.stacked tfoot td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 14px;
    padding: 3px 0;
    border: 0;
    text-align: right;
  }
  table.stacked td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-size: 11.5px;
    color: var(--muted);
    text-align: left;
  }
  table.stacked td:not([data-label]) { justify-content: flex-end; }
  /* Первая ячейка — заголовок карточки, во всю ширину и без подписи */
  table.stacked tbody td:first-child {
    display: block;
    text-align: left;
    font-size: 15px;
    margin-bottom: 5px;
  }
  table.stacked tbody td:first-child::before { content: none; }
  table.stacked td:empty, table.stacked td[data-blank] { display: none; }
  table.stacked .cell-sub { display: inline; margin-left: 6px; }
  table.stacked tbody td:first-child .cell-sub { display: block; margin: 2px 0 0; font-size: 12px; }
  table.stacked .row-actions { justify-content: flex-end; }

  /* Финансы остаются сеткой: листаем вбок, месяц держим на виду */
  [data-finance] .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  [data-finance] td:first-child, [data-finance] th:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--surface);
    box-shadow: 1px 0 0 var(--line);
  }
  [data-finance] tr.total-row td:first-child { background: var(--surface-2); }
  .fin-input { height: 38px; font-size: 15px; }

  /* Посещаемость: имя сверху, управление под ним — в строку они не влезают.
     min-width: 0 обязателен: без него длинное имя тренера в списке распирает
     строку шире экрана и появляется горизонтальная прокрутка. */
  .attend__row { flex-wrap: wrap; gap: 9px; padding: 12px 0; min-width: 0; }
  .attend__who { flex: 1 1 100%; min-width: 0; }
  .attend__ind { flex: 1 1 100%; min-width: 0; margin-left: 0; }
  .attend__ind select { flex: 1 1 0; min-width: 0; width: auto; height: 42px; font-size: 16px; }
  .attend__ind input { flex: 0 0 96px; min-width: 0; width: auto; height: 42px; font-size: 16px; }
  .attend__toggle { flex: 1 1 100%; min-width: 0; }
  .attend__toggle .seg-btn { flex: 1 1 0; min-width: 0; }
  .attend { padding: 4px 15px 15px; }

  /* Длинные подзаголовки переносятся, а не растягивают карточку */
  .card__head > div { min-width: 0; }
  .eyebrow { white-space: normal; overflow-wrap: anywhere; }

  /* Модальные окна — «шторкой» снизу, как принято на телефоне */
  .overlay { align-items: flex-end; padding: 0; }
  .modal, .modal--narrow, .confirm {
    width: 100%;
    max-height: 92dvh;
    display: flex;
    flex-direction: column;
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
    animation: sheet .24s cubic-bezier(.2, .8, .2, 1);
  }
  .modal__head { padding: 16px 16px 12px; }
  .modal__body { grid-template-columns: 1fr; padding: 16px; overflow-y: auto; }
  .modal__foot {
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    flex-wrap: wrap;
    gap: 9px;
  }
  .modal__foot .btn { flex: 1 1 auto; justify-content: center; }
  .modal__foot-right { flex: 1 1 auto; order: 1; }
  .modal__foot-right .btn { flex: 1 1 0; }
  /* Удаление — отдельной строкой под основными кнопками: пальцем легко
     промахнуться, а действие необратимое. */
  .modal__foot > .btn--danger { flex: 1 1 100%; order: 2; }

  .grid--kpi { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
  .kpi__value { font-size: 26px; }
  .bars__row { grid-template-columns: 96px 1fr 46px; gap: 9px; font-size: 12px; }
  .expiring__row { flex-wrap: wrap; gap: 6px; }
  .expiring__row .pill { margin-left: auto; }
  .gate__card { width: 100%; }
  .banner { flex-wrap: wrap; }
  .toasts { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); align-items: stretch; }
  .saving { bottom: calc(12px + env(safe-area-inset-bottom)); }
}

@media (max-width: 430px) {
  /* На узком экране заголовок и кнопка действия не уживаются в одной строке —
     кнопка уходит вниз во всю ширину, её всё равно удобнее нажимать. */
  #primaryAction { grid-column: 1 / -1; grid-row: 3; justify-content: center; }
  .topbar__title h1 { overflow-wrap: anywhere; }
}

@media (max-width: 420px) {
  .view { padding: 14px 10px 40px; }
  .card__head { padding: 14px 13px 11px; }
  .grid--kpi { grid-template-columns: 1fr 1fr; }
  .kpi__value { font-size: 23px; }
  .toolbar select { flex: 1 1 100%; }
  table.stacked tbody tr, table.stacked tfoot tr { padding: 12px 13px; }
}

@keyframes sheet { from { transform: translateY(24px); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
