/* ============================================================================
   UMPK Finance — fin-ui design system  (v2 shell)
   ----------------------------------------------------------------------------
   Layers on Bootstrap 5.3. Design language follows Tabler (spacing scale,
   restrained borders, muted chrome, tabular numerals) in the finance teal.

   NAMESPACE RULE — every class we own is prefixed `fin-`.
   Bootstrap owns .btn/.card/.badge/.row/.table/.nav; we never redefine them,
   we only re-token them. This is why the two can share a page at all, and it
   is the same trick ams-old uses with its `ams-` prefix. Do not add an
   unprefixed class to this file.

   Pages opt in with `$ui2 = true;` before including header.php. Such pages get
   Bootstrap + this file and NOT app.css, so the old and new systems never meet.
   ========================================================================== */

/* ── Tokens ───────────────────────────────────────────────────────────────── */
:root,
[data-bs-theme="light"] {
  /* Brand — finance teal, carried over from app.css unchanged. */
  --fin-brand:        #0f766e;
  --fin-brand-hover:  #0d5f58;
  --fin-brand-active: #0b4a45;
  --fin-brand-soft:   #ccfbf1;
  --fin-brand-ink:    #115e59;

  /* Sidebar */
  --fin-sidebar-bg:     #134e4a;
  --fin-sidebar-text:   #a7cfca;
  --fin-sidebar-hover:  rgba(255,255,255,.08);
  --fin-sidebar-active: #ffffff;
  --fin-sidebar-w:      256px;
  --fin-topbar-h:       58px;

  /* Surfaces */
  --fin-bg:      #f6f8fa;
  --fin-surface: #ffffff;
  --fin-line:    #e6eaef;
  --fin-ink:     #16202c;
  --fin-muted:   #6b7a8d;

  /* Money direction. Never the only signal — every figure using these is also
     prefixed + or −, so the meaning survives colour-blindness and print. */
  --fin-pos:      #15803d;
  --fin-neg:      #b91c1c;
  --fin-pos-soft: #f2fbf5;
  --fin-neg-soft: #fef5f5;
  --fin-pos-line: #cdeed8;
  --fin-neg-line: #f7d5d5;
  /* Caution — a third state that is neither in nor out (duplicate rows, expiring
     contracts). Distinct from --fin-neg so "needs a look" never reads as "wrong". */
  --fin-warn:      #b45309;
  --fin-warn-soft: #fffaf0;

  --fin-radius: .5rem;
  --fin-shadow: 0 1px 2px rgba(16,32,44,.04), 0 1px 3px rgba(16,32,44,.06);

  /* Re-token Bootstrap to the finance palette. Overriding these vars rather
     than the components themselves is what keeps us upgrade-safe. */
  --bs-primary:     #0f766e;
  --bs-primary-rgb: 15, 118, 110;
  --bs-link-color:  #0f766e;
  --bs-link-hover-color: #0d5f58;
  --bs-body-bg:     var(--fin-bg);
  --bs-body-color:  var(--fin-ink);
  --bs-border-color: var(--fin-line);
  --bs-border-radius: var(--fin-radius);
  --bs-font-sans-serif: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
}

