/* =========================================================================
   Fund Management — design system (vanilla CSS, light + dark)
   ========================================================================= */
:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #f8f8f6;
  --surface-3: #eff0ec;
  --border: #e3e4df;
  --border-strong: #cfd1ca;
  --text: #15171a;
  --text-2: #4f534f;
  --text-3: #7a7e78;
  --brand: #1f6f5c;
  --brand-strong: #17584a;
  --brand-soft: #e3f1ec;
  --on-brand: #ffffff;
  --income: #2a78d6;
  --income-soft: #e4effc;
  --expense: #eb6834;
  --expense-soft: #fdece4;
  --good: #0a7d0a;
  --good-soft: #e3f4e3;
  --warning: #9a6400;
  --warning-soft: #fdf2d8;
  --critical: #c22f2f;
  --critical-soft: #fbe6e6;
  --info-soft: #e8eefb;
  --chart-grid: #ecece8;
  --chart-text: #52514e;
  --shadow-sm: 0 1px 2px rgba(16, 24, 20, .06);
  --shadow: 0 1px 3px rgba(16, 24, 20, .08), 0 6px 24px rgba(16, 24, 20, .06);
  --shadow-lg: 0 20px 60px rgba(16, 24, 20, .22);
  --radius: 14px;
  --radius-sm: 9px;
  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --mono: ui-monospace, 'SFMono-Regular', Consolas, monospace;
  --sidebar-w: 248px;
  --topbar-h: 60px;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121312; --surface: #1a1a19; --surface-2: #20211f; --surface-3: #272825;
    --border: #2f302d; --border-strong: #42443f;
    --text: #f2f2ef; --text-2: #c3c2b7; --text-3: #8e8d85;
    --brand: #3fae90; --brand-strong: #5cc4a7; --brand-soft: #173a31; --on-brand: #06120f;
    --income: #3987e5; --income-soft: #172a42; --expense: #d95926; --expense-soft: #3a2117;
    --good: #3cc63c; --good-soft: #15301a; --warning: #f0b23a; --warning-soft: #3a2e14;
    --critical: #ef6b6b; --critical-soft: #3c1b1b; --info-soft: #1c2638;
    --chart-grid: #2b2c29; --chart-text: #c3c2b7;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 6px 24px rgba(0, 0, 0, .3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121312; --surface: #1a1a19; --surface-2: #20211f; --surface-3: #272825;
  --border: #2f302d; --border-strong: #42443f;
  --text: #f2f2ef; --text-2: #c3c2b7; --text-3: #8e8d85;
  --brand: #3fae90; --brand-strong: #5cc4a7; --brand-soft: #173a31; --on-brand: #06120f;
  --income: #3987e5; --income-soft: #172a42; --expense: #d95926; --expense-soft: #3a2117;
  --good: #3cc63c; --good-soft: #15301a; --warning: #f0b23a; --warning-soft: #3a2e14;
  --critical: #ef6b6b; --critical-soft: #3c1b1b; --info-soft: #1c2638;
  --chart-grid: #2b2c29; --chart-text: #c3c2b7;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 6px 24px rgba(0, 0, 0, .3);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 14.5px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.55rem; font-weight: 700; }
