/* MARK: shared (all pages) */
:root {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --surface-muted: #f2f2f7;
    --line: #e3e4eb;
    --line-strong: #d6d8e2;
    --ink: #1d1d1f;
    --muted: #6e6e73;
    --accent: #ef97b0;
    --accent-strong: #e97fa0;
    --accent-soft: rgba(239, 151, 176, 0.14);
    --danger: #d8566f;
    --danger-soft: rgba(216, 86, 111, 0.1);

    --font-display: "Montserrat", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-body: "Montserrat", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --wrap: 1180px;
    --gutter: clamp(16px, 4vw, 40px);
    --radius: 6px;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-font-smoothing: antialiased; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.6;
}
a { color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 700; line-height: 1.1; }
p { margin: 0; }

.wrap { width: min(100% - 2 * var(--gutter), var(--wrap)); margin-inline: auto; }

.eyebrow {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--muted);
}

/* buttons: ink is the main action, accent stays decorative (white on pink is hard to read) */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    height: 48px;
    padding: 0 26px;
    border: 1px solid var(--ink);
    border-radius: 999px;
    background: var(--ink);
    color: #fff;
    font: 700 15px/1 var(--font-body);
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease;
}
.btn:hover { transform: translateY(-2px); }
.btn:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn-ghost { background: transparent; color: var(--ink); }
.btn-ghost:hover { background: var(--ink); color: #fff; }
.btn-small { height: 40px; padding: 0 18px; font-size: 14px; }
.btn[disabled] { opacity: 0.5; cursor: progress; transform: none; }

input {
    width: 100%;
    height: 48px;
    padding: 0 14px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font: 500 15px var(--font-body);
}
input:focus { border-color: var(--ink); }
/* min-width 0: inside the two-column .field-row a field may shrink instead of overflowing */
label.field { display: grid; gap: 6px; min-width: 0; font-size: 13px; font-weight: 600; color: var(--muted); }

/* iOS Safari: native date/time/month fields keep their own width and centred text, overflowing the card
   and overlapping each other; drop the native look so they size like the other inputs */
input[type="date"], input[type="time"], input[type="month"], input[type="week"], input[type="datetime-local"] {
    -webkit-appearance: none;
    appearance: none;
    display: block;
    min-width: 0;
    max-width: 100%;
    line-height: 46px; /* without the native look the value sticks to the top; 48px height - 2px border */
    text-align: left;
}
input::-webkit-date-and-time-value { margin: 0; text-align: left; }

/* MARK: toast: #error floats over the page and fades out by itself.
   Errors: server sends a fresh <div id="error" class="toast-error">; success: <p class="msg"> lines.
   A new element each time restarts the animation, so no JS is needed. */
#error {
    --tone: var(--danger);
    --tone-soft: var(--danger-soft);
    position: fixed;
    z-index: 50;
    top: 92px; /* just under the 80px sticky header */
    left: 16px;
    right: 16px;
    max-width: 460px;
    margin-inline: auto;
    display: grid;
    grid-template-columns: 28px 1fr;
    column-gap: 12px;
    align-items: center;
    padding: 12px 16px 12px 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(16, 24, 40, 0.12), 0 2px 6px rgba(16, 24, 40, 0.06);
    color: var(--ink);
    font-size: 15px;
    font-weight: 600;
    line-height: 1.4;
    pointer-events: none;
    animation: toast-in 0.3s ease, toast-out 0.3s ease 7s forwards;
}
/* round icon: "!" for errors, check mark for success */
#error::before {
    content: "!";
    grid-row: 1 / span 9; /* spans all message lines (unused rows are 0px high) */
    align-self: center;
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--tone-soft);
    color: var(--tone);
    font-size: 15px;
    font-weight: 800;
}
#error:empty { display: none; }
#error:has(.msg) { --tone: #2e9c6a; --tone-soft: rgba(46, 156, 106, 0.12); animation: toast-in 0.3s ease, toast-out 0.3s ease 4s forwards; }
#error:has(.msg)::before { content: "✓"; }
#error p { grid-column: 2; }
#error p + p { margin-top: 2px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px); visibility: hidden; } }

.logo { display: block; flex-shrink: 0; }
.logo img { display: block; height: 62px; width: auto; }

.site-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(245, 245, 247, 0.82);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
}
.site-header .wrap { display: flex; align-items: center; gap: 16px; height: 80px; }
.header-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.header-actions form { margin: 0; }
.back-link { display: inline-flex; align-items: center; min-height: 40px; padding: 0 6px; font-size: 14px; font-weight: 700; color: var(--muted); text-decoration: none; white-space: nowrap; }
.back-link:hover { color: var(--ink); }

