/* =====================================================================
   Components: cards, KPIs, tables, badges, modals, tabs, kanban,
   ledger matrix, timeline, charts, states
   ===================================================================== */

/* ------------------------------------------------------------- cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.card:hover { box-shadow: var(--shadow); }
.card + .card { margin-top: var(--sp-4); }
.card-head {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border-soft);
}
.card-head h3 { font-size: .98rem; }
.card-head .sub { font-size: .78rem; color: var(--ink-faint); margin-top: 2px; }
.card-head .actions { margin-inline-start: auto; display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.card-body { padding: var(--sp-5); }
.card-body.tight { padding: var(--sp-3) var(--sp-4); }
.card-body.flush { padding: 0; }
.card-foot {
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border-soft);
  background: var(--surface-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
  display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap;
}

.grid { display: grid; gap: var(--sp-4); }
/* A grid item may not refuse to shrink, or a wide table inside it
   blows the whole row past the viewport. */
.grid > * { min-width: 0; }

/* k2/k3/k4 name the *maximum* column count: the tracks stay fluid and drop
   to fewer columns when narrow, but never pack more than N on a wide screen. */
.grid.k2 { grid-template-columns: repeat(auto-fit, minmax(max(320px, calc((100% - 1 * var(--sp-4)) / 2)), 1fr)); }
.grid.k3 { grid-template-columns: repeat(auto-fit, minmax(max(258px, calc((100% - 2 * var(--sp-4)) / 3)), 1fr)); }
.grid.k4 { grid-template-columns: repeat(auto-fit, minmax(max(214px, calc((100% - 3 * var(--sp-4)) / 4)), 1fr)); }

.grid.split-2-1 { grid-template-columns: 2fr 1fr; align-items: start; }
@media (max-width: 980px) { .grid.split-2-1 { grid-template-columns: 1fr; } }

/* --------------------------------------------------------- KPI cards */
.kpi {
  position: relative;
  padding: var(--sp-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
  text-align: start;
  font-family: inherit;
  width: 100%;
  display: block;
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--brand-200); }
[data-theme='dark'] .kpi:hover { border-color: var(--border-strong); }

/* The card stays plain; its tone is carried by the tile behind the glyph. */
.kpi.k-navy  .kpi-icon { background: var(--tone-navy-bg);  color: var(--tone-navy-ink); }
.kpi.k-green .kpi-icon { background: var(--tone-green-bg); color: var(--tone-green-ink); }
.kpi.k-red   .kpi-icon { background: var(--tone-red-bg);   color: var(--tone-red-ink); }
.kpi.k-blue  .kpi-icon { background: var(--tone-blue-bg);  color: var(--tone-blue-ink); }
.kpi-top { display: flex; align-items: flex-start; gap: var(--sp-3); }
.kpi-label {
  font-size: .74rem; font-weight: 640; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-muted); line-height: 1.35;
}
.kpi-icon {
  width: 40px; height: 40px; flex: none;
  border-radius: var(--r); background: var(--tone-navy-bg);
  display: grid; place-items: center; color: var(--tone-navy-ink);
}
/* In the dashboard KPI header the icon is trailing; elsewhere it leads. */
.kpi-top .kpi-icon { margin-inline-start: auto; }
.kpi-icon .ic { width: 19px; height: 19px; }
.kpi-value {
  margin-top: var(--sp-3);
  font-size: 1.62rem; font-weight: 700; letter-spacing: -.025em;
  color: var(--ink-strong); font-variant-numeric: tabular-nums; line-height: 1.1;
}
.kpi-value .cur { font-size: .8rem; font-weight: 600; color: var(--ink-faint); margin-inline-end: 3px; }
.kpi-foot { margin-top: var(--sp-2); display: flex; align-items: center; gap: var(--sp-2); font-size: .77rem; color: var(--ink-faint); flex-wrap: wrap; }
.trend { display: inline-flex; align-items: center; gap: 3px; font-weight: 650; }
.trend .ic { width: 14px; height: 14px; }
.trend.up { color: var(--green-600); } .trend.down { color: var(--red-600); } .trend.flat { color: var(--ink-faint); }
[data-theme='dark'] .trend.up { color: var(--green-500); }
[data-theme='dark'] .trend.down { color: var(--red-500); }

/* ------------------------------------------------- quick action rows */
/* A full-width row whose glyph rides on a tone tile, matching the KPI tiles. */
.btn.qa {
  justify-content: flex-start;
  gap: var(--sp-3);
  padding: 7px 10px;
  min-height: 46px;
  font-weight: 580;
}
/* The quick-action row lifts with a shadow instead of the button halo. */
.btn.qa { --btn-bg-hover: var(--surface); --btn-border-hover: var(--brand-200); --btn-ring: transparent; }
.btn.qa:hover:not(:disabled):not([aria-disabled='true']) { box-shadow: var(--shadow-sm); }
[data-theme='dark'] .btn.qa { --btn-bg-hover: var(--surface-2); --btn-border-hover: var(--border-strong); }

.qa-tile {
  width: 30px; height: 30px; flex: none;
  border-radius: var(--r-sm);
  display: grid; place-items: center;
  background: var(--tone-navy-bg); color: var(--tone-navy-ink);
}
.qa-tile .ic { width: 16px; height: 16px; }
.qa-tile.t-green { background: var(--tone-green-bg); color: var(--tone-green-ink); }
.qa-tile.t-red   { background: var(--tone-red-bg);   color: var(--tone-red-ink); }
.qa-tile.t-blue  { background: var(--tone-blue-bg);  color: var(--tone-blue-ink); }
.qa-tile.t-amber { background: var(--tone-amber-bg); color: var(--tone-amber-ink); }