h2 { font-size: 1.12rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0 0 .6em; }
small, .muted { color: var(--text-3); }
.text-2 { color: var(--text-2); }
code, .mono { font-family: var(--mono); font-size: .88em; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------------- shell: public ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { max-width: 1240px; margin: 0 auto; height: 100%; display: flex; align-items: center; gap: 18px; padding: 0 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--brand); color: var(--on-brand); font-size: 17px;
}
.brand small { display: block; font-weight: 500; font-size: 11.5px; color: var(--text-3); line-height: 1.1; }
.topnav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.topnav a {
  padding: 8px 12px; border-radius: 9px; color: var(--text-2); font-weight: 500; white-space: nowrap;
}
.topnav a:hover { background: var(--surface-3); text-decoration: none; color: var(--text); }
.topnav a.active { background: var(--brand-soft); color: var(--brand-strong); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.page { max-width: 1240px; margin: 0 auto; padding: 26px 20px 60px; }
.footer { max-width: 1240px; margin: 0 auto; padding: 18px 20px 30px; color: var(--text-3); font-size: 12.5px; }

/* ---------------- shell: admin ---------------- */
.admin-shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--surface);
  border-right: 1px solid var(--border); padding: 16px 12px 24px; display: flex; flex-direction: column; gap: 4px;
}
.sidebar .brand { padding: 4px 8px 16px; }
.nav-group { margin-top: 10px; }
.nav-group-title { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); padding: 6px 10px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px;
  color: var(--text-2); font-weight: 500;
}
.nav-link .ico { width: 20px; text-align: center; opacity: .85; }
.nav-link:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--brand-soft); color: var(--brand-strong); }
.nav-link.sub { padding-left: 38px; font-size: 13.5px; }
.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); display: grid; gap: 6px; }
.admin-main { min-width: 0; display: flex; flex-direction: column; }
.admin-top {
  position: sticky; top: 0; z-index: 20; height: var(--topbar-h); display: flex; align-items: center; gap: 12px;
  padding: 0 24px; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.admin-top .crumb { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-content { padding: 24px; max-width: 1400px; width: 100%; }
.btn.menu-toggle { display: none; }
.backdrop { display: none; }

/* ---------------- page header ---------------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------- cards & grid ---------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px 0; flex-wrap: wrap; }
.card-head p { margin: 2px 0 0; color: var(--text-3); font-size: 12.5px; }
.card-body { padding: 14px 20px 18px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.stack { display: grid; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.mt { margin-top: 16px; } .mt-lg { margin-top: 24px; } .mb { margin-bottom: 16px; }

/* ---------------- stat tiles ---------------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat { padding: 16px 18px; position: relative; overflow: hidden; }
.stat-label { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 13px; font-weight: 500; }
.stat-ico { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-size: 15px; background: var(--surface-3); }
.stat-value { font-size: 1.5rem; font-weight: 700; margin-top: 10px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat-sub { color: var(--text-3); font-size: 12.5px; margin-top: 2px; }
.stat.hero { grid-column: span 2; background: linear-gradient(135deg, var(--brand) 0%, var(--brand-strong) 100%); color: var(--on-brand); border: 0; }
.stat.hero .stat-label, .stat.hero .stat-sub { color: color-mix(in srgb, var(--on-brand) 82%, transparent); }
.stat.hero .stat-ico { background: color-mix(in srgb, var(--on-brand) 18%, transparent); }
.stat.hero .stat-value { font-size: 2.1rem; }
/* 8-tile dashboards: the hero keeps its colour but takes one cell so the grid stays 4 × 2 */
.stats.eight .stat.hero { grid-column: auto; }
.stats.eight .stat.hero .stat-value { font-size: 1.6rem; }
.tone-income .stat-ico { background: var(--income-soft); }
.tone-expense .stat-ico { background: var(--expense-soft); }
.tone-warn .stat-ico { background: var(--warning-soft); }
.tone-good .stat-ico { background: var(--good-soft); }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: 9px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; font-size: 13.5px; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-strong); }
.btn-danger { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn-danger:hover { filter: brightness(.95); background: var(--critical); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.btn-icon { width: 34px; padding: 0; }
.btn-sm.btn-icon { width: 30px; }
.btn .spinner { width: 14px; height: 14px; border-width: 2px; }

/* ---------------- forms ---------------- */
.field { display: grid; gap: 5px; }
.field label, .label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--text-3); }
.field .error { font-size: 12px; color: var(--critical); }
.input, select.input, textarea.input {
  width: 100%; height: 38px; padding: 0 11px; border-radius: 9px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-size: 14px;
}
textarea.input { height: auto; min-height: 84px; padding: 9px 11px; resize: vertical; }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent); }
.input.invalid { border-color: var(--critical); }
.input-sm { height: 32px; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }

