/* ---------- Токены ---------- */
:root {
  color-scheme: light;
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --surface-3: #e8ebf2;
  --border: #e2e5ee;
  --text: #111827;
  --text-2: #4b5563;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --on-accent: #ffffff;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --info: #1d4ed8;
  --info-soft: #dbeafe;
  --grid: #e9ebf1;
  --grid-strong: #c9cdd8;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 20px 48px rgba(16, 24, 40, 0.18);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #0f1117;
    --surface: #171a22;
    --surface-2: #1e222c;
    --surface-3: #272c38;
    --border: #2a2f3b;
    --text: #eef0f4;
    --text-2: #c2c7d2;
    --muted: #8d94a3;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-soft: #23264a;
    --on-accent: #0f1117;
    --ok: #4ade80;
    --ok-soft: #12301f;
    --bad: #f87171;
    --bad-soft: #3a1717;
    --warn: #fbbf24;
    --warn-soft: #3a2c0d;
    --info: #93c5fd;
    --info-soft: #172a4a;
    --grid: #252a35;
    --grid-strong: #3a4050;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.55);
  }
}

/* Тёмная тема, выбранная явно (атрибут data-theme), — те же значения. */
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0f1117;
  --surface: #171a22;
  --surface-2: #1e222c;
  --surface-3: #272c38;
  --border: #2a2f3b;
  --text: #eef0f4;
  --text-2: #c2c7d2;
  --muted: #8d94a3;
  --accent: #818cf8;
  --accent-hover: #a5b4fc;
  --accent-soft: #23264a;
  --on-accent: #0f1117;
  --ok: #4ade80;
  --ok-soft: #12301f;
  --bad: #f87171;
  --bad-soft: #3a1717;
  --warn: #fbbf24;
  --warn-soft: #3a2c0d;
  --info: #93c5fd;
  --info-soft: #172a4a;
  --grid: #252a35;
  --grid-strong: #3a4050;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.55);
}

