:root {
  --ink: #1e2924;
  --muted: #66716b;
  --line: #dfe6e1;
  --paper: #ffffff;
  --canvas: #f4f7f4;
  --green: #176a4b;
  --green-dark: #10543b;
  --green-soft: #e7f3ed;
  --red: #a73c3c;
  --red-soft: #fbeaea;
  --shadow: 0 14px 38px rgba(25, 55, 41, .08);
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--canvas); font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: .4rem; font-size: clamp(1.8rem, 4vw, 2.5rem); line-height: 1.15; }
h2 { margin-bottom: .25rem; font-size: 1.2rem; }

.topbar { position: sticky; top: 0; z-index: 10; min-height: 68px; display: flex; align-items: center; gap: 2rem; padding: max(.75rem, env(safe-area-inset-top)) clamp(1rem, 4vw, 3rem) .75rem; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.95); backdrop-filter: blur(12px); }
.brand { display: flex; align-items: center; gap: .7rem; color: var(--ink); font-weight: 750; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; color: white; background: var(--green); border-radius: 10px; font-weight: 800; }
.brand-mark-large { width: 52px; height: 52px; margin: 0 auto 1.2rem; border-radius: 15px; font-size: 1.35rem; }
.nav { display: flex; flex-wrap: wrap; column-gap: 1.4rem; row-gap: .2rem; flex: 1; min-width: 0; }
.nav a { color: var(--muted); font-weight: 600; white-space: nowrap; }
@media (min-width: 761px) and (max-width: 1240px) {
  .topbar { gap: 1.2rem; }
  .nav { column-gap: .9rem; }
  .nav a { font-size: .92rem; }
}
.account { display: flex; align-items: center; gap: .9rem; color: var(--muted); }
.account form { margin: 0; }
.link-button { padding: 0; color: var(--green); border: 0; background: none; cursor: pointer; }
.nav-toggle { display: none; flex-direction: column; justify-content: center; gap: 4px; width: 40px; height: 40px; padding: 0; border: 1px solid var(--line); border-radius: 9px; background: white; cursor: pointer; flex-shrink: 0; }
.nav-toggle span { display: block; height: 2px; margin: 0 8px; background: var(--ink); border-radius: 2px; }
.nav-backdrop { display: none; }
.nav-close { display: none; }