.stat-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); padding: 9px 0; border-bottom: 1px solid var(--border-soft); }
.stat-row:last-child { border-bottom: 0; }
.stat-row .k { font-size: .82rem; color: var(--ink-muted); }
.stat-row .v { font-weight: 660; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: .73rem; font-weight: 620; letter-spacing: .01em;
  background: var(--surface-3); color: var(--ink-muted);
  white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-green  { background: var(--st-paid-bg);    color: var(--st-paid-ink); }
.badge-amber  { background: var(--st-partial-bg); color: var(--st-partial-ink); }
.badge-red    { background: var(--st-unpaid-bg);  color: var(--st-unpaid-ink); }
.badge-blue   { background: var(--st-advance-bg); color: var(--st-advance-ink); }
.badge-gray   { background: var(--st-exempt-bg);  color: var(--st-exempt-ink); }
.badge-purple { background: var(--st-adjust-bg);  color: var(--st-adjust-ink); }
.badge-gold   { background: var(--brand-100);      color: var(--accent-ink); }
[data-theme='dark'] .badge-gold { background: var(--accent-soft); color: var(--brand-300); }
.badge-lg { padding: 4px 12px; font-size: .8rem; }

/* ------------------------------------------------------------ tables */
.table-wrap { width: 100%; overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .87rem; }
table.tbl th {
  padding: 10px var(--sp-4);
  text-align: start;
  font-size: .7rem; font-weight: 660; letter-spacing: .07em; text-transform: uppercase;
  color: var(--ink-faint);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky; top: 0; z-index: 2;
}
table.tbl th.sortable { cursor: pointer; user-select: none; }
table.tbl th.sortable:hover { color: var(--ink); }
table.tbl th .sort-ind { opacity: .5; margin-inline-start: 3px; }
table.tbl td { padding: 10px var(--sp-4); border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl tbody tr.clickable { cursor: pointer; }
table.tbl tbody tr:last-child td { border-bottom: 0; }
table.tbl td.num, table.tbl th.num { text-align: end; font-variant-numeric: tabular-nums; }
table.tbl .cell-main { font-weight: 600; color: var(--ink-strong); }
table.tbl .cell-sub { font-size: .76rem; color: var(--ink-faint); }
table.tbl tfoot td { padding: 10px var(--sp-4); font-weight: 680; background: var(--surface-2); border-top: 2px solid var(--border); }

/* mobile card view for wide tables */
.cards-list { display: none; }
@media (max-width: 760px) {
  .tbl-responsive .table-wrap { display: none; }
  .tbl-responsive .cards-list { display: grid; gap: var(--sp-2); }
  .rec-card {
    border: 1px solid var(--border); border-radius: var(--r);
    padding: var(--sp-3) var(--sp-4); background: var(--surface);
  }
  .rec-card .rc-head { display: flex; justify-content: space-between; gap: var(--sp-2); align-items: flex-start; }
  .rec-card .rc-title { font-weight: 640; color: var(--ink-strong); }
  .rec-card .rc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px var(--sp-3); margin-top: var(--sp-2); }
  .rec-card .rc-grid .k { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-faint); }
  .rec-card .rc-grid .v { font-size: .85rem; }
  .rec-card .rc-actions { margin-top: var(--sp-3); display: flex; gap: var(--sp-2); flex-wrap: wrap; }
}

