/* =====================================================================
   CHIT FUND MANAGEMENT SYSTEM - STYLESHEET
   Theme: passbook green + brass. Change the variables below to re-theme.
   ===================================================================== */
:root {
  --bg:          #EDF1EE;
  --surface:     #FFFFFF;
  --surface-2:   #F6F8F6;
  --ink:         #15241F;
  --ink-2:       #4A5A54;
  --ink-3:       #7C8A84;
  --line:        #D9E1DC;
  --line-2:      #E8EEEA;

  --primary:     #1E5A49;
  --primary-ink: #FFFFFF;
  --primary-2:   #174A3C;
  --primary-soft:#E2EEE8;

  --brass:       #B7862C;
  --brass-soft:  #F6ECD6;

  --sidebar:     #0F2A24;
  --sidebar-2:   #163A31;
  --sidebar-ink: #C9D8D1;

  --success: #1F7A4D;  --success-soft: #E0F2E8;
  --warning: #A86A12;  --warning-soft: #FBEFD9;
  --danger:  #B3261E;  --danger-soft:  #FBE3E1;
  --info:    #2B5C8A;  --info-soft:    #E1ECF6;
  --neutral: #5D6B66;  --neutral-soft: #E9EEEB;

  --radius-lg: 14px;
  --radius:    10px;
  --radius-sm: 7px;
  --shadow:    0 1px 2px rgba(16, 42, 36, .06), 0 4px 14px rgba(16, 42, 36, .05);
  --sidebar-w: 264px;
  --topbar-h:  64px;
  --font: "Manrope", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 14.5px; line-height: 1.5;
  color: var(--ink); background: var(--bg);
  font-variant-numeric: tabular-nums;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
p { margin: 0 0 .75rem; }
.icon { flex: none; vertical-align: middle; }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.amount { font-weight: 700; white-space: nowrap; }
.amount-danger { color: var(--danger); font-weight: 700; white-space: nowrap; }
.amount-success { color: var(--success); font-weight: 700; white-space: nowrap; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--brass) 65%, transparent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: var(--sidebar); color: var(--sidebar-ink);
  position: fixed; inset: 0 auto 0 0; z-index: 40; display: flex; flex-direction: column;
  overflow-y: auto; transition: transform .25s ease;
}
.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.content { padding: 24px; flex: 1; max-width: 1440px; width: 100%; }
.app-footer { padding: 16px 24px; color: var(--ink-3); font-size: 12.5px; }