/* ---------------- toolbar / filters ---------------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.toolbar .input { width: auto; min-width: 130px; height: 34px; font-size: 13.5px; }
.toolbar .search { min-width: 220px; flex: 1 1 220px; max-width: 360px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.filters .input { width: auto; min-width: 120px; height: 34px; font-size: 13.5px; }

/* ---------------- tables ---------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-weight: 600; font-size: 12px; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em;
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; position: sticky; top: 0;
}
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text); }
.table th .sort-ind { margin-left: 4px; opacity: .8; }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tbody tr.clickable { cursor: pointer; }
.table tfoot td { font-weight: 700; background: var(--surface-2); border-bottom: 0; }
.table .actions-cell { text-align: right; white-space: nowrap; width: 1%; }
.table .actions-cell .btn { margin-left: 4px; }
.cell-sub { display: block; color: var(--text-3); font-size: 12px; margin-top: 2px; max-width: 420px; }
.amount-in { color: var(--good); }
.amount-out { color: var(--critical); }
.table-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 16px; color: var(--text-2); font-size: 13px; }
.pager { display: flex; gap: 4px; align-items: center; }
.sum-bar { display: flex; gap: 22px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); font-size: 13px; color: var(--text-2); }
.sum-bar strong { color: var(--text); font-size: 15px; }

/* ---------------- badges ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-3); color: var(--text-2); white-space: nowrap;
}
.badge-good { background: var(--good-soft); color: var(--good); }
.badge-warn { background: var(--warning-soft); color: var(--warning); }
.badge-bad { background: var(--critical-soft); color: var(--critical); }
.badge-info { background: var(--info-soft); color: var(--income); }
.badge-brand { background: var(--brand-soft); color: var(--brand-strong); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---------------- contribution matrix ---------------- */
.matrix { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
.matrix th, .matrix td { padding: 0; border-bottom: 1px solid var(--border); text-align: center; }
.matrix th { font-size: 11.5px; color: var(--text-3); font-weight: 600; padding: 9px 4px; background: var(--surface-2); position: sticky; top: 0; z-index: 1; }
.matrix .name-col {
  text-align: left; padding: 8px 12px; position: sticky; left: 0; background: var(--surface); z-index: 2; min-width: 150px; font-weight: 550;
  border-right: 1px solid var(--border);
}
.matrix th.name-col { background: var(--surface-2); z-index: 3; }
.matrix .total-col { padding: 8px 12px; text-align: right; font-weight: 650; white-space: nowrap; }
.mcell {
  display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 54px; height: 44px; margin: 3px;
  border-radius: 8px; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 12.5px; border: 1px solid transparent; background: transparent; color: inherit; font-family: inherit;
}
button.mcell { cursor: pointer; width: calc(100% - 6px); }
button.mcell:hover { border-color: var(--brand); }
.mcell small { font-size: 10px; font-weight: 500; color: inherit; opacity: .75; line-height: 1; }
.mcell.PAID { background: var(--good-soft); color: var(--good); }
.mcell.PARTIAL { background: var(--warning-soft); color: var(--warning); }
.mcell.UNPAID { background: var(--critical-soft); color: var(--critical); }
.mcell.EXEMPT { background: var(--surface-3); color: var(--text-3); }
.mcell.none { color: var(--text-3); }
.mcell.review { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--warning) 70%, transparent); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); align-items: center; }
.legend .sw { width: 14px; height: 14px; border-radius: 4px; display: inline-block; vertical-align: -2px; margin-right: 5px; }

/* ---------------- charts ---------------- */
.chart-box { position: relative; height: 290px; min-width: 0; }
.chart-box canvas { max-width: 100%; }
.card { min-width: 0; }
.chart-box.tall { height: 360px; }
.chart-box.short { height: 230px; }
.chart-legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-2); flex-wrap: wrap; }
.chart-legend span::before { content: ''; display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; background: var(--c); }

