/* ── Tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg: #f4f6f9;
  --bg-elev: #ffffff;
  --bg-sunken: #eceff4;
  --text: #131a26;
  --text-soft: #5b6779;
  --text-faint: #8b95a5;
  --line: #e2e7ee;
  --line-strong: #cfd6e0;
  --accent: #2f6fed;
  --accent-soft: #e8effe;
  --danger: #d0433a;
  --ok: #14857a;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 6px 20px -12px rgba(16, 24, 40, .25);
  --shadow-lift: 0 10px 40px -12px rgba(16, 24, 40, .35);
  --tabbar-h: 62px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e131c;
    --bg-elev: #171e2b;
    --bg-sunken: #121926;
    --text: #e8edf6;
    --text-soft: #9aa6b8;
    --text-faint: #6d7b8f;
    --line: #263145;
    --line-strong: #33415a;
    --accent: #5f8ffb;
    --accent-soft: #1b2b4d;
    --danger: #f0736a;
    --ok: #3fb8a8;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -16px rgba(0, 0, 0, .8);
    --shadow-lift: 0 12px 44px -14px rgba(0, 0, 0, .9);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  overscroll-behavior-y: none;
}

h2, h3 { margin: 0; font-size: 15px; letter-spacing: .01em; }

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

/* ── Topbar ─────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar__brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar__mark {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(140deg, #2f6fed, #1b4fc0);
  flex: none;
}
.topbar__brand > span { min-width: 0; }
.topbar__brand b,
.topbar__brand small {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar__brand b { font-size: 15px; line-height: 1.25; }
.topbar__brand small { color: var(--text-soft); font-size: 12px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line-strong);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  max-width: 42vw;
  overflow: hidden;
}
.chip #who-label { overflow: hidden; text-overflow: ellipsis; }
.chip:active { transform: scale(.97); }

.dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--text-faint);
  flex: none;
}

/* ── Layout ─────────────────────────────────────────────────────────── */
main { max-width: 620px; margin: 0 auto; padding: 4px 16px 28px; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 26px 2px 10px;
}
.section-head h2 { color: var(--text-soft); text-transform: uppercase; font-size: 11.5px; letter-spacing: .07em; font-weight: 650; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card--flush { padding: 0; overflow: hidden; }

.muted { color: var(--text-soft); margin: 0 0 12px; font-size: 14px; }
.muted.small { font-size: 12.5px; margin: 10px 0 0; }
.footnote { color: var(--text-faint); font-size: 12px; margin: 22px 4px 0; line-height: 1.5; }

/* ── Next session hero ──────────────────────────────────────────────── */
.next {
  margin-top: 16px;
  border-radius: var(--radius);
  padding: 16px;
  color: #fff;
  background: linear-gradient(150deg, #2f6fed 0%, #1e46a8 100%);
  box-shadow: var(--shadow-lift);
}
.next__eyebrow { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; opacity: .8; font-weight: 650; }
.next__date { font-size: 22px; font-weight: 680; letter-spacing: -.02em; margin-top: 2px; }
.next__time { opacity: .85; font-size: 13.5px; }
.next__legs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.next__legs--single { grid-template-columns: 1fr; }
.next__leg {
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  text-align: left;
  color: #fff;
  cursor: pointer;
}
.next__leg:active { background: rgba(255, 255, 255, .24); }
.next__leg span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; opacity: .78; }
.next__leg b { font-size: 14.5px; font-weight: 620; }
.next--none { background: linear-gradient(150deg, #4b5566, #333b49); }

/* ── Segmented control ──────────────────────────────────────────────── */
.segmented {
  display: inline-flex;
  background: var(--bg-sunken);
  border-radius: 999px;
  padding: 3px;
  border: 1px solid var(--line);
}
.segmented button {
  border: 0;
  background: transparent;
  color: var(--text-soft);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.segmented button.is-active {
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(16, 24, 40, .12);
}

/* ── Sessions list ──────────────────────────────────────────────────── */
.month-label {
  text-transform: uppercase;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 20px 4px 8px;
}

.session {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 13px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}
.session--past { opacity: .58; }
.session--next { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.session__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 9px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.session__date { font-size: 14.5px; font-weight: 640; letter-spacing: -.01em; }
.session__tag { font-size: 11px; color: var(--text-faint); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }

.legs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.legs--single { grid-template-columns: 1fr; }

.leg {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--bg-sunken);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  cursor: pointer;
  min-height: 52px;
  transition: transform .06s ease;
}
.leg:active { transform: scale(.985); }
.leg--empty { border-style: dashed; border-color: var(--line-strong); }
.leg--mine { border-color: currentColor; }

.leg__bar { width: 4px; align-self: stretch; border-radius: 4px; background: var(--line-strong); flex: none; }
.leg__text { min-width: 0; }
.leg__label { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); font-weight: 650; }
.leg__who {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.leg__who--empty { color: var(--text-faint); font-weight: 500; }

.session--off {
  background: repeating-linear-gradient(
    -45deg,
    var(--bg-sunken) 0 10px,
    color-mix(in srgb, var(--bg-sunken) 60%, var(--bg)) 10px 20px
  );
  border-style: dashed;
  box-shadow: none;
}
.session--off .session__head { margin-bottom: 0; }
.session--off .session__date { font-weight: 560; color: var(--text-soft); }
.session__reason { font-size: 12.5px; color: var(--text-faint); font-style: italic; }

/* ── Stats ──────────────────────────────────────────────────────────── */
.stats-cards { display: grid; gap: 8px; }

.stat {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  box-shadow: var(--shadow);
}
.stat__top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stat__name { display: flex; align-items: center; gap: 9px; font-weight: 620; font-size: 14.5px; min-width: 0; }
.stat__name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat__child { font-size: 12px; color: var(--text-faint); font-weight: 500; }
.stat__total { font-size: 21px; font-weight: 700; letter-spacing: -.02em; flex: none; }
.stat__total small { font-size: 12px; font-weight: 550; color: var(--text-faint); letter-spacing: 0; }

.bar { height: 7px; border-radius: 4px; background: var(--bg-sunken); overflow: hidden; margin: 10px 0 8px; display: flex; }
.bar i { display: block; height: 100%; }
.bar i:first-child { opacity: 1; }
.bar i:last-child { opacity: .38; }

.stat__meta { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-soft); flex-wrap: wrap; }
.stat__meta b { font-weight: 640; color: var(--text); }

.delta { font-size: 12px; font-weight: 640; padding: 2px 7px; border-radius: 999px; }
.delta--up { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.delta--down { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.delta--flat { color: var(--text-faint); background: var(--bg-sunken); }

.balance-line { display: flex; justify-content: space-between; font-size: 13.5px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.balance-line:last-child { border-bottom: 0; }
.balance-line span { color: var(--text-soft); }
.balance-line b { font-weight: 620; }

/* ── Log ────────────────────────────────────────────────────────────── */
.log-item { padding: 11px 14px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.log-item:last-child { border-bottom: 0; }
.log-item b { font-weight: 640; }
.log-item time { display: block; font-size: 11.5px; color: var(--text-faint); margin-top: 1px; }
.empty-line { padding: 16px; color: var(--text-faint); font-size: 13.5px; text-align: center; }

/* ── Buttons & forms ────────────────────────────────────────────────── */
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.btn {
  border-radius: var(--radius-sm);
  padding: 11px 15px;
  font-size: 14px;
  font-weight: 620;
  border: 1px solid transparent;
  cursor: pointer;
  flex: 1 1 auto;
  min-height: 44px;
}
.btn:active { transform: scale(.98); }
.btn--primary { background: var(--accent); color: #fff; }
.btn--ghost { background: var(--bg-elev); border-color: var(--line-strong); color: var(--text); }
.btn--danger-ghost { background: transparent; border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; color: var(--text-soft); margin-bottom: 5px; font-weight: 600; }
.field input {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: var(--bg-sunken);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  min-height: 44px;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.family-row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.family-row:last-child { border-bottom: 0; }
.family-row input[type=color] {
  width: 34px; height: 34px; padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: none;
  flex: none;
}
.family-row .inputs { display: grid; gap: 6px; flex: 1; min-width: 0; }
.family-row input[type=text] {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: var(--bg-sunken);
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 14px;
}
.family-row .remove {
  border: 0;
  background: none;
  color: var(--text-faint);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 6px;
  flex: none;
}

/* ── Tab bar ────────────────────────────────────────────────────────── */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
  display: flex;
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1;
  border: 0;
  background: none;
  color: var(--text-faint);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 9px 0 7px;
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
  height: var(--tabbar-h);
}
.tabbar button svg { width: 22px; height: 22px; }
.tabbar button.is-active { color: var(--accent); }

/* ── Bottom sheet ───────────────────────────────────────────────────── */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 20, .45);
  z-index: 40;
  animation: fade .18s ease;
}
.sheet {
  position: fixed;
  z-index: 50;
  left: 0; right: 0; bottom: 0;
  background: var(--bg-elev);
  border-radius: 22px 22px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-lift);
  animation: rise .24s cubic-bezier(.32, .72, 0, 1);
  max-height: 86vh;
  overflow-y: auto;
}
@media (min-width: 620px) {
  .sheet { left: 50%; right: auto; bottom: 24px; width: 480px; transform: translateX(-50%); border-radius: 22px; }
  @keyframes rise { from { transform: translate(-50%, 14px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
}
@media (max-width: 619px) {
  @keyframes rise { from { transform: translateY(100%); } to { transform: translateY(0); } }
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet__grip { width: 38px; height: 4px; border-radius: 4px; background: var(--line-strong); margin: 4px auto 12px; }
.sheet h3 { font-size: 17px; font-weight: 660; letter-spacing: -.01em; }
.sheet__sub { color: var(--text-soft); font-size: 13.5px; margin: 2px 0 14px; }

.sheet__hint {
  font-size: 11.5px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-faint);
  margin: 16px 2px 8px;
}
.sheet__hint:first-child { margin-top: 0; }

.pick {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--bg-sunken);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  min-height: 56px;
}
.pick:active { transform: scale(.99); }
.pick--on { border-color: var(--accent); background: var(--accent-soft); }
.pick__dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.pick__text { flex: 1; min-width: 0; }
.pick__text b { display: block; font-size: 14.5px; font-weight: 620; }
.pick__text small { color: var(--text-soft); font-size: 12px; }
.pick__count { font-size: 12px; color: var(--text-faint); font-weight: 600; flex: none; }
.pick__check { color: var(--accent); font-weight: 700; flex: none; }
.pick--clear { border-style: dashed; background: transparent; }

/* ── Login ──────────────────────────────────────────────────────────── */
.login-body { padding-bottom: 0; display: grid; place-items: center; min-height: 100svh; }

.login {
  width: min(380px, calc(100vw - 40px));
  padding: 32px 24px calc(28px + env(safe-area-inset-bottom));
  text-align: center;
}
.login__mark {
  display: grid;
  place-items: center;
  width: 62px; height: 62px;
  margin: 0 auto 18px;
  border-radius: 18px;
  color: #fff;
  background: linear-gradient(140deg, #2f6fed, #1b4fc0);
  box-shadow: var(--shadow-lift);
}
.login h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.login__sub { color: var(--text-soft); font-size: 14.5px; margin: 4px 0 26px; }

.login__form { text-align: left; }
.login__form .field > span { text-align: center; }
.login__form input { text-align: center; font-size: 17px; letter-spacing: .02em; }
.login__submit { width: 100%; margin-top: 4px; }

.login__error {
  color: var(--danger);
  font-size: 13.5px;
  font-weight: 600;
  text-align: center;
  margin: -4px 0 12px;
}
.login__note { color: var(--text-faint); font-size: 12.5px; margin-top: 22px; }

/* ── Toast ──────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  background: #131a26;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 550;
  box-shadow: var(--shadow-lift);
  animation: fade .18s ease;
  max-width: 90vw;
}
.toast--error { background: var(--danger); }

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