/* ═══════════════════════════════════════════════════
   FINANCE MANAGER — sub-tabs, stat cards, tables, modals
   Reuses existing design tokens (--border, --text-*, --green, --red,
   --amber, --accent, --font-mono) already defined in lms-app.css.

   Design intent: this is a ledger — a working tool an accountant reads
   numbers off of all day, not a marketing surface. Every money/numeric
   value in Finance renders in --font-mono (tabular figures) so columns
   of PKR amounts line up and scan quickly; this mirrors the .td-mono
   convention already used elsewhere in the app, applied consistently
   here instead of ad hoc. Stat cards get a top accent bar keyed to
   financial polarity (green = inflow, red = outflow, amber = pending/
   warning, neutral = informational) — a small structural device that
   encodes real meaning rather than decorating. Everything below is
   scoped under .fin-section / .fin-* so it never bleeds into the
   shared .data-table styling used by the rest of the app.
═══════════════════════════════════════════════════ */

/* ── Sub-tab bar ─────────────────────────────────────────────────────── */
.fin-subtabs {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  margin-bottom: 1.3rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: .9rem;
}

.fin-subtab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: .78rem;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 7px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
  white-space: nowrap;
}

.fin-subtab:hover {
  background: var(--bg-subtle);
  border-color: var(--border-mid);
  color: var(--text-primary);
}

.fin-subtab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.fin-section { display: none; }
.fin-section.active { display: block; }

/* ── Overview panel sub-tabs (School Overview / Finance Overview) ──────
   Same visual language as the Finance sub-tabs above, reused generically
   so the Overview panel doesn't need its own duplicate CSS block. */
.ov-subtabs {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  margin-bottom: 1.3rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: .9rem;
}

.ov-subtab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: .78rem;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 7px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
  white-space: nowrap;
}

.ov-subtab:hover {
  background: var(--bg-subtle);
  border-color: var(--border-mid);
  color: var(--text-primary);
}

.ov-subtab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.ov-section { display: none; }
.ov-section.active { display: block; }

.fin-quick-actions {
  display: flex;
  gap: .7rem;
  margin-bottom: 1.2rem;
  flex-wrap: wrap;
}

.fin-setup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
@media (max-width: 900px) {
  .fin-setup-grid { grid-template-columns: 1fr; }
}
.fin-step-label {
  font-size: .76rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: .5rem;
}

/* ── Stat cards ──────────────────────────────────────────────────────── */
.fin-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}

.fin-stat-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem .95rem;
  overflow: hidden;
}

/* Polarity accent bar — the module's one signature device */
.fin-stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--border-mid);
}
.fin-stat-card:has(.fin-stat-value.positive)::before { background: var(--green); }
.fin-stat-card:has(.fin-stat-value.negative)::before { background: var(--red); }
.fin-stat-card:has(.fin-stat-value.warning)::before  { background: var(--amber); }

.fin-stat-label {
  font-size: .7rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: .4rem;
}

.fin-stat-value {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}

.fin-stat-value.positive { color: var(--green); }
.fin-stat-value.negative { color: var(--red); }
.fin-stat-value.warning  { color: var(--amber); }

/* ── Status pills ────────────────────────────────────────────────────── */
.pill-unpaid   { background: var(--red-light);   color: var(--red); }
.pill-partial  { background: var(--amber-light); color: var(--amber); }
.pill-paid     { background: var(--green-light); color: var(--green); }
.pill-waived   { background: var(--bg-subtle);   color: var(--text-secondary); }
.pill-draft    { background: var(--bg-subtle);   color: var(--text-secondary); }
.pill-issued   { background: var(--accent-light); color: var(--accent); }

/* ── Tables (scoped to Finance only — does not touch the shared
   .data-table styling used elsewhere in the app) ───────────────────── */
.fin-section .table-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: auto;
  max-height: 70vh;
}

.fin-section .data-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-subtle);
}

.fin-section .data-table tbody tr:nth-child(even) td {
  background: var(--bg);
}
.fin-section .data-table tbody tr:hover td {
  background: var(--accent-light);
}

/* Numeric/money cells — any <td> whose row is inside a Finance table.
   Money values already come through as plain "PKR 1,234" text from
   fmtMoney(); this makes every such cell align on tabular-width digits
   without needing to touch the JS string output itself. */
.fin-section .data-table td {
  font-family: var(--font-mono);
  font-size: .78rem;
  font-variant-numeric: tabular-nums;
}
/* ...except the first couple of columns, which are almost always names/
   labels/dates rather than amounts — restore the body font there so
   student names, categories, remarks etc. stay legible prose, not mono. */