/* ---------------- tabs / segmented ---------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab { padding: 10px 14px; border: 0; background: none; color: var(--text-2); font: inherit; font-weight: 550; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab.active { color: var(--brand-strong); border-color: var(--brand); }
.tab .badge { margin-left: 6px; }
.seg { display: inline-flex; background: var(--surface-3); padding: 3px; border-radius: 10px; gap: 2px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 8px; font: inherit; font-size: 13px; font-weight: 550; color: var(--text-2); cursor: pointer; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------------- modal ---------------- */
.modal-root { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: rgba(10, 14, 12, .45); animation: fade .15s ease; }
.modal { width: 100%; max-width: 560px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); animation: pop .16s ease; }
.modal.wide { max-width: 920px; }
.modal.narrow { max-width: 420px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 12px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }

/* ---------------- toasts ---------------- */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: grid; gap: 8px; max-width: min(400px, calc(100vw - 36px)); }
.toast {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-lg);
  border: 1px solid var(--border); border-left: 4px solid var(--brand); animation: pop .18s ease; font-size: 13.5px;
}
.toast.error { border-left-color: var(--critical); }
.toast.warning { border-left-color: var(--warning); }
.toast .t-title { font-weight: 650; }
.toast ul { margin: 4px 0 0; padding-left: 18px; color: var(--text-2); }

/* ---------------- states ---------------- */
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--border-strong); border-top-color: var(--brand); animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 40px 16px; color: var(--text-3); }
.empty { text-align: center; padding: 40px 16px; color: var(--text-3); }
.empty .empty-ico { font-size: 30px; margin-bottom: 6px; }
.empty h3 { color: var(--text-2); margin-bottom: 4px; }
.skeleton { background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; color: transparent !important; }
@keyframes shimmer { to { background-position: -200% 0; } }
.alert { padding: 12px 14px; border-radius: 10px; background: var(--info-soft); color: var(--text); font-size: 13.5px; border: 1px solid color-mix(in srgb, var(--income) 25%, transparent); }
.alert-warn { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 30%, transparent); }
.alert-bad { background: var(--critical-soft); border-color: color-mix(in srgb, var(--critical) 30%, transparent); }
.alert-good { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 30%, transparent); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13.5px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; }
.pill-list { display: flex; flex-wrap: wrap; gap: 6px; }
.month-pills { display: flex; flex-wrap: wrap; gap: 4px; }
.month-pills .badge { min-width: 34px; justify-content: center; }
.dropzone { display: block; border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 34px 20px; text-align: center; background: var(--surface-2); cursor: pointer; transition: border-color .12s, background .12s; }
.dropzone.over, .dropzone:hover { border-color: var(--brand); background: var(--brand-soft); }
.steps { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.step { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--surface-3); color: var(--text-3); font-size: 13px; font-weight: 550; }
.step .n { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: var(--border-strong); color: var(--surface); font-size: 11px; }
.step.active { background: var(--brand-soft); color: var(--brand-strong); }
.step.active .n, .step.done .n { background: var(--brand); color: var(--on-brand); }
.step.done { color: var(--text-2); }
.rule-item { display: flex; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--border); align-items: flex-start; }
.rule-item:last-child { border-bottom: 0; }
.rule-no { flex: none; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-strong); font-weight: 700; font-size: 13px; }
.team-card .member { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.team-card .member:last-child { border-bottom: 0; }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11.5px; font-weight: 700; background: var(--brand-soft); color: var(--brand-strong); flex: none; }
.pre-line { white-space: pre-line; }
.pre { white-space: pre-wrap; font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); max-height: 240px; overflow: auto; }
.words { font-size: 12.5px; opacity: .85; margin-top: 4px; font-style: italic; }

