/* =====================================================================
   Kiran Chit Fund — application styles (on top of Bootstrap 5.3)
   Tokens: ledger green on paper; amounts set in tabular figures.
   ===================================================================== */
:root {
  --kcf-ink: #1b2621;
  --kcf-muted: #5e6b66;
  --kcf-paper: #ffffff;
  --kcf-canvas: #f3f5f4;
  --kcf-line: #dde3e0;
  --kcf-green: #12684c;
  --kcf-green-dark: #0c4f39;
  --kcf-green-weak: #e6f1ec;
  --kcf-amber: #9a5b0b;
  --kcf-amber-weak: #fbf1e1;
  --kcf-red: #b42318;
  --kcf-sidebar-w: 256px;

  --bs-body-font-family: "Source Sans 3", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --bs-body-font-size: 0.96rem;
  --bs-body-color: var(--kcf-ink);
  --bs-body-bg: var(--kcf-paper);   /* inputs, dropdowns, modals stay white */
  --bs-border-color: var(--kcf-line);
  --bs-primary: var(--kcf-green);
  --bs-primary-rgb: 18, 104, 76;
  --bs-link-color: var(--kcf-green);
  --bs-link-color-rgb: 18, 104, 76;
  --bs-link-hover-color: var(--kcf-green-dark);
  --bs-secondary-color: var(--kcf-muted);
  --bs-focus-ring-color: rgba(18, 104, 76, .3);
}

body { background: var(--kcf-canvas); }
.num, .figure-value, .count-value, .table-ledger td.text-end { font-variant-numeric: tabular-nums; }
.text-muted { color: var(--kcf-muted) !important; }

.btn-primary {
  --bs-btn-bg: var(--kcf-green); --bs-btn-border-color: var(--kcf-green);
  --bs-btn-hover-bg: var(--kcf-green-dark); --bs-btn-hover-border-color: var(--kcf-green-dark);
  --bs-btn-active-bg: var(--kcf-green-dark); --bs-btn-active-border-color: var(--kcf-green-dark);
  --bs-btn-disabled-bg: var(--kcf-green); --bs-btn-disabled-border-color: var(--kcf-green);
  font-weight: 600;
}
.btn-outline-primary {
  --bs-btn-color: var(--kcf-green); --bs-btn-border-color: var(--kcf-green);
  --bs-btn-hover-bg: var(--kcf-green); --bs-btn-hover-border-color: var(--kcf-green);
  --bs-btn-active-bg: var(--kcf-green-dark);
}
.form-control:focus, .form-select:focus, .form-check-input:focus {
  border-color: var(--kcf-green); box-shadow: 0 0 0 .2rem rgba(18, 104, 76, .2);
}
.form-check-input:checked { background-color: var(--kcf-green); border-color: var(--kcf-green); }
.page-link { color: var(--kcf-green); }
.active > .page-link, .page-link.active { background-color: var(--kcf-green); border-color: var(--kcf-green); }
:focus-visible { outline: 2px solid var(--kcf-green); outline-offset: 2px; }

