/* ============ tokens ============ */
:root {
  --ink: #20242a;
  --ink-soft: #5a6270;
  --paper: #faf9f5;
  --card: #ffffff;
  --line: #e4e2da;
  --ledger: #1f6e52;      /* cashbook green */
  --ledger-dark: #14503b;
  --marigold: #e8a33d;    /* dues / highlights */
  --danger: #b3372f;
  --sidebar: #182420;
  --sidebar-text: #b9c6c0;
  --radius: 10px;
  --font-display: 'Zilla Slab', Georgia, serif;
  --font-body: 'Inter', -apple-system, Segoe UI, Roboto, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}
h1, h2, h3, .num { font-family: var(--font-display); }
a { color: var(--ledger); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ============ layout ============ */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: var(--sidebar); color: var(--sidebar-text);
  padding: 20px 0; flex-shrink: 0; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand {
  font-family: var(--font-display); font-size: 19px; font-weight: 700; color: #fff;
  padding: 0 20px 16px; border-bottom: 1px solid rgba(255,255,255,.08); margin-bottom: 10px;
}
.sidebar .brand small { display: block; font-family: var(--font-body); font-size: 10px; font-weight: 500; letter-spacing: .14em; text-transform: uppercase; color: var(--marigold); margin-top: 2px; }
.nav-group { padding: 10px 20px 4px; font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: #6d7d76; }
.nav-item {
  display: block; padding: 8px 20px; color: var(--sidebar-text); font-size: 13.5px;
  border-left: 3px solid transparent;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,.04); }
.nav-item.active { color: #fff; border-left-color: var(--marigold); background: rgba(255,255,255,.06); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px; background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 21px; font-weight: 600; }
.topbar .meta { display: flex; align-items: center; gap: 14px; font-size: 13px; color: var(--ink-soft); }
.badge {
  background: #eef4f1; color: var(--ledger-dark); border: 1px solid #d2e2da;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.content { padding: 24px 28px; max-width: 1200px; width: 100%; }

/* ============ cards / stats ============ */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.card h2 { font-size: 17px; margin-bottom: 14px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.stat .label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-soft); }
.stat .num { font-size: 30px; font-weight: 700; color: var(--ledger-dark); margin-top: 2px; }
.stat.warn .num { color: var(--marigold); }

/* ============ forms ============ */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
label.field { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
label.field input, label.field select, label.field textarea {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 7px; font: inherit; background: #fff; color: var(--ink);
}
label.field input:focus, label.field select:focus, label.field textarea:focus {
  outline: 2px solid var(--ledger); outline-offset: 0; border-color: var(--ledger);
}
.btn {
  display: inline-block; border: 1px solid transparent; border-radius: 7px;
  padding: 8px 16px; font-size: 13.5px; font-weight: 600;
  background: var(--ledger); color: #fff;
}
.btn:hover { background: var(--ledger-dark); }
.btn.secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.secondary:hover { border-color: var(--ink-soft); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn:focus-visible { outline: 2px solid var(--marigold); outline-offset: 2px; }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row .grow { flex: 1; }
.mt { margin-top: 14px; }

/* ============ tables ============ */
table.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.grid th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-soft); border-bottom: 2px solid var(--line); padding: 8px 10px;
}
table.grid td { padding: 9px 10px; border-bottom: 1px solid #efede6; vertical-align: top; }
table.grid tr:hover td { background: #fbfaf6; }
table.grid td.r, table.grid th.r { text-align: right; font-variant-numeric: tabular-nums; }
.amount { font-family: var(--font-display); font-weight: 600; }
.due-chip { color: var(--danger); font-weight: 700; }
.ok-chip { color: var(--ledger-dark); font-weight: 700; }
.muted { color: var(--ink-soft); font-size: 12.5px; }
.pill { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.pill.cash { background: #eef4f1; color: var(--ledger-dark); }
.pill.bank, .pill.upi, .pill.cheque { background: #f4efe4; color: #8a6414; }
.pill.cancelled { background: #f8e8e6; color: var(--danger); }

/* ============ attendance toggles ============ */
.att-toggle { display: inline-flex; gap: 4px; }
.att-btn {
  width: 30px; height: 26px; border-radius: 6px; border: 1px solid var(--line);
  background: #fff; color: var(--ink-soft); font-weight: 700; font-size: 12px;
}
.att-btn.on.present { background: var(--ledger); border-color: var(--ledger); color: #fff; }
.att-btn.on.absent { background: var(--danger); border-color: var(--danger); color: #fff; }
.att-btn.on.leave { background: var(--marigold); border-color: var(--marigold); color: #fff; }
.att-btn.on.half_day { background: var(--ink-soft); border-color: var(--ink-soft); color: #fff; }
.att-btn:focus-visible { outline: 2px solid var(--marigold); outline-offset: 1px; }

/* ============ login (two-panel) ============ */
/* centered-card fallback (used by signup and simple auth screens) */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center;
  background: linear-gradient(135deg, #e9eef1, #d7dee2); padding: 20px;
}
.login-card {
  width: min(420px, 100%); background: var(--card); border-radius: 14px; padding: 34px;
  border-top: 6px solid var(--marigold);
  box-shadow: 0 18px 44px rgba(20, 36, 32, 0.16);
}
.login-card h1 { font-family: var(--font-display); font-size: 26px; }
.login-card .sub { color: var(--ink-soft); font-size: 13px; margin: 4px 0 20px; }
.login-card .field { margin-bottom: 12px; }
.login-card .field input, .login-card .field select {
  width: 100%; margin-top: 5px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
}

.login-page {
  min-height: 100vh; display: grid; place-items: center;
  background: linear-gradient(135deg, #e9eef1, #d7dee2);
  padding: 20px;
}
.login-shell {
  width: min(900px, 100%); min-height: 520px;
  display: grid; grid-template-columns: 1fr 1fr;
  background: var(--card); border-radius: 18px; overflow: hidden;
  box-shadow: 0 24px 60px rgba(20, 36, 32, 0.22);
}
.login-left {
  position: relative;
  background: linear-gradient(160deg, var(--ledger), var(--ledger-dark));
  color: #fff; padding: 40px 36px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
}
.login-brand {
  position: absolute; top: 28px; left: 32px;
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-weight: 700; font-size: 18px; color: #fff;
}
.login-logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--marigold); color: #14503b;
  display: grid; place-items: center; font-weight: 800; font-size: 15px;
}
.login-art { width: 82%; max-width: 300px; margin: 10px auto 20px; }
.login-tag { font-family: var(--font-display); font-size: 22px; font-weight: 600; line-height: 1.3; }
.login-tag-sub { font-size: 14px; opacity: 0.82; margin-top: 8px; }

.login-right { padding: 48px 44px; display: flex; align-items: center; }
.login-form { width: 100%; max-width: 320px; margin: 0 auto; }
.login-form h1 { font-family: var(--font-display); font-size: 27px; color: var(--ink); }
.login-form .sub { color: var(--ink-soft); font-size: 13px; margin: 6px 0 22px; }
.login-form .field { display: block; margin-bottom: 16px; font-size: 13px; color: var(--ink-soft); font-weight: 500; }
.login-form .field input {
  width: 100%; margin-top: 6px; padding: 11px 13px;
  border: 1px solid var(--line); border-radius: 9px; font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}
.login-form .field input:focus {
  outline: none; border-color: var(--ledger);
  box-shadow: 0 0 0 3px rgba(31, 110, 82, 0.14);
}
.login-btn { width: 100%; margin-top: 4px; padding: 12px; font-size: 15px; border-radius: 9px; }
.login-foot { text-align: center; font-size: 12px; margin-top: 18px; }
.login-foot a { color: var(--ledger); font-weight: 600; text-decoration: none; }
.login-foot a:hover { text-decoration: underline; }
.error-box { background: #f8e8e6; color: var(--danger); border-radius: 8px; padding: 9px 12px; font-size: 13px; margin-bottom: 16px; }

@media (max-width: 680px) {
  .login-shell { grid-template-columns: 1fr; min-height: 0; }
  .login-left { display: none; }
  .login-right { padding: 40px 28px; }
}

/* ============ modal / toast ============ */
.modal-backdrop { position: fixed; inset: 0; background: rgba(24,36,32,.55); display: grid; place-items: center; z-index: 50; }
.modal { background: var(--card); border-radius: 12px; padding: 24px; width: min(680px, 94vw); max-height: 90vh; overflow-y: auto; }
.modal h2 { font-size: 18px; margin-bottom: 14px; }
.toast {
  position: fixed; bottom: 22px; right: 22px; z-index: 60;
  background: var(--sidebar); color: #fff; padding: 11px 18px; border-radius: 9px;
  border-left: 4px solid var(--ledger); font-size: 13.5px; animation: rise .18s ease-out;
}
.toast.err { border-left-color: var(--danger); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ============ receipt print (signature element) ============ */
.receipt-sheet {
  background: #fff; border: 2px solid var(--ink); padding: 4px; max-width: 640px; margin: 0 auto;
}
.receipt-inner { border: 1px solid var(--ink); padding: 18px 22px; }
.receipt-head { text-align: center; border-bottom: 2px double var(--ink); padding-bottom: 10px; margin-bottom: 12px; }
.receipt-head .school { font-family: var(--font-display); font-size: 22px; font-weight: 700; }
.receipt-head .addr { font-size: 12px; color: var(--ink-soft); }
.receipt-head .title { display: inline-block; margin-top: 6px; font-size: 12px; font-weight: 700; letter-spacing: .18em; text-transform: uppercase; border: 1px solid var(--ink); padding: 2px 14px; }
.receipt-meta { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 10px; }
.receipt-table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0; }
.receipt-table th, .receipt-table td { border: 1px solid var(--ink); padding: 6px 10px; text-align: left; }
.receipt-table td.r, .receipt-table th.r { text-align: right; font-variant-numeric: tabular-nums; }
.receipt-total td { font-family: var(--font-display); font-weight: 700; font-size: 14px; }
.receipt-foot { display: flex; justify-content: space-between; margin-top: 26px; font-size: 12px; }
.receipt-foot .sig { border-top: 1px solid var(--ink); padding-top: 4px; width: 160px; text-align: center; }
.words { font-size: 12px; font-style: italic; margin-top: 4px; }
@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area { position: absolute; inset: 0; }
  .no-print { display: none !important; }
  /* always show all grouped rows when printing, regardless of collapse state */
  .grp-row { display: table-row !important; }
  .grp-caret { display: none !important; }
}
.grouped-table .grp-head:hover { background: #eeece4 !important; }

/* ============ hamburger (hidden on desktop) ============ */
.hamburger { display: none; flex-direction: column; gap: 4px; background: none; border: none; padding: 6px; margin-right: 4px; }
.hamburger span { display: block; width: 22px; height: 2.5px; background: var(--ink); border-radius: 2px; }
.sidebar-overlay { display: none; }

/* ============ responsive ============ */
@media (max-width: 900px) {
  /* off-canvas drawer sidebar */
  .layout { display: block; }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: 250px; z-index: 60;
    transform: translateX(-100%); transition: transform .22s ease; box-shadow: 2px 0 16px rgba(0,0,0,.2);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 55; opacity: 0; pointer-events: none; transition: opacity .22s ease; }
  .sidebar-overlay.show { opacity: 1; pointer-events: auto; }

  .main { min-height: 100vh; }
  .hamburger { display: flex; }
  .topbar { padding: 12px 16px; gap: 8px; position: sticky; top: 0; z-index: 40; }
  .topbar h1 { font-size: 18px; flex: 1; }
  .topbar .meta { gap: 8px; }
  .hide-sm { display: none !important; }

  .content { padding: 16px 14px; }
  .card { padding: 16px 14px; }

  /* stack forms and rows into one column */
  .form-grid { grid-template-columns: 1fr; }
  .row { flex-direction: column; align-items: stretch; }
  .row > .field, .row > label.field { width: 100%; }
  .row > .btn { width: 100%; }
  .row .grow { flex: none; width: 100%; }

  /* tables scroll sideways instead of squishing */
  table.grid { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }

  /* report cards / marksheets are fixed-width — let them scroll on small screens */
  .print-area { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .receipt-sheet { max-width: 100%; }

  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
  .stat .num { font-size: 24px; }

  .modal { width: 96vw; padding: 18px 16px; max-height: 92vh; }
  .toast { left: 12px; right: 12px; bottom: 12px; text-align: center; }
}

@media (max-width: 480px) {
  .topbar h1 { font-size: 16px; }
  .content { padding: 12px 10px; }
  .card { padding: 14px 12px; }
  .btn { padding: 9px 14px; } /* larger tap target */
  .stat-grid { grid-template-columns: 1fr 1fr; }
}
