:root {
  --paper: #FAF7F0;
  --paper-line: #E3DCC8;
  --card: #FFFFFF;
  --ink: #1B2A4A;
  --ink-soft: #52608A;
  --maroon: #8B2635;
  --maroon-dark: #6E1E2A;
  --maroon-bg: #F6E8E6;
  --gold: #A8842C;
  --gold-bg: #FBF1DD;
  --green: #2F6B4F;
  --green-bg: #E7F1EC;
  --red: #A6433C;
  --red-bg: #F6E8E6;
  --shadow: 0 2px 14px rgba(27,42,74,0.09);
  --radius: 10px;
  --mono: 'IBM Plex Mono', monospace;
  --hi-serif: 'Noto Serif Devanagari', serif;
  --hi-sans: 'Noto Sans Devanagari', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  background-image: linear-gradient(var(--paper-line) 1px, transparent 1px);
  background-size: 100% 38px;
  color: var(--ink);
  font-family: var(--hi-sans);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}
#app { max-width: 1140px; margin: 0 auto; padding: 18px 18px 60px; }
h1, h2, h3 { font-family: var(--hi-serif); margin: 0; color: var(--ink); }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
a { color: var(--maroon); }
.mono { font-family: var(--mono); }
.muted { color: var(--ink-soft); }
.hidden { display: none !important; }

/* ---------- Header ---------- */
.header {
  display: flex; justify-content: space-between; align-items: flex-end;
  padding: 18px 22px; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 16px; border-bottom: 4px double var(--gold);
  gap: 14px; flex-wrap: wrap;
}
.header-left .school-name { font-size: 26px; font-weight: 700; color: var(--maroon); }
.header-left .school-sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; letter-spacing: .3px; }
.header-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.today-pill { font-family: var(--mono); font-size: 12.5px; color: var(--ink-soft); background: var(--paper); border: 1px solid var(--paper-line); padding: 6px 10px; border-radius: 20px; }
.mode-badge { font-size: 12.5px; font-weight: 700; padding: 6px 14px; border-radius: 20px; letter-spacing: .3px; }
.mode-badge.operator { background: var(--green-bg); color: var(--green); }
.mode-badge.admin { background: var(--maroon-bg); color: var(--maroon); }