/* ---------- База ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
}
h1 {
  font-size: 24px;
  font-weight: 700;
}
h2 {
  font-size: 16px;
  font-weight: 650;
}
h3 {
  font-size: 14px;
  font-weight: 650;
}
p {
  margin: 0 0 8px;
}
a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 13px;
}
.pre {
  white-space: pre-wrap;
  word-break: break-word;
}
.nowrap {
  white-space: nowrap;
}
.spacer {
  flex: 1;
}
.icon {
  width: 18px;
  height: 18px;
  flex: none;
  vertical-align: -3px;
}
.boot {
  display: grid;
  place-items: center;
  min-height: 100vh;
  color: var(--muted);
}

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover {
  background: var(--surface-2);
  text-decoration: none;
}
.btn:disabled {
  opacity: 0.55;
  cursor: default;
}
.btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
}
.btn-success {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
}
.btn-success:hover {
  filter: brightness(1.08);
  background: var(--ok);
}
.btn-danger {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
}
.btn-danger:hover {
  background: var(--bad);
  filter: brightness(1.08);
}
.btn-ghost-danger {
  color: var(--bad);
}
.btn-ghost-danger:hover {
  background: var(--bad-soft);
}
.btn-link {
  border: 0;
  background: none;
  color: var(--accent);
  padding: 4px 0;
  min-height: 0;
}
.btn-link:hover {
  background: none;
  text-decoration: underline;
}
.btn-sm {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 13px;
}
.btn-block {
  width: 100%;
}
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.icon-btn:disabled {
  opacity: 0.4;
}
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border-radius: 10px;
}
.segmented button {
  border: 0;
  background: none;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-2);
  font-weight: 550;
  font-size: 14px;
  white-space: nowrap;
}
.segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* ---------- Значки ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--text-2);
}
.badge-ok {
  background: var(--ok-soft);
  color: var(--ok);
}
.badge-bad {
  background: var(--bad-soft);
  color: var(--bad);
}
.badge-warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.badge-info {
  background: var(--info-soft);
  color: var(--info);
}
.amount {
  font-weight: 650;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.amount.bad,
.bad > .kpi-value {
  color: var(--bad);
}
.amount.good,
.good > .kpi-value {
  color: var(--ok);
}
.avatar {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 50%;
  background: var(--c);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.avatar.sm {
  width: 28px;
  height: 28px;
  font-size: 11px;
}
.avatar.lg {
  width: 52px;
  height: 52px;
  font-size: 18px;
}
.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c);
}

/* ---------- Каркас ---------- */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 750;
  font-size: 16px;
  padding: 0 8px;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 800;
}
.brand-lg {
  font-size: 20px;
  justify-content: center;
}
.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 550;
}
.nav a:hover {
  background: var(--surface-2);
  text-decoration: none;
  color: var(--text);
}
.nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.sidebar-user {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px 0;
  border-top: 1px solid var(--border);
}
.sidebar-user-info {
  min-width: 0;
  flex: 1;
}
.sidebar-user-info > div {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-user-name {
  font-weight: 600;
  font-size: 14px;
}
.sidebar-backdrop,
.topbar {
  display: none;
}
.main {
  min-width: 0;
}
.view {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 28px 48px;
  transition: opacity 0.15s;
}
.view.loading {
  opacity: 0.6;
}
.refetching {
  opacity: 0.6;
}
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-head .muted {
  margin: 2px 0 0;
}
.actions,
.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.row-actions {
  margin-top: 10px;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.card .stack {
  gap: 8px;
}
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- Карточки ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card > h2 {
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.card-warn {
  border-color: color-mix(in srgb, var(--warn) 45%, var(--border));
}
.subhead {
  margin: 16px 0 8px;
  color: var(--text-2);
}
.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.kpis-sm {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.kpi-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 550;
}
.kpi-value {
  font-size: 24px;
  font-weight: 700;
  margin: 2px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-value-sm {
  font-size: 19px;
}
.kpi-sub {
  color: var(--muted);
  font-size: 13px;
}
.empty {
  text-align: center;
  padding: 28px 16px;
  color: var(--muted);
}
.empty p {
  margin-bottom: 12px;
}

/* ---------- Списки ---------- */
.list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  min-height: 48px;
}
.list-item:last-child {
  border-bottom: 0;
}
.list-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  color: inherit;
}
.list-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
a.list-main:hover {
  text-decoration: none;
  color: var(--accent);
}
.lesson-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.lesson-line {
  display: flex;
  align-items: center;
  gap: 8px;
}
.day-label {
  width: 78px;
  flex: none;
  font-size: 13px;
  color: var(--muted);
}
.lesson-row {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--c);
  border-radius: var(--radius-sm);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}
.lesson-row:hover {
  background: var(--surface-2);
}
.lesson-row.status-cancelled {
  opacity: 0.6;
}
.lesson-row.status-cancelled .lesson-row-title {
  text-decoration: line-through;
}
.lesson-row-time {
  display: flex;
  flex-direction: column;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  min-width: 46px;
  line-height: 1.25;
}
.lesson-row-time small {
  color: var(--muted);
  font-weight: 500;
}
.lesson-row-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.lesson-row-main > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lesson-row-title {
  font-weight: 600;
}

.dash-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}
.onboarding {
  margin-bottom: 18px;
  border-color: var(--accent);
}
.onboarding ol {
  margin: 10px 0 14px;
  padding-left: 20px;
  color: var(--text-2);
}
.onboarding li {
  margin-bottom: 4px;
}
.task-check {
  flex: 1;
}

