:root {
  --bg: #F2F5F4;
  --surface: #FFFFFF;
  --surface-2: #F7F9F8;
  --line: #E1E7E5;
  --ink: #1D2A2C;
  --muted: #677679;
  --faint: #9AA7A9;
  --accent: #23776F;
  --accent-ink: #FFFFFF;
  --accent-soft: #DCEEEA;
  --now: #E2613F;
  --ok: #2B9460;
  --ok-soft: #DDF2E6;
  --warn: #C9861A;
  --warn-soft: #FBEFD8;
  --bad: #CC4158;
  --bad-soft: #FADFE4;
  --shadow: 0 1px 2px rgba(20, 40, 38, .06), 0 4px 16px rgba(20, 40, 38, .06);
  --radius: 14px;
  --font: "Nunito", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121A1B; --surface: #1A2425; --surface-2: #202C2D; --line: #2D3B3C; --ink: #E6EEEC; --muted: #9DB0AF; --faint: #6D8080;
    --accent: #4FB3A8; --accent-ink: #0E1C1B; --accent-soft: #1F3B38; --now: #FF7D5C;
    --ok: #53C189; --ok-soft: #1B3527; --warn: #E7AE4A; --warn-soft: #3A2E17; --bad: #F06F84; --bad-soft: #3D1F25;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121A1B; --surface: #1A2425; --surface-2: #202C2D; --line: #2D3B3C; --ink: #E6EEEC; --muted: #9DB0AF; --faint: #6D8080;
  --accent: #4FB3A8; --accent-ink: #0E1C1B; --accent-soft: #1F3B38; --now: #FF7D5C;
  --ok: #53C189; --ok-soft: #1B3527; --warn: #E7AE4A; --warn-soft: #3A2E17; --bad: #F06F84; --bad-soft: #3D1F25;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
h1, h2, h3 { margin: 0; text-wrap: balance; line-height: 1.2; }
h1 { font-size: 24px; font-weight: 800; }
h2 { font-size: 18px; font-weight: 800; }
h3 { font-size: 15px; font-weight: 800; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.label { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 1fr; min-height: 100%; }
.side { display: none; }
.main { padding: 16px 16px calc(84px + env(safe-area-inset-bottom, 0px)); max-width: 1180px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0px); }
.tabbar a, .side a.nav { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; font-size: 11px; font-weight: 700; color: var(--muted); text-decoration: none; }
.tabbar a.on, .side a.nav.on { color: var(--accent); }
.tabbar svg, .side svg { width: 24px; height: 24px; }
@media (min-width: 900px) {
  .app { grid-template-columns: 220px 1fr; }
  .tabbar { display: none; }
  .side { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; padding: 20px 12px; background: var(--surface); border-right: 1px solid var(--line); }
  .side .brand { padding: 4px 12px 18px; }
  .side a.nav { flex-direction: row; gap: 12px; padding: 10px 12px; font-size: 15px; border-radius: 10px; }
  .side a.nav.on { background: var(--accent-soft); }
  .side .sync { margin-top: auto; padding: 10px 12px; }
  .main { padding: 24px 28px 40px; }
}
.brand b { display: block; font-size: 20px; font-weight: 900; color: var(--accent); letter-spacing: -.01em; }
.brand span { font-size: 12px; color: var(--muted); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.section-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 11px; padding: 10px 16px; font-weight: 800; background: var(--accent); color: var(--accent-ink); min-height: 42px; text-decoration: none; }
.btn:hover { filter: brightness(1.06); }
.btn.ghost { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.ok { background: var(--ok); color: #fff; }
.btn.warn { background: var(--warn-soft); color: var(--warn); }
.btn.bad { background: var(--bad-soft); color: var(--bad); }
.btn.sm { min-height: 34px; padding: 6px 12px; font-size: 13px; border-radius: 9px; }
.btn.icon { padding: 0; width: 40px; min-height: 40px; }
.btn svg { width: 18px; height: 18px; }
.fab { position: fixed; right: 18px; bottom: calc(80px + env(safe-area-inset-bottom, 0px)); z-index: 21; width: 58px; height: 58px; border-radius: 18px; border: 0;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 20px rgba(35, 119, 111, .35); display: grid; place-items: center; }
.fab svg { width: 28px; height: 28px; }
@media (min-width: 900px) { .fab { bottom: 28px; right: 28px; } }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 13px; font-weight: 700; color: var(--muted); }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 10px 12px; min-height: 42px; }
textarea.input { min-height: 80px; resize: vertical; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form .full { grid-column: 1 / -1; }
@media (max-width: 480px) { .form { grid-template-columns: 1fr; } }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; min-height: 36px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: .2s; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(18px); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 6px 12px; font-size: 13px; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.pill { display: inline-flex; align-items: center; gap: 4px; border-radius: 99px; padding: 2px 9px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.gray { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.pill.acc { background: var(--accent-soft); color: var(--accent); }

.avatar { width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; font-weight: 900; color: #fff; flex: none; font-size: 16px; }
.avatar.lg { width: 60px; height: 60px; border-radius: 18px; font-size: 24px; }

/* ---------- today ---------- */
.hello h1 { font-size: 26px; }
.hello .date { color: var(--muted); font-weight: 700; }
.hello .date::first-letter { text-transform: uppercase; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 560px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--surface); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 22px; font-weight: 900; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); font-weight: 700; }

.nextup { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; border-left: 6px solid var(--svc, var(--accent)); cursor: pointer; }
.nextup .when { font-size: 13px; font-weight: 800; color: var(--now); text-transform: uppercase; letter-spacing: .05em; }
.nextup .who { font-size: 20px; font-weight: 900; }
.nextup .bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.nextup .bar i { display: block; height: 100%; background: var(--now); border-radius: 99px; }
.nextup .hint { margin-top: 6px; font-size: 13px; color: var(--muted); }

.today-grid { display: grid; grid-template-columns: 1fr; gap: 16px; align-items: start; }
@media (min-width: 1000px) { .today-grid { grid-template-columns: minmax(0, 1.4fr) minmax(300px, 1fr); } }

/* ---------- timeline ---------- */
.tl-wrap { position: relative; overflow: auto; max-height: 70vh; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.tl-head { display: grid; position: sticky; top: 0; z-index: 3; background: var(--surface); border-bottom: 1px solid var(--line); }
.tl-head div { padding: 8px 6px; text-align: center; font-weight: 800; font-size: 13px; cursor: pointer; }
.tl-head div small { display: block; font-size: 11px; color: var(--muted); font-weight: 700; }
.tl-head div.today { color: var(--accent); }
.tl { display: grid; position: relative; }
.tl-hours { position: relative; }
.tl-hours span { position: absolute; right: 8px; transform: translateY(-50%); font-size: 12px; color: var(--faint); font-weight: 700; font-variant-numeric: tabular-nums; }
.tl-col { position: relative; border-left: 1px solid var(--line); }
.tl-col.today { background: color-mix(in srgb, var(--accent-soft) 35%, transparent); }
.tl-line { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.tl-line.half { border-top-style: dashed; opacity: .6; }
.lesson { position: absolute; border-radius: 10px; padding: 6px 8px; overflow: hidden; cursor: pointer; border-left: 4px solid var(--svc); background: color-mix(in srgb, var(--svc) 16%, var(--surface)); color: var(--ink); font-size: 13px; line-height: 1.25; transition: transform .12s; }
.lesson:hover { transform: translateY(-1px); box-shadow: var(--shadow); z-index: 2; }
.lesson b { display: block; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lesson .t { font-size: 11.5px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.lesson .p { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lesson.done { opacity: .62; }
.lesson.done b::after { content: " ✓"; color: var(--ok); }
.lesson.missed_free, .lesson.missed_paid { opacity: .55; background: repeating-linear-gradient(135deg, var(--surface-2) 0 6px, var(--surface) 6px 12px); }
.lesson.cancelled { opacity: .4; text-decoration: line-through; }
.lesson .st { position: absolute; right: 6px; top: 5px; }
.now-line { position: absolute; left: 0; right: 0; height: 0; border-top: 2px solid var(--now); z-index: 4; pointer-events: none; }
.now-line::before { content: ""; position: absolute; left: -6px; top: -6px; width: 10px; height: 10px; border-radius: 50%; background: var(--now); }
.now-line span { position: absolute; right: 4px; top: -20px; font-size: 11px; font-weight: 900; color: var(--now); background: var(--surface); padding: 0 4px; border-radius: 4px; }

.weekstrip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.weekstrip button { border: 0; background: var(--surface); border-radius: 12px; padding: 8px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 1px; box-shadow: var(--shadow); }
.weekstrip button small { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; }
.weekstrip button b { font-size: 17px; font-weight: 900; }
.weekstrip button i { height: 6px; display: flex; gap: 2px; }
.weekstrip button i em { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.weekstrip button.on { background: var(--accent); color: var(--accent-ink); }
.weekstrip button.on small { color: inherit; opacity: .8; }
.weekstrip button.on i em { background: var(--accent-ink); }
.weekstrip button.today:not(.on) b { color: var(--accent); }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); cursor: pointer; text-decoration: none; color: inherit; }
.item:last-child { border-bottom: 0; }
.item .grow b { display: block; font-weight: 800; }
.item .grow small { color: var(--muted); font-size: 13px; }
.item .right { text-align: right; font-variant-numeric: tabular-nums; font-weight: 800; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 12px; cursor: pointer; }
.alert.warn { background: var(--warn-soft); }
.alert.bad { background: var(--bad-soft); }
.alert.info { background: var(--accent-soft); }
.alert .ic { font-size: 18px; line-height: 1.2; }
.alert b { font-weight: 800; }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
.empty .big { font-size: 38px; }

.kids { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.kid { display: flex; gap: 12px; align-items: center; cursor: pointer; }
.kid .grow b { font-weight: 800; display: block; }
.kid .grow small { color: var(--muted); }
.search { position: relative; }
.search input { padding-left: 38px; }
.search svg { position: absolute; left: 11px; top: 11px; width: 20px; height: 20px; color: var(--faint); }

.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; border: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 8px 14px; border-radius: 9px; font-weight: 800; color: var(--muted); white-space: nowrap; }
.tabs button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.notebox { white-space: pre-wrap; background: var(--surface-2); border-radius: 10px; padding: 10px 12px; border: 1px solid var(--line); min-height: 20px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); font-weight: 700; font-size: 13px; }
.kv dd { margin: 0; font-weight: 600; }
.subcard { border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.meter { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 8px; }
.meter i { width: 16px; height: 16px; border-radius: 5px; background: var(--accent); }
.meter i.used { background: var(--line); }

/* ---------- money ---------- */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding-top: 10px; }
.bars div { flex: 1; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; opacity: .85; }
.bars div.zero { background: var(--line); }
.bars div:hover { opacity: 1; }
.bars-x { display: flex; gap: 3px; font-size: 10px; color: var(--faint); font-variant-numeric: tabular-nums; }
.bars-x span { flex: 1; text-align: center; }
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-nav b { min-width: 140px; text-align: center; text-transform: capitalize; font-size: 17px; }
.money-plus { color: var(--ok); }
.money-minus { color: var(--bad); }

/* ---------- sheet (modal) ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 20, 20, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { background: var(--surface); width: 100%; max-width: 620px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 18px 16px calc(20px + env(safe-area-inset-bottom, 0px)); animation: up .2s ease-out; }
.sheet .sheet-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.sheet .foot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 20px; padding: 22px; } }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
@keyframes fade { from { opacity: 0; } }
.status-btns { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.status-btns .btn { justify-content: flex-start; text-align: left; }
.status-btns .btn.cur { outline: 2px solid currentColor; outline-offset: -2px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 700; z-index: 60; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.banner { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 10px 14px; border-radius: 12px; background: var(--warn-soft); font-weight: 600; }
.sync-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 6px; vertical-align: middle; }
.sync-dot.off { background: var(--faint); }
.sync-dot.err { background: var(--bad); }
.sync-dot.busy { background: var(--warn); }

.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login .card { max-width: 380px; width: 100%; display: flex; flex-direction: column; gap: 14px; padding: 26px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button { width: 32px; height: 32px; border-radius: 10px; border: 3px solid transparent; }
.swatches button.on { border-color: var(--ink); }
.hr { height: 1px; background: var(--line); margin: 4px 0; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
