/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* brand */
  --navy:    #0f1c38;
  --navy-2:  #1a2d52;
  --blue:    #2450a4;
  --blue-h:  #1a3d8f;
  --gold:    #c9923a;
  --gold-h:  #e8b048;

  /* status */
  --green:   #16a34a;
  --green-bg:#dcfce7;
  --red:     #c0342b;
  --red-bg:  #fee2e2;
  --amber:   #d4820a;
  --amber-bg:#fef9c3;
  --blue-bg: #dbeafe;
  --purple:  #7c3aed;

  /* neutrals */
  --gray-50:  #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-500: #64748b;
  --gray-700: #334155;
  --gray-900: #0f172a;

  /* per-student slot colours (JS sets --stu-color on each card) */
  --stu-1:   #2450a4;
  --stu-2:   #7c3aed;
  --stu-3:   #0891b2;
  --stu-4:   #059669;

  --radius:  8px;
  --shadow:  0 1px 4px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,.12);
}

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: var(--gray-900);
  background: var(--gray-100);
  min-height: 100vh;
}

/* serif utility for numbers/amounts */
.serif, .num { font-family: 'Libre Baskerville', Georgia, serif; }

/* ── Login ── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-2) 60%, #1a3566 100%);
}

.login-card {
  background: white;
  border-radius: 16px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 40px rgba(0,0,0,.3);
}

.login-brand { text-align: center; margin-bottom: 2rem; }
.login-icon {
  font-size: 3rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px; height: 72px;
  background: linear-gradient(135deg, var(--gold), var(--gold-h));
  border-radius: 18px;
  margin-bottom: .75rem;
  box-shadow: 0 4px 16px rgba(201,146,58,.35);
}
.login-brand h1 {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: .25rem;
}
.subtitle { color: var(--gray-500); font-size: .9rem; }

.login-card form { text-align: left; display: flex; flex-direction: column; gap: 1rem; }
.login-card label { display: flex; flex-direction: column; gap: .35rem; font-weight: 600; font-size: .875rem; color: var(--gray-700); }
.login-card input {
  padding: .6rem .85rem;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: .9375rem;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.login-card input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(36,80,164,.15); }

/* ── Buttons ── */
button, .btn {
  cursor: pointer; border: none; border-radius: var(--radius);
  font-family: inherit; font-size: .875rem; font-weight: 600;
  padding: .5rem 1rem; transition: background .15s, opacity .15s, transform .1s;
  display: inline-flex; align-items: center; gap: .35rem;
}
button:active { transform: scale(.97); }

.btn-primary, button[type=submit] { background: var(--blue); color: white; width: 100%; padding: .7rem; font-size: 1rem; justify-content: center; }
.btn-primary:hover, button[type=submit]:hover { background: var(--blue-h); }
.btn-sm { padding: .3rem .65rem; font-size: .8125rem; }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #a82520; }
.btn-ghost { background: transparent; color: var(--gray-700); border: 1.5px solid var(--gray-200); }
.btn-ghost:hover { background: var(--gray-100); }
.btn-outline { background: white; border: 1.5px solid var(--blue); color: var(--blue); }
.btn-outline:hover { background: var(--blue); color: white; }
.btn-gold { background: linear-gradient(135deg, var(--gold), var(--gold-h)); color: white; border: none; }
.btn-gold:hover { opacity: .9; }

/* ── Header ── */
header {
  background: var(--navy);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .65rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.hdr-brand { display: flex; align-items: center; gap: .6rem; }
.hdr-icon {
  font-size: 1.2rem;
  background: linear-gradient(135deg, var(--gold), var(--gold-h));
  border-radius: 8px;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
}
header .hdr-brand span:last-child {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-weight: 700;
  font-size: .9375rem;
  color: white;
}
header .btn-ghost {
  color: rgba(255,255,255,.8);
  border-color: rgba(255,255,255,.2);
}
header .btn-ghost:hover { background: rgba(255,255,255,.1); color: white; }

/* ── Nav ── */
#main-nav {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  gap: .125rem;
  padding: 0 1.5rem;
  overflow-x: auto;
  scrollbar-width: none;
}
#main-nav::-webkit-scrollbar { display: none; }