/* ---------------- login ---------------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1000px 500px at 10% -10%, var(--brand-soft), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 400px; padding: 28px; }
.auth-card .brand { justify-content: center; margin-bottom: 18px; }

/* ---------------- responsive ---------------- */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .admin-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 270px; z-index: 60; transform: translateX(-100%); transition: transform .2s ease; visibility: hidden; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); visibility: visible; }
  .backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 50; }
  .btn.menu-toggle { display: inline-flex; }
  .admin-content { padding: 16px; }
  .admin-top { padding: 0 16px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .topnav { display: none; }
  .topnav.open { display: flex; flex-direction: column; position: absolute; top: var(--topbar-h); left: 0; right: 0; background: var(--surface); padding: 10px 16px 16px; border-bottom: 1px solid var(--border); box-shadow: var(--shadow); }
  .topbar .btn.menu-toggle { display: inline-flex; }
}
@media (max-width: 640px) {
  body { font-size: 14px; }
  .page { padding: 18px 16px 48px; }
  .stats, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .stat.hero { grid-column: auto; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .toolbar .search { max-width: none; }
  .toolbar .input { flex: 1 1 140px; }
  h1 { font-size: 1.3rem; }
  .chart-box { height: 240px; }
  /* tables become cards */
  table.table.responsive thead { display: none; }
  table.table.responsive, table.table.responsive tbody, table.table.responsive tr, table.table.responsive td { display: block; width: 100%; }
  table.table.responsive tr { border-bottom: 1px solid var(--border); padding: 8px 0; }
  table.table.responsive td { border: 0; padding: 4px 16px; display: flex; justify-content: space-between; gap: 14px; text-align: right; }
  table.table.responsive td::before { content: attr(data-label); color: var(--text-3); font-size: 12px; font-weight: 600; text-align: left; flex: none; }
  table.table.responsive td.actions-cell { width: auto; justify-content: flex-end; }
  table.table.responsive td.actions-cell::before { content: ''; }
  table.table.responsive tfoot tr { padding: 4px 0; }
  .modal-root { padding: 0; align-items: end; }
  .modal { border-radius: 16px 16px 0 0; max-height: 92vh; }
}
/* legend swatches reuse the matrix cell colours */
.legend .sw.mcell { display: inline-block; min-width: 0; width: 14px; height: 14px; margin: 0 5px 0 0; border-radius: 4px; vertical-align: -2px; }
.legend .sw.PAID { border: 1px solid var(--good); }
.legend .sw.PARTIAL { border: 1px solid var(--warning); }
.legend .sw.UNPAID { border: 1px solid var(--critical); }

@media print {
  .sidebar, .admin-top, .topbar, .toolbar, .actions, .btn { display: none !important; }
  .admin-shell { display: block; }
  .card { box-shadow: none; }
}

/* ---------- payment QR (public "Đóng quỹ" card, admin settings preview) ---------- */
.pay-body { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 20px; align-items: center; }
.pay-body.no-qr { grid-template-columns: minmax(0, 1fr); }
.pay-body .stack { gap: 10px; }
/* QR codes need a white quiet zone to scan, also in dark mode */
.pay-qr, .qr-full, .qr-preview { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 6px; object-fit: contain; }
.pay-qr { width: 180px; height: 180px; cursor: zoom-in; }
.qr-full { width: min(100%, 420px); height: auto; margin: 0 auto; display: block; }
.qr-preview { width: 160px; height: 160px; }
.pay-text { white-space: pre-wrap; overflow-wrap: anywhere; font-weight: 500; }
.modal .pay-card { border: 0; box-shadow: none; }
@media (max-width: 600px) {
  .pay-body { grid-template-columns: minmax(0, 1fr); justify-items: center; text-align: center; }
  .pay-body .row { justify-content: center; }
  .pay-qr { width: min(240px, 100%); height: auto; aspect-ratio: 1; }
}