[data-bs-theme="dark"] {
  --fin-brand:        #2dd4bf;
  --fin-brand-hover:  #5eead4;
  --fin-brand-active: #99f6e4;
  --fin-brand-soft:   #134e4a;
  --fin-brand-ink:    #99f6e4;

  --fin-sidebar-bg:     #0b1620;
  --fin-sidebar-text:   #8fa3b4;
  --fin-sidebar-hover:  rgba(255,255,255,.06);
  --fin-sidebar-active: #ffffff;

  --fin-bg:      #0f1720;
  --fin-surface: #16202c;
  --fin-line:    #263243;
  --fin-ink:     #e6edf5;
  --fin-muted:   #8fa3b4;

  /* Dark tints are built from the accent at low alpha rather than pale pastels —
     a light-mode tint would glow against a dark surface. */
  --fin-pos:      #4ade80;
  --fin-neg:      #f87171;
  --fin-pos-soft: rgba(74,222,128,.07);
  --fin-neg-soft: rgba(248,113,113,.07);
  --fin-pos-line: rgba(74,222,128,.22);
  --fin-neg-line: rgba(248,113,113,.22);
  --fin-warn:      #fbbf24;
  --fin-warn-soft: rgba(251,191,36,.08);

  --fin-shadow: 0 1px 2px rgba(0,0,0,.3);

  --bs-primary:     #2dd4bf;
  --bs-primary-rgb: 45, 212, 191;
  --bs-link-color:  #5eead4;
  --bs-link-hover-color: #99f6e4;
  --bs-body-bg:     var(--fin-bg);
  --bs-body-color:  var(--fin-ink);
  --bs-border-color: var(--fin-line);
}

/* ── Base ─────────────────────────────────────────────────────────────────── */
/* Alpine sets x-cloak on elements it hasn't initialised yet. Without this the
   mobile backdrop flashes on every page load. */
[x-cloak] { display: none !important; }