#main-nav button {
  background: none;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  color: var(--gray-500);
  padding: .75rem .9rem;
  white-space: nowrap;
  font-size: .875rem;
  font-weight: 500;
}
#main-nav button:hover { color: var(--navy); }
#main-nav button.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }
#main-nav button:active { transform: none; }

/* ── Main content ── */
#content { padding: 1.5rem; max-width: 1100px; margin: 0 auto; }

/* ── Section title ── */
.section-title {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 1.25rem;
}

/* ── Cards ── */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.card-header h2 { font-size: 1rem; font-weight: 700; color: var(--navy); }

/* ── Dashboard grid ── */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.status-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
  padding: 1.25rem 1rem;
  text-align: center;
  border-top: 4px solid var(--stu-color, var(--blue));
  transition: box-shadow .15s;
}
.status-card:hover { box-shadow: var(--shadow-md); }

.status-card .stu-avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--stu-color, var(--blue));
  color: white;
  font-family: 'Libre Baskerville', serif;
  font-size: 1.3rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto .6rem;
}
.status-card .status-name { font-weight: 700; color: var(--navy); margin-bottom: .5rem; font-size: .9375rem; }
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .3rem .75rem;
  border-radius: 999px;
  font-size: .8125rem;
  font-weight: 600;
}
.badge-present { background: var(--green-bg); color: var(--green); }
.badge-left    { background: var(--amber-bg); color: var(--amber); }
.badge-absent  { background: var(--red-bg);   color: var(--red); }
.badge-sick    { background: #fff7ed;          color: #c2410c; }
.badge-none    { background: var(--gray-100);  color: var(--gray-500); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  padding: .55rem .75rem;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--gray-500);
  border-bottom: 2px solid var(--gray-200);
  background: var(--gray-50);
}
tbody tr:hover { background: var(--gray-50); }
tbody td { padding: .65rem .75rem; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
.empty-row td { text-align: center; color: var(--gray-500); padding: 2.5rem; font-size: .9rem; }

/* ── Status pills in tables ── */
.pill { display: inline-block; padding: .2rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 700; letter-spacing: .01em; }
.pill-green  { background: var(--green-bg); color: var(--green); }
.pill-gray   { background: var(--gray-100); color: var(--gray-500); }
.pill-amber  { background: var(--amber-bg); color: var(--amber); }
.pill-red    { background: var(--red-bg);   color: var(--red); }
.pill-blue   { background: var(--blue-bg);  color: var(--blue); }
.pill-purple { background: #ede9fe;          color: var(--purple); }
.pill-navy   { background: var(--navy);      color: white; }

/* ── Forms ── */
form.stacked { display: flex; flex-direction: column; gap: .875rem; }
form.stacked label { display: flex; flex-direction: column; gap: .3rem; font-size: .8125rem; font-weight: 600; color: var(--gray-700); }
form.stacked input,
form.stacked select,
form.stacked textarea {
  padding: .55rem .75rem;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: .9375rem;
  font-family: inherit;
  transition: border-color .15s;
}
form.stacked input:focus,
form.stacked select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(36,80,164,.12); }
form.stacked .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
form.stacked .form-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .5rem; }
form.stacked button[type=submit] { width: auto; padding: .5rem 1.25rem; }

/* ── Routing table ── */
.routing-table td:first-child { font-weight: 600; }
.routing-table select { font-size: .8125rem; }

/* ── Modal ── */
dialog {
  border: none;
  border-radius: 14px;
  box-shadow: 0 12px 48px rgba(0,0,0,.25);
  padding: 0;
  max-width: 540px;
  width: 95%;
}
dialog::backdrop { background: rgba(15,28,56,.6); }
.modal-inner { padding: 1.5rem; position: relative; }
.modal-close {
  position: absolute; top: 1rem; right: 1rem;
  background: none; border: none; font-size: 1.1rem;
  color: var(--gray-500); cursor: pointer; padding: .25rem .4rem; border-radius: 4px;
}
.modal-close:hover { background: var(--gray-100); }
#modal-title {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 1.1rem; font-weight: 700; color: var(--navy);
  margin-bottom: 1.25rem; padding-right: 2rem;
}