.page { width: min(1180px, calc(100% - 2rem)); margin: 0 auto; padding: clamp(1.5rem, 4vw, 3rem) 0 calc(5rem + env(safe-area-inset-bottom)); }
.page-centered { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.5rem; }
.eyebrow { margin-bottom: .35rem; color: var(--green); font-size: .75rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.muted, .form-note { color: var(--muted); }
.fine-print { margin: 1.5rem 0 0; color: var(--muted); font-size: .82rem; }
.back-link { display: inline-block; margin-bottom: .8rem; }

.button { display: inline-flex; justify-content: center; align-items: center; padding: .72rem 1rem; color: white; border: 1px solid var(--green); border-radius: 10px; background: var(--green); font-weight: 700; cursor: pointer; }
.button:hover { background: var(--green-dark); text-decoration: none; }
.button-secondary { color: var(--ink); border-color: var(--line); background: white; }
.button-secondary:hover { background: #f7faf8; }
.button-small { padding: .45rem .65rem; font-size: .85rem; }
.button-full { width: 100%; }
.button-danger { border-color: var(--red); background: var(--red); }
.button-danger:hover { background: #873030; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat-card, .section-card, .form-card, .login-card { border: 1px solid var(--line); background: var(--paper); box-shadow: var(--shadow); }
.stat-card { padding: 1.4rem; border-radius: 16px; }
.stat-card strong { display: block; font-size: 2rem; line-height: 1.1; }
.stat-card span { color: var(--muted); }
.stat-card strong.figure-bad { color: var(--red); }
.stat-card strong.figure-warn { color: #8a5a00; }
.stat-card-wide { padding: 1.4rem 1.6rem; }
.stat-card-wide strong { font-size: 2.4rem; }
.section-card { padding: clamp(1rem, 3vw, 1.5rem); border-radius: 18px; }
.section-card + .section-card { margin-top: 1.25rem; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .9rem .75rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: .76rem; letter-spacing: .04em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
.status { display: inline-flex; padding: .28rem .55rem; border-radius: 999px; background: #edf1ef; color: #53615a; font-size: .78rem; font-weight: 750; }
.status-open, .status-attended { color: var(--green); background: var(--green-soft); }
.status-cancelled, .status-missed { color: var(--red); background: var(--red-soft); }
.status-warning { color: #8a5a00; background: #fff1cc; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.chip { display: inline-flex; align-items: center; gap: .4rem; padding: .4rem .8rem; border: 1px solid var(--line); border-radius: 999px; color: var(--ink); background: white; font-weight: 600; font-size: .92rem; }
.chip:hover { text-decoration: none; border-color: var(--green); }
.chip b { color: var(--muted); font-weight: 700; }
.chip-active { color: white; background: var(--green); border-color: var(--green); }
.chip-active b { color: white; }
.tag { display: inline-flex; align-items: center; gap: .4rem; padding: .4rem .8rem; border: 1px solid var(--line); border-radius: 999px; color: var(--ink); background: white; font-weight: 600; font-size: .92rem; cursor: default; }
.tag b { color: var(--muted); font-weight: 700; }
.member-since { margin-top: .6rem; }
.member-since summary { cursor: pointer; color: var(--muted); text-decoration: underline; }
.member-since[open] summary { margin-bottom: .5rem; }
.member-since label { display: block; max-width: 220px; }
.pay-summary { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0 0 .75rem; }
.pay-inline summary { list-style: none; cursor: pointer; display: inline-flex; }
.pay-inline summary::-webkit-details-marker { display: none; }
.pay-inline form { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: .5rem 0 0; }
.pay-inline input { width: auto; }
.lesson-actions.member-actions { flex-direction: row; flex-wrap: wrap; align-items: flex-start; gap: .5rem; min-width: 0; }
.more-menu[open] { flex-basis: 100%; }
.more-menu[open] summary { margin-bottom: .1rem; }
.owners-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.owner-card { padding: 1.1rem 1.3rem; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); }
.owner-card h3 { margin: 0 0 .5rem; font-size: 1.05rem; }
.subheading { margin: 1.25rem 0 .5rem; font-size: 1.05rem; }
.subheading:first-of-type { margin-top: 1rem; }
.month-nav { display: flex; align-items: center; gap: .6rem; }
.money-tabs { display: flex; gap: .4rem; margin: .5rem 0 .4rem; }
.money-tabs a { padding: .35rem .9rem; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-weight: 600; }
.money-tabs a:hover { text-decoration: none; color: var(--ink); }
.money-tabs a[aria-current="page"] { color: white; background: var(--green); border-color: var(--green); }
.month-nav input[type=month] { min-width: 150px; }

.login-card { width: min(440px, 100%); padding: clamp(2rem, 7vw, 3rem); border-radius: 24px; text-align: center; }
.login-card code { padding: .12rem .35rem; border-radius: 5px; background: var(--green-soft); }
.form-card { max-width: 760px; padding: clamp(1.25rem, 4vw, 2rem); border-radius: 18px; }
.form-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 1.2rem; }
label span { display: block; margin-bottom: .4rem; font-weight: 700; }
input, select, textarea { width: 100%; padding: .72rem .8rem; color: var(--ink); border: 1px solid #cbd5cf; border-radius: 9px; background: white; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(23,106,75,.14); border-color: var(--green); }
.full-width { grid-column: 1 / -1; }
.form-note { margin: 0; font-size: .88rem; }
.form-actions { display: flex; justify-content: flex-end; gap: .7rem; }
.alert { margin-bottom: 1.25rem; padding: .85rem 1rem; border-radius: 10px; }
.alert ul { margin: 0; padding-left: 1.2rem; }
.alert-error { color: #7d2929; border: 1px solid #f1c6c6; background: var(--red-soft); }
.alert-success { color: var(--green-dark); border: 1px solid #bedecf; background: var(--green-soft); }
.empty-state { padding: 2rem 1rem; color: var(--muted); text-align: center; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1.25rem; align-items: start; }
.side-card { position: sticky; top: 88px; }
.details-list { margin: 1.2rem 0; }
.details-list div { display: flex; justify-content: space-between; gap: 1rem; padding: .65rem 0; border-bottom: 1px solid var(--line); }
.details-list dt { color: var(--muted); }
.details-list dd { margin: 0; text-align: right; }
.student-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1rem 0; border-bottom: 1px solid var(--line); }
.student-row:last-child { border-bottom: 0; }
.student-row p { margin: .25rem 0 0; color: var(--muted); }
.inline-actions { display: flex; flex-wrap: wrap; gap: .45rem; }
.single-column { grid-template-columns: 1fr; }
.separator { margin: 1.4rem 0; border: 0; border-top: 1px solid var(--line); }
.danger-zone { margin-top: 1rem; color: var(--red); }
.danger-zone summary { cursor: pointer; font-weight: 700; }
.collapsible + .collapsible { margin-top: 1.4rem; padding-top: 1.4rem; border-top: 1px solid var(--line); }
.collapsible summary { cursor: pointer; font-weight: 700; font-size: 1.2rem; color: var(--ink); }
.collapsible summary::-webkit-details-marker { color: var(--muted); }
.collapsible[open] summary { margin-bottom: 1rem; }
.pre-line { white-space: pre-line; }
.search-card { margin-bottom: 1.25rem; }
.search-form { display: grid; grid-template-columns: minmax(260px, 2fr) minmax(180px, 1fr) auto auto; gap: .8rem; align-items: end; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 1.25rem; }
.content-stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; }
.student-detail-grid { grid-template-columns: minmax(0, 1fr) 320px; }
.schedule-card { margin-top: 1.25rem; }
.schedule-rule-list { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.schedule-form { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 1rem; }
.schedule-form .form-actions { align-items: end; }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; margin-top: 1.25rem; align-items: stretch; }
.inline-form { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin: .8rem 0; }
.inline-form select { width: auto; flex: 1 1 200px; }
.lesson-actions { display: flex; flex-direction: column; gap: .5rem; min-width: 240px; }
.lesson-actions form { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: 0; }
.lesson-actions input { width: auto; }
.lesson-actions .field-datetime { width: 150px; }
.lesson-actions .field-duration { width: 66px; }
.lesson-actions .field-reason { width: 170px; }
.lesson-actions .button { flex-shrink: 0; }

@media (max-width: 760px) {
  .nav-toggle { display: flex; }
  .account { margin-left: auto; }
  .account > span { display: none; }
  .nav {
    position: fixed; top: 0; left: 0; z-index: 50; display: flex; flex-direction: column;
    gap: 0; width: min(300px, 82vw); height: 100vh; height: 100dvh;
    padding: calc(1.1rem + env(safe-area-inset-top)) 1.1rem calc(1.1rem + env(safe-area-inset-bottom));
    background: var(--paper); box-shadow: var(--shadow); overflow-y: auto;
    transform: translateX(-100%); transition: transform .25s ease;
  }
  .nav.nav-open { transform: translateX(0); }
  .nav a { padding: .95rem .3rem; border-bottom: 1px solid var(--line); font-size: 1.05rem; }
  .nav-close {
    display: flex; justify-content: center; align-items: center; align-self: flex-end;
    width: 40px; height: 40px; margin-bottom: .5rem; border: 1px solid var(--line); border-radius: 9px;
    background: white; font-size: 1.1rem; cursor: pointer; flex-shrink: 0;
  }
  .nav-backdrop:not([hidden]) {
    display: block; position: fixed; top: 0; left: 0; right: 0; height: 100dvh;
    z-index: 40; background: rgba(15, 30, 22, .4);
  }
  .stats-grid, .detail-grid, .settings-grid, .owners-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .search-form { grid-template-columns: 1fr; }
  .full-width { grid-column: auto; }
  .side-card { position: static; }
  .student-row { align-items: stretch; flex-direction: column; }
  .inline-actions { flex-direction: column; align-items: stretch; }
  .page-heading { align-items: flex-start; flex-wrap: wrap; }
  .month-nav { flex-wrap: wrap; width: 100%; }
  .month-nav input[type=month] { min-width: 0; flex: 1 1 140px; }

  .button, .button-small, .link-button, select { min-height: 44px; }
  .button-small { padding: .6rem .8rem; }
  .inline-actions, .lesson-actions { gap: .7rem; }
  .student-row .button, .inline-actions .button { width: 100%; }
  .lesson-actions form { flex-direction: column; align-items: stretch; }
  .lesson-actions .field-datetime, .lesson-actions .field-duration, .lesson-actions .field-reason {
    width: 100%;
  }

  .table-wrap table, .table-wrap thead, .table-wrap tbody, .table-wrap th, .table-wrap tr { display: block; width: 100%; }
  .table-wrap thead { position: absolute; left: -9999px; }
  .table-wrap tbody tr {
    margin-bottom: .9rem; padding: .9rem 1rem; border: 1px solid var(--line); border-radius: 14px;
  }
  .table-wrap tbody tr:last-child { margin-bottom: 0; }
  .table-wrap td {
    display: block; padding: .55rem 0; border-bottom: 1px solid var(--line); vertical-align: top;
  }
  .table-wrap td:first-child { padding-top: 0; }
  .table-wrap td:last-child { border-bottom: 0; padding-bottom: 0; }
  .table-wrap td[data-label]::before {
    content: attr(data-label); display: block; margin-bottom: .3rem; color: var(--muted);
    font-size: .72rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase;
  }
  .table-wrap td:empty { display: none; }
}

/* Журнал посещаемости группы: ученики строками, занятия столбцами. Отдельная обёртка, а не
   .table-wrap, чтобы на узком экране таблица не превращалась в карточки, а прокручивалась. */
.journal-legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; margin: 0 0 .8rem; color: var(--muted); font-size: .85rem; }
.journal-legend span { display: inline-flex; align-items: center; gap: .35rem; }
.journal-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.journal { border-collapse: separate; border-spacing: 0; font-size: .85rem; }
.journal th, .journal td { padding: .35rem .3rem; border-bottom: 1px solid var(--line); text-align: center; white-space: nowrap; background: var(--paper); }
.journal tbody tr:last-child th, .journal tbody tr:last-child td { border-bottom: 0; }
.journal thead th { position: sticky; top: 0; z-index: 1; font-weight: 650; }
.journal thead a { display: flex; flex-direction: column; color: var(--ink); line-height: 1.15; }
.journal-num { font-size: .72rem; color: var(--muted); }
.journal-date { font-weight: 700; }
.journal .journal-name { position: sticky; left: 0; z-index: 2; min-width: 9rem; max-width: 13rem; padding-left: .75rem; text-align: left; white-space: normal; border-right: 1px solid var(--line); }
.journal thead .journal-name { z-index: 3; }
.journal-name .form-note { display: block; font-size: .72rem; font-weight: 500; }
.journal-former .journal-name a { color: var(--muted); }
.journal-mark { display: inline-grid; place-items: center; width: 1.75rem; height: 1.75rem; border-radius: 7px; font-style: normal; font-weight: 800; font-size: .8rem; line-height: 1; text-decoration: none; }
a.journal-mark:hover { text-decoration: none; outline: 2px solid var(--ink); outline-offset: 1px; }
.journal-present { color: white; background: #2f9e6a; }
.journal-excused { color: #4f5853; background: #d9dfdb; }
.journal-unexcused { color: white; background: #c94848; }
.journal-unknown { color: #8a5a00; background: #fff1cc; border: 1px dashed #d9a640; }
.journal-none { color: #b8c1bc; background: transparent; }
.journal th.journal-cancelled, .journal td.journal-cancelled { background: repeating-linear-gradient(135deg, #f4f6f5 0 6px, #e9edeb 6px 12px); }
.journal th.journal-cancelled .journal-num { color: var(--red); font-weight: 700; }
.journal tbody th { text-transform: none; letter-spacing: normal; font-size: .88rem; font-weight: 650; }

/* Обзор и список ближайших занятий. */
.stats-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
a.stat-card { color: var(--ink); text-decoration: none; }
a.stat-card:hover { border-color: var(--green); text-decoration: none; }
.stat-warning strong { color: #8a5a00; }
.stat-danger strong { color: var(--red); }
.schedule-list, .plain-list { margin: 0; padding: 0; list-style: none; }
.schedule-item { display: grid; grid-template-columns: minmax(12rem, 16rem) 1fr; gap: .25rem 1rem; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.schedule-item:last-child { border-bottom: 0; }
.schedule-time { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.schedule-what { display: flex; flex-direction: column; }
.plain-list li { padding: .45rem 0; border-bottom: 1px solid var(--line); }
.plain-list li:last-child { border-bottom: 0; }
@media (max-width: 760px) {
  .stats-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .schedule-item { grid-template-columns: 1fr; }
}
/* Редко нужные настройки группы свёрнуты под одним заголовком. */
.settings-panel { margin-bottom: 1.25rem; }
.settings-panel > summary { cursor: pointer; list-style: none; padding: .9rem 1.2rem; border: 1px dashed var(--line); border-radius: 14px; color: var(--muted); }
.settings-panel > summary::-webkit-details-marker { display: none; }
.settings-panel > summary h2 { display: inline; font-size: 1rem; }
.settings-panel > summary::before { content: "▸ "; }
.settings-panel[open] > summary::before { content: "▾ "; }
.settings-panel[open] > summary { margin-bottom: 1rem; }
/* Карточка ученика: данные сводкой. */
.compact-details { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: .6rem 1.2rem; margin: 0 0 .6rem; }
.compact-details > div { display: flex; flex-direction: column; justify-content: flex-start; gap: .1rem; padding: 0; border-bottom: 0; }
.compact-details dt { color: var(--muted); font-size: .78rem; }
.compact-details dd { margin: 0; font-weight: 600; text-align: left; }
/* Справа у ученика остались только заявки, поэтому карточка в одну колонку. */
.student-detail-grid { grid-template-columns: minmax(0, 1fr); max-width: 980px; }
.money-line { margin: .2rem 0 .4rem; font-size: 1.05rem; }
.money-line .muted { font-size: .85rem; }
/* Пояснения к цифрам — по клику, чтобы не занимать экран. */
.hint { margin: .3rem 0 1rem; color: var(--muted); font-size: .85rem; }
.hint > summary { cursor: pointer; width: fit-content; }
.hint > p { margin: .4rem 0 0; }
/* «Итог месяца» на странице финансов — лесенка от выручки к прибыли. */
.ledger { width: 100%; max-width: 560px; border-collapse: collapse; }
.ledger th, .ledger td { padding: .45rem 0; border-bottom: 1px solid var(--line); font-size: .95rem; text-transform: none; letter-spacing: normal; color: var(--ink); font-weight: 500; }
.ledger td { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ledger .ledger-note td { padding: 0 0 .5rem; text-align: left; color: var(--muted); font-size: .82rem; white-space: normal; }
.ledger .ledger-total th, .ledger .ledger-total td { font-weight: 750; border-bottom: 0; }
.ledger .ledger-result th, .ledger .ledger-result td { font-weight: 800; font-size: 1.1rem; border-top: 2px solid var(--ink); border-bottom: 0; padding-top: .6rem; }

/* Ссылки с метками */
.links-form { display: flex; flex-wrap: wrap; gap: .8rem; align-items: flex-end; }
.links-form label { display: grid; gap: .3rem; flex: 1 1 200px; }
.links-table td { vertical-align: top; font-variant-numeric: tabular-nums; }
.links-table td:first-child { min-width: 260px; }
.links-table tr.is-archived { opacity: .55; }
.link-urls { display: grid; gap: .3rem; margin-top: .4rem; }
.link-url { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; font-size: .85rem; }
.link-url code { overflow-wrap: anywhere; }
.links-table .inline-form { margin: .3rem 0 0; }

/* Предпросмотр конспекта ученического Mini App. */
.note-preview { overflow-wrap: anywhere; }
.note-preview h2 { font-size: 1.15rem; margin: 1rem 0 .5rem; }
.note-preview h3 { font-size: 1rem; margin: .9rem 0 .4rem; }
.note-preview .table { overflow-x: auto; }
.note-preview table { border-collapse: collapse; }
.note-preview th, .note-preview td { border: 1px solid #cbd5cf; padding: .35rem .55rem; text-align: left; }
