:root {
  /* Color tokens */
  --canvas: #EFF1EC;
  --surface: #FFFFFF;
  --surface-soft: #F7F8F5;
  --ink: #272622;
  --ink-soft: #6B6A64;
  --line: #DCDED7;

  --cobalt: #2E6F9E;
  --cobalt-dark: #234F73;
  --cadmium: #E2562B;
  --leaf: #4C8C5C;
  --sunflower: #D9962E;
  --violet: #7A5C9E;
  --rose: #C75B7A;
  --danger: #C84B3C;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(39,38,34,0.06), 0 6px 16px rgba(39,38,34,0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: 'Inter', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

button, input, select {
  font-family: inherit;
}

.hidden { display: none !important; }

/* ---------- Login ---------- */
.view-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 28px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-mark { margin-bottom: 12px; }

.login-card h1 { font-size: 1.5rem; margin-bottom: 6px; }

.login-sub {
  color: var(--ink-soft);
  font-size: 0.92rem;
  margin: 0 0 22px;
}

#login-form input {
  width: 100%;
  padding: 13px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-soft);
  font-size: 1rem;
  margin-bottom: 14px;
}

.error-text {
  color: var(--danger);
  font-size: 0.88rem;
  margin-top: 14px;
}

/* ---------- App shell ---------- */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 520px;
  margin: 0 auto;
  background: var(--canvas);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 10px;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 1.08rem;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--ink-soft);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(39,38,34,0.06); color: var(--ink); }

.main {
  flex: 1;
  padding: 4px 18px 24px;
  overflow-y: auto;
}

/* ---------- Month nav ---------- */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 6px 0 18px;
}
.month-nav h2 { font-size: 1.15rem; min-width: 160px; text-align: center; }

/* ---------- Stat tiles ---------- */
.stat-row {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  gap: 10px;
  margin-bottom: 26px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.stat-tile-accent {
  border-color: var(--cobalt);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 0.72rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.stat-value {
  font-family: 'Fraunces', serif;
  font-size: 1.5rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat-sub {
  font-size: 0.7rem;
  color: var(--ink-soft);
  margin-top: 2px;
}

/* ---------- Section heading ---------- */
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.section-heading-spaced { margin-top: 28px; }
.section-heading h3 { font-size: 1rem; }

.pill {
  font-size: 0.78rem;
  color: var(--ink-soft);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 11px;
}

/* ---------- Kid list ---------- */
.kid-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.kid-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.kid-list-muted .kid-row { opacity: 0.6; }

/* The paint dab: hollow ring when unpaid, filled with the kid's
   assigned color when paid - a little "wet paint" transition. */
.dab {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2.5px solid var(--dab-color, var(--cobalt));
  background: transparent;
  transition: background 0.25s ease, transform 0.25s ease;
}
.dab.paid {
  background: var(--dab-color, var(--cobalt));
  transform: scale(1.05);
}

.dab[data-color="cobalt"] { --dab-color: var(--cobalt); }
.dab[data-color="cadmium"] { --dab-color: var(--cadmium); }
.dab[data-color="leaf"] { --dab-color: var(--leaf); }
.dab[data-color="sunflower"] { --dab-color: var(--sunflower); }
.dab[data-color="violet"] { --dab-color: var(--violet); }
.dab[data-color="rose"] { --dab-color: var(--rose); }

.kid-info { flex: 1; min-width: 0; }
.kid-name { font-weight: 600; font-size: 0.96rem; }
.kid-meta { font-size: 0.8rem; color: var(--ink-soft); }

.kid-row button.btn-sm { flex-shrink: 0; }

.field-hint {
  font-size: 0.76rem;
  color: var(--ink-soft);
  margin: -6px 0 14px;
  line-height: 1.35;
}

/* ---------- Family grouping ---------- */
.family-group {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 10px 12px;
  margin-bottom: 8px;
}

.family-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 4px 8px;
  border-bottom: 1px dashed var(--line);
  margin-bottom: 8px;
}

.family-name {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.family-phone {
  font-size: 0.74rem;
  color: var(--ink-soft);
}

.family-group .kid-row {
  border: none;
  background: none;
  padding: 8px 4px;
}

.family-group .kid-list {
  gap: 2px;
  margin-bottom: 8px;
}

.family-pay-btn {
  width: 100%;
  background: rgba(46,111,158,0.08);
  border: 1px solid rgba(46,111,158,0.25);
  color: var(--cobalt-dark);
  border-radius: var(--radius-sm);
  padding: 9px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.owes-badge {
  display: inline-block;
  margin-left: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--danger);
  background: rgba(200,75,60,0.1);
  border-radius: 999px;
  padding: 2px 7px;
}

/* ---------- Day picker (class days) ---------- */
.day-picker {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.day-chip {
  flex: 1;
  min-width: 38px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 0;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}
.day-chip.selected {
  background: var(--cobalt);
  border-color: var(--cobalt);
  color: white;
}

/* ---------- Attendance ---------- */
.attend-buttons {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.attend-btn {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 7px 12px;
  cursor: pointer;
}
.attend-btn.present-active {
  background: rgba(76,140,92,0.14);
  border-color: rgba(76,140,92,0.35);
  color: var(--leaf);
}
.attend-btn.absent-active {
  background: rgba(200,75,60,0.12);
  border-color: rgba(200,75,60,0.3);
  color: var(--danger);
}

.summary-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.summary-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
}
.summary-row .kid-name { flex: 1; font-size: 0.88rem; }
.summary-counts {
  display: flex;
  gap: 10px;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}
.summary-counts .present-count { color: var(--leaf); font-weight: 600; }
.summary-counts .absent-count { color: var(--danger); font-weight: 600; }

.empty-state {
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.9rem;
  padding: 30px 10px;
}

/* ---------- History ---------- */
.history-list {
  list-style: none;
  margin: 14px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  font-size: 0.88rem;
}
.history-row .hr-name { font-weight: 600; }
.history-row .hr-meta { color: var(--ink-soft); font-size: 0.78rem; }
.history-row .hr-amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.history-row .hr-undo {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 0.78rem;
  cursor: pointer;
  padding: 4px;
}

/* ---------- Buttons ---------- */
.btn {
  border-radius: var(--radius-sm);
  border: none;
  padding: 11px 16px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}
.btn:active { transform: scale(0.98); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 0.82rem; }

.btn-primary { background: var(--cobalt); color: white; }
.btn-primary:hover { background: var(--cobalt-dark); }

.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  margin-bottom: 14px;
}

.btn-ghost {
  background: none;
  color: var(--ink-soft);
}

.btn-danger {
  background: none;
  color: var(--danger);
  border: 1px solid rgba(200,75,60,0.3);
  margin-top: 14px;
}

.mark-paid-btn {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.mark-paid-btn.is-paid {
  background: rgba(76,140,92,0.12);
  border-color: rgba(76,140,92,0.3);
  color: var(--leaf);
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 0.7rem;
  padding: 6px 0;
  cursor: pointer;
}
.nav-btn.active { color: var(--cobalt); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(39,38,34,0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.modal-sheet {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 480px;
  max-height: 86vh;
  overflow-y: auto;
}
.modal-sheet h3 { margin-bottom: 16px; }
.modal-sheet label {
  display: block;
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin-bottom: 12px;
}
.modal-sheet input, .modal-sheet select {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-soft);
  font-size: 0.95rem;
  color: var(--ink);
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}
.modal-actions .btn { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 100;
}

@media (prefers-reduced-motion: reduce) {
  .dab, .btn { transition: none; }
}