/* ── QR code ── */
.qr-wrap { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.qr-wrap canvas { border: 1px solid var(--gray-200); border-radius: 8px; padding: .5rem; }
.qr-token { font-family: monospace; font-size: .9rem; background: var(--gray-100); padding: .35rem .6rem; border-radius: 4px; }

/* ── Toast ── */
#toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  display: flex; flex-direction: column; gap: .5rem; z-index: 100;
}
.toast-msg {
  background: var(--navy); color: white;
  padding: .65rem 1rem; border-radius: var(--radius);
  font-size: .875rem; font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  animation: slideIn .2s ease;
  max-width: 320px;
}
.toast-msg.success { background: var(--green); }
.toast-msg.error   { background: var(--red); }
@keyframes slideIn { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Misc ── */
.hidden   { display: none !important; }
.error    { color: var(--red); font-size: .8125rem; margin-top: .5rem; min-height: 1.2em; }
.loading  { text-align: center; color: var(--gray-500); padding: 3rem; font-size: .9rem; }
.tab-bar  { display: flex; gap: .5rem; margin-bottom: 1rem; }
.tab-bar button { border: 1.5px solid var(--gray-200); background: white; color: var(--gray-700); font-weight: 500; }
.tab-bar button.active { background: var(--blue); color: white; border-color: var(--blue); }
.hint   { font-size: .75rem; color: var(--gray-500); margin-top: .25rem; }
.mono   { font-family: monospace; font-size: .875rem; }

/* ── Balance cards ── */
.balance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.balance-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
  border-top: 4px solid var(--stu-color, var(--blue));
  padding: 1.25rem;
}
.balance-card .bc-name {
  font-family: 'Libre Baskerville', serif;
  font-weight: 700; color: var(--navy);
  margin-bottom: .75rem; font-size: 1rem;
  display: flex; align-items: center; gap: .5rem;
}
.bc-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--stu-color, var(--blue));
  display: inline-block; flex-shrink: 0;
}
.balance-row { display: flex; justify-content: space-between; font-size: .8125rem; margin-bottom: .35rem; color: var(--gray-700); }
.balance-row span:last-child { font-weight: 600; }
.balance-row.total { font-weight: 700; border-top: 1px solid var(--gray-200); margin-top: .5rem; padding-top: .5rem; font-size: .9375rem; color: var(--navy); }
.balance-row.paid span:last-child { color: var(--green); }
.balance-row.outstanding { margin-top: .25rem; }
.balance-row.outstanding span:last-child { font-family: 'Libre Baskerville', serif; font-size: 1.15rem; font-weight: 700; color: var(--red); }
.balance-row.outstanding.zero span:last-child { color: var(--green); }

/* ── Calendar ── */
.cal-nav { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.cal-nav button { padding: .35rem .85rem; font-size: 1rem; }
.cal-nav span {
  font-family: 'Libre Baskerville', serif;
  font-weight: 700; font-size: 1rem;
  color: var(--navy); min-width: 160px; text-align: center;
}

.student-calendars { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1.25rem; }
.student-calendar { background: white; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--gray-200); padding: 1rem; }
.student-calendar h3 {
  font-family: 'Libre Baskerville', serif;
  font-size: .9375rem; font-weight: 700; color: var(--navy);
  margin-bottom: .75rem;
  border-bottom: 2px solid var(--stu-color, var(--blue));
  padding-bottom: .4rem;
}