/* ---------- Таблицы ---------- */
.table-wrap {
  overflow-x: auto;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tr:last-child td {
  border-bottom: 0;
}
.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.table tr.clickable {
  cursor: pointer;
}
.table tr.clickable:hover td {
  background: var(--surface-2);
}
.row-tools {
  white-space: nowrap;
  text-align: right;
  width: 1%;
}

/* ---------- Формы ---------- */
.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.form > h2 {
  margin: 6px 0 -2px;
}
.form-section {
  margin-top: 4px;
  color: var(--text-2);
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  border: 0;
  margin: 0;
  padding: 0;
}
.field > span,
.field > legend {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  padding: 0;
}
input:not([type='checkbox']):not([type='radio']),
select,
textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
textarea {
  resize: vertical;
}
input[type='checkbox'],
input[type='radio'] {
  accent-color: var(--accent);
  width: 17px;
  height: 17px;
  margin: 0;
  flex: none;
}
.check {
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
}
.grid-2,
.grid-3 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 14px;
}
.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.span-2 {
  grid-column: span 2;
}
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.search {
  max-width: 340px;
}
.select-inline {
  width: auto !important;
  min-width: 200px;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: -6px;
}
.chips:empty {
  display: none;
}
.chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  cursor: pointer;
}
.chip:hover {
  border-color: var(--accent);
}
.swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.swatch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.swatch span {
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--c);
  cursor: pointer;
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border);
}
.swatch input:checked + span {
  box-shadow: 0 0 0 2px var(--c);
}
.swatch input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.participant {
  display: grid;
  grid-template-columns: 1fr 130px 34px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.price-input {
  position: relative;
}
.price-input input {
  padding-right: 28px !important;
}
.price-input span {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 13px;
}
.repeat-box {
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.repeat-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.repeat-options[hidden] {
  display: none;
}
.weekday-picker {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.wd input {
  position: absolute;
  opacity: 0;
}
.wd span {
  display: grid;
  place-items: center;
  width: 40px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}
.wd input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.wd input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
details.more {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
details.more > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-2);
  font-size: 14px;
  margin-bottom: 10px;
}
details.more[open] {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.att-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}
.att-name {
  flex: 1;
  min-width: 0;
  font-weight: 550;
}
.att-row select {
  width: auto;
}
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.seg-option input {
  position: absolute;
  opacity: 0;
}
.seg-option span {
  display: block;
  padding: 6px 11px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.seg-option:last-child span {
  border-right: 0;
}
.seg-option input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.seg-ok input:checked + span {
  background: var(--ok-soft);
  color: var(--ok);
}
.seg-bad input:checked + span {
  background: var(--bad-soft);
  color: var(--bad);
}
.seg-warn input:checked + span {
  background: var(--warn-soft);
  color: var(--warn);
}
.lesson-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.total-line {
  font-weight: 650;
}
.copy-field {
  display: flex;
  gap: 6px;
}
.copy-field input {
  font-size: 13px;
  color: var(--text-2);
}

/* ---------- Окна и тосты ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 17, 23, 0.45);
  display: grid;
  place-items: center;
  padding: 16px;
  animation: fade 0.15s;
}
.modal {
  width: min(520px, 100%);
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  animation: pop 0.18s;
}
.modal-wide {
  width: min(720px, 100%);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 12px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 {
  font-size: 18px;
}
.modal-body {
  padding: 18px 20px 20px;
  overflow-y: auto;
}
.confirm-text {
  margin-bottom: 16px;
}
@keyframes fade {
  from {
    opacity: 0;
  }
}
@keyframes pop {
  from {
    transform: translateY(8px) scale(0.98);
    opacity: 0;
  }
}
#toasts {
  position: fixed;
  z-index: 100;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  width: max-content;
  max-width: calc(100vw - 32px);
}
.toast {
  padding: 10px 16px;
  border-radius: 10px;
  background: #111827;
  color: #fff;
  box-shadow: var(--shadow-lg);
  font-weight: 550;
  font-size: 14px;
  transition: opacity 0.3s, transform 0.3s;
}
.toast-error {
  background: #b91c1c;
}
.toast.hide {
  opacity: 0;
  transform: translateY(6px);
}

/* ---------- Календарь ---------- */
.cal-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.cal-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
}
.cal-title {
  font-size: 18px;
  margin-left: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-hint {
  margin-top: 10px;
}
.tg {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.tg-scroll {
  max-height: calc(100vh - 230px);
  min-height: 420px;
  overflow: auto;
}
.tg-head,
.tg-body {
  display: grid;
  grid-template-columns: 56px repeat(var(--cols), minmax(104px, 1fr));
  min-width: calc(56px + var(--cols) * 104px);
}
.tg-head {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.tg-corner {
  position: sticky;
  left: 0;
  background: var(--surface);
}
.tg-day-head {
  border: 0;
  background: none;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  color: var(--text-2);
  font-size: 12px;
  text-transform: uppercase;
  border-left: 1px solid var(--border);
}
.tg-day-head b {
  font-size: 18px;
  color: var(--text);
  line-height: 1.3;
  text-transform: none;
}
.tg-day-head.weekend span {
  color: var(--bad);
}
.tg-day-head.today b {
  background: var(--accent);
  color: var(--on-accent);
  border-radius: 999px;
  min-width: 32px;
  padding: 0 6px;
}
.tg-times {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
}
.tg-time {
  height: var(--hour);
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  padding-right: 8px;
  transform: translateY(-7px);
  font-variant-numeric: tabular-nums;
}
.tg-time:first-child {
  transform: none;
}
.tg-col {
  position: relative;
  border-left: 1px solid var(--border);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px);
  background-size: 100% var(--hour);
  cursor: copy;
}
.tg-col.today {
  background-color: color-mix(in srgb, var(--accent) 4%, transparent);
}
.ev {
  position: absolute;
  z-index: 1;
  overflow: hidden;
  padding: 3px 6px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--c) 16%, var(--surface));
  border-left: 3px solid var(--c);
  font-size: 12px;
  line-height: 1.3;
  cursor: pointer;
  user-select: none;
  transition: box-shadow 0.15s;
}
.ev:hover {
  box-shadow: 0 2px 8px rgba(16, 24, 40, 0.18);
  z-index: 2;
}
.ev-time {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
}
.ev-title {
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ev-sub {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ev-compact {
  display: flex;
  gap: 6px;
  align-items: center;
  padding-top: 1px;
}
.ev.status-done {
  background: color-mix(in srgb, var(--c) 32%, var(--surface));
}
.ev.status-cancelled {
  opacity: 0.55;
  background: repeating-linear-gradient(135deg, var(--surface-2), var(--surface-2) 6px, var(--surface) 6px, var(--surface) 12px);
}
.ev.status-cancelled .ev-title {
  text-decoration: line-through;
}
.ev.needs-confirm {
  outline: 2px dashed var(--warn);
  outline-offset: -2px;
}
.ev.status-planned {
  cursor: grab;
}
.ev.dragging {
  z-index: 5;
  cursor: grabbing;
  opacity: 0.9;
  box-shadow: var(--shadow-lg);
}
.now-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--bad);
  z-index: 2;
  pointer-events: none;
}
.now-line::before {
  content: '';
  position: absolute;
  left: -5px;
  top: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--bad);
}
.month {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.month-head,
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}
.month-head div {
  padding: 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
  border-bottom: 1px solid var(--border);
}
.month-cell {
  min-height: 108px;
  padding: 6px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 3px;
  cursor: pointer;
  min-width: 0;
}
.month-cell:nth-child(7n) {
  border-right: 0;
}
.month-cell:hover {
  background: var(--surface-2);
}
.month-cell.other {
  background: var(--bg);
}
.month-cell.other .month-num {
  color: var(--muted);
}
.month-num {
  font-weight: 650;
  font-size: 13px;
  align-self: flex-start;
  min-width: 24px;
  text-align: center;
  border-radius: 999px;
}
.month-cell.today .month-num {
  background: var(--accent);
  color: var(--on-accent);
}
.month-chip {
  display: block;
  font-size: 12px;
  padding: 1px 6px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--c) 16%, var(--surface));
  border-left: 3px solid var(--c);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.month-chip.status-cancelled {
  text-decoration: line-through;
  opacity: 0.55;
}
.month-more {
  font-size: 12px;
  color: var(--muted);
  padding-left: 4px;
}