.skip-link { position: absolute; left: -999px; top: 0; z-index: 2000; background: var(--kcf-ink); color: #fff; padding: .5rem 1rem; }
.skip-link:focus { left: 1rem; top: 1rem; }

/* ---------- Shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--kcf-sidebar-w); flex: 0 0 var(--kcf-sidebar-w);
  background: var(--kcf-paper); border-right: 1px solid var(--kcf-line);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  padding: 1rem .75rem 2rem; transition: width .2s ease, flex-basis .2s ease;
}
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.brand { display: flex; align-items: center; gap: .65rem; padding: .25rem .5rem 1.25rem; text-decoration: none; color: var(--kcf-ink); }
.brand-name { display: block; font-weight: 700; font-size: 1.05rem; line-height: 1.15; }
.brand-sub { display: block; font-size: .8rem; color: var(--kcf-muted); }

.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-list .nav-link {
  display: flex; align-items: center; gap: .7rem;
  padding: .55rem .75rem; margin: 1px 0; border-radius: 6px;
  color: var(--kcf-ink); text-decoration: none; font-weight: 500;
  border-left: 3px solid transparent;
}
.nav-list .nav-link i { color: var(--kcf-muted); width: 1.1rem; flex: 0 0 auto; }
.nav-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-list a.nav-link:hover { background: var(--kcf-canvas); }
.nav-list .nav-link.active {
  background: var(--kcf-green-weak); color: var(--kcf-green-dark);
  border-left-color: var(--kcf-green); border-radius: 0 6px 6px 0; font-weight: 600;
}
.nav-list .nav-link.active i { color: var(--kcf-green); }
.nav-list .nav-link.is-pending { color: #98a39e; cursor: default; }
.nav-list .nav-link.is-pending i { color: #b8c0bc; }
.phase-tag { margin-left: auto; font-size: .7rem; color: #98a39e; border: 1px solid var(--kcf-line); border-radius: 4px; padding: 0 .3rem; }
.nav-section { margin: 1.25rem .75rem .35rem; font-size: .8rem; font-weight: 600; color: var(--kcf-muted); }

.topbar {
  display: flex; align-items: center; gap: .75rem;
  background: var(--kcf-paper); border-bottom: 1px solid var(--kcf-line);
  padding: .6rem 1.25rem; position: sticky; top: 0; z-index: 1010;
}
.topbar-title { font-size: 1.15rem; font-weight: 700; margin: 0; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .35rem; }
.btn-icon { border: 0; background: transparent; width: 2.4rem; height: 2.4rem; border-radius: 6px; color: var(--kcf-ink); }
.btn-icon:hover { background: var(--kcf-canvas); }
.notif-dot { position: absolute; top: .55rem; right: .6rem; width: .5rem; height: .5rem; border-radius: 50%; background: var(--kcf-red); }
.notif-menu { width: 320px; padding: 0; }
.notif-head { font-weight: 600; padding: .65rem 1rem; border-bottom: 1px solid var(--kcf-line); }
.notif-empty { padding: 1rem; margin: 0; color: var(--kcf-muted); font-size: .9rem; }
.notif-item { padding: .65rem 1rem; border-bottom: 1px solid var(--kcf-line); }
.user-chip { display: flex; align-items: center; gap: .6rem; border: 0; text-align: left; line-height: 1.15; padding: .25rem .5rem; }
.user-chip:hover { background: var(--kcf-canvas); }
.avatar { width: 2.1rem; height: 2.1rem; border-radius: 50%; display: grid; place-items: center; background: var(--kcf-green); color: #fff; font-weight: 700; }

.content { padding: 1.5rem; flex: 1; outline: none; }
.app-footer { padding: 1rem 1.5rem; font-size: .85rem; color: var(--kcf-muted); border-top: 1px solid var(--kcf-line); }

/* Collapsed sidebar (desktop) */
.app.sidebar-collapsed .sidebar { width: 72px; flex-basis: 72px; }
.app.sidebar-collapsed .brand-text, .app.sidebar-collapsed .nav-text,
.app.sidebar-collapsed .phase-tag, .app.sidebar-collapsed .nav-section { display: none; }
.app.sidebar-collapsed .nav-list .nav-link { justify-content: center; padding-inline: .5rem; }

/* Mobile: sidebar slides over content */
@media (max-width: 991.98px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 1040; transform: translateX(-100%); transition: transform .2s ease; box-shadow: none; }
  .app.sidebar-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .18); }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(27, 38, 33, .35); z-index: 1035; }
  .content { padding: 1rem; }
  .topbar { padding: .5rem .75rem; }
}

/* ---------- Building blocks ---------- */
.panel { background: var(--kcf-paper); border: 1px solid var(--kcf-line); border-radius: 8px; padding: 1.25rem; }
.panel-title { font-size: 1.05rem; font-weight: 700; margin-bottom: 1rem; }