.cal-grid { width: 100%; border-collapse: separate; border-spacing: 3px; }
.cal-grid th { font-size: .625rem; text-align: center; color: var(--gray-500); font-weight: 700; padding-bottom: .3rem; text-transform: uppercase; }
.cal-cell {
  width: 14.28%; aspect-ratio: 1;
  border-radius: 6px;
  text-align: center;
  font-size: .75rem;
  vertical-align: middle;
  cursor: default;
}
.cal-cell.empty    { background: none; }
.cal-cell.no-event { background: var(--gray-50); color: var(--gray-400); }
.cal-cell.present  { background: var(--green-bg); color: var(--green); font-weight: 700; }
.cal-cell.absent   { background: var(--red-bg);   color: var(--red); }
.cal-cell.sick     { background: #fff7ed;          color: #c2410c; }
.cal-cell.left     { background: var(--amber-bg);  color: var(--amber); font-weight: 600; }
.cal-cell .cal-day  { display: block; }
.cal-cell .cal-rate { display: block; font-size: .6rem; opacity: .8; }
.cal-cell.today     { outline: 2px solid var(--blue); outline-offset: -2px; }

/* ── Monthly report ── */
.monthly-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: .75rem;
  margin-bottom: .25rem;
}
.monthly-stat {
  background: var(--gray-50);
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  padding: .875rem;
  text-align: center;
}
.monthly-stat .ms-value {
  font-family: 'Libre Baskerville', serif;
  font-size: 1.4rem; font-weight: 700; color: var(--navy);
}
.monthly-stat .ms-label { font-size: .7rem; color: var(--gray-500); margin-top: .2rem; text-transform: uppercase; letter-spacing: .04em; }

/* ── Stats strip (for reports) ── */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.stat-box {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
  border-top: 3px solid var(--accent, var(--blue));
  padding: 1rem .875rem;
}
.stat-lbl { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--gray-500); }
.stat-val {
  font-family: 'Libre Baskerville', serif;
  font-size: 1.75rem; font-weight: 700; color: var(--navy);
  margin: .2rem 0 .1rem;
}
.stat-sub { font-size: .75rem; color: var(--gray-500); }

/* ── Payment timeline ── */
.timeline { position: relative; padding-left: 1.5rem; }
.timeline::before {
  content: ''; position: absolute;
  left: 6px; top: 4px; bottom: 4px;
  width: 2px; background: var(--gray-200);
}
.tl-item { position: relative; margin-bottom: 1.25rem; }
.tl-item::before {
  content: ''; position: absolute;
  left: -1.5rem; top: .3rem;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--green);
  border: 2px solid white;
  box-shadow: 0 0 0 2px var(--green);
}
.tl-date { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--gray-500); margin-bottom: .3rem; }
.tl-body {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  box-shadow: var(--shadow);
}
.tl-desc { font-size: .875rem; color: var(--gray-700); }
.tl-who  { font-size: .75rem; color: var(--gray-500); margin-top: .15rem; }
.tl-amt  {
  font-family: 'Libre Baskerville', serif;
  font-size: 1.05rem; font-weight: 700; color: var(--green);
  white-space: nowrap;
}

/* ── Category bars ── */
.cat-list { display: flex; flex-direction: column; gap: .75rem; }
.cat-row  { display: flex; align-items: center; gap: .75rem; }
.cat-label { font-size: .8125rem; font-weight: 600; min-width: 120px; color: var(--navy); text-transform: capitalize; }
.cat-bar-wrap { flex: 1; background: var(--gray-100); border-radius: 4px; height: 8px; overflow: hidden; }
.cat-bar-fill { height: 100%; border-radius: 4px; background: var(--blue); transition: width .4s ease; }
.cat-val { font-family: 'Libre Baskerville', serif; font-size: .875rem; font-weight: 700; min-width: 70px; text-align: right; color: var(--navy); }

/* ── Att-rate ring ── */
.rate-rings { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.rate-ring-item { text-align: center; }
.rate-ring-svg { width: 80px; height: 80px; }
.rate-val {
  font-family: 'Libre Baskerville', serif;
  font-size: .9rem; font-weight: 700; fill: var(--navy);
}
.rate-lbl { font-size: .75rem; color: var(--gray-500); margin-top: .25rem; }