/* --------------------------------------------------------- filter bar */
.filters {
  display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center;
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-soft);
}
.filters .input, .filters .select { min-height: 34px; padding: 5px 10px; font-size: .82rem; width: auto; }
.filters .select { padding-inline-end: 28px; }
.search-box { position: relative; flex: 1 1 220px; max-width: 340px; }
.search-box .ic { position: absolute; inset-inline-start: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--ink-faint); pointer-events: none; }
.search-box .input { width: 100%; padding-inline-start: 32px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 4px 11px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface);
  font-size: .78rem; font-weight: 560; color: var(--ink-muted);
  cursor: pointer; font-family: inherit;
  transition: all var(--dur) var(--ease);
}
.chip:hover { border-color: var(--brand-300); color: var(--ink); }
.chip.active { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
[data-theme='dark'] .chip.active { background: var(--brand-500); border-color: var(--brand-500); }

.pagination { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.pagination .pinfo { font-size: .8rem; color: var(--ink-muted); margin-inline-end: auto; }

/* ------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  padding: 10px var(--sp-4);
  border: 0; border-bottom: 2px solid transparent;
  background: transparent; color: var(--ink-muted);
  font: inherit; font-size: .85rem; font-weight: 580;
  cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--brand-700); border-bottom-color: var(--brand-600); font-weight: 650; }
[data-theme='dark'] .tab.active { color: var(--brand-300); border-bottom-color: var(--brand-400); }

/* ------------------------------------------------------------ modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(15, 23, 42, .5);
  backdrop-filter: blur(2px);
  display: grid; place-items: center;
  padding: var(--sp-4);
  animation: fade-in 140ms var(--ease);
  overflow-y: auto;
}
.modal {
  width: min(680px, 100%);
  max-height: min(88vh, 900px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  animation: modal-in 180ms var(--ease);
  margin: auto;
}
.modal.wide { width: min(1000px, 100%); }
.modal.narrow { width: min(460px, 100%); }
.modal-head {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border-soft);
}
.modal-head h3 { font-size: 1.02rem; }
.modal-head .sub { font-size: .8rem; color: var(--ink-faint); margin-top: 2px; }
.modal-head .close { margin-inline-start: auto; }
.modal-body { padding: var(--sp-5); overflow-y: auto; flex: 1; }
.modal-foot {
  display: flex; gap: var(--sp-2); justify-content: flex-end; flex-wrap: wrap;
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border-soft);
  background: var(--surface-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}
@keyframes fade-in { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(.985); } }

/* drawer (right side panel) */
.drawer-backdrop { position: fixed; inset: 0; z-index: 55; background: rgba(15,23,42,.45); backdrop-filter: blur(2px); animation: fade-in 140ms var(--ease); }
.drawer {
  position: fixed; inset-block: 0; inset-inline-end: 0; z-index: 56;
  width: min(560px, 100%);
  background: var(--surface); border-inline-start: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  animation: drawer-in 200ms var(--ease);
}
@keyframes drawer-in { from { transform: translateX(100%); } }
[dir='rtl'] .drawer { animation-name: drawer-in-rtl; }
@keyframes drawer-in-rtl { from { transform: translateX(-100%); } }

/* ------------------------------------------------------------ toasts */
.toasts {
  position: fixed; z-index: 80;
  inset-block-end: var(--sp-5); inset-inline-end: var(--sp-5);
  display: flex; flex-direction: column; gap: var(--sp-2);
  max-width: min(390px, calc(100vw - 32px));
}
.toast {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--brand-500);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  animation: toast-in 200ms var(--ease);
  font-size: .87rem;
}
.toast.success { border-inline-start-color: var(--green-500); }
.toast.error   { border-inline-start-color: var(--red-500); }
.toast.warning { border-inline-start-color: var(--amber-500); }
.toast .ic { width: 17px; height: 17px; flex: none; margin-top: 2px; }
.toast.success .ic { color: var(--green-600); }
.toast.error .ic   { color: var(--red-600); }
.toast.warning .ic { color: var(--amber-600); }
.toast b { display: block; font-weight: 640; margin-bottom: 1px; }
.toast .x { margin-inline-start: auto; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
@media (max-width: 620px) {
  .toasts { inset-block-end: calc(var(--bottomnav-h) + 12px); inset-inline: 12px; max-width: none; }
}

/* ------------------------------------------------------------ states */
.empty, .error-state {
  padding: var(--sp-8) var(--sp-5);
  text-align: center;
  color: var(--ink-muted);
}
.empty .ic, .error-state .ic { width: 38px; height: 38px; color: var(--ink-faint); opacity: .6; margin-bottom: var(--sp-3); }
.empty h4, .error-state h4 { margin-bottom: 4px; color: var(--ink); }
.empty p, .error-state p { font-size: .87rem; max-width: 420px; margin: 0 auto var(--sp-4); }

.skel { background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: var(--r-xs); }
.skel-line { height: 12px; margin-bottom: 9px; }
.skel-line.w60 { width: 60%; } .skel-line.w40 { width: 40%; } .skel-line.w80 { width: 80%; }
.skel-card { height: 116px; border-radius: var(--r-lg); }
@keyframes shimmer { to { background-position: -200% 0; } }

.spinner {
  width: 17px; height: 17px; flex: none;
  border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress { height: 7px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.progress > span {
  display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--green-500), color-mix(in srgb, var(--green-500) 55%, var(--brand-400)));
  transition: width 420ms var(--ease);
}
.progress.gold > span { background: var(--brand-500); }
.progress.amber > span { background: var(--amber-500); }
.progress.red > span { background: var(--red-500); }

/* --------------------------------------------------------- banners */
.banner {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: .87rem;
}
.banner .ic { width: 18px; height: 18px; flex: none; }
.banner.ok    { background: color-mix(in srgb, var(--green-100) 42%, var(--surface)); border-color: color-mix(in srgb, var(--green-500) 26%, transparent); color: var(--green-600); }
.banner.warn  { background: color-mix(in srgb, var(--amber-100) 42%, var(--surface)); border-color: color-mix(in srgb, var(--amber-500) 26%, transparent); color: var(--amber-600); }
.banner.bad   { background: color-mix(in srgb, var(--red-100) 42%, var(--surface));   border-color: color-mix(in srgb, var(--red-500) 26%, transparent);   color: var(--red-600); }
.banner.info  { background: color-mix(in srgb, var(--blue-100) 42%, var(--surface));  border-color: color-mix(in srgb, var(--blue-500) 26%, transparent);  color: var(--blue-600); }
[data-theme='dark'] .banner.ok { color: var(--green-500); }
[data-theme='dark'] .banner.warn { color: var(--amber-500); }
[data-theme='dark'] .banner.bad { color: var(--red-500); }
[data-theme='dark'] .banner.info { color: var(--blue-500); }

/* --------------------------------------------------- ledger matrix */
.ledger-wrap { overflow: auto; max-height: 68vh; }
table.matrix { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .82rem; }
table.matrix th, table.matrix td { padding: 6px 8px; border-bottom: 1px solid var(--border-soft); white-space: nowrap; }
table.matrix thead th {
  position: sticky; top: 0; z-index: 3;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
  font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-faint); font-weight: 660;
  text-align: center;
}
table.matrix thead th.name-col, table.matrix tbody td.name-col {
  position: sticky; inset-inline-start: 0; z-index: 2;
  background: var(--surface); text-align: start;
  border-inline-end: 1px solid var(--border);
  min-width: 200px;
}
table.matrix thead th.name-col { z-index: 4; background: var(--surface-2); }
table.matrix tbody tr:hover td { background: var(--surface-2); }
table.matrix tbody tr:hover td.name-col { background: var(--surface-2); }
.m-cell {
  display: block; width: 100%;
  min-width: 42px; padding: 5px 4px;
  border: 1px solid transparent; border-radius: var(--r-xs);
  font: inherit; font-size: .74rem; font-weight: 620; font-variant-numeric: tabular-nums;
  cursor: pointer; text-align: center;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.m-cell:hover { transform: scale(1.07); box-shadow: var(--shadow); z-index: 1; position: relative; }
.m-paid     { background: var(--st-paid-bg);    color: var(--st-paid-ink); }
.m-partial  { background: var(--st-partial-bg); color: var(--st-partial-ink); }
.m-unpaid   { background: var(--st-unpaid-bg);  color: var(--st-unpaid-ink); }
.m-advance  { background: var(--st-advance-bg); color: var(--st-advance-ink); }
.m-exempted { background: var(--st-exempt-bg);  color: var(--st-exempt-ink); }
.m-adjusted { background: var(--st-adjust-bg);  color: var(--st-adjust-ink); }
/* a month that has not fallen due yet is neutral, never "unpaid" red */
.m-future   { background: transparent; color: var(--ink-faint); border-color: var(--border-soft); }
.legend-list { display: flex; gap: var(--sp-4); flex-wrap: wrap; font-size: .78rem; color: var(--ink-muted); }
.legend-list span { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 13px; height: 13px; border-radius: 3px; display: inline-block; }

/* ------------------------------------------------------------ kanban */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(288px, 1fr); gap: var(--sp-4); overflow-x: auto; padding-bottom: var(--sp-3); align-items: start; }
.kcol { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-lg); display: flex; flex-direction: column; max-height: 74vh; }
.kcol-head { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); }
.kcol-head h4 { font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-muted); }
.kcol-head .count { margin-inline-start: auto; background: var(--surface-3); color: var(--ink-muted); border-radius: 999px; padding: 1px 8px; font-size: .72rem; font-weight: 700; }
.kcol-head .stage-dot { width: 8px; height: 8px; border-radius: 50%; }
.kcol-body { padding: var(--sp-3); overflow-y: auto; display: flex; flex-direction: column; gap: var(--sp-2); }
.kcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: var(--sp-3); cursor: pointer; text-align: start; font-family: inherit; color: inherit;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.kcard:hover { border-color: var(--brand-300); box-shadow: var(--shadow); transform: translateY(-1px); }
.kcard .kc-top { display: flex; align-items: center; gap: var(--sp-2); }
.kcard .kc-code { font-size: .74rem; font-weight: 700; color: var(--brand-600); letter-spacing: .02em; }
[data-theme='dark'] .kcard .kc-code { color: var(--brand-300); }
.kcard .kc-name { font-weight: 600; font-size: .87rem; margin-top: 4px; }
.kcard .kc-meta { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-2); font-size: .74rem; color: var(--ink-faint); }
.kcard .kc-amount { margin-inline-start: auto; font-weight: 680; color: var(--ink); font-variant-numeric: tabular-nums; }