/* ---------- Ученики ---------- */
.student-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
  margin-bottom: 12px;
}
.student-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: inherit;
  transition: border-color 0.15s, transform 0.15s;
}
.student-card:hover {
  text-decoration: none;
  border-color: var(--accent);
}
.student-card-head {
  display: flex;
  gap: 12px;
  align-items: center;
}
.student-card-name {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.student-card-name > * {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tg-mark {
  color: var(--info);
}
.student-card-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.student-card-stats > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
}
.student-card-next {
  display: flex;
  align-items: center;
  gap: 6px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.student-title {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.student-title h1 {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.student-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: start;
}
.student-side {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
}
.tab {
  border: 0;
  background: none;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.info {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  margin: 0;
  font-size: 14px;
}
.info dt {
  color: var(--muted);
}
.info dd {
  margin: 0;
  word-break: break-word;
}
.hw-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.hw-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.hw-item[data-lesson] {
  cursor: pointer;
}
.hw-item:last-child {
  border-bottom: 0;
}
.hw-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

/* ---------- Оплаты, задачи, настройки ---------- */
.payments-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: start;
}
.month-label {
  min-width: 140px;
  text-align: center;
}
.quick-add {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  padding: 10px;
}
.quick-add input[name='title'] {
  flex: 1;
}
.quick-add input[type='date'] {
  width: 170px;
}
.task-group {
  margin-bottom: 18px;
}
.group-title {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-2);
  margin-bottom: 8px;
}
.group-title.bad {
  color: var(--bad);
}
.group-title.warn {
  color: var(--warn);
}
.task-list {
  list-style: none;
  margin: 0;
  padding: 4px 14px;
}
.task {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.task:last-child {
  border-bottom: 0;
}
.task-body {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: 0;
  background: none;
  padding: 2px 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.task-title {
  font-weight: 550;
}
.task-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.task-list.done .task-title {
  text-decoration: line-through;
  color: var(--muted);
}
.settings-grid,
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}
.steps {
  padding-left: 20px;
  margin: 0 0 10px;
}
.steps li {
  margin-bottom: 6px;
}

/* ---------- Графики ---------- */
.chart {
  --h: 200px;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-2);
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.legend-item b {
  color: var(--text);
}
.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}
.chart-plot {
  position: relative;
  height: calc(var(--h) + 24px);
  padding-left: 52px;
}
.chart-grid {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: var(--h);
}
.gridline {
  position: absolute;
  left: 52px;
  right: 0;
  border-top: 1px solid var(--grid);
}
.gridline.baseline {
  border-top-color: var(--grid-strong);
}
.gridline span {
  position: absolute;
  right: calc(100% + 8px);
  top: -8px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.chart-cols {
  position: relative;
  display: flex;
  height: 100%;
}
.chart-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.chart-bars {
  height: var(--h);
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 2px;
}
.bar-wrap {
  position: relative;
  height: 100%;
  width: 24px;
  flex: 0 1 24px;
  display: flex;
  align-items: flex-end;
  outline-offset: 1px;
  cursor: default;
}
.bar {
  width: 100%;
  border-radius: 4px 4px 0 0;
  min-height: 0;
  transition: filter 0.15s;
}
.bar-wrap:hover .bar,
.bar-wrap:focus .bar {
  filter: brightness(1.12);
}
.bar-label {
  position: absolute;
  left: 50%;
  transform: translate(-50%, -4px);
  font-size: 11px;
  font-weight: 650;
  color: var(--text-2);
  white-space: nowrap;
}
.chart-x {
  height: 24px;
  padding-top: 6px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.share-bar {
  display: flex;
  gap: 2px;
  height: 22px;
  margin-bottom: 12px;
}
.share-seg {
  min-width: 4px;
}
.share-seg:first-child {
  border-radius: 4px 0 0 4px;
}
.share-seg:last-child {
  border-radius: 0 4px 4px 0;
}
.share-seg:only-child {
  border-radius: 4px;
}
.share-seg:hover,
.share-seg:focus {
  filter: brightness(1.12);
}
.barlist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.barlist-text {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  margin-bottom: 4px;
}
.barlist-text b {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.barlist-track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 4px;
}
.barlist-fill {
  height: 100%;
  background: var(--series-1);
  border-radius: 0 4px 4px 0;
  min-width: 4px;
}
#chart-tip {
  position: fixed;
  z-index: 200;
  pointer-events: none;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: none;
  flex-direction: column;
  font-size: 12px;
  color: var(--text-2);
}
#chart-tip.show {
  display: flex;
}
#chart-tip strong {
  font-size: 14px;
  color: var(--text);
}

/* ---------- Вход ---------- */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(circle at 20% 10%, var(--accent-soft), transparent 50%), var(--bg);
}
.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.auth-sub {
  text-align: center;
  margin: -6px 0 0;
}
.auth-tabs {
  align-self: center;
}