/* app header menu: inline links on wide screens, ☰ drop-down on phones (native <details>) */
.nav-menu { display: none; margin-left: auto; }
.nav-menu > summary {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--ink);
    border-radius: 50%;
    cursor: pointer;
    list-style: none;
}
.nav-menu > summary::-webkit-details-marker { display: none; }
/* ☰ drawn with one bar + two shadows; turns into × when open */
.nav-menu > summary i { position: relative; width: 18px; height: 2px; background: var(--ink); box-shadow: 0 -6px 0 var(--ink), 0 6px 0 var(--ink); transition: transform 0.2s ease; }
.nav-menu[open] > summary i { box-shadow: none; transform: rotate(45deg); }
.nav-menu[open] > summary i::after { content: ""; position: absolute; inset: 0; background: var(--ink); transform: rotate(90deg); }
.nav-menu-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: var(--gutter);
    display: grid;
    gap: 4px;
    min-width: 220px;
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(16, 24, 40, 0.12);
}
.nav-menu-panel .back-link { min-height: 48px; padding: 0 14px; border-radius: var(--radius); font-size: 16px; color: var(--ink); }
.nav-menu-panel .back-link:hover { background: var(--surface-muted); }
.nav-menu-panel form { margin-top: 4px; padding-top: 8px; border-top: 1px solid var(--line); }
.nav-menu-panel .btn { width: 100%; height: 44px; }
@media (max-width: 760px) {
    .nav-inline { display: none; }
    .nav-menu { display: block; }
}

/* MARK: one-screen pages: header + hero fill the viewport */
body { display: flex; flex-direction: column; min-height: 100vh; }
.hero { position: relative; flex: 1; display: flex; align-items: center; overflow: hidden; padding: clamp(40px, 7vw, 80px) 0; }
.hero .wrap { position: relative; display: grid; grid-template-columns: 1.25fr 1fr; gap: clamp(32px, 6vw, 80px); align-items: center; }
.hero .wrap.single { grid-template-columns: 1fr; }
.hero h1 {
    margin: 20px 0 28px;
    font-family: var(--font-display);
    font-size: clamp(40px, 7vw, 88px);
    letter-spacing: -0.03em;
    line-height: 1;
}
.hero h1 em {
    font-style: italic;
    background: linear-gradient(transparent 62%, var(--accent) 62%, var(--accent) 88%, transparent 88%);
}
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin: 36px 0 16px; }
.hero-glow {
    position: absolute;
    top: 10%;
    right: -10%;
    width: 46vw;
    aspect-ratio: 1;
    border-radius: 50%;
    background: radial-gradient(circle, var(--accent-soft), transparent 68%);
    pointer-events: none;
}

/* form card (login, registration) */
.card {
    display: grid;
    gap: 14px;
    padding: 28px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 24px 60px rgba(16, 24, 40, 0.08);
}
.card h2 { font-family: var(--font-display); font-size: 26px; }
.card .btn { width: 100%; }
.card-note { font-size: 14px; color: var(--muted); }
.card-note a { font-weight: 700; color: var(--ink); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* segmented radio choice (registration: parent / student) */
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; padding: 0; border: 0; }
.choice legend { grid-column: 1 / -1; margin-bottom: 6px; padding: 0; }
.choice-option {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
}
.choice-option input { width: 18px; height: 18px; margin: 0; padding: 0; accent-color: var(--ink); }
.choice-option:has(input:checked) { border-color: var(--ink); background: var(--accent-soft); }

@media (max-width: 900px) {
    .hero .wrap { grid-template-columns: 1fr; }
}
@media (max-width: 340px) {
    .field-row { grid-template-columns: 1fr; }
}

/* MARK: app pages (lessons, children): phone-first narrow column */
.page { --wrap: 680px; padding: 28px 0 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head h1 { margin-top: 8px; font-family: var(--font-display); font-size: clamp(30px, 8vw, 44px); letter-spacing: -0.02em; }

#content, .side, .main { display: grid; gap: 28px; align-content: start; }
.main { min-width: 0; }

.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-title h2 { font-family: var(--font-display); font-size: 22px; }
.section-title span { font-size: 14px; font-weight: 600; color: var(--muted); }

/* panels: create lesson / children lists; <details> opens and closes without JS */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 56px;
    padding: 0 18px;
    font-weight: 700;
    cursor: pointer;
    list-style: none;
}
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::after { content: "+"; display: inline-block; font-size: 24px; font-weight: 400; transition: transform 0.2s ease; }
.panel[open] > summary::after { transform: rotate(45deg); }
.panel-body { display: grid; gap: 14px; padding: 4px 18px 18px; }
.panel-body .btn { width: 100%; }
.panel-add { border: 0; }
.children + .panel-add { border-top: 1px solid var(--line); border-radius: 0; }