/* SLA meter */
.sla { display: inline-flex; align-items: center; gap: 6px; font-size: .74rem; font-weight: 620; }
.sla .bulb { width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 18%, transparent); }
.sla.green  { color: var(--green-600); }
.sla.amber  { color: var(--amber-600); }
.sla.red, .sla.breached { color: var(--red-600); }
.sla.met    { color: var(--green-600); }
[data-theme='dark'] .sla.green, [data-theme='dark'] .sla.met { color: var(--green-500); }
[data-theme='dark'] .sla.amber { color: var(--amber-500); }
[data-theme='dark'] .sla.red, [data-theme='dark'] .sla.breached { color: var(--red-500); }
.sla .bulb { background: currentColor; }
.sla-panel { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: var(--sp-3); }
.sla-panel .cell { padding: var(--sp-3); background: var(--surface-2); border-radius: var(--r); border: 1px solid var(--border-soft); }
.sla-panel .cell .k { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); }
.sla-panel .cell .v { font-size: 1.05rem; font-weight: 680; margin-top: 3px; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------- approval tracker */
.appr-track { display: flex; flex-direction: column; gap: var(--sp-2); }
.appr-slot {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3);
  border: 1px solid var(--border); border-radius: var(--r);
  background: var(--surface-2);
}
.appr-slot .num {
  width: 30px; height: 30px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-3); color: var(--ink-faint);
  font-weight: 700; font-size: .82rem;
}
.appr-slot.approved { border-color: color-mix(in srgb, var(--green-500) 42%, transparent); background: var(--green-100); }
.appr-slot.approved .num { background: var(--green-500); color: #fff; }
.appr-slot.rejected { border-color: color-mix(in srgb, var(--red-500) 42%, transparent); background: var(--red-100); }
.appr-slot.rejected .num { background: var(--red-500); color: #fff; }
.appr-slot .who { font-weight: 620; font-size: .87rem; }
.appr-slot .when { font-size: .74rem; color: var(--ink-faint); }
.appr-slot .state { margin-inline-start: auto; }

/* ---------------------------------------------------------- timeline */
.timeline { position: relative; padding-inline-start: var(--sp-5); }
.timeline::before {
  content: ''; position: absolute; inset-block: 6px 6px; inset-inline-start: 6px;
  width: 2px; background: var(--border);
}
.tl-item { position: relative; padding-bottom: var(--sp-4); }
.tl-item::before {
  content: ''; position: absolute; inset-inline-start: calc(var(--sp-5) * -1 + 2px); top: 5px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--brand-300);
}
.tl-item.done::before { background: var(--green-500); border-color: var(--green-500); }
.tl-item.active::before { background: var(--brand-500); border-color: var(--brand-500); box-shadow: 0 0 0 4px var(--accent-soft); }
.tl-item .tl-title { font-weight: 620; font-size: .88rem; }
.tl-item .tl-meta { font-size: .76rem; color: var(--ink-faint); }
.tl-item .tl-body { font-size: .84rem; color: var(--ink-muted); margin-top: 3px; }

/* roadmap */
.roadmap { display: grid; gap: var(--sp-3); }
.rm-item {
  display: flex; gap: var(--sp-4); align-items: flex-start;
  padding: var(--sp-4);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface);
}
.rm-item.active { border-color: var(--brand-300); background: linear-gradient(180deg, var(--accent-soft), var(--surface) 70%); }
.rm-num {
  width: 38px; height: 38px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700;
  background: var(--surface-3); color: var(--ink-muted);
}
.rm-item.active .rm-num { background: var(--brand-600); color: #fff; }

/* ------------------------------------------------------------ charts */
.chart-box { position: relative; width: 100%; }
.chart-box canvas { display: block; width: 100%; }
.chart-legend { display: flex; gap: var(--sp-4); flex-wrap: wrap; margin-top: var(--sp-3); font-size: .78rem; color: var(--ink-muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--ink-strong); color: var(--bg);
  padding: 6px 10px; border-radius: var(--r-sm);
  font-size: .76rem; font-weight: 560; white-space: nowrap;
  box-shadow: var(--shadow-lg); opacity: 0; transition: opacity 120ms var(--ease);
}
.chart-tip.show { opacity: 1; }

/* --------------------------------------------------- misc utilities */
/* A form section: heading, optional one-line note, then the field grid. */
.form-section + .form-section { margin-top: var(--sp-6); }
.form-section .divider-label { margin-top: 0; }
.section-sub { margin: -4px 0 var(--sp-4); font-size: .8rem; color: var(--ink-faint); }

.divider-label { display: flex; align-items: center; gap: var(--sp-3); margin: var(--sp-5) 0 var(--sp-3); }
.divider-label span { font-size: .72rem; font-weight: 680; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); }
.divider-label::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.quote-card {
  position: relative;
  display: flex; flex-direction: column;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 100% 0%, rgba(255, 255, 255, .16), transparent 60%),
    linear-gradient(135deg, var(--brand-600), var(--indigo-600));
  color: #fff; border-radius: var(--r-lg); padding: var(--sp-6) var(--sp-5) var(--sp-5);
  border: 1px solid transparent;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