body {
  background: var(--fin-bg);
  color: var(--fin-ink);
  font-size: .875rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Money and any figure that stacks in a column must line up digit-to-digit. */
.fin-num, .fin-table td.fin-num, .fin-table th.fin-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ── Layout shell ─────────────────────────────────────────────────────────── */
.fin-layout { display: flex; min-height: 100vh; }

.fin-sidebar {
  width: var(--fin-sidebar-w);
  flex-shrink: 0;
  background: var(--fin-sidebar-bg);
  color: var(--fin-sidebar-text);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.fin-brand {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.fin-brand-logo {
  width: 38px; height: 38px;
  object-fit: contain;
  background: #fff;
  border-radius: .45rem;
  padding: 3px;
  flex-shrink: 0;
}
.fin-brand-text {
  font-size: .8rem;
  font-weight: 700;
  line-height: 1.25;
  color: #fff;
}
.fin-brand-text small {
  display: block;
  font-size: .625rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .09em;
  opacity: .6;
  margin-top: 2px;
}

.fin-nav { padding: .6rem .55rem 1.2rem; }
.fin-nav-group {
  font-size: .625rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  opacity: .45;
  font-weight: 600;
  margin: 1rem .65rem .3rem;
}
.fin-nav-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .5rem .65rem;
  border-radius: .4rem;
  color: var(--fin-sidebar-text);
  font-weight: 500;
  text-decoration: none;
  margin-bottom: 1px;
  transition: background .12s ease, color .12s ease;
}
.fin-nav-link:hover { background: var(--fin-sidebar-hover); color: #fff; }
.fin-nav-link.active {
  background: var(--fin-brand);
  color: #fff;
  font-weight: 600;
}
[data-bs-theme="dark"] .fin-nav-link.active { color: #04211e; }
.fin-nav-link i { font-size: 1rem; width: 1.15rem; text-align: center; opacity: .9; }

.fin-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.fin-topbar {
  height: var(--fin-topbar-h);
  background: var(--fin-surface);
  border-bottom: 1px solid var(--fin-line);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 1030;
}
.fin-topbar h1 { font-size: 1rem; font-weight: 600; margin: 0; }
.fin-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--fin-brand-soft);
  color: var(--fin-brand-ink);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: .8rem;
  flex-shrink: 0;
}
.fin-content { padding: 1.25rem; flex: 1; }
.fin-footer {
  padding: .8rem 1.25rem;
  color: var(--fin-muted);
  font-size: .75rem;
  border-top: 1px solid var(--fin-line);
  background: var(--fin-surface);
}

/* Sidebar toggle — hidden on desktop, shown when the sidebar collapses. */
.fin-sidebar-toggle { display: none; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
/* Bootstrap's .card, re-tokened. Flatter and quieter than stock Bootstrap. */
.card {
  --bs-card-bg: var(--fin-surface);
  --bs-card-border-color: var(--fin-line);
  --bs-card-border-radius: var(--fin-radius);
  --bs-card-cap-bg: transparent;
  --bs-card-spacer-x: 1.15rem;
  --bs-card-spacer-y: 1.15rem;
  box-shadow: var(--fin-shadow);
  margin-bottom: 1.15rem;
}
.card-header {
  border-bottom: 1px solid var(--fin-line);
  padding: .8rem 1.15rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  font-weight: 600;
  font-size: .875rem;
}

/* ── KPI tile ─────────────────────────────────────────────────────────────── */
.fin-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: .9rem;
  margin-bottom: 1.15rem;
}
.fin-kpi {
  background: var(--fin-surface);
  border: 1px solid var(--fin-line);
  border-radius: var(--fin-radius);
  padding: .95rem 1.05rem;
  box-shadow: var(--fin-shadow);
  border-left: 3px solid var(--fin-brand);
}
.fin-kpi.is-blue  { border-left-color: #2563eb; }
.fin-kpi.is-green { border-left-color: #16a34a; }
.fin-kpi.is-amber { border-left-color: #d97706; }
.fin-kpi.is-red   { border-left-color: #dc2626; }
.fin-kpi-label {
  font-size: .6875rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--fin-muted);
  font-weight: 600;
}
.fin-kpi-value {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: .3rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.fin-kpi-sub { font-size: .75rem; color: var(--fin-muted); margin-top: .15rem; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.fin-table {
  --bs-table-bg: var(--fin-surface);
  --bs-table-color: var(--fin-ink);
  --bs-table-border-color: var(--fin-line);
  --bs-table-hover-bg: rgba(15,118,110,.04);
  margin-bottom: 0;
  font-size: .8125rem;
}
[data-bs-theme="dark"] .fin-table { --bs-table-hover-bg: rgba(45,212,191,.06); }
.fin-table > thead > tr > th {
  font-size: .6875rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--fin-muted);
  font-weight: 600;
  background: var(--fin-bg);
  border-bottom: 1px solid var(--fin-line);
  padding: .6rem .9rem;
  white-space: nowrap;
}
.fin-table > tbody > tr > td {
  padding: .6rem .9rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--fin-line);
}
.fin-table > tbody > tr:last-child > td { border-bottom: 0; }

/* Row actions stay quiet until you're on the row — less visual noise on a
   dense grid, still discoverable because the whole row lights up. */
.fin-row-actions { text-align: right; white-space: nowrap; }
.fin-row-actions .btn { opacity: .55; transition: opacity .12s ease; }
tr:hover .fin-row-actions .btn,
.fin-row-actions .btn:focus-visible { opacity: 1; }

.fin-empty {
  text-align: center;
  color: var(--fin-muted);
  padding: 2.5rem 1rem;
}
.fin-empty i { font-size: 1.75rem; opacity: .35; display: block; margin-bottom: .5rem; }

/* ── Detail list ──────────────────────────────────────────────────────────── */
/* Key/value pairs on a record page. Replaces v1's `.row`/`.k`/`.v`, whose bare
   `.row` collided with Bootstrap's grid — hence the fin- prefix here.

   The label sits ABOVE its value, not across a gap from it. Label-left/value-right
   works in one narrow column; across three it strands each label a long way from
   the thing it names and the eye has to zig-zag. Stacked, you read straight down.
   No dividers either — the grid gap already groups the pairs, and 28 hairlines
   made the panel read as a price list. */
.fin-dl {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 1rem 1.5rem;
}
.fin-dl-item { min-width: 0; }
.fin-dl-k {
  display: block;
  font-size: .625rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 600;
  color: var(--fin-muted);
  margin-bottom: .1rem;
}
.fin-dl-v {
  font-size: .8125rem;
  font-weight: 500;
  color: var(--fin-ink);
  word-break: break-word;
}
/* A blank field is the absence of information — it shouldn't cost as much ink as
   a real value. Still present (so the shape of the record is honest), just quiet. */
.fin-dl-v.is-empty { color: var(--fin-muted); font-weight: 400; opacity: .45; }
/* Identifiers are compared digit by digit, same as money — so they get the same
   tabular figures. Applies to CNIC, IBAN, account and NTN numbers. */
.fin-dl-v.is-id { font-variant-numeric: tabular-nums; letter-spacing: .01em; }

/* ── Detail section ───────────────────────────────────────────────────────── */
/* Groups the panel into scannable blocks. The rule + icon give each section a
   real edge; small-caps grey text alone read as one undifferentiated wall. */
.fin-detail-group + .fin-detail-group {
  margin-top: 1.4rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--fin-line);
}
.fin-detail-head {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .6875rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  font-weight: 700;
  color: var(--fin-brand);
  margin-bottom: .85rem;
}
.fin-detail-head i { font-size: .85rem; opacity: .8; }

.fin-section-title {
  font-size: .6875rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--fin-muted);
  font-weight: 700;
  margin: 1.35rem 0 .35rem;
}
.fin-section-title:first-child { margin-top: 0; }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.nav-tabs {
  --bs-nav-tabs-border-color: var(--fin-line);
  --bs-nav-tabs-link-active-color: var(--fin-brand);
  --bs-nav-tabs-link-active-bg: transparent;
  --bs-nav-tabs-link-active-border-color: transparent transparent var(--fin-brand);
  --bs-nav-link-color: var(--fin-muted);
  --bs-nav-link-hover-color: var(--fin-ink);
  --bs-nav-link-font-size: .8125rem;
  border-bottom-width: 2px;
  gap: .15rem;
}
.nav-tabs .nav-link {
  border-width: 0 0 2px;
  margin-bottom: -2px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.nav-tabs .nav-link.active { border-bottom-width: 2px; }

/* ── Payslip breakdown ────────────────────────────────────────────────────── */
/* Basic pay leads because every percentage component derives from it; then three
   columns — what's added, what's taken, and how that resolves to net. Figures
   share a right edge in every column so they compare digit by digit. */
/* Basic pay rides in the card header: every percentage component is derived from
   it, so it belongs with the title rather than as a fourth block competing with
   the three columns. */
.fin-basic-tag {
  display: inline-block;
  margin-left: .4rem;
  padding: .1rem .5rem;
  border-radius: 1rem;
  background: var(--fin-brand-soft);
  color: var(--fin-brand-ink);
  border: 1px solid var(--fin-brand);
  font-size: .6875rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  vertical-align: middle;
}

.fin-payslip-cols {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  align-items: start;
}
/* Each column is tinted by what it does to pay: money in is green, money out is
   red, and the calculation stays neutral because it's the result, not a
   direction. Tints are faint on purpose — the figures must stay the loudest
   thing in the card, and every value is also signed (+ / −) so the meaning does
   not depend on colour alone. */
.fin-payslip-col {
  min-width: 0;
  border: 1px solid var(--fin-line);
  border-radius: var(--fin-radius);
  padding: .1rem .9rem .9rem;
}
.fin-payslip-col.is-allow {
  background: var(--fin-pos-soft);
  border-color: var(--fin-pos-line);
}
.fin-payslip-col.is-deduct {
  background: var(--fin-neg-soft);
  border-color: var(--fin-neg-line);
}
.fin-payslip-col.is-calc { background: var(--fin-bg); }
.fin-payslip-col .fin-section-title { margin-top: .8rem; }
/* Separators inside a tinted block need to read against the tint, not the page. */
.fin-payslip-col.is-allow .fin-payslip-line { border-bottom-color: var(--fin-pos-line); }
.fin-payslip-col.is-deduct .fin-payslip-line { border-bottom-color: var(--fin-neg-line); }

/* A rate tag, not a value: distinguishes "45%" the rule from "83,430" the money. */
.fin-pct {
  font-size: .625rem;
  font-weight: 600;
  color: var(--fin-muted);
  background: var(--fin-bg);
  border: 1px solid var(--fin-line);
  border-radius: 1rem;
  padding: 0 .35rem;
  margin-left: .2rem;
  white-space: nowrap;
}
.fin-payslip-col.is-calc .fin-pct { background: var(--fin-surface); }

@media (max-width: 900px) {
  .fin-payslip-cols { grid-template-columns: 1fr; gap: .5rem; }
  .fin-payslip-col.is-calc { margin-top: .6rem; }
}

.fin-payslip-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.5rem;
  padding: .5rem 0;
  border-bottom: 1px solid var(--fin-line);
  font-size: .8125rem;
}
.fin-payslip-line > span:first-child { color: var(--fin-muted); }
.fin-payslip-line.is-subtotal {
  font-weight: 600;
  border-bottom-width: 2px;
}
.fin-payslip-line.is-subtotal > span:first-child { color: var(--fin-ink); }
.fin-payslip-line.is-net {
  border-bottom: 0;
  border-top: 2px solid var(--fin-brand);
  margin-top: .25rem;
  padding-top: .7rem;
  font-size: 1.05rem;
  font-weight: 700;
}
.fin-payslip-line.is-net > span:first-child { color: var(--fin-ink); }
.fin-payslip-line.is-net > span:last-child { color: var(--fin-brand); }

/* ── Totals row ───────────────────────────────────────────────────────────── */
.fin-table tr.fin-total > td {
  border-top: 2px solid var(--fin-line);
  font-weight: 700;
  background: var(--fin-bg);
}

/* ── Utilisation bar ──────────────────────────────────────────────────────── */
/* Inline mini progress bar for budget utilisation. State classes (ok/warn/bad)
   are what budgetUtilClass() returns, so pages pass them straight through. */
.fin-ubar { display: inline-block; width: 110px; height: 8px; border-radius: 6px; background: var(--fin-line); overflow: hidden; vertical-align: middle; }
.fin-ubar span { display: block; height: 100%; background: var(--fin-brand); }
.fin-ubar span.ok   { background: var(--fin-pos); }
.fin-ubar span.warn { background: var(--fin-warn); }
.fin-ubar span.bad  { background: var(--fin-neg); }
.fin-kpi .fin-ubar { width: 100%; margin-top: 6px; }

/* ── Workflow tracker ─────────────────────────────────────────────────────── */
/* Horizontal status tracker for approval chains (voucher, receipt, budget:
   Draft→Submitted→Checked→Approved→Paid). Distinct from the wizard stepper —
   this one shows who did each step and when, and reflects a record's state
   rather than driving navigation. */
.fin-track { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 0; }
.fin-track-step { flex: 1; min-width: 120px; text-align: center; position: relative; }
.fin-track-dot {
  width: 30px; height: 30px;
  border-radius: 50%;
  margin: 0 auto;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: .8rem;
  background: var(--fin-line);
  color: var(--fin-muted);
}
.fin-track-step.is-done .fin-track-dot { background: var(--fin-brand); color: #fff; }
[data-bs-theme="dark"] .fin-track-step.is-done .fin-track-dot { color: #04211e; }
.fin-track-lbl { font-size: .75rem; font-weight: 600; margin-top: 6px; color: var(--fin-muted); }
.fin-track-step.is-done .fin-track-lbl { color: var(--fin-ink); }
.fin-track-meta { font-size: .65rem; color: var(--fin-muted); }

/* ── Toolbar ──────────────────────────────────────────────────────────────── */
.fin-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: 1.15rem;
}
.fin-toolbar form { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn { --bs-btn-font-size: .8125rem; --bs-btn-font-weight: 500; }
.btn-primary {
  --bs-btn-bg: var(--fin-brand);
  --bs-btn-border-color: var(--fin-brand);
  --bs-btn-hover-bg: var(--fin-brand-hover);
  --bs-btn-hover-border-color: var(--fin-brand-hover);
  --bs-btn-active-bg: var(--fin-brand-active);
  --bs-btn-active-border-color: var(--fin-brand-active);
  --bs-btn-disabled-bg: var(--fin-brand);
  --bs-btn-disabled-border-color: var(--fin-brand);
}
[data-bs-theme="dark"] .btn-primary {
  --bs-btn-color: #04211e;
  --bs-btn-hover-color: #04211e;
  --bs-btn-active-color: #04211e;
}
.btn-outline-secondary {
  --bs-btn-color: var(--fin-muted);
  --bs-btn-border-color: var(--fin-line);
  --bs-btn-hover-bg: var(--fin-bg);
  --bs-btn-hover-color: var(--fin-ink);
  --bs-btn-hover-border-color: var(--fin-line);
}

/* ── Badges ───────────────────────────────────────────────────────────────── */
/* Soft badges — a dense grid of saturated pills is unreadable. */
.fin-badge {
  display: inline-block;
  padding: .2rem .5rem;
  border-radius: 1rem;
  font-size: .6875rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}
.fin-badge.is-ok    { background: #dcfce7; color: #14532d; }
.fin-badge.is-warn  { background: #fef3c7; color: #78350f; }
.fin-badge.is-bad   { background: #fee2e2; color: #7f1d1d; }
.fin-badge.is-info  { background: #dbeafe; color: #1e3a8a; }
.fin-badge.is-muted { background: #e9eef3; color: #475569; }
.fin-badge.is-brand { background: var(--fin-brand-soft); color: var(--fin-brand-ink); }
[data-bs-theme="dark"] .fin-badge.is-ok    { background: #14532d; color: #bbf7d0; }
[data-bs-theme="dark"] .fin-badge.is-warn  { background: #78350f; color: #fde68a; }
[data-bs-theme="dark"] .fin-badge.is-bad   { background: #7f1d1d; color: #fecaca; }
[data-bs-theme="dark"] .fin-badge.is-info  { background: #1e3a8a; color: #bfdbfe; }
[data-bs-theme="dark"] .fin-badge.is-muted { background: #263243; color: #cbd5e1; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-control, .form-select {
  --bs-body-bg: var(--fin-surface);
  border-color: var(--fin-line);
  font-size: .8125rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--fin-brand);
  box-shadow: none;
}
.form-label { font-size: .75rem; font-weight: 600; color: var(--fin-muted); margin-bottom: .25rem; }

/* ── Flash messages ───────────────────────────────────────────────────────── */
.fin-flash {
  padding: .7rem 1rem;
  border-radius: var(--fin-radius);
  margin-bottom: 1rem;
  font-size: .8125rem;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: .55rem;
}
.fin-flash.is-success { background: #dcfce7; border-color: #bbf7d0; color: #14532d; }
.fin-flash.is-error   { background: #fee2e2; border-color: #fecaca; color: #7f1d1d; }
.fin-flash.is-info    { background: #dbeafe; border-color: #bfdbfe; color: #1e3a8a; }
.fin-flash.is-warning { background: #fef3c7; border-color: #fde68a; color: #78350f; }

/* ── Toast notifications (floating, top-right — see finToast() in fin-ui.js) ─ */
.fin-toast-host {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  pointer-events: none;
}
.fin-toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  min-width: 260px;
  max-width: 360px;
  padding: .75rem 1rem;
  border-radius: var(--fin-radius);
  border: 1px solid transparent;
  background: var(--fin-surface);
  color: var(--fin-ink);
  box-shadow: var(--fin-shadow), 0 10px 25px rgba(2,6,23,.14);
  font-size: .8125rem;
  font-weight: 600;
  line-height: 1.4;
  transform: translateX(120%);
  opacity: 0;
  transition: transform .28s ease, opacity .28s ease;
}
.fin-toast.is-shown   { transform: translateX(0); opacity: 1; }
.fin-toast.is-leaving { transform: translateX(120%); opacity: 0; }
.fin-toast .fin-toast-icon { flex: 0 0 auto; font-size: 1rem; line-height: 1.4; }
.fin-toast .fin-toast-msg  { flex: 1 1 auto; }
.fin-toast .fin-toast-close {
  flex: 0 0 auto;
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
  opacity: .55;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}
.fin-toast .fin-toast-close:hover { opacity: 1; }
.fin-toast.is-success { background: var(--fin-pos-soft); border-color: var(--fin-pos-line); color: var(--fin-pos); }
.fin-toast.is-error   { background: var(--fin-neg-soft); border-color: var(--fin-neg-line); color: var(--fin-neg); }
.fin-toast.is-warning { background: var(--fin-warn-soft); border-color: var(--fin-warn); color: var(--fin-warn); }
.fin-toast.is-info    { background: var(--fin-brand-soft); border-color: var(--fin-brand); color: var(--fin-brand-ink); }
@media (max-width: 480px) {
  .fin-toast-host { left: 1rem; right: 1rem; }
  .fin-toast { max-width: none; }
}

/* ── Confirm modal (data-fin-confirm, replaces native confirm()) ───────────── */
.fin-confirm-modal {
  border: none;
  border-radius: calc(var(--fin-radius) * 2);
  background: var(--fin-surface);
  color: var(--fin-ink);
  box-shadow: 0 24px 60px rgba(16,32,44,.28);
}
.fin-confirm-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto .9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--fin-neg-soft);
  color: var(--fin-neg);
  font-size: 1.4rem;
}
.fin-confirm-msg { font-weight: 600; font-size: .9375rem; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 992px) {
  .fin-sidebar {
    position: fixed;
    left: 0; top: 0;
    z-index: 1045;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.3);
  }
  .fin-sidebar.is-open { transform: translateX(0); }
  .fin-sidebar-toggle { display: inline-flex; }
  .fin-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 1040;
  }
}
@media (max-width: 576px) {
  .fin-content { padding: .9rem; }
  .fin-kpis { grid-template-columns: 1fr; }
  .fin-toolbar, .fin-toolbar form { width: 100%; }
  .fin-toolbar .form-control, .fin-toolbar .form-select { width: 100%; }
}

/* ── Print ────────────────────────────────────────────────────────────────── */
/* ── Modal (native <dialog>) ──────────────────────────────────────────────── */
/* The app's modal convention: a native <dialog class="fin-modal"> — the browser
   gives Esc, focus-trap and backdrop for free. Renamed from the v1 `.modal`
   because Bootstrap OWNS `.modal` (display:none + fixed) and would hide the
   dialog outright. Structure: .modal-head / .modal-body / .modal-foot / .modal-x. */
dialog.fin-modal {
  padding: 0; border: 0; border-radius: var(--fin-radius);
  box-shadow: 0 24px 60px rgba(16,32,44,.28);
  width: min(680px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
  background: var(--fin-surface); color: var(--fin-ink); overflow: visible;
}
dialog.fin-modal::backdrop { background: rgba(16,32,44,.55); }
dialog.fin-modal[open] { display: flex; flex-direction: column; animation: fin-modal-in .14s ease-out; }
@keyframes fin-modal-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.fin-modal .modal-head { padding: 16px 20px; border-bottom: 1px solid var(--fin-line); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-shrink: 0; }
.fin-modal .modal-head h2 { font-size: 16px; margin: 0; font-weight: 600; }
.fin-modal .modal-head .sub { font-size: .78rem; color: var(--fin-muted); margin-top: 2px; }
.fin-modal .modal-body { padding: 20px; overflow-y: auto; flex: 1; min-height: 0; }
.fin-modal .modal-foot { padding: 14px 20px; border-top: 1px solid var(--fin-line); display: flex; gap: 10px; justify-content: flex-end; flex-shrink: 0; background: var(--fin-bg); border-radius: 0 0 var(--fin-radius) var(--fin-radius); flex-wrap: wrap; }
.fin-modal .modal-x { position: absolute; top: 10px; right: 12px; margin: 0; }
.fin-modal .modal-x button { border: 0; background: transparent; font-size: 20px; line-height: 1; color: var(--fin-muted); cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.fin-modal .modal-x button:hover { background: var(--fin-bg); color: var(--fin-ink); }
@media (max-width: 520px) {
  dialog.fin-modal { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .fin-modal .modal-foot { border-radius: 0; }
  .fin-modal .modal-foot .btn { flex: 1; justify-content: center; }
}

/* ── Printable document ───────────────────────────────────────────────────── */
/* Formal single-page documents: payment voucher, official receipt, and future
   accounting print-outs. Shared scaffold lives here; each page keeps only its
   own amount block inline. Namespaced .fin-doc — the v1 pages used bare `.doc`. */
.fin-doc .doc-head { display: flex; align-items: center; gap: 16px; border-bottom: 2px solid var(--fin-brand); padding-bottom: 14px; }
.fin-doc .doc-head img { width: 66px; height: 66px; object-fit: contain; }
.fin-doc .doc-title { flex: 1; }
.fin-doc .uni { font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
.fin-doc .dir { color: var(--fin-muted); font-size: 13px; }
.fin-doc .dt { margin-top: 6px; font-weight: 700; letter-spacing: .12em; color: var(--fin-brand-ink); font-size: 13px; }
.fin-doc .doc-meta { font-size: 12.5px; min-width: 180px; }
.fin-doc .doc-meta div { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
.fin-doc .doc-meta span { color: var(--fin-muted); }
.fin-doc table.kv { width: 100%; border-collapse: collapse; margin: 18px 0; font-size: 13.5px; }
.fin-doc table.kv td { padding: 8px 10px; border: 1px solid var(--fin-line); vertical-align: top; }
.fin-doc table.kv td.l { background: var(--fin-bg); color: var(--fin-muted); width: 140px; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.fin-doc .words { margin-top: 10px; font-size: 13px; }
.fin-doc .sigs { display: grid; gap: 22px; margin-top: 54px; }
.fin-doc .sig { text-align: center; }
.fin-doc .sig .line { border-top: 1px solid var(--fin-ink); margin-bottom: 6px; }
.fin-doc .sig .role { font-size: 12px; font-weight: 600; }
.fin-doc .sig .who { font-size: 11.5px; color: var(--fin-muted); }
.fin-doc .foot { margin-top: 26px; text-align: center; color: var(--fin-muted); font-size: 11px; }
@media print { .fin-doc { box-shadow: none; border: none; max-width: 100%; } }

/* Multilingual question text — Urdu (Nastaliq) and Sindhi (Naskh-style Arabic)
   read right-to-left and need script-appropriate fonts; plain Bootstrap text
   renders them but shapes the script poorly. */
.lang-ur, .lang-sd {
  direction: rtl;
  text-align: right;
  unicode-bidi: isolate;
}
.lang-ur { font-family: 'Noto Nastaliq Urdu', serif; line-height: 2; }
.lang-sd { font-family: 'Noto Naskh Arabic', serif; }
.lang-en { text-align: left; } /* explicit — overrides an ancestor's text-center, e.g. a table row */

/* Print utilities — reports and payslips print across several modules. */
.fin-print-only { display: none; }   /* shown on paper, hidden on screen */
@media print {
  .fin-sidebar, .fin-topbar, .fin-toolbar, .fin-footer, .fin-row-actions,
  .fin-no-print { display: none !important; }
  .fin-print-only { display: flex !important; }
  .fin-content { padding: 0; }
  .card { box-shadow: none; border: 0; }
}