.fin-section .data-table td.fin-label,
.fin-section .data-table td:first-child {
  font-family: var(--font);
  font-size: .8rem;
}

.fin-section .data-table tfoot td,
.fin-section .data-table tr.fin-totals-row td {
  font-weight: 700;
  background: var(--bg-subtle);
  border-top: 2px solid var(--border-mid);
}

/* View-toggle buttons (Expenses: List / By Account Head / Exp Report by Type) */
.fin-section .btn-secondary.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Deposit / Withdrawal type toggle in Record Transaction */
.fin-txn-type-btn.active#bt-type-deposit {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.fin-txn-type-btn.active#bt-type-withdrawal {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

/* Muted text-link style for rare, low-emphasis destructive actions
   (e.g. "Deactivate" on a bank account) — deliberately lighter than a
   solid button so it doesn't visually compete with primary actions like
   Record Transaction that sit right next to it. */
.fin-section .btn-link-muted {
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: .76rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px 0;
}
.fin-section .btn-link-muted:hover {
  color: var(--red);
}

/* Placeholder cross-links (Class List, Contact Us, etc.) — read as
   "not built yet" rather than a broken/dead button. */
.fin-section .btn-secondary[disabled] {
  opacity: .5;
  cursor: not-allowed;
  background: transparent;
}

/* ── Modal overlay reused for receipt + record-payment dialogs ──────── */
.fin-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.fin-modal-overlay.open { display: flex; }

.fin-modal {
  background: var(--bg-card);
  border-radius: 14px;
  padding: 1.4rem;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}

/* Wider variant for forms with a 2-column grid (e.g. withdraw student) —
   the default 420px squeezes form-grid-2 into a single cramped column. */
.fin-modal-lg {
  max-width: 760px;
}

/* ── Invoice picker rows (Collect, when a student has 2+ outstanding fees) ── */
.fin-picker-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: .7rem .9rem;
  margin-bottom: .5rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-size: .85rem;
  text-align: left;
  color: var(--text-primary);
}
.fin-picker-row:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}
.fin-picker-row:last-child { margin-bottom: 0; }

/* ── Printable receipt ───────────────────────────────────────────────── */
.fin-receipt {
  font-size: .85rem;
  line-height: 1.5;
}
.fin-receipt-header {
  text-align: center;
  border-bottom: 2px dashed var(--border);
  padding-bottom: .8rem;
  margin-bottom: .8rem;
}
.fin-receipt-school {
  font-weight: 800;
  font-size: 1.05rem;
}
.fin-receipt-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
}
.fin-receipt-row span:last-child {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.fin-receipt-total {
  border-top: 1px solid var(--border);
  margin-top: .6rem;
  padding-top: .6rem;
  font-weight: 800;
  display: flex;
  justify-content: space-between;
}
.fin-receipt-total span:last-child {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* Invoice modal — sized close to real A4 width so the on-screen preview
   matches what prints, rather than the narrow 420px default. */
.fin-invoice-modal {
  max-width: 780px;
  padding: 0;
  background: #f4f3f0;
}
.fin-invoice-modal > div:first-child {
  background: #fff;
  padding: 40px 48px;
  margin: 1rem;
  border: 0.5px solid var(--border);
}
.fin-invoice-modal > div:last-child {
  padding: 0 1rem 1rem;
}

@media print {
  body * { visibility: hidden; }
  #fin-receipt-overlay, #fin-receipt-overlay *,
  #fin-invoice-overlay, #fin-invoice-overlay *,
  #fin-slips-overlay, #fin-slips-overlay *,
  #ps-view-overlay, #ps-view-overlay * { visibility: visible; }
  #fin-receipt-overlay, #fin-invoice-overlay, #fin-slips-overlay, #ps-view-overlay {
    position: absolute; inset: 0; background: #fff;
  }
  #fin-receipt-overlay .btn,
  #fin-invoice-overlay .btn,
  #fin-slips-overlay .btn,
  #ps-view-overlay .btn { display: none; }
  .fin-invoice-modal { max-width: 100%; background: #fff; }
  .fin-invoice-modal > div:first-child { margin: 0; border: none; padding: 20px 32px; }
  .fin-slip { page-break-after: always; }
  .fin-slip:last-child { page-break-after: auto; }
}

/* ── Reduced motion ──────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .fin-subtab { transition: none; }
}