/* Light rule along the leading edge, plus a faint ornament in the corner. */
.quote-card::before {
  content: ''; position: absolute; inset-block: 0; inset-inline-start: 0; width: 3px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .7), transparent);
}
.quote-card::after {
  content: '۞'; position: absolute; top: 2px; inset-inline-end: 14px;
  font-family: var(--font-arabic); font-size: 2.4rem; line-height: 1;
  color: rgba(255, 255, 255, .18); pointer-events: none;
}
.quote-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.quote-card .arabic {
  display: block;
  font-family: var(--font-arabic);
  font-size: clamp(1.25rem, 1.05rem + .8vw, 1.6rem);
  line-height: 2.05;
  direction: rtl; unicode-bidi: isolate; text-align: right;
  color: #fff;
  text-wrap: balance;
}
.quote-card .tr {
  display: block;
  position: relative;
  margin-top: var(--sp-4); padding-top: var(--sp-4);
  font-size: .89rem; line-height: 1.65;
  color: rgba(255, 255, 255, .84);
  unicode-bidi: isolate;
  border-top: 1px solid rgba(255, 255, 255, .24);
}
.quote-card .ref {
  display: block;
  margin-top: auto; padding-top: var(--sp-4);
  font-size: .74rem; font-weight: 600; letter-spacing: .04em;
  color: rgba(255, 255, 255, .78); unicode-bidi: isolate;
}

/* Urdu translations need the Nastaliq face and its taller leading. */
[dir='rtl'] .quote-card .tr { font-family: var(--font-ur); line-height: 2.1; text-align: right; }
[dir='rtl'] .quote-card .ref { text-align: right; }

@media (prefers-reduced-motion: reduce) {
  .quote-card, .quote-card:hover { transition: none; transform: none; }
}

.kv { display: grid; grid-template-columns: minmax(120px, 34%) 1fr; gap: 7px var(--sp-4); font-size: .87rem; }
.kv dt { color: var(--ink-faint); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.kv dd { margin: 0; font-weight: 550; word-break: break-word; }

.doc-tile {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3); border: 1px solid var(--border); border-radius: var(--r);
  background: var(--surface-2); font-size: .85rem;
}
.doc-tile .ic { width: 20px; height: 20px; color: var(--ink-faint); flex: none; }

/* ------------------------------------------- document cards & viewer */
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(206px, 1fr)); gap: var(--sp-4); }

.doc-card {
  display: flex; flex-direction: column;
  min-width: 0; padding: 0; overflow: hidden;
  font: inherit; color: inherit; text-align: start; cursor: pointer;
  background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.doc-card:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-2px); }
.doc-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.doc-thumb {
  position: relative;
  aspect-ratio: 4 / 3;
  display: grid; place-items: center;
  overflow: hidden;
  background: var(--surface-3);
  border-bottom: 1px solid var(--border);
}
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.doc-thumb .ph { display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--ink-faint); }
.doc-thumb .ph .ic { width: 30px; height: 30px; }
.doc-thumb .ph span { font-size: .7rem; font-weight: 680; letter-spacing: .08em; }

/* Magnifier badge: hinted on hover, always visible on touch. */
.doc-zoom {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(15, 23, 42, .45);
  color: #fff; opacity: 0;
  transition: opacity var(--dur) var(--ease);
}
.doc-zoom .ic { width: 26px; height: 26px; }
.doc-card:hover .doc-zoom, .doc-card:focus-visible .doc-zoom { opacity: 1; }

.doc-meta { display: flex; flex-direction: column; gap: 2px; padding: var(--sp-3); min-width: 0; }
.doc-meta > * { min-width: 0; }