.auth-note {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  font-size: 14px;
}
.auth-note-bad {
  background: var(--bad-soft);
  color: var(--bad);
}

/* ---------- Доступ (администратор) ---------- */
.invite-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 10px 0 12px;
}
.invite-form input {
  flex: 1 1 260px;
}
.fresh-link {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
}
.access-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 24px;
}
@media (max-width: 900px) {
  .access-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---------- Кабинет ученика ---------- */
.portal {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.portal-head {
  display: flex;
  align-items: center;
  gap: 16px;
}
.portal .kpis {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0;
}
.portal .tabs {
  margin-bottom: -4px;
}
.portal-foot {
  text-align: center;
}

/* ---------- Адаптивность ---------- */
@media (max-width: 1100px) {
  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .student-layout,
  .payments-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    position: fixed;
    z-index: 40;
    left: 0;
    width: 264px;
    transform: translateX(-100%);
    transition: transform 0.2s;
  }
  .menu-open .sidebar {
    transform: none;
    box-shadow: var(--shadow-lg);
  }
  .menu-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(15, 17, 23, 0.4);
  }
  .topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 8px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }
  .view {
    padding: 18px 16px 40px;
  }
  .dash-grid,
  .settings-grid,
  .stats-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .span-2 {
    grid-column: auto;
  }
}

@media (max-width: 600px) {
  h1 {
    font-size: 21px;
  }
  .grid-2,
  .grid-3 {
    grid-template-columns: minmax(0, 1fr);
  }
  .grid-2 > .span-2 {
    grid-column: auto;
  }
  .kpi-value {
    font-size: 20px;
  }
  .kpis {
    gap: 10px;
  }
  .portal .kpis {
    grid-template-columns: minmax(0, 1fr);
  }
  .card {
    padding: 14px;
  }
  .modal-overlay {
    padding: 0;
    align-items: end;
  }
  .modal,
  .modal-wide {
    width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
  }
  .participant {
    grid-template-columns: 1fr 100px 34px;
  }
  .day-label {
    width: 64px;
  }
  .search,
  .select-inline {
    max-width: none;
    width: 100% !important;
  }
  .quick-add {
    flex-wrap: wrap;
  }
  .quick-add input[name='title'] {
    flex-basis: 100%;
  }
  .quick-add input[type='date'] {
    flex: 1;
    width: auto;
  }
  .month-cell {
    min-height: 64px;
    padding: 3px;
  }
  .month-chip {
    font-size: 0;
    height: 6px;
    padding: 0;
    border-left-width: 0;
    background: var(--c);
  }
  .month-more {
    font-size: 10px;
  }
  .table {
    font-size: 13px;
  }
  .table th,
  .table td {
    padding: 8px 6px;
  }
  .page-head .actions .btn {
    flex: 1;
  }
  .att-row {
    flex-wrap: wrap;
  }
}

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

/* Широкие таблицы прокручиваются внутри карточки, а не всей страницы. */
.card:has(> .table) {
  overflow-x: auto;
}

@media (max-width: 600px) {
  .cal-nav {
    flex-basis: 100%;
  }
  .cal-title {
    font-size: 16px;
  }
  .cal-toolbar .segmented {
    margin-left: auto;
  }
  .lesson-line {
    flex-wrap: wrap;
    gap: 4px 8px;
  }
  .lesson-line .day-label {
    width: 100%;
  }
  /* «Запланирован» — обычное состояние, на узком экране его значок только занимает место. */
  .lesson-row .badge-info {
    display: none;
  }
}

.access-grid .list-main span {
  white-space: normal;
}