.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.25rem; }
.greeting { font-size: 1.5rem; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.period-filter { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.period-filter .form-control { width: auto; }

/* Money strip: one continuous ledger line rather than separate cards */
.figures {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  background: var(--kcf-paper); border: 1px solid var(--kcf-line); border-radius: 8px; margin-bottom: 1rem;
}
.figure { padding: 1.1rem 1.25rem; border-left: 1px solid var(--kcf-line); display: flex; flex-direction: column; gap: .2rem; }
.figure:first-child { border-left: 0; }
.figure-label { font-size: .88rem; color: var(--kcf-muted); }
.figure-value { font-size: 1.45rem; font-weight: 700; letter-spacing: -.01em; }
.figure-note { font-size: .82rem; color: var(--kcf-amber); }
.figure-lead { background: var(--kcf-green); color: #fff; border-radius: 7px 0 0 7px; }
.figure-lead .figure-label { color: rgba(255, 255, 255, .8); }
.figure-lead .figure-value { font-size: 1.85rem; }
@media (max-width: 767.98px) {
  .figure { border-left: 0; border-top: 1px solid var(--kcf-line); }
  .figure:first-child { border-top: 0; }
  .figure-lead { border-radius: 7px 7px 0 0; }
}

.counts { display: flex; flex-wrap: wrap; gap: .5rem 2rem; padding: .25rem .25rem 1.5rem; }
.counts > div { display: flex; align-items: baseline; gap: .45rem; }
.count-value { font-size: 1.2rem; font-weight: 700; }
.count-label { color: var(--kcf-muted); font-size: .92rem; }

.table-ledger { --bs-table-bg: transparent; margin: 0; }
.table-ledger thead th { font-size: .82rem; font-weight: 600; color: var(--kcf-muted); border-bottom: 1px solid var(--kcf-line); white-space: nowrap; }
.table-ledger td { border-color: #edf0ee; white-space: nowrap; }
.table-ledger td.wrap { white-space: normal; }
.table-ledger tr.is-reversed td { color: #98a39e; text-decoration: line-through; }
.table-ledger tr.is-reversed td .badge { text-decoration: none; }

.empty-state { text-align: center; padding: 2.25rem 1rem; color: var(--kcf-muted); }
.empty-state i { font-size: 1.75rem; color: #b8c0bc; margin-bottom: .75rem; }
.empty-state p { max-width: 42ch; margin: 0 auto; }

.filter-bar { display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: flex-end; }
.filter-bar > div { min-width: 150px; }

/* Roles & permissions */
.role-list { list-style: none; margin: 0; padding: 0; }
.role-list a { display: block; padding: .65rem .75rem; border-radius: 6px; text-decoration: none; color: var(--kcf-ink); border-left: 3px solid transparent; }
.role-list a:hover { background: var(--kcf-canvas); }
.role-list a.active { background: var(--kcf-green-weak); border-left-color: var(--kcf-green); border-radius: 0 6px 6px 0; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; }
.perm-group { border: 1px solid var(--kcf-line); border-radius: 8px; padding: .75rem 1rem 1rem; }
.perm-group legend { float: none; width: auto; font-size: .95rem; font-weight: 700; padding: 0 .35rem; margin: 0 0 .25rem -.35rem; }
.sensitive-tag { font-size: .72rem; color: var(--kcf-amber); background: var(--kcf-amber-weak); border-radius: 4px; padding: 0 .35rem; margin-left: .25rem; }

/* Audit */
.action-tag { font-size: .82rem; padding: .1rem .45rem; border-radius: 4px; background: var(--kcf-green-weak); color: var(--kcf-green-dark); white-space: nowrap; }
.action-tag.action-warn { background: var(--kcf-amber-weak); color: var(--kcf-amber); }
.audit-json { font-size: .78rem; background: var(--kcf-canvas); padding: .5rem; border-radius: 6px; max-width: 420px; white-space: pre-wrap; word-break: break-word; }
details summary { cursor: pointer; color: var(--kcf-green); }

/* ---------- Login ---------- */
.login-body { background: var(--kcf-paper); }
.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(320px, 480px) 1fr; }
.login-panel { background: var(--kcf-paper); padding: 3rem 3rem 2rem; display: flex; flex-direction: column; justify-content: center; border-right: 1px solid var(--kcf-line); }
.login-brand { display: flex; align-items: center; gap: .75rem; margin-bottom: 2.5rem; }
.login-company { font-weight: 700; font-size: 1.15rem; }
.login-title { font-size: 1.75rem; font-weight: 700; margin-bottom: .35rem; }

/* The one decorative moment: a passbook page */
.login-aside { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 3rem; background:
  repeating-linear-gradient(to bottom, transparent 0 39px, rgba(18, 104, 76, .08) 39px 40px), var(--kcf-green-weak); }
.ledger { width: min(440px, 100%); background: var(--kcf-paper); border: 1px solid #cfdcd5; border-radius: 4px; box-shadow: 8px 8px 0 rgba(18, 104, 76, .12); font-variant-numeric: tabular-nums; }
.ledger-row { display: grid; grid-template-columns: 70px 1fr 110px; padding: .7rem 1.1rem; border-top: 1px solid #e3ebe7; }
.ledger-row:first-child { border-top: 0; }
.ledger-row span:nth-child(2) { text-align: right; padding-right: 1.5rem; }
.ledger-head { font-size: .82rem; font-weight: 600; color: var(--kcf-muted); border-bottom: 2px solid var(--kcf-green); }
.st { font-size: .85rem; color: var(--kcf-muted); }
.st-paid { color: var(--kcf-green); font-weight: 600; }
.st-part { color: var(--kcf-amber); font-weight: 600; }
.login-aside-note { margin-top: 1.75rem; max-width: 36ch; text-align: center; color: var(--kcf-green-dark); font-size: 1.05rem; }
@media (max-width: 860px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-aside { display: none; }
  .login-panel { padding: 2rem 1.25rem; border-right: 0; }
}

/* ---------- Error page ---------- */
.error-body { margin: 0; min-height: 100vh; display: grid; place-items: center; background: var(--kcf-canvas); font-family: var(--bs-body-font-family); color: var(--kcf-ink); }
.error-card { background: #fff; border: 1px solid var(--kcf-line); border-radius: 8px; padding: 2rem 2.25rem; max-width: 460px; margin: 1rem; }
.error-code { font-size: .9rem; color: var(--kcf-muted); margin: 0 0 .25rem; }
.error-card h1 { font-size: 1.4rem; margin: 0 0 .5rem; }
.error-link { color: var(--kcf-green); font-weight: 600; }

/* Status pills */
.status { display: inline-block; font-size: .8rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; white-space: nowrap; }
.status-ok { background: var(--kcf-green-weak); color: var(--kcf-green-dark); }
.status-warn { background: var(--kcf-amber-weak); color: var(--kcf-amber); }
.status-bad { background: #fde8e6; color: var(--kcf-red); }
.status-muted { background: #eef1ef; color: var(--kcf-muted); }

.toolbar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.toolbar form { display: flex; flex-wrap: wrap; gap: .5rem; }
.toolbar .form-control, .toolbar .form-select { width: auto; min-width: 180px; }
.detail-list { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.25rem; margin: 0; }
.detail-list dt { font-weight: 500; color: var(--kcf-muted); }
.detail-list dd { margin: 0; }
.form-section-title { font-size: .95rem; font-weight: 700; margin: 1.25rem 0 .75rem; }
.required::after { content: " *"; color: var(--kcf-red); }

/* Collection entry */
.customer-strip { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .85rem 1rem; background: var(--kcf-green-weak); border-radius: 8px; }
.chit-choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .75rem; }
.chit-choice { display: flex; flex-direction: column; padding: .8rem 1rem; border: 1px solid var(--kcf-line); border-radius: 8px; text-decoration: none; color: var(--kcf-ink); }
.chit-choice:hover { border-color: var(--kcf-green); }
.chit-choice.is-selected { border: 2px solid var(--kcf-green); background: var(--kcf-green-weak); }
.calc-preview { padding: .75rem 1rem; background: var(--kcf-canvas); border-radius: 8px; font-size: .95rem; }

/* Receipt */
.receipt { background: #fff; border: 1px solid var(--kcf-line); border-radius: 8px; padding: 1.5rem; max-width: 720px; margin: 0 auto; font-variant-numeric: tabular-nums; position: relative; }
.receipt-head { display: flex; gap: 1rem; align-items: center; border-bottom: 2px solid var(--kcf-green); padding-bottom: 1rem; margin-bottom: 1rem; }
.receipt-company { font-size: 1.25rem; font-weight: 700; }
.receipt-no { margin-left: auto; text-align: right; }
.receipt-grid { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.25rem; margin: 0 0 1rem; }
.receipt-grid dt { color: var(--kcf-muted); font-weight: 500; }
.receipt-grid dd { margin: 0; }
.receipt-amounts { width: 100%; border-top: 1px solid var(--kcf-line); }
.receipt-amounts td { padding: .45rem 0; border-bottom: 1px solid #eef1ef; }
.receipt-amounts td:last-child { text-align: right; }
.receipt-paid td { font-size: 1.2rem; font-weight: 700; color: var(--kcf-green-dark); }
.receipt-foot { margin-top: 1rem; font-size: .9rem; }
.receipt-void { background: #fde8e6; color: var(--kcf-red); font-weight: 700; padding: .5rem .75rem; border-radius: 6px; margin-bottom: 1rem; }
.receipt.is-void .receipt-amounts { text-decoration: line-through; color: var(--kcf-muted); }

.report-index { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.report-links { margin: 0; padding-left: 1.1rem; }
.report-links li { margin: .3rem 0; }
.quick-links { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.25rem; }
.chart-box { position: relative; height: 260px; }

.print-body { background: #fff; }
.print-page { max-width: 1100px; margin: 0 auto; padding: 1.25rem; }
.print-brand { display: flex; gap: .75rem; align-items: center; margin-bottom: 1rem; }
.print-page .panel { border: 0; padding: 0; }

/* Card listing (chit charts) */
.card-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1rem; }
.item-card { display: flex; gap: 1rem; background: var(--kcf-paper); border: 1px solid var(--kcf-line); border-radius: 14px; padding: 1.1rem 1.15rem; box-shadow: 0 1px 2px rgba(27, 38, 33, .04); }
.item-avatar { flex: 0 0 auto; width: 3.1rem; height: 3.1rem; border-radius: 50%; background: var(--kcf-green-weak); color: var(--kcf-green); display: grid; place-items: center; font-weight: 700; }
.item-main { flex: 1; min-width: 0; }
.item-top { display: flex; justify-content: space-between; align-items: baseline; gap: .75rem; }
.item-title { font-size: 1.15rem; font-weight: 700; color: var(--kcf-ink); text-decoration: none; overflow-wrap: anywhere; }
.item-title:hover { color: var(--kcf-green); }
.item-amount { font-size: 1.15rem; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.item-meta { display: flex; flex-wrap: wrap; gap: .25rem 1rem; margin-top: .25rem; color: var(--kcf-green-dark); font-weight: 500; font-size: .92rem; }
.item-bottom { display: flex; align-items: center; gap: .5rem; margin-top: .75rem; flex-wrap: wrap; }
.item-actions { margin-left: auto; display: flex; gap: .4rem; }
.item-actions form { margin: 0; }
.icon-btn { width: 2.5rem; height: 2.5rem; border-radius: 50%; display: inline-grid; place-items: center; border: 0; background: #eaf0fb; color: #2f55c9; text-decoration: none; }
.icon-btn:hover { filter: brightness(.95); }
.icon-btn-teal { background: #e3f4f2; color: #0f766e; }
.icon-btn-green { background: var(--kcf-green-weak); color: var(--kcf-green); }
.icon-btn-violet { background: #ecebfb; color: #4b45c4; }
@media (max-width: 575.98px) { .card-list { grid-template-columns: 1fr; } .item-avatar { width: 2.6rem; height: 2.6rem; } }

/* Chit chart editor */
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: .5rem; flex-wrap: wrap; }
.chart-scroll { max-height: 520px; overflow: auto; border: 1px solid var(--kcf-line); border-radius: 10px; }
.chart-table thead th { position: sticky; top: 0; background: var(--kcf-canvas); z-index: 1; text-transform: uppercase; letter-spacing: .03em; padding: .6rem .75rem; }
.chart-table td { padding: .35rem .75rem; }
.chart-table { table-layout: fixed; width: 100%; }
.chart-table th:first-child, .chart-table td:first-child { width: 3.2rem; }
.chart-table input { width: 100%; min-width: 0; font-variant-numeric: tabular-nums; }
.chart-table .disc { white-space: nowrap; }
.chart-table tfoot td, .chart-view tfoot td { background: var(--kcf-canvas); }
.chart-view thead th { text-transform: uppercase; letter-spacing: .03em; }
.quick-fill { border: 1px dashed #c9d5cf; border-radius: 10px; padding: .75rem 1rem; }
.quick-fill summary { font-weight: 600; color: var(--kcf-green); }
.form-actions { display: flex; justify-content: flex-end; gap: .75rem; }
@media (max-width: 575.98px) {
  .form-actions { position: sticky; bottom: 0; z-index: 5; background: #fff; padding: .75rem 1.25rem; margin: 0 -1.25rem -1.25rem; border-top: 1px solid var(--kcf-line); }
  .chart-table th, .chart-table td { padding-left: .3rem !important; padding-right: .3rem !important; font-size: .88rem; }
  .chart-table th:first-child, .chart-table td:first-child { width: 2.6rem; }
  .form-actions .btn { font-size: 1rem; padding: .6rem .75rem; }
  .chart-view th, .chart-view td { padding-left: .35rem; padding-right: .35rem; font-size: .9rem; }
  .chart-table input { padding: .25rem .35rem; font-size: .88rem; }
  .form-actions .btn { flex: 1; }
}

/* ======================== Phone: app layout ======================== */
.tabbar { display: none; }
.code-chip { display: flex; flex-direction: column; background: var(--kcf-green-weak); border-radius: 10px; padding: .55rem .85rem; }
.item-sub { color: var(--kcf-green); font-weight: 600; font-size: .92rem; }
.item-adv { color: #15803d; font-weight: 700; font-size: .92rem; white-space: nowrap; }
.icon-btn-red { background: #fde8e6; color: var(--kcf-red); }
.icon-btn-muted { background: #eef1ef; color: #98a39e; }
.icon-btn:disabled { opacity: .5; }
.card-list-narrow { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.member-form { background: var(--kcf-canvas); border-radius: 12px; padding: .9rem 1rem; }
.member-list { list-style: none; margin: 1rem 0 0; padding: 0; }
.member-row { display: flex; align-items: center; gap: .75rem; padding: .7rem .25rem; border-bottom: 1px solid #edf0ee; }
.member-row.is-inactive { opacity: .55; }
.member-row.is-editing { background: var(--kcf-green-weak); border-radius: 10px; padding-inline: .5rem; }
.member-no { flex: 0 0 auto; width: 2.4rem; height: 2.4rem; border-radius: 50%; background: var(--kcf-green-weak); color: var(--kcf-green); display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
.member-info { flex: 1; min-width: 0; }
.member-info a { color: var(--kcf-ink); text-decoration: none; }

@media (max-width: 991.98px) {
  body { background: #f4f6f8; }
  .content { padding: .9rem .9rem calc(84px + env(safe-area-inset-bottom)); }
  .app-footer { display: none; }
  .topbar { padding: .55rem .75rem; padding-top: calc(.55rem + env(safe-area-inset-top)); box-shadow: 0 1px 0 var(--kcf-line); }
  .topbar-title { font-size: 1.2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .user-chip .avatar { width: 2.3rem; height: 2.3rem; }
  #sidebarToggle:not(.d-none) { display: none; }
  .btn-back { background: #fff; border: 1px solid var(--kcf-line); border-radius: 12px; color: var(--kcf-green); }
  .panel { border-radius: 16px; padding: 1rem; border-color: #e6eaee; }
  .form-control, .form-select { font-size: 16px; min-height: 2.9rem; border-radius: 10px; }
  .form-control-sm, .form-select-sm { min-height: 2.4rem; }
  .btn { border-radius: 10px; }
  .breadcrumb { display: none; }
  .greeting { font-size: 1.25rem; }

  /* bottom tab bar */
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030; background: #fff; border-top: 1px solid var(--kcf-line);
            padding: .3rem .25rem calc(.3rem + env(safe-area-inset-bottom)); box-shadow: 0 -4px 16px rgba(27, 38, 33, .06); }
  .tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .15rem; padding: .35rem 0; color: #7b8781; text-decoration: none;
         font-size: .72rem; font-weight: 600; border: 0; background: none; }
  .tab i { font-size: 1.25rem; }
  .tab.active { color: var(--kcf-green); }
  .tab-main i { width: 2.6rem; height: 2.6rem; display: grid; place-items: center; border-radius: 14px; background: var(--kcf-green); color: #fff; margin-top: -1.1rem; box-shadow: 0 4px 12px rgba(18, 104, 76, .35); }
  .tab-main.active { color: var(--kcf-green); }

  /* list "Add" buttons become a floating + button */
  .toolbar a.btn-primary[href$="form.php"] { position: fixed; right: 1rem; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 1025; width: 3.5rem; height: 3.5rem;
      border-radius: 16px; font-size: 0; padding: 0; display: grid; place-items: center; box-shadow: 0 6px 18px rgba(18, 104, 76, .35); }
  .toolbar a.btn-primary[href$="form.php"] i { font-size: 1.35rem; margin: 0 !important; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar form { flex-wrap: wrap; }
  .toolbar form .form-control { min-width: 0; flex: 1 1 100%; }
  .toolbar form .form-select { min-width: 0; width: auto; max-width: none; flex: 1 1 8rem; }
  .toolbar form .btn { flex: 0 0 auto; }
  .toolbar > .d-flex { flex-wrap: wrap; }
  .toolbar form.period-filter, .period-filter { width: 100%; flex-wrap: nowrap; }
  .toolbar form.period-filter .form-control, .period-filter .form-control { flex: 1 1 0; min-width: 0; width: 0; padding-left: .5rem; padding-right: .25rem; }
  .table-ledger.keep-table td { white-space: normal; }

  /* figures: 2 per row */
  .figures { grid-template-columns: 1fr 1fr; border-radius: 16px; }
  .figure { border-left: 0 !important; border-top: 1px solid var(--kcf-line); padding: .8rem .9rem; }
  .figure:nth-child(even) { border-left: 1px solid var(--kcf-line) !important; }
  .figure-lead { grid-column: 1 / -1; border-radius: 15px 15px 0 0; border-top: 0; }
  .figure-lead + .figure { border-left: 0 !important; }
  .figure-lead ~ .figure:nth-child(odd) { border-left: 1px solid var(--kcf-line) !important; }
  .figure-lead ~ .figure:nth-child(even) { border-left: 0 !important; }
  .figure-value { font-size: 1.15rem; }
  .figure-lead .figure-value { font-size: 1.6rem; }
  .quick-links { flex-wrap: nowrap; overflow-x: auto; padding-bottom: .25rem; }
  .quick-links .btn { white-space: nowrap; }

  .form-actions { position: sticky; bottom: calc(68px + env(safe-area-inset-bottom)); z-index: 5; background: #fff; padding: .75rem 1rem; margin: 0 -1rem -1rem; border-top: 1px solid var(--kcf-line); border-radius: 0 0 16px 16px; }
  .form-actions .btn { flex: 1; }
}

/* tables become cards on phones */
@media (max-width: 767.98px) {
  table.stack-on-phone thead { display: none; }
  table.stack-on-phone, table.stack-on-phone tbody, table.stack-on-phone tfoot, table.stack-on-phone tr, table.stack-on-phone td { display: block; width: 100%; }
  table.stack-on-phone tr { background: #fff; border: 1px solid #e6eaee; border-radius: 14px; padding: .55rem .85rem; margin-bottom: .6rem; }
  table.stack-on-phone tfoot tr { background: var(--kcf-green-weak); }
  table.stack-on-phone td { border: 0 !important; padding: .2rem 0 !important; display: flex; justify-content: space-between; gap: 1rem; text-align: right !important; white-space: normal !important; }
  table.stack-on-phone td::before { content: attr(data-label); color: var(--kcf-muted); font-size: .82rem; font-weight: 500; text-align: left; flex: 0 0 auto; }
  table.stack-on-phone td:first-child { font-weight: 700; font-size: 1rem; }
  table.stack-on-phone td:empty, table.stack-on-phone td:not([data-label]) { display: none; }
  table.stack-on-phone td[data-label=""]::before { content: none; }
  table.stack-on-phone td > div.small { display: none; }
  .panel > .table-responsive, .panel .table-responsive { overflow: visible; }
  .panel:has(> .table-responsive > table.stack-on-phone) { background: transparent; border: 0; padding: 0; }
}

/* Customer type-ahead */
.cs-wrap { position: relative; }
.cs-wrap input { scroll-margin-top: 84px; }
@media (max-width: 991.98px) { .cs-list { max-height: 240px; } }
.cs-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 1050; list-style: none; margin: 0; padding: .3rem 0; background: #fff;
           border: 1px solid var(--kcf-line); border-radius: 12px; box-shadow: 0 10px 28px rgba(27, 38, 33, .14); max-height: 320px; overflow-y: auto; min-width: 260px; }
.cs-list li[role="option"] { padding: .7rem .9rem; cursor: pointer; -webkit-tap-highlight-color: rgba(18, 104, 76, .12); touch-action: manipulation; }
.cs-list li[role="option"] + li[role="option"] { border-top: 1px solid #f0f2f1; }
.cs-list li[role="option"] a { color: inherit; text-decoration: none; display: block; }
.cs-list li[role="option"]:hover, .cs-list li.is-active { background: var(--kcf-green-weak); }
.cs-list li.is-disabled { opacity: .55; cursor: not-allowed; }
.cs-head { padding: .3rem .85rem .35rem; font-size: .75rem; font-weight: 600; color: var(--kcf-muted); text-transform: uppercase; letter-spacing: .03em; }
.cs-empty { padding: .55rem .85rem; color: var(--kcf-muted); font-size: .9rem; }
.cs-name { font-weight: 600; }
.cs-meta { display: block; font-size: .82rem; color: var(--kcf-muted); }
.cs-tag { margin-left: .4rem; font-size: .72rem; background: #eef1ef; color: var(--kcf-muted); border-radius: 999px; padding: .05rem .45rem; }

/* Collection entry: search, pending-due list, pay card */
.min-w-0 { min-width: 0; }
.collect-search-row { display: flex; gap: .5rem; align-items: stretch; }
.collect-search-row .btn { flex: 0 0 auto; }
.due-list-wrap { display: flex; flex-direction: column; border: 1px solid var(--kcf-line); border-radius: 12px; overflow: hidden; }
.due-item { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .7rem .9rem; color: var(--kcf-ink); text-decoration: none; background: #fff; }
.due-item + .due-item { border-top: 1px solid #edf0ee; }
.due-item:hover, .due-item:focus-visible { background: var(--kcf-green-weak); }
.due-item-main { min-width: 0; display: flex; flex-direction: column; }
.due-item-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.due-item-meta { font-size: .82rem; color: var(--kcf-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.due-item-amt, .due-opt-amt { flex: 0 0 auto; text-align: right; font-weight: 700; color: var(--kcf-red); font-variant-numeric: tabular-nums; }
.due-item-amt span, .due-opt-amt span { display: block; font-size: .75rem; font-weight: 500; color: var(--kcf-muted); }
.cs-list li.due-opt { display: flex; justify-content: space-between; align-items: center; gap: .75rem; }
.due-opt-main { min-width: 0; }
.due-opt-main .cs-name, .due-opt-main .cs-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.chit-choice.is-clear { opacity: .7; }
.pay-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: .75rem; }
.pay-title { font-size: 1.05rem; font-weight: 700; margin: 0; word-break: break-word; }
.pay-due { text-align: right; flex: 0 0 auto; }
.pay-due span { display: block; font-size: .8rem; color: var(--kcf-muted); }
.pay-due strong { font-size: 1.6rem; color: var(--kcf-green-dark); font-variant-numeric: tabular-nums; line-height: 1.1; }
.due-months { list-style: none; margin: 0 0 .5rem; padding: 0; border: 1px solid var(--kcf-line); border-radius: 12px; }
.due-months li { display: flex; justify-content: space-between; gap: 1rem; padding: .6rem .85rem; font-variant-numeric: tabular-nums; }
.due-months li + li { border-top: 1px solid #edf0ee; }
.more-opts > summary { color: var(--kcf-green); font-weight: 600; font-size: .92rem; cursor: pointer; padding: .35rem 0; }
.advance-toggle > summary { list-style: none; }
.advance-toggle > summary::-webkit-details-marker { display: none; }
.advance-toggle[open] > summary { display: none; }
@media (max-width: 991.98px) {
  .pay-btn { position: sticky; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 6; box-shadow: 0 6px 18px rgba(18, 104, 76, .3); }
  .customer-strip { padding: .7rem .85rem; gap: .75rem; }
}

/* Busy buttons (double-submit guard) */
.btn.is-busy { pointer-events: none; opacity: .75; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

@media print {
  .sidebar, .topbar, .app-footer, .no-print { display: none !important; }
  .content { padding: 0; }
  .panel { border: 0; padding: 0; }
}

/* Receipt on phones */
@media (max-width: 575.98px) {
  .receipt { padding: 1rem; border-radius: 14px; }
  .receipt-head { flex-wrap: wrap; gap: .6rem; }
  .receipt-head img { width: 36px; height: 36px; }
  .receipt-head > div:nth-child(2) { flex: 1 1 0; min-width: 0; }
  .receipt-no { margin-left: 0; text-align: left; flex: 1 0 100%; display: flex; gap: .75rem; align-items: baseline; flex-wrap: wrap; }
  .receipt-company { font-size: 1.1rem; }
  .receipt-grid { grid-template-columns: 1fr; gap: 0; }
  .receipt-grid dt { font-size: .8rem; margin-top: .45rem; }
  .receipt-actions { width: 100%; }
  .receipt-actions .btn { flex: 1; }
}

/* Filter bars on phones: two fields per row, full width */
@media (max-width: 767.98px) {
  .filter-bar { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; align-items: end; }
  .filter-bar > div { min-width: 0; }
  .filter-bar .form-control, .filter-bar .form-select { width: 100%; }
  .filter-bar > div:has(input[type="search"]), .filter-bar > div:has(.btn), .filter-bar > .d-flex { grid-column: 1 / -1; }
  .filter-bar > .d-flex .btn, .filter-bar > div:has(.btn) .btn { flex: 1; }
  .filter-bar label { margin-bottom: .2rem; }
}

/* Chit chart editor: keep its own scroll box on phones (the generic phone rule above sets overflow: visible) */
@media (max-width: 767.98px) {
  .panel .table-responsive.chart-scroll { overflow: auto; max-height: 60vh; -webkit-overflow-scrolling: touch; }
}

/* Scroll long tables inside their panel on wider screens only; on phones the rows become cards and the page scrolls */
@media (min-width: 768px) { .scroll-lg { max-height: 460px; overflow: auto; } }
@media (max-width: 767.98px) { .scroll-lg { max-height: none !important; overflow: visible !important; } }

/* Group list: clickable member / chit-taken counts */
.meta-link { color: inherit; text-decoration: none; border-radius: 6px; padding: .1rem .35rem; margin: -.1rem -.1rem; }
.meta-link:hover, .meta-link:focus-visible { background: var(--kcf-green-weak, #e8f3ee); color: var(--kcf-green, #136b4f); text-decoration: underline; }