.doc-viewer { display: grid; place-items: center; }
.doc-viewer img {
  max-width: 100%; max-height: 68vh; object-fit: contain;
  border-radius: var(--r); background: var(--surface-3);
}
.doc-viewer iframe { width: 100%; height: 68vh; border: 0; border-radius: var(--r); background: var(--surface-3); }
.doc-fallback { display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); padding: var(--sp-7) var(--sp-4); text-align: center; }
.doc-fallback .ic { width: 40px; height: 40px; color: var(--ink-faint); }

@media (hover: none) {
  .doc-zoom { opacity: 1; background: linear-gradient(180deg, transparent 55%, rgba(15, 23, 42, .5)); align-items: end; padding-bottom: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .doc-card, .doc-card:hover { transition: none; transform: none; }
}

.copy-field {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-3); border: 1px dashed var(--brand-300); border-radius: var(--r);
  background: var(--accent-soft); font-family: var(--font-mono); font-size: .9rem; font-weight: 600;
  color: var(--accent-ink); word-break: break-all;
}

/* ---------------------------------------------------------- date picker */
/* The panel is a body-level fixed layer, so a scrolling modal body cannot
   clip it and no z-index war with the modal is needed. */
.dp-wrap { position: relative; display: block; }
.dp-wrap .dp-input { padding-inline-end: 40px; cursor: pointer; }

.dp-trigger {
  position: absolute;
  inset-inline-end: 6px;
  inset-block-start: 50%;
  transform: translateY(-50%);
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border: 0; border-radius: var(--r-xs);
  background: transparent; color: var(--ink-faint); cursor: pointer;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.dp-wrap:hover .dp-trigger, .dp-input:focus ~ .dp-trigger { color: var(--accent-ink); }
.dp-trigger:hover { background: var(--surface-3); }

.dp-panel {
  position: fixed;
  z-index: 70;                        /* over modals (60) and drawers (56), under toasts (80) */
  width: 296px;
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: dp-in 120ms var(--ease);
}
@keyframes dp-in { from { opacity: 0; transform: translateY(-4px); } }
@media (prefers-reduced-motion: reduce) { .dp-panel { animation: none; } }

.dp-head { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-3); }

/* The title doubles as the drill-out control: month view, then a year page. */
.dp-title {
  flex: 1; min-width: 0;
  display: flex; align-items: center; justify-content: center; gap: 4px;
  height: 34px; padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-strong);
  font: inherit; font-size: .9rem; font-weight: 650;
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.dp-title:hover:not(:disabled) { background: var(--surface-3); }
.dp-title:disabled { cursor: default; }
.dp-title:disabled .dp-caret { display: none; }
.dp-title:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 1px; }
.dp-caret { width: 15px; height: 15px; color: var(--ink-faint); }
.dp-title-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dp-nav {
  width: 30px; height: 30px; flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  background: var(--surface);
  color: var(--ink-muted);
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.dp-nav:hover:not(:disabled) { background: var(--surface-3); color: var(--ink); }
.dp-nav:disabled { opacity: .35; cursor: not-allowed; }

.dp-week, .dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dp-grid.cells { grid-template-columns: repeat(3, 1fr); gap: 6px; }
.dp-week[hidden] { display: none; }

.dp-cell {
  min-height: 44px;
  display: grid; place-items: center;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit; font-size: .85rem; font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.dp-cell:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border-strong); }
.dp-cell:disabled { opacity: .35; cursor: not-allowed; }
.dp-cell:focus-visible { outline: 2px solid var(--brand-500); outline-offset: -1px; }
.dp-cell.today { border-color: var(--brand-300); color: var(--accent-ink); }
.dp-cell.on, .dp-cell.on:hover:not(:disabled) {
  background: var(--brand-600); border-color: var(--brand-600); color: #fff;
}
[data-theme='dark'] .dp-cell.on, [data-theme='dark'] .dp-cell.on:hover:not(:disabled) {
  background: var(--brand-500); border-color: var(--brand-500);
}
.dp-week {
  margin-bottom: 4px;
  font-size: .68rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--ink-faint); text-align: center;
}