/* ---------- Buttons ---------- */
.btn { border: none; border-radius: 8px; padding: 9px 16px; font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; transition: transform .05s; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--maroon); color: #fff; }
.btn-primary:hover { background: var(--maroon-dark); }
.btn-income { background: var(--green); color: #fff; }
.btn-expense { background: var(--red); color: #fff; }
.btn-outline { background: transparent; border: 1.5px solid var(--ink-soft); color: var(--ink); }
.btn-outline-gold { background: transparent; border: 1.5px solid var(--gold); color: var(--gold); }
.btn-ghost { background: var(--paper); color: var(--ink); border: 1px solid var(--paper-line); }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 6px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Nav ---------- */
.nav { display: flex; gap: 6px; margin-bottom: 18px; border-bottom: 2px solid var(--paper-line); flex-wrap: wrap; }
.nav-tab { padding: 10px 16px; font-weight: 600; color: var(--ink-soft); border-bottom: 3px solid transparent; font-size: 14.5px; background: none; border-top: none; border-left: none; border-right: none; }
.nav-tab.active { color: var(--maroon); border-bottom-color: var(--maroon); }

/* ---------- Cards / Grid ---------- */
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
@media (max-width: 880px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .grid-4 { grid-template-columns: 1fr; } }
.stat-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; border-left: 4px solid var(--ink); }
.stat-card.c-income { border-left-color: var(--green); }
.stat-card.c-expense { border-left-color: var(--red); }
.stat-card.c-balance { border-left-color: var(--ink); }
.stat-card.c-pending { border-left-color: var(--gold); }
.stat-card .label { font-size: 12.5px; color: var(--ink-soft); font-weight: 600; margin-bottom: 6px; }
.stat-card .value { font-family: var(--mono); font-size: 22px; font-weight: 700; }
.stat-card.c-income .value { color: var(--green); }
.stat-card.c-expense .value { color: var(--red); }
.stat-card.c-pending .value { color: var(--gold); }

.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 8px; }
.panel-head h2 { font-size: 18px; }
.section-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.8px; }
thead th { background: var(--ink); color: #F4EFE2; text-align: right; padding: 9px 10px; font-weight: 600; font-size: 12.8px; }
thead th:first-child { border-radius: 6px 0 0 0; }
thead th:last-child { border-radius: 0 6px 0 0; }
tbody td { padding: 9px 10px; border-bottom: 1px solid var(--paper-line); text-align: right; vertical-align: middle; }
tbody tr:hover { background: var(--paper); }
.amt-income { color: var(--green); font-family: var(--mono); font-weight: 600; }
.amt-expense { color: var(--red); font-family: var(--mono); font-weight: 600; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 11.5px; font-weight: 700; }
.badge-pending { background: var(--gold-bg); color: var(--gold); }
.badge-settled { background: var(--green-bg); color: var(--green); }
.badge-income { background: var(--green-bg); color: var(--green); }
.badge-expense { background: var(--red-bg); color: var(--red); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.empty-row td { text-align: center; color: var(--ink-soft); padding: 26px 10px; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }
.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field.full { grid-column: 1/-1; }
.form-field label { font-size: 12.8px; font-weight: 600; color: var(--ink-soft); }
.form-field input, .form-field select, .form-field textarea {
  border: 1.5px solid var(--paper-line); border-radius: 7px; padding: 9px 10px; font-size: 14.5px; background: #fff; color: var(--ink);
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus { outline: 2px solid var(--gold); border-color: var(--gold); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.field-error { color: var(--red); font-size: 12px; margin-top: 2px; }
.helptext { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }

/* ---------- Filters ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: flex-end; }
.filters .form-field { min-width: 140px; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(27,42,74,.45); display: flex; align-items: center; justify-content: center; z-index: 200; padding: 18px; }
.modal-box { background: #fff; border-radius: 12px; max-width: 640px; width: 100%; max-height: 88vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal-box.wide { max-width: 760px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--paper-line); }
.modal-head h3 { font-size: 17px; color: var(--maroon); }
.modal-close { background: none; border: none; font-size: 20px; color: var(--ink-soft); line-height: 1; }
.modal-body { padding: 18px 20px; }
.modal-msg { font-size: 14.5px; color: var(--ink); margin-bottom: 6px; }

/* ---------- Toast ---------- */
#toastRoot { position: fixed; bottom: 18px; right: 18px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13.5px; box-shadow: var(--shadow); opacity: 0; transform: translateY(8px); animation: toastIn .25s forwards; }
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }
@keyframes toastIn { to { opacity: 1; transform: translateY(0); } }

/* ---------- Receipt ---------- */
.receipt-wrap { font-family: var(--hi-sans); }
.receipt-block { border: 2px solid var(--ink); border-radius: 8px; overflow: hidden; }
.receipt-half { padding: 16px 18px; }
.receipt-top { background: #fff; }
.receipt-head-row { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--ink); padding-bottom: 10px; margin-bottom: 10px; }
.receipt-school { font-family: var(--hi-serif); font-weight: 700; color: var(--maroon); font-size: 19px; }
.receipt-title { font-family: var(--hi-serif); font-weight: 700; font-size: 14px; color: var(--ink); margin-top: 2px; }
.receipt-no { font-family: var(--mono); font-size: 13px; text-align: left; }
.receipt-no .id { font-weight: 700; color: var(--maroon); font-size: 15px; }
.receipt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 14px; font-size: 13.5px; margin-bottom: 10px; }
.receipt-grid .full { grid-column: 1/-1; }
.receipt-grid .k { color: var(--ink-soft); font-weight: 600; }
.receipt-grid .v { font-weight: 600; }
.receipt-amount-words { font-size: 13.5px; border: 1px dashed var(--paper-line); padding: 8px 10px; border-radius: 6px; background: var(--paper); margin-bottom: 10px; }
.receipt-sign-row { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 18px; gap: 10px; }
.sign-block { flex: 1; text-align: center; }
.sign-line { border-top: 1.3px solid var(--ink); margin-top: 30px; padding-top: 5px; font-size: 12px; color: var(--ink-soft); }
.seal { width: 54px; height: 54px; border-radius: 50%; border: 2px dashed var(--ink-soft); display: flex; align-items: center; justify-content: center; font-size: 10.5px; font-weight: 700; text-align: center; margin: 0 auto 4px; color: var(--ink-soft); line-height: 1.1; }
.seal.filled-green { border: 2px solid var(--green); color: var(--green); background: var(--green-bg); }
.seal.filled-maroon { border: 2px solid var(--maroon); color: var(--maroon); background: var(--maroon-bg); }
.cut-line { position: relative; border-top: 2px dashed var(--ink-soft); margin: 0; display: flex; justify-content: center; }
.cut-line span { position: relative; top: -9px; background: var(--paper); padding: 0 10px; font-size: 11px; color: var(--ink-soft); font-family: var(--mono); }
.receipt-bottom { background: #FBF8F1; }
.status-line { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }

@media print {
  body * { visibility: hidden; }
  #receiptPrintArea, #receiptPrintArea * { visibility: visible; }
  #receiptPrintArea { position: absolute; left: 0; top: 0; width: 100%; padding: 0; margin: 0; background: #fff; }
  .no-print { display: none !important; }
  body { background: #fff; }
}

/* ---------- Setup screen ---------- */
.setup-wrap { max-width: 480px; margin: 60px auto; }
.setup-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 30px 28px; border-top: 5px solid var(--maroon); }
.setup-card h1 { font-size: 22px; color: var(--maroon); margin-bottom: 4px; }
.setup-card p.muted { margin-bottom: 18px; }

/* ---------- Bars (reports) ---------- */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; font-size: 13px; }
.bar-label { width: 160px; flex-shrink: 0; color: var(--ink-soft); }
.bar-track { flex: 1; background: var(--paper-line); border-radius: 5px; height: 14px; overflow: hidden; }
.bar-track .bar-fill { height: 100%; border-radius: 5px; }
.bar-track .bar-fill.income { background: var(--green); }
.bar-track .bar-fill.expense { background: var(--red); }
.bar-amt { width: 100px; text-align: left; font-family: var(--mono); font-size: 12.5px; }

/* ---------- Footer note ---------- */
.foot-note { text-align: center; color: var(--ink-soft); font-size: 12px; margin-top: 28px; }