.children { display: grid; margin: 0; padding: 0; list-style: none; }
.children li { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; padding: 0 18px; border-top: 1px solid var(--line); }
.children li:first-child { border-top: 0; }
.badge { flex-shrink: 0; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge-ok { background: rgba(46, 156, 106, 0.12); color: #1f6e4a; }
.badge-wait { background: var(--surface-muted); color: var(--muted); }
.badge-full { background: var(--danger-soft); color: var(--danger); }

.empty { padding: 28px 18px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius); }
.empty a { font-weight: 700; color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    /* near-zero durations instead of none, so toasts still disappear after their delay */
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* MARK: lessons page */
/* MARK: lesson card */
.lessons { display: grid; gap: 14px; }
.lesson {
    display: grid;
    grid-template-columns: 64px 1fr;
    gap: 16px;
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
/* time block: start on top, end at the bottom, dashed "in progress" line stretching between them */
.lesson-time { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 0; border-radius: var(--radius); background: var(--accent-soft); }
.lesson-time strong { font: 700 18px/1 var(--font-display); }
.lesson-time span { font-size: 15px; font-weight: 600; color: var(--muted); }
.lesson-time i { flex: 1; min-height: 18px; border-left: 2px dashed var(--accent-strong); opacity: 0.7; }

/* MARK: day strip: arrows + Mon..Sun, fits a phone width without scrolling */
/* arrows + week range on the top row, the 7 days full width below (same on phone and desktop) */
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; align-items: stretch; }
.day, .days-arrow {
    display: grid;
    place-items: center;
    align-content: center;
    gap: 2px;
    min-height: 60px;
    border-radius: var(--radius);
    text-decoration: none;
}
.day { position: relative; background: var(--surface); border: 1px solid var(--line); }
.day span { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--muted); }
.day strong { font: 700 18px/1 var(--font-display); }
/* dot = day has lessons; top-left corner, clear of the date number */
.day i { position: absolute; top: 4px; left: 4px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent-strong); }
.day.selected { background: var(--ink); border-color: var(--ink); color: #fff; }
.day.selected span { color: rgba(255, 255, 255, 0.7); }
.day.selected i { background: var(--accent); }
.day.past { opacity: 0.35; }
.days-arrow { font-size: 22px; font-weight: 600; color: var(--ink); }
.days-arrow:empty { visibility: hidden; }
.days > .days-arrow:first-child { grid-row: 1; grid-column: 1; }
.days > .days-arrow:last-child { grid-row: 1; grid-column: 7; }
.days-week { grid-row: 1; grid-column: 2 / 7; align-self: center; text-align: center; font-size: 14px; font-weight: 700; }
.days > .days-arrow { min-height: 40px; }
.lesson-body, .lesson-info, .lesson-actions { display: grid; gap: 12px; min-width: 0; }
.lesson-info { align-content: start; }
.lesson-actions:not(:has(form)), .side:not(:has(*)) { display: none; }
.lesson h3 { font-family: var(--font-display); font-size: 20px; line-height: 1.2; overflow-wrap: anywhere; }
.lesson-meta { font-size: 14px; color: var(--muted); }

/* lesson name with the seats pill next to it (wraps under the name on narrow cards) */
.lesson-title { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }

.names { display: flex; flex-wrap: wrap; gap: 6px; }
.names > span { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; background: var(--surface-muted); font-size: 13px; font-weight: 600; }
.names form { display: contents; }
/* teacher's remove button inside a name chip; padding keeps the tap target finger-sized */
.chip-x { display: grid; place-items: center; width: 28px; height: 28px; margin: -6px -8px -6px 0; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--muted); font-size: 17px; line-height: 1; cursor: pointer; }
.chip-x:hover { background: var(--danger-soft); color: var(--danger); }

/* child pickers: whole pill is the tap target */
.lesson-form { display: grid; gap: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.lesson-form p { font-size: 13px; font-weight: 700; color: var(--muted); }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 16px 0 12px;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}
.check input { width: 20px; height: 20px; margin: 0; padding: 0; accent-color: var(--ink); }
.check:has(input:checked) { border-color: var(--ink); background: var(--accent-soft); }
.lesson-form .btn { width: 100%; }

.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }

/* MARK: desktop: same single column, wider; each lesson is a row: time | info | actions */
@media (min-width: 960px) {
    .page { --wrap: 900px; padding-top: 40px; }
    .days { gap: 8px; }
    .day { min-height: 76px; }
    .day strong { font-size: 22px; }
    .day:not(.selected):not(.past):hover { border-color: var(--ink); }
    .lesson { grid-template-columns: 80px 1fr; gap: 24px; padding: 20px 24px; }
    .lesson-body { grid-template-columns: 1fr 260px; gap: 24px; align-items: stretch; }
    /* full card height (divider line) with the buttons centered in it */
    .lesson-actions { align-content: center; padding-left: 24px; border-left: 1px solid var(--line); }
    .lesson-actions .lesson-form:first-child { padding-top: 0; border-top: 0; }
}