.dp-day {
  aspect-ratio: 1;
  display: grid; place-items: center;
  border: 1px solid transparent;
  border-radius: var(--r-xs);
  background: transparent;
  color: var(--ink);
  font: inherit; font-size: .84rem; font-weight: 550;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.dp-day.out { color: var(--ink-faint); }
.dp-day.weekend:not(.on) { color: var(--red-600); }
[data-theme='dark'] .dp-day.weekend:not(.on) { color: var(--red-500); }
.dp-day.weekend.out:not(.on) { opacity: .5; }
.dp-day:hover:not(:disabled) { background: var(--surface-3); }
.dp-day:disabled { opacity: .3; cursor: not-allowed; }
.dp-day:focus-visible { outline: 2px solid var(--brand-500); outline-offset: -1px; }

/* Today is outlined; the selected day is filled — so both can show at once. */
.dp-day.today { border-color: var(--brand-300); color: var(--accent-ink); font-weight: 700; }
.dp-day.on, .dp-day.on:hover:not(:disabled) {
  background: var(--brand-600); border-color: var(--brand-600); color: #fff; font-weight: 650;
}
[data-theme='dark'] .dp-day.on, [data-theme='dark'] .dp-day.on:hover:not(:disabled) {
  background: var(--brand-500); border-color: var(--brand-500);
}

.dp-foot {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: var(--sp-3); padding-top: var(--sp-2);
  border-top: 1px solid var(--border-soft);
}
.dp-link {
  border: 0; background: transparent; padding: 4px 6px; border-radius: var(--r-xs);
  font: inherit; font-size: .8rem; font-weight: 620; color: var(--accent-ink); cursor: pointer;
}
.dp-link.muted { color: var(--ink-faint); }
.dp-link:hover { background: var(--surface-3); }

/* Phones: a docked sheet beats a popup pinned to a cramped field. The class is
   set by the picker itself — see `position()` in datepicker.js. */
.dp-panel.sheet {
  inset-block-start: auto;
  inset-block-end: 0;
  inset-inline: 0;
  width: auto;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: var(--sp-4) var(--sp-4) var(--sp-5);
  animation: dp-up 150ms var(--ease);
}
.dp-panel.sheet .dp-day { font-size: .95rem; }
@keyframes dp-up { from { transform: translateY(12px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .dp-panel.sheet { animation: none; } }

/* Nastaliq weekday names need room that Latin initials do not. */
.dp-week span { min-height: 18px; }

/* --------------------------------------------- trilingual article text */
/* The constitution shows every article in English, Urdu script and Roman
   Urdu together. Each block is self-contained so it can carry its own
   direction and font without the others inheriting them. */
.tri-text { display: flex; flex-direction: column; gap: var(--sp-4); }

.tri-part { padding-inline-start: var(--sp-4); border-inline-start: 3px solid var(--border); }
.tri-part[dir='rtl'] { text-align: right; }
.tri-part:nth-child(1) { border-inline-start-color: var(--brand-400); }
.tri-part:nth-child(2) { border-inline-start-color: var(--green-500); }
.tri-part:nth-child(3) { border-inline-start-color: var(--amber-500); }

.tri-tag {
  display: inline-block;
  margin-bottom: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--ink-muted);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  line-height: 1.7;
}
.tri-part[dir='rtl'] .tri-tag { text-transform: none; letter-spacing: 0; }

.tri-part h4 { margin: 0 0 4px; font-size: .92rem; color: var(--ink-strong); }
.tri-part p { margin: 0; font-size: .88rem; color: var(--ink-muted); line-height: 1.75; }
/* `.ur-text` is an inline-block badge elsewhere; here it is the paragraph. */
.tri-part .ur-text { display: block; }
/* Nastaliq carries far less ink per point than Latin, so the Urdu block needs
   a larger size and more leading to read at the same comfort. */
.tri-part[dir='rtl'] h4 { font-size: 1.05rem; line-height: 2; }
.tri-part[dir='rtl'] p { font-size: 1.02rem; line-height: 2.25; }

@media (max-width: 620px) {
  .tri-part { padding-inline-start: var(--sp-3); }
}

/* ------------------------------------------------------ member profile */
/* A family head's own page: a cover-and-avatar header over two columns of
   cards, who they are on the narrow side, their family and papers on the
   wide one. */
.profile { display: flex; flex-direction: column; gap: var(--sp-4); }
.profile .card + .card { margin-top: 0; }
.profile .card { scroll-margin-top: calc(var(--header-h) + var(--sp-3)); }
.profile .badge .ic { width: 11px; height: 11px; fill: currentColor; }

.profile-hero { overflow: hidden; }
.profile-cover {
  position: relative;
  height: 132px;
  background:
    radial-gradient(90% 140% at 100% 0%, rgba(255, 255, 255, .2), transparent 55%),
    radial-gradient(60% 120% at 0% 100%, rgba(255, 255, 255, .1), transparent 60%),
    linear-gradient(135deg, var(--brand-600), var(--indigo-600));
}
[data-theme='dark'] .profile-cover {
  background:
    radial-gradient(90% 140% at 100% 0%, rgba(255, 255, 255, .12), transparent 55%),
    linear-gradient(135deg, var(--brand-800), var(--indigo-600));
}
.profile-cover::after {
  content: '۞'; position: absolute; top: 12px; inset-inline-end: 24px;
  font-family: var(--font-arabic); font-size: 3.4rem; line-height: 1;
  color: rgba(255, 255, 255, .16); pointer-events: none;
}

.profile-head {
  display: flex; align-items: flex-start; gap: var(--sp-5); flex-wrap: wrap;
  padding: 0 var(--sp-6) var(--sp-5);
}
/* Only the avatar rides up onto the cover; the name stays on the card. */
.profile-avatar-wrap { position: relative; flex: none; margin-top: -58px; }
.profile-avatar {
  position: relative; overflow: hidden;
  width: 116px; height: 116px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand-500), var(--indigo-500));
  color: #fff; font-size: 2.3rem; font-weight: 700; letter-spacing: .02em;
  border: 4px solid var(--surface);
  box-shadow: var(--shadow);
}
.profile-avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.profile-avatar-edit {
  position: absolute; bottom: 4px; inset-inline-end: 4px;
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; overflow: hidden;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border-strong); box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.profile-avatar-edit:hover { background: var(--accent-soft); color: var(--accent-ink); }
.profile-avatar-edit .ic { width: 16px; height: 16px; }

/* The picker lies invisibly over its button, so it keeps keyboard focus. */
.file-btn { position: relative; overflow: hidden; }
.file-overlay { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.profile-avatar-edit:focus-within, .file-btn:focus-within { outline: 2px solid var(--brand-500); outline-offset: 2px; }

.profile-id { flex: 1 1 300px; min-width: 0; padding-top: var(--sp-4); }
.profile-id h2 { font-size: 1.5rem; line-height: 1.25; }
.profile-name-ur { font-size: 1.02rem; color: var(--ink-muted); }
.profile-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px var(--sp-4);
  margin-top: var(--sp-2);
  font-size: .84rem; color: var(--ink-muted);
}
.profile-meta > span { display: inline-flex; align-items: center; gap: 6px; }
.profile-meta .ic { width: 15px; height: 15px; color: var(--ink-faint); }
.profile-code {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: 999px;
  border: 1px solid var(--brand-200); background: var(--brand-50); color: var(--accent-ink);
  font-weight: 650; cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.profile-code:hover { background: var(--brand-100); }
.profile-meta .profile-code .ic { width: 13px; height: 13px; color: currentColor; opacity: .7; }
[data-theme='dark'] .profile-code { background: var(--accent-soft); border-color: var(--border-strong); color: var(--brand-300); }
[data-theme='dark'] .profile-code:hover { background: var(--surface-3); }
.profile-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--sp-3); }
.profile-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; padding-top: var(--sp-4); margin-inline-start: auto; }