.brand { display: flex; align-items: center; gap: 12px; padding: 20px 20px 18px; color: #fff; text-decoration: none !important; border-bottom: 1px solid rgba(255,255,255,.07); }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: var(--brass); color: var(--sidebar); display: grid; place-items: center; font-weight: 800; font-size: 18px; }
.brand-logo { width: 38px; height: 38px; object-fit: contain; border-radius: 8px; background: #fff; padding: 3px; }
.brand-text { font-weight: 800; font-size: 15px; line-height: 1.2; }
.brand-text small { display: block; font-weight: 500; font-size: 11.5px; color: var(--sidebar-ink); opacity: .75; margin-top: 2px; }

.nav { padding: 12px 10px 20px; display: flex; flex-direction: column; gap: 2px; }
.nav-link, .nav-sublink {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--sidebar-ink); font-weight: 600; font-size: 14px; text-decoration: none !important;
  border: 0; background: none; width: 100%; text-align: left; cursor: pointer; font-family: inherit;
  position: relative;
}
.nav-link:hover, .nav-sublink:hover { background: var(--sidebar-2); color: #fff; }
.nav-link.active { background: var(--sidebar-2); color: #fff; }
.nav-link.active::before { content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brass); }
.nav-group summary { list-style: none; }
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group summary::after { content: "▾"; margin-left: auto; font-size: 11px; opacity: .7; transition: transform .2s; }
.nav-group[open] summary::after { transform: rotate(180deg); }
.nav-sublink { padding: 8px 12px 8px 42px; font-weight: 500; font-size: 13.5px; }
.nav-sublink.active { color: var(--brass); }
.nav-logout { margin: 0; margin-top: 8px; border-top: 1px solid rgba(255,255,255,.07); padding-top: 8px; }

.topbar {
  height: var(--topbar-h); background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px; padding: 0 24px; position: sticky; top: 0; z-index: 30;
}
.page-title { font-size: 19px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn.hamburger { display: none; }
.topbar-search { position: relative; margin-left: auto; display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 0 14px; width: min(340px, 34vw); color: var(--ink-3); }
.topbar-search input[type=search] { border: 0; background: transparent; padding: 9px 0; min-height: 0; width: 100%; font: inherit; color: var(--ink); outline: none; box-shadow: none; }
.search-pop { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); max-height: 380px; overflow-y: auto; z-index: 60; }
.search-pop a, .search-pop .sp-empty { display: block; padding: 9px 14px; color: var(--ink); border-bottom: 1px solid var(--line-2); text-decoration: none; }
.search-pop a:hover, .search-pop a.focused { background: var(--primary-soft); }
.search-pop .sp-head { padding: 7px 14px; font-size: 11.5px; font-weight: 700; color: var(--ink-3); background: var(--surface-2); }
.search-pop small { color: var(--ink-3); display: block; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn { position: relative; width: 40px; height: 40px; border-radius: 10px; border: 1px solid transparent; background: none; display: grid; place-items: center; color: var(--ink-2); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); border-color: var(--line); }
.dot-count { position: absolute; top: 3px; right: 1px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 800; border-radius: 999px; padding: 1px 5px; line-height: 1.4; }
.user-chip { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); padding: 4px 12px 4px 4px; border-radius: 999px; cursor: pointer; font: inherit; color: var(--ink); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 13px; }
.user-name { font-weight: 600; font-size: 13.5px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dropdown { position: relative; }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 190px; padding: 6px; display: none; z-index: 70; }
.dropdown-menu.wide { min-width: 290px; }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu form { margin: 0; }
.dropdown-item { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: var(--radius-sm); color: var(--ink); font: inherit; font-size: 13.5px; border: 0; background: none; width: 100%; text-align: left; cursor: pointer; text-decoration: none !important; }
.dropdown-item:hover { background: var(--surface-2); }
.dropdown-item.muted { color: var(--ink-3); cursor: default; }
.sidebar-backdrop { display: none; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { font-size: 22px; font-weight: 800; }
.page-head p { margin: 4px 0 0; color: var(--ink-3); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.breadcrumb { font-size: 13px; color: var(--ink-3); margin-bottom: 6px; display: flex; gap: 6px; align-items: center; }
.breadcrumb a { color: var(--ink-2); }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); margin-bottom: 20px; min-width: 0; }
.card-head { padding: 16px 20px; border-bottom: 1px solid var(--line-2); display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.card-head h3 { font-size: 15.5px; font-weight: 800; }
.card-head .sub { color: var(--ink-3); font-size: 12.5px; font-weight: 500; }
.card-body { padding: 20px; }
.card-body.tight { padding: 0; }
.card-foot { padding: 14px 20px; border-top: 1px solid var(--line-2); }

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-main-side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

/* Statistic tiles: number-first, laid out like passbook entries */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); margin-bottom: 20px; overflow: hidden; }
.stat { padding: 18px 20px; border-right: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); min-width: 0; }
.stat:nth-child(4n) { border-right: 0; }
.stat:nth-last-child(-n+4) { border-bottom: 0; }
.stat-label { font-size: 12.5px; color: var(--ink-3); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.stat-label .icon { color: var(--primary); }
.stat-value { font-size: 24px; font-weight: 800; margin-top: 6px; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value.brass { color: var(--brass); }
.stat-value.danger { color: var(--danger); }
.stat-note { font-size: 12px; color: var(--ink-3); margin-top: 2px; }

.mini-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.mini-stat { background: var(--surface-2); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 12px 14px; }
.mini-stat span { display: block; font-size: 12px; color: var(--ink-3); font-weight: 600; }
.mini-stat b { font-size: 17px; font-weight: 800; }

.progress { height: 8px; background: var(--line-2); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; }

/* ---------- Detail lists ---------- */
.dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px 24px; margin: 0; }
.dl div { min-width: 0; }
.dl dt { font-size: 12px; color: var(--ink-3); font-weight: 600; }
.dl dd { margin: 2px 0 0; font-weight: 600; word-break: break-word; }

.profile-head { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.profile-photo { width: 76px; height: 76px; border-radius: 14px; object-fit: cover; background: var(--primary-soft); display: grid; place-items: center; font-size: 28px; font-weight: 800; color: var(--primary); flex: none; }
.profile-head h2 { font-size: 21px; font-weight: 800; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid transparent; font: inherit; font-weight: 700; font-size: 13.5px; cursor: pointer; text-decoration: none !important; line-height: 1.2; white-space: nowrap; transition: background .15s, border-color .15s; min-height: 38px; }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary-2); }
.btn-brass { background: var(--brass); color: #fff; }
.btn-brass:hover { background: #9e7323; }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-whatsapp { background: #25d366; color: #fff; border-color: #25d366; }
.btn-whatsapp:hover { background: #1ebe5b; color: #fff; }
.danger-zone { border: 1px solid var(--danger); }
.danger-zone h3 { color: var(--danger); margin: 0 0 6px; }
.clear-counts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 12px 0; }
.clear-counts div { background: rgba(179,38,30,.06); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.clear-counts b { display: block; font-size: 18px; }
.btn-danger:hover { background: #95201a; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; min-height: 32px; }
.btn-block { width: 100%; }
.btn[disabled], .btn.is-loading { opacity: .65; pointer-events: none; }
.btn.is-loading::after { content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.actions { display: flex; gap: 4px; flex-wrap: nowrap; }
.actions .btn-sm { padding: 6px 7px; min-height: 32px; }
.actions form { margin: 0; }
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; font-weight: 600; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px 18px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 13px; font-weight: 700; color: var(--ink-2); }
.field label .req { color: var(--danger); }
.field .hint { font-size: 12px; color: var(--ink-3); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=tel], input[type=search], input[type=file], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); font: inherit; color: var(--ink); min-height: 40px;
}
input[readonly] { background: var(--surface-2); color: var(--ink-2); }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.is-invalid { border-color: var(--danger) !important; box-shadow: 0 0 0 3px var(--danger-soft) !important; }
.field-error { color: var(--danger); font-size: 12.5px; font-weight: 600; }
.section-title { font-size: 13px; font-weight: 800; color: var(--primary); margin: 6px 0 -4px; grid-column: 1 / -1; padding-top: 10px; border-top: 1px dashed var(--line); }
.section-title:first-child { border-top: 0; padding-top: 0; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; flex-wrap: wrap; }
.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13.5px; }
.checkbox input { width: 18px; height: 18px; accent-color: var(--primary); }

/* Filters bar */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; align-items: end; }
.filters .field label { font-size: 12px; }
.filter-actions { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }

/* ---------- 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-size: 12px; font-weight: 700; color: var(--ink-3); background: var(--surface-2); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 11px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tbody tr:hover { background: #FAFBFA; }
.table tfoot td { font-weight: 800; background: var(--surface-2); border-top: 2px solid var(--line); }
.table .num, .table th.num { text-align: right; white-space: nowrap; }
.table td.strong { font-weight: 700; min-width: 160px; }
.table td.strong small { white-space: nowrap; }
.table td.wide { min-width: 220px; }
.table small { color: var(--ink-3); display: block; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { color: var(--success); background: var(--success-soft); }
.badge-warning { color: var(--warning); background: var(--warning-soft); }
.badge-danger  { color: var(--danger);  background: var(--danger-soft); }
.badge-info    { color: var(--info);    background: var(--info-soft); }
.badge-neutral { color: var(--neutral); background: var(--neutral-soft); }
.pill { display: inline-block; white-space: nowrap; padding: 2px 8px; border-radius: 6px; background: var(--brass-soft); color: #7a5615; font-weight: 700; font-size: 12px; }

/* ---------- Alerts / toasts ---------- */
.alert { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-weight: 600; border: 1px solid transparent; }
.alert-success { background: var(--success-soft); color: #145234; border-color: #bfe3cf; }
.alert-error   { background: var(--danger-soft);  color: #7d1913; border-color: #f2c3bf; }
.alert-warning { background: var(--warning-soft); color: #74490b; border-color: #f0d7a8; }
.alert-info    { background: var(--info-soft);    color: #1e4366; border-color: #c4d8ec; }
.alert ul { margin: 6px 0 0; padding-left: 18px; font-weight: 500; }
.alert-close { background: none; border: 0; font-size: 20px; line-height: 1; cursor: pointer; color: inherit; opacity: .6; }
.toast-stack { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: var(--radius); box-shadow: var(--shadow); font-weight: 600; font-size: 13.5px; max-width: 360px; }
.toast.error { background: var(--danger); }

/* ---------- Empty / loading ---------- */
.empty { text-align: center; padding: 42px 20px; color: var(--ink-3); }
.empty .icon { color: var(--line); margin-bottom: 8px; }
.empty h4 { color: var(--ink-2); font-size: 15px; margin-bottom: 4px; }
.empty .btn { margin-top: 12px; }
.loading { padding: 24px; text-align: center; color: var(--ink-3); }
.loading::before { content: ""; display: inline-block; width: 16px; height: 16px; margin-right: 8px; vertical-align: -3px; border: 2px solid var(--primary); border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }

/* ---------- Pagination ---------- */
.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 20px; flex-wrap: wrap; }
.pager-info { font-size: 12.5px; color: var(--ink-3); }
.pager-links { display: flex; gap: 4px; flex-wrap: wrap; }
.pager-link { padding: 6px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: 13px; font-weight: 600; color: var(--ink-2); text-decoration: none !important; background: var(--surface); }
.pager-link.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pager-link.disabled { opacity: .45; }
.pager-gap { padding: 6px 4px; color: var(--ink-3); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tab { padding: 10px 16px; font-weight: 700; color: var(--ink-3); border: 0; background: none; border-bottom: 2px solid transparent; cursor: pointer; font: inherit; font-weight: 700; white-space: nowrap; margin-bottom: -1px; }
.tab.active { color: var(--primary); border-bottom-color: var(--brass); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- Passbook ledger (signature element) ----------
   Members x months matrix used in group details. */
.ledger { overflow-x: auto; }
.ledger table { border-collapse: separate; border-spacing: 3px; font-size: 12px; }
.ledger th { font-weight: 700; color: var(--ink-3); padding: 4px 6px; white-space: nowrap; text-align: center; }
.ledger th.member { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 170px; }
.ledger td.member { position: sticky; left: 0; background: var(--surface); z-index: 1; font-weight: 600; white-space: nowrap; padding-right: 8px; }
.ledger td.member small { color: var(--ink-3); font-weight: 500; }
.lcell { width: 34px; height: 30px; border-radius: 6px; text-align: center; font-weight: 800; font-size: 11px; cursor: default; }
.lcell a { display: block; width: 100%; height: 100%; line-height: 30px; color: inherit; text-decoration: none; }
.lcell.paid    { background: var(--success); color: #fff; }
.lcell.partial { background: #E9B65A; color: #4b3207; }
.lcell.overdue { background: var(--danger); color: #fff; }
.lcell.pending { background: var(--neutral-soft); color: var(--ink-3); }
.lcell.taken   { box-shadow: inset 0 0 0 2px var(--brass); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--ink-2); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(12, 30, 25, .5); display: grid; place-items: center; z-index: 200; padding: 16px; }
.modal-card { background: var(--surface); border-radius: var(--radius-lg); padding: 24px; width: min(440px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-card.wide { width: min(640px, 100%); }
.modal-card h3 { font-size: 17px; font-weight: 800; margin-bottom: 8px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ---------- Search results (collection entry) ---------- */
.result-list { display: flex; flex-direction: column; }
.result { display: grid; grid-template-columns: minmax(0, 2fr) repeat(4, minmax(0, 1fr)) auto; gap: 12px; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--line-2); }
.result:hover { background: #FAFBFA; }
.result .r-label { font-size: 11.5px; color: var(--ink-3); font-weight: 600; display: block; }
.result b { font-weight: 700; }
.big-search { display: flex; align-items: center; gap: 10px; border: 2px solid var(--primary); border-radius: var(--radius); padding: 4px 6px 4px 14px; background: var(--surface); color: var(--primary); }
.big-search input { border: 0 !important; box-shadow: none !important; font-size: 16px; padding: 10px 4px; }

/* ---------- Charts ---------- */
.chart-box { position: relative; height: 280px; }

/* ---------- Auth pages ---------- */
.auth-body { background: var(--sidebar); min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-wrap { display: grid; grid-template-columns: 1.1fr 1fr; width: min(940px, 100%); background: var(--surface); border-radius: 18px; overflow: hidden; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.auth-side { background: var(--sidebar-2); color: var(--sidebar-ink); padding: 44px; display: flex; flex-direction: column; justify-content: flex-end; gap: 10px; }
.auth-side h2 { color: #fff; font-size: 26px; font-weight: 800; }
.ledger-art { display: flex; flex-direction: column; gap: 6px; margin-bottom: auto; }
.ledger-row { display: flex; gap: 6px; }
.ledger-art .cell { width: 26px; height: 22px; border-radius: 5px; }
.ledger-art .cp { background: #2E8A5E; }
.ledger-art .ch { background: #E9B65A; }
.ledger-art .co { background: #C7473F; }
.ledger-art .ce { background: rgba(255,255,255,.1); }
.auth-card { padding: 44px; }
.auth-card h1 { font-size: 26px; font-weight: 800; margin-bottom: 4px; }
.auth-card form { margin-top: 22px; display: flex; flex-direction: column; gap: 16px; }
.error-page { background: var(--surface); padding: 44px; border-radius: 18px; text-align: center; max-width: 460px; }
.error-code { font-size: 64px; font-weight: 800; color: var(--brass); line-height: 1; }
.error-page h1 { font-size: 22px; margin: 10px 0 8px; }
.error-page p { color: var(--ink-2); margin-bottom: 20px; }

/* Install */
.install-card { background: var(--surface); width: min(760px, 100%); border-radius: 18px; padding: 32px; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.install-card h1 { font-size: 24px; font-weight: 800; }

/* ---------- Receipt (A4) ---------- */
.receipt-toolbar { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 16px; flex-wrap: wrap; }
.receipt { background: #fff; width: 100%; max-width: 794px; margin: 0 auto; padding: 40px 44px; border: 1px solid var(--line); border-radius: 6px; color: #111; }
.receipt-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 3px double var(--primary); padding-bottom: 16px; }
.receipt-head img { max-height: 64px; max-width: 160px; }
.receipt-company h2 { font-size: 22px; color: var(--primary); font-weight: 800; }
.receipt-company p { margin: 2px 0; font-size: 12.5px; color: #333; }
.receipt-title { text-align: center; margin: 18px 0; font-size: 15px; font-weight: 800; letter-spacing: .06em; color: var(--primary); }
.receipt-meta { display: flex; justify-content: space-between; font-size: 13.5px; margin-bottom: 14px; }
.receipt table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.receipt td { border: 1px solid #cfd8d3; padding: 9px 12px; }
.receipt td:first-child { width: 38%; background: #f4f7f5; font-weight: 700; }
.receipt .paid-row td { font-size: 16px; font-weight: 800; }
.receipt-words { margin-top: 12px; font-size: 13px; font-style: italic; }
.receipt-sign { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 60px; font-size: 13px; }
.receipt-sign .sig { border-top: 1px solid #333; padding-top: 6px; min-width: 200px; text-align: center; font-weight: 700; }
.receipt-foot { margin-top: 24px; font-size: 11.5px; color: #555; text-align: center; border-top: 1px dashed #bbb; padding-top: 10px; }
.void-stamp { color: var(--danger); border: 3px solid var(--danger); display: inline-block; padding: 4px 14px; font-weight: 800; transform: rotate(-6deg); font-size: 20px; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(4n) { border-right: 1px solid var(--line-2); }
  .stat:nth-child(2n) { border-right: 0; }
  .stat:nth-last-child(-n+4) { border-bottom: 1px solid var(--line-2); }
  .stat:nth-last-child(-n+2) { border-bottom: 0; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result { grid-template-columns: minmax(0, 2fr) repeat(2, minmax(0, 1fr)) auto; }
  .result .r-hide-md { display: none; }
}
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  .app.sidebar-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .app.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 35; }
  .main { margin-left: 0; }
  .icon-btn.hamburger { display: grid; }
  .grid-main-side, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  body { font-size: 15px; }
  .content { padding: 14px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-search { display: none; }
  .topbar-actions { margin-left: auto; }
  .user-name { display: none; }
  .user-chip { padding: 4px; }
  .page-title { font-size: 17px; }
  .stats { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .stat { padding: 14px; }
  .stat-value { font-size: 19px; }
  .grid-3, .form-grid, .form-grid.two { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .card-body { padding: 16px; }
  .btn { min-height: 44px; padding: 10px 16px; }
  .btn-sm { min-height: 36px; }
  .form-actions .btn { flex: 1; }
  .result { grid-template-columns: 1fr 1fr; padding: 14px 16px; }
  .result .r-main { grid-column: 1 / -1; }
  .result .r-act { grid-column: 1 / -1; }
  .result .r-act .btn { width: 100%; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  .auth-card { padding: 28px; }
  .receipt { padding: 22px; }
  .receipt-head { flex-direction: column; }
  .mobile-only-mt { margin-top: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- Print ---------- */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; font-size: 12px; }
  .sidebar, .topbar, .app-footer, .no-print, .page-actions, .filters-card, .pager, .alert, .receipt-toolbar, .toast-stack { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; }
  .receipt { border: 0; padding: 0; max-width: none; }
  .table th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-only { display: block !important; }
  a { color: inherit; text-decoration: none; }
}
.print-only { display: none; }
.sr-only { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; }

/* =====================================================================
   MOBILE APP LAYOUT
   Bottom tab bar, card-style lists, sticky actions, installable (PWA).
   ===================================================================== */
.mobile-only { display: none !important; }
.pay-summary { display: none; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.bottom-nav { display: none; }
.filters-toggle { display: none; }

@media (max-width: 720px) {
  :root { --topbar-h: 56px; }
  html { -webkit-tap-highlight-color: transparent; }
  body { overscroll-behavior-y: none; }
  .mobile-only { display: grid !important; }
  .icon-btn.hamburger { display: none; }

  /* App header */
  .topbar { height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px)); padding: env(safe-area-inset-top, 0px) 8px 0 16px; background: var(--sidebar); border-bottom: 0; color: #fff; }
  .topbar .page-title { color: #fff; font-size: 17px; flex: 1; min-width: 0; }
  .topbar .icon-btn { color: #fff; }
  .topbar .icon-btn:hover { background: rgba(255,255,255,.08); border-color: transparent; }
  .topbar .user-chip { background: transparent; border-color: rgba(255,255,255,.2); }
  .topbar.search-open .topbar-search { display: flex; position: absolute; left: 8px; right: 8px; top: calc(env(safe-area-inset-top, 0px) + 8px); width: auto; z-index: 5; background: #fff; }
  .topbar.search-open .page-title, .topbar.search-open .topbar-actions { visibility: hidden; }
  .dropdown-menu { position: fixed; right: 8px; left: 8px; top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px) + 4px); min-width: 0; }
  .dropdown-menu.wide { min-width: 0; }

  /* Bottom tab bar */
  body.has-bottom-nav .main { padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px)); }
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -4px 18px rgba(16,42,36,.08);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px)); }
  .bn-item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 52px;
    color: var(--ink-3); font: inherit; font-size: 11px; font-weight: 700; text-decoration: none !important; background: none; border: 0; border-radius: 12px; cursor: pointer; }
  .bn-item.active { color: var(--primary); }
  .bn-item.active .bn-icon { background: var(--primary-soft); }
  .bn-icon { display: grid; place-items: center; width: 44px; height: 28px; border-radius: 999px; }
  .bn-primary .bn-icon { width: 54px; height: 54px; margin-top: -26px; border-radius: 50%; background: var(--primary) !important; color: #fff;
    box-shadow: 0 6px 16px rgba(30,90,73,.35); border: 4px solid var(--surface); }
  .bn-primary.active .bn-icon { background: var(--brass) !important; }
  .toast-stack { bottom: calc(80px + env(safe-area-inset-bottom, 0px)); left: 12px; right: 12px; }
  .app-footer { display: none; }
  .sidebar { z-index: 60; }
  .app.sidebar-open .sidebar-backdrop { z-index: 55; }

  /* Content */
  .content { padding: 14px 12px; }
  input, select, textarea { font-size: 16px !important; } /* stops iOS zoom on focus */
  .page-head { margin-bottom: 14px; align-items: stretch; }
  .page-head h2 { font-size: 19px; }
  .page-actions { width: 100%; display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
  .page-actions .btn, .page-actions form, .page-actions form .btn { width: 100%; }
  .card { border-radius: 16px; margin-bottom: 14px; }
  .card-head { padding: 14px 16px; }
  .breadcrumb { font-size: 12.5px; overflow-x: auto; white-space: nowrap; }
  .mini-stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .mini-stat b { font-size: 15px; }
  .tabs { position: sticky; top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px)); background: var(--bg); z-index: 20; margin: 0 -12px 14px; padding: 0 12px; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .profile-head { gap: 12px; }
  .profile-photo { width: 56px; height: 56px; font-size: 22px; }

  /* Sticky save bar on forms */
  .form-actions { position: sticky; bottom: calc(68px + env(safe-area-inset-bottom, 0px)); z-index: 30; background: var(--surface);
    margin: 18px -16px -16px; padding: 12px 16px; border-top: 1px solid var(--line); border-radius: 0 0 16px 16px; }
  .form-actions { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 10px; }
  .form-actions .btn-primary { grid-column: span 2; }
  .form-actions .btn:only-child { grid-column: 1 / -1; }
  .dl { grid-template-columns: 1fr 1fr; gap: 12px 16px; }
  .first-on-mobile { order: -1; }
  .hide-mobile { display: none !important; }
  .pay-summary { display: grid; }
  .modal-card .form-actions, .modal .modal-actions { position: static; }
  .modal { align-items: end; padding: 0; }
  .modal-card { width: 100%; border-radius: 20px 20px 0 0; padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }
  .modal-actions .btn { flex: 1; }

  /* Collapsible filters */
  .filters-toggle { display: flex; width: 100%; align-items: center; justify-content: space-between; padding: 14px 16px; background: none; border: 0;
    font: inherit; font-weight: 800; color: var(--ink); cursor: pointer; }
  .filters-toggle .count { background: var(--primary); color: #fff; border-radius: 999px; padding: 1px 8px; font-size: 12px; margin-left: 6px; }
  .filters-card.collapsed .filters { display: none; }
  .filters-card .filters { padding-top: 0; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .field[style*="span 2"] { grid-column: 1 / -1; }
  .filter-actions { display: grid; grid-template-columns: 1fr 1fr; grid-column: 1 / -1; }
  .filter-actions .btn { width: 100%; }

  /* Tables become cards */
  .table-wrap { overflow: visible; }
  .card-body.tight.table-wrap, .card-body.tight .table-wrap { padding: 10px; }
  table.table.stack, table.table.stack tbody, table.table.stack tfoot, table.table.stack tr, table.table.stack td { display: block; width: 100%; }
  table.table.stack thead { display: none; }
  table.table.stack tr { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(16,42,36,.04); }
  table.table.stack tbody tr:hover { background: var(--surface); }
  table.table.stack td { border: 0; padding: 5px 0; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; text-align: right; min-width: 0; white-space: normal; }
  table.table.stack td::before { content: attr(data-label); font-size: 12px; font-weight: 700; color: var(--ink-3); text-align: left; flex: none; max-width: 45%; }
  table.table.stack td.cell-head { display: block; text-align: left; font-size: 15px; padding: 2px 0 8px; margin-bottom: 4px; border-bottom: 1px dashed var(--line); }
  table.table.stack td.cell-head::before { display: none; }
  table.table.stack td.cell-head small { white-space: normal; max-width: none; }
  table.table.stack td.cell-actions { justify-content: flex-end; padding-top: 10px; }
  table.table.stack td.cell-actions::before { display: none; }
  table.table.stack td.cell-actions .actions { gap: 8px; }
  table.table.stack td.cell-actions .btn { min-height: 40px; padding: 8px 14px; }
  table.table.stack td.cell-empty { display: none; }
  table.table.stack .cell-val { min-width: 0; text-align: right; overflow-wrap: anywhere; }
  table.table.stack .cell-val small { display: block; margin-top: 1px; }
  table.table.stack .cell-val .badge { margin-left: auto; }
  table.table.stack td.cell-head small { display: block; margin: 2px 0 0; }
  table.table.stack tfoot tr { background: var(--primary-soft); border-color: transparent; }
  table.table.stack tfoot td { background: none; border: 0; font-size: 14px; }
  table.table.stack .num { text-align: right; }
  .table td.strong { min-width: 0; }
  .result-list { padding: 4px 0; }
  .pager { justify-content: center; padding: 12px; }
  .pager-info { width: 100%; text-align: center; }

  /* Small tables without headers (dashboard lists) wrap instead of overflowing */
  .table:not(.stack) td, .table:not(.stack) .num, .table:not(.stack) td small { white-space: normal; }
  .table:not(.stack) td { padding: 10px; }
  .content { overflow-x: clip; }

  /* Collection search results as cards */
  .result { margin: 0 10px 10px; border: 1px solid var(--line); border-radius: 14px; }
  .big-search { border-radius: 14px; }

  /* Ledger keeps horizontal scroll */
  .ledger { margin: 0 -16px; padding: 0 16px; }

  /* Receipt */
  .receipt-toolbar { display: grid; grid-template-columns: 1fr 1fr; }
  .receipt-toolbar .btn-primary { grid-column: 1 / -1; order: -1; }
  .receipt-toolbar .btn-whatsapp { grid-column: 1 / -1; order: -2; }
  .receipt-toolbar .btn { width: 100%; }
  .receipt td:first-child { width: 42%; }
}
@media (min-width: 721px) {
  .topbar-search { display: flex !important; }
}
@media print {
  .bottom-nav, .filters-toggle { display: none !important; }
  table.table.stack thead { display: table-header-group !important; }
}

/* ---------- Wallet ---------- */
.wallet-hero { background: linear-gradient(135deg, var(--sidebar) 0%, var(--primary) 100%); color: #fff; border-radius: var(--radius-lg); padding: 22px 24px;
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 18px; margin-bottom: 20px; box-shadow: var(--shadow); }
.wh-label { display: block; font-size: 13px; opacity: .8; font-weight: 600; }
.wh-amount { display: block; font-size: 32px; font-weight: 800; letter-spacing: -.02em; margin: 2px 0; }
.wh-sub { font-size: 12.5px; opacity: .8; }
.wh-stats { display: flex; gap: 22px; flex-wrap: wrap; align-items: flex-end; }
.wh-stats span { display: block; font-size: 12px; opacity: .75; }
.wh-stats b { font-size: 16px; }
@media (max-width: 720px) {
  .wallet-hero { padding: 18px; border-radius: 18px; }
  .wh-amount { font-size: 28px; }
  .wh-stats { width: 100%; justify-content: space-between; gap: 10px; }
}

/* ---------- Compact collection results & pending total ---------- */
.result.rc { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px; color: var(--ink); text-decoration: none !important; }
.rc-main { min-width: 0; }
.rc-main b { display: block; font-size: 14.5px; }
.rc-main small { display: block; color: var(--ink-3); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rc-amt { text-align: right; flex: none; }
.rc-amt b { display: block; font-size: 15.5px; }
.rc-amt small { display: block; font-size: 11.5px; color: var(--ink-3); }
.pending-total { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 12px; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 12px 16px; }
.pending-total span { font-weight: 700; color: var(--ink-2); font-size: 13px; }
.pending-total b { font-size: 22px; font-weight: 800; }
.pending-total small { width: 100%; color: var(--ink-3); }
@media (max-width: 720px) {
  .result.rc { margin: 0 10px 8px; padding: 10px 14px; }
}

/* ---------- Compact mobile cards ---------- */
@media (max-width: 720px) {
  table.table.stack tr { padding: 8px 12px; margin-bottom: 8px; border-radius: 12px; }
  table.table.stack td { padding: 3px 0; font-size: 13.5px; gap: 10px; }
  table.table.stack td::before { font-size: 11.5px; }
  table.table.stack td.cell-head { font-size: 14.5px; padding: 0 0 6px; margin-bottom: 3px; }
  table.table.stack td.cell-head small { font-size: 12px; }
  table.table.stack td.cell-actions { padding-top: 6px; }
  table.table.stack td.cell-actions .btn { min-height: 34px; padding: 6px 12px; }
  table.table.stack .badge { padding: 2px 8px; font-size: 11.5px; }
  .card-body.tight.table-wrap, .card-body.tight .table-wrap { padding: 8px; }
  .profile-head h2 { font-size: 18px; }
  .mini-stat { padding: 9px 12px; }
}
@media (min-width: 721px) {
  .table .hide-mobile { display: table-cell; }
}
@media (max-width: 720px) {
  /* Customer list: action icons sit beside the data rows (smaller cards) */
  table.table.stack.compact-list tr { position: relative; }
  table.table.stack.compact-list td.cell-actions { position: absolute; right: 12px; bottom: 8px; width: auto; padding: 0; }
  table.table.stack.compact-list td:not(.cell-head):not(.cell-actions) { padding-right: 92px; }
}
}

/* Seats per customer in the member picker */
.picker-seat { align-items: center; }
.seat-qty { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; white-space: nowrap; }
.seat-qty .btn { min-width: 30px; padding: 2px 8px; }
.seat-qty small { color: var(--muted, #667); }