@media (max-width: 380px) {
    .lesson { grid-template-columns: 1fr; }
    /* tiny phones: block on top of the card, line runs sideways */
    .lesson-time { flex-direction: row; padding: 8px 12px; gap: 10px; }
    .lesson-time i { min-height: 0; min-width: 18px; border-left: 0; border-top: 2px dashed var(--accent-strong); }
}

/* MARK: students page */
.child-row { flex-wrap: wrap; padding: 12px 18px !important; }
.child-info { display: grid; gap: 2px; min-width: 0; flex: 1; }
.child-info strong { font-size: 16px; }
.child-info span { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.child-row form { margin: 0; }

/* MARK: statistics page */
.stats-period { display: grid; gap: 14px; }
.period-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.period-btn {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: 0 16px;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    background: var(--surface);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}
.period-btn:hover { border-color: var(--ink); }
.period-btn.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.period-pickers { display: grid; gap: 12px; }
.period-pickers form { margin: 0; }
.period-range { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: end; }
.period-range .btn { height: 48px; }
.stats-title { margin-top: 6px; font-size: 22px; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile { display: grid; gap: 4px; align-content: start; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.tile-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.tile strong { font-size: 30px; line-height: 1.1; }
.tile-delta { font-size: 12px; font-weight: 700; }
.tile-delta.up { color: #1f6e4a; }
.tile-delta.down { color: var(--danger); }

.stats-card { display: grid; gap: 16px; padding: 18px; }
.stats-card h3 { font-size: 17px; }
.stats-empty { color: var(--muted); }

/* month bars: 12 columns, bar height = share of the busiest month */
.month-bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; align-items: end; }
.month-bar { display: grid; justify-items: center; gap: 4px; min-width: 0; }
.month-count { min-height: 16px; font-size: 11px; font-weight: 700; color: var(--muted); }
.month-track { display: flex; align-items: flex-end; width: 100%; height: 120px; border-bottom: 2px solid var(--line-strong); }
.month-track i { display: block; width: 100%; border-radius: 4px 4px 0 0; background: var(--line-strong); }
.month-bar.selected .month-track i { background: var(--accent-strong); }
.month-bar.selected .month-count, .month-bar.selected .month-label { color: var(--ink); }
.month-label { font-size: 11px; font-weight: 600; color: var(--muted); }

/* heatmap: hour column + Mon..Sun; cell color strength = --v (0-100) */
.heat { display: grid; grid-template-columns: 48px repeat(7, 1fr); gap: 4px; }
.heat-day { text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); }
.heat-hour { align-self: center; font-size: 12px; font-weight: 600; color: var(--muted); }
.heat-cell {
    display: grid;
    place-items: center;
    min-height: 36px;
    border-radius: 6px;
    background: color-mix(in srgb, var(--accent-strong) calc(var(--v) * 1%), var(--surface-muted));
    font-size: 12px;
    font-weight: 700;
}

/* ranked lists: name | bar | number */
.rank { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.rank li { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) 40px; gap: 12px; align-items: center; }
.rank-text { display: grid; min-width: 0; }
.rank-text strong { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-text span { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-bar { height: 8px; border-radius: 999px; background: var(--surface-muted); overflow: hidden; }
.rank-bar i { display: block; height: 100%; border-radius: 999px; background: var(--accent-strong); }
.rank-value { text-align: right; font-weight: 700; }

@media (min-width: 760px) {
    .tiles { grid-template-columns: repeat(4, 1fr); }
    .period-pickers { grid-template-columns: 200px 1fr; align-items: end; }
}
@media (max-width: 420px) {
    .period-range { grid-template-columns: 1fr 1fr; }
    .period-range .btn { grid-column: 1 / -1; }
    .rank li { grid-template-columns: minmax(0, 1fr) 70px 32px; }
}

/* MARK: fill schedule panel (lessons page, teachers) */
.fill-hint { font-size: 13px; color: var(--muted); }
.fill-groups { display: grid; gap: 8px; }
.fill-group {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    cursor: pointer;
}
.fill-group input { flex-shrink: 0; width: 20px; height: 20px; margin: 0; padding: 0; accent-color: var(--ink); }
.fill-group span { display: grid; min-width: 0; }
.fill-group strong { font-size: 15px; }
.fill-group small { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.fill-group:has(input:checked) { border-color: var(--ink); background: var(--accent-soft); }