.profile-stats {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--border-soft);
  background: var(--surface-2);
}
.profile-stat {
  display: flex; align-items: center; gap: var(--sp-3); min-width: 0;
  padding: var(--sp-4) var(--sp-5);
  border: 0; background: transparent; color: inherit; font: inherit; text-align: start;
  cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.profile-stat + .profile-stat { border-inline-start: 1px solid var(--border-soft); }
.profile-stat:hover { background: var(--surface-3); }
.profile-stat:focus-visible { outline-offset: -2px; }
.profile-stat-text { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.profile-stat-text b { font-size: 1.15rem; font-weight: 700; line-height: 1.25; color: var(--ink-strong); }
.profile-stat-text span { font-size: .76rem; line-height: 1.35; color: var(--ink-muted); }

.profile-grid { display: grid; grid-template-columns: minmax(300px, 360px) minmax(0, 1fr); gap: var(--sp-4); align-items: start; }
.profile-col { display: flex; flex-direction: column; gap: var(--sp-4); min-width: 0; }

.info-list { list-style: none; margin: 0; padding: 0; }
.info-row { display: flex; align-items: center; gap: var(--sp-3); padding: 10px 0; }
.info-row:first-child { padding-top: 0; }
.info-row:last-child { padding-bottom: 0; }
.info-row + .info-row { border-top: 1px solid var(--border-soft); }
.info-ic {
  width: 34px; height: 34px; flex: none; border-radius: var(--r-sm);
  display: grid; place-items: center;
  background: var(--surface-3); color: var(--ink-muted);
}
.info-ic .ic { width: 16px; height: 16px; }
.info-text { display: flex; flex-direction: column; align-items: flex-start; flex: 1; min-width: 0; }
.info-label { font-size: .74rem; line-height: 1.4; color: var(--ink-faint); }
.info-value { max-width: 100%; font-size: .9rem; font-weight: 580; line-height: 1.45; color: var(--ink); word-break: break-word; }
.info-sub { font-size: .8rem; color: var(--ink-muted); }

.member-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--sp-3); }
.member-card {
  display: flex; align-items: center; gap: var(--sp-3); min-width: 0;
  padding: var(--sp-3);
  border: 1px solid var(--border); border-radius: var(--r);
  background: var(--surface-2);
}
.member-card .avatar { width: 46px; height: 46px; font-size: .92rem; }
.avatar.tone-navy  { background: var(--tone-navy-bg);  color: var(--tone-navy-ink); }
.avatar.tone-green { background: var(--tone-green-bg); color: var(--tone-green-ink); }
.avatar.tone-blue  { background: var(--tone-blue-bg);  color: var(--tone-blue-ink); }
.avatar.tone-amber { background: var(--tone-amber-bg); color: var(--tone-amber-ink); }
.member-info { flex: 1; min-width: 0; }
.member-name { font-weight: 640; line-height: 1.3; color: var(--ink-strong); }
.member-name-ur { font-size: .86rem; color: var(--ink-muted); }
.member-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 5px; font-size: .78rem; color: var(--ink-muted); }
.member-donor { display: inline-flex; color: var(--red-500); }
.member-donor .ic { width: 14px; height: 14px; fill: currentColor; }

.fact-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--sp-3); }
.fact {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border-soft); border-radius: var(--r);
  background: var(--surface-2);
}
.fact-k { font-size: .74rem; color: var(--ink-faint); }
.fact-v { max-width: 100%; font-size: .95rem; font-weight: 650; color: var(--ink-strong); word-break: break-word; }

.profile-empty {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4);
  border: 1px dashed var(--border-strong); border-radius: var(--r);
  background: var(--surface-2); color: var(--ink-muted);
}
.profile-empty > .ic { width: 26px; height: 26px; color: var(--ink-faint); }
.profile-empty b { display: block; font-weight: 600; color: var(--ink); }
.profile-empty span { font-size: .8rem; }

/* Nastaliq labels need their taller leading. */
[dir='rtl'] .info-label, [dir='rtl'] .info-value, [dir='rtl'] .fact-k, [dir='rtl'] .fact-v,
[dir='rtl'] .profile-stat-text span { line-height: 1.9; }

@media (max-width: 1100px) {
  .profile-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .profile-cover { height: 104px; }
  .profile-head { flex-direction: column; align-items: center; gap: var(--sp-2); padding: 0 var(--sp-4) var(--sp-4); text-align: center; }
  .profile-avatar-wrap { margin-top: -52px; }
  .profile-avatar { width: 100px; height: 100px; font-size: 2rem; }
  .profile-id { flex: none; width: 100%; padding-top: 0; }
  .profile-id h2 { font-size: 1.3rem; }
  .profile-meta, .profile-badges { justify-content: center; }
  .profile-actions { width: 100%; margin-inline-start: 0; padding-top: var(--sp-2); }
  .profile-actions .btn { flex: 1 1 0; }
  .profile-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .profile-stat { padding: var(--sp-3) var(--sp-4); }
  .profile-stat + .profile-stat { border-inline-start: 0; }
  .profile-stat:nth-child(even) { border-inline-start: 1px solid var(--border-soft); }
  .profile-stat:nth-child(n + 3) { border-top: 1px solid var(--border-soft); }
}
