/* ==========================================================================
   Loan Management System - mobile-first app shell
   Phones get a native-feeling app: bottom tab bar, top app bar, card lists,
   bottom sheets and full-width sticky actions. Desktop keeps the sidebar and
   dense tables the office needs.
   ========================================================================== */

:root {
  --app-primary:      #1d4ed8;
  --app-primary-dark: #1e3a8a;
  --app-navy:         #14264a;
  --app-ink:          #0f172a;
  --app-muted:        #64748b;
  --app-line:         #e5e7eb;
  --app-bg:           #f4f6f9;
  --app-surface:      #ffffff;

  --app-success: #15803d;
  --app-danger:  #dc2626;
  --app-warning: #ea580c;

  --sidebar-w:  250px;
  --topbar-h:   56px;
  --tabbar-h:   58px;
  --radius:     14px;

  /* Notch and home-indicator padding on iPhones and gesture-nav Androids. */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

* { -webkit-tap-highlight-color: transparent; }

html {
  -webkit-text-size-adjust: 100%;   /* stop iOS enlarging text in landscape */
}

body {
  background: var(--app-bg);
  color: var(--app-ink);
  font-size: 15px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior-y: contain;   /* no rubber-band bounce behind the shell */
}

/* Chrome the user should not be able to select or long-press. */
.lms-topbar, .lms-tabbar, .lms-sidebar, .btn, .badge, .nav-link {
  -webkit-user-select: none;
  user-select: none;
}

/* Anything scrollable gets momentum and keeps its scroll to itself. */
.scroll-y, .table-responsive, .lms-content, .sheet-body {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

a { text-decoration: none; }

/* ---- shell --------------------------------------------------------- */
.lms-shell { display: flex; min-height: 100dvh; }

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

.lms-content {
  flex: 1 1 auto;
  padding: 16px;
  padding-left:  calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
}

.lms-footer {
  padding: 14px 20px;
  color: var(--app-muted);
  font-size: 13px;
  border-top: 1px solid var(--app-line);
}

/* ---- top app bar --------------------------------------------------- */
.lms-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--topbar-h);
  padding: 8px 14px;
  padding-top:   calc(8px + var(--safe-top));
  padding-left:  calc(14px + var(--safe-left));
  padding-right: calc(14px + var(--safe-right));
  background: var(--app-surface);
  border-bottom: 1px solid var(--app-line);
  position: sticky;
  top: 0;
  z-index: 1030;
}

.lms-title {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lms-subtitle {
  font-size: 12.5px;
  color: var(--app-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Back chevron: only meaningful on a phone, where there is no sidebar. */
.lms-back {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  margin-left: -8px;
  border: 0; background: transparent;
  color: var(--app-ink);
  font-size: 22px;
  border-radius: 50%;
  flex: none;
}
.lms-back:active { background: rgba(15,23,42,.08); }

.lms-topbar-actions { display: flex; align-items: center; gap: 6px; flex: none; }

/* ---- bottom tab bar (phones only) ---------------------------------- */
.lms-tabbar {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 1040;
  background: var(--app-surface);
  border-top: 1px solid var(--app-line);
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -1px 8px rgba(15,23,42,.06);
}

.lms-tabbar-inner {
  display: flex;
  align-items: stretch;
  height: var(--tabbar-h);
}

.lms-tab {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--app-muted);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: .01em;
  border: 0;
  background: transparent;
  padding: 6px 2px;
  position: relative;
  transition: color .12s;
}
.lms-tab i { font-size: 20px; line-height: 1; }
.lms-tab span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lms-tab.active { color: var(--app-primary); }
.lms-tab.active::before {
  content: "";
  position: absolute;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 26px; height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--app-primary);
}
.lms-tab:active { background: rgba(15,23,42,.05); }

/* ---- sidebar (desktop only) ---------------------------------------- */
.lms-sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--app-navy);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
  z-index: 1040;
}

.lms-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px;
  font-weight: 600; font-size: 17px; color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.09);
}
.lms-brand i { font-size: 22px; color: #7dd3fc; }
/* The logo sits on white so a dark mark stays readable on the navy sidebar. */
.lms-brand img {
  width: 30px; height: 30px; flex: none;
  border-radius: 7px; object-fit: contain;
  background: #fff; padding: 2px;
}
.lms-brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Settings: current logo / app icon. The checkerboard shows transparency. */
.brand-preview {
  min-height: 104px; padding: 12px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 16px;
  border: 1px dashed var(--app-line); border-radius: var(--radius);
  background: repeating-conic-gradient(#eef2f6 0% 25%, #fff 0% 50%) 50% / 16px 16px;
}
.brand-preview img { max-width: 100%; max-height: 96px; object-fit: contain; }
.brand-preview .brand-icon { width: 72px; height: 72px; border-radius: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.18); }
.brand-preview .brand-icon.is-round { border-radius: 50%; }

.lms-nav { list-style: none; margin: 8px 0; padding: 0; }
.lms-nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px;
  color: #cbd5e1;
  border-left: 3px solid transparent;
  transition: background .12s, color .12s;
}
.lms-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.lms-nav a.active {
  background: #1e3a6b; color: #fff;
  border-left-color: #38bdf8; font-weight: 500;
}
.lms-nav a i { font-size: 17px; width: 20px; text-align: center; flex: none; }

.lms-nav-heading {
  padding: 14px 20px 4px;
  font-size: 11px; letter-spacing: .09em; text-transform: uppercase;
  color: #7c8ba1;
}

.lms-sidebar-footer {
  margin-top: auto;
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,.09);
  color: #94a3b8;
}

/* ---- cards --------------------------------------------------------- */
.card {
  border-color: var(--app-line);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(15,23,42,.04);
}
.card-header {
  background: var(--app-surface);
  border-bottom: 1px solid var(--app-line);
  font-weight: 600;
  border-radius: var(--radius) var(--radius) 0 0 !important;
  padding: 12px 16px;
}
.card-footer {
  background: var(--app-surface);
  border-top: 1px solid var(--app-line);
  border-radius: 0 0 var(--radius) var(--radius) !important;
}

/* ---- stat tiles ---------------------------------------------------- */
.stat {
  background: var(--app-surface);
  border: 1px solid var(--app-line);
  border-radius: var(--radius);
  padding: 14px 16px;
  height: 100%;
  border-left: 4px solid var(--app-primary);
}
.stat-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--app-muted); font-weight: 600;
}
.stat-value {
  font-size: 22px; font-weight: 700; line-height: 1.2; margin-top: 4px;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}
.stat-note { font-size: 11.5px; color: var(--app-muted); margin-top: 2px; }
.stat-success { border-left-color: var(--app-success); }
.stat-danger  { border-left-color: var(--app-danger); }
.stat-warning { border-left-color: var(--app-warning); }
.stat-info    { border-left-color: #0891b2; }
.stat-dark    { border-left-color: var(--app-navy); }

/* ---- tables (desktop) ---------------------------------------------- */
.table { font-size: 14px; margin-bottom: 0; }
.table > thead > tr > th {
  background: #f8fafc; font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .04em; color: var(--app-muted);
  border-bottom: 1px solid var(--app-line); white-space: nowrap;
}
.num, .table td.num, .table th.num {
  text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
}
.table-empty { text-align: center; color: var(--app-muted); padding: 40px 16px; }

/* ---- forms --------------------------------------------------------- */
.required::after { content: " *"; color: var(--app-danger); }
.form-label { font-weight: 600; font-size: 12.5px; margin-bottom: 4px; color: #334155; }
.form-control, .form-select {
  border-radius: 10px;
  border-color: #d5dae1;
  font-size: 15px;
}
.form-control:focus, .form-select:focus {
  border-color: var(--app-primary);
  box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}
.input-group-text { border-radius: 10px; background: #f1f5f9; border-color: #d5dae1; }

.btn { border-radius: 10px; font-weight: 500; }
.btn:active { transform: scale(.985); }
.btn-primary { background: var(--app-primary); border-color: var(--app-primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--app-primary-dark); border-color: var(--app-primary-dark); }

.badge { font-weight: 600; border-radius: 6px; }

/* ---- calculation preview ------------------------------------------- */
.calc-preview {
  background: #f8fafc;
  border: 1px dashed var(--app-line);
  border-radius: 12px;
  padding: 14px 16px;
}
.calc-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 6px 0; font-size: 14px;
}
.calc-row + .calc-row { border-top: 1px solid var(--app-line); }
.calc-row.total {
  font-weight: 700; font-size: 16px;
  border-top: 2px solid var(--app-ink);
  margin-top: 4px; padding-top: 10px;
}

/* ---- collection cards ---------------------------------------------- */
.collect-card {
  border: 1px solid var(--app-line);
  border-radius: var(--radius);
  background: var(--app-surface);
  margin-bottom: 10px;
  overflow: hidden;
}
.collect-card.is-overdue { border-left: 4px solid var(--app-danger); }
.collect-card.is-due     { border-left: 4px solid var(--app-warning); }
.collect-card.is-paid    { border-left: 4px solid var(--app-success); }
.collect-card.is-done    { border-left: 4px solid var(--app-success); }
.collect-card.is-done.is-refused { border-left-color: var(--app-danger); }

/* Customer name with the orange "alert admin" button directly under it. The
   stack is as wide as the name: the button's own text never widens it
   (inline-size containment), and a short name still gets a tappable button. */
.coll-name { font-weight: 500; line-height: 1.25; overflow-wrap: anywhere; }
.name-stack {
  display: inline-flex; flex-direction: column; align-items: stretch;
  gap: 3px; max-width: 100%; vertical-align: top;
}
.name-stack-alert { margin: 0; min-width: 4.25rem; container-type: inline-size; }
.btn-alert-name {
  display: flex; align-items: center; justify-content: center; gap: 5px;
  width: 100%; min-height: 30px; padding: 3px 6px;
  border: 1px solid #fd7e14; border-radius: 8px;
  background: #fd7e14; color: #fff;
  font-size: .8125rem; font-weight: 600; line-height: 1; white-space: nowrap; overflow: hidden;
}
.btn-alert-name:hover, .btn-alert-name:focus-visible { background: #e8590c; border-color: #e8590c; color: #fff; }
.btn-alert-name:disabled { opacity: .6; }
.btn-alert-name .bi { flex: none; font-size: .875rem; }
.btn-alert-name .lbl { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.btn-alert-name .cnt {
  flex: none; min-width: 1.3rem; padding: 2px 5px; border-radius: 999px;
  background: #fff; color: #c2410c; font-size: .72rem; font-weight: 700; text-align: center;
}
@container (max-width: 8.5rem) { .btn-alert-name .lbl-long { display: none; } }
@container (max-width: 5.75rem) { .btn-alert-name .lbl { display: none; } }

/* How many times the office was alerted about a customer (no alert today). */
.alert-count-pill { background: #fff4e6; color: #c2410c; border: 1px solid #fed7aa; }

/* Per-user access card on the user form. */
.access-section { border: 1px solid var(--app-line); border-radius: 10px; padding: 8px 10px; height: 100%; }
.access-section.is-off { background: #f8fafc; }
.access-section-head { margin-bottom: 2px; }
.access-count { font-size: .72rem; color: #64748b; margin-left: 4px; }
.access-hint { font-size: .72rem; color: #64748b; margin: -2px 0 4px 2.5em; }
.access-flag {
  margin-left: 4px; padding: 1px 6px; border-radius: 999px;
  font-size: .62rem; font-weight: 700; text-transform: uppercase; letter-spacing: .02em;
}
.access-flag:empty { display: none; }
.access-flag.is-added   { background: #dcfce7; color: #166534; }
.access-flag.is-removed { background: #fee2e2; color: #991b1b; }
.badge-custom { background: #fd7e14; color: #fff; }

/* "Collect now" fold on the done list. */
.collect-more > summary { list-style: none; display: inline-block; }
.collect-more > summary::-webkit-details-marker { display: none; }

/* Quick amount chips so a collector rarely has to type. */
.amount-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.amount-chip {
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
  white-space: nowrap;
}
.amount-chip:active { background: #e2e8f0; transform: scale(.96); }
.amount-chip.is-active { background: var(--app-primary); border-color: var(--app-primary); color: #fff; }

/* ---- list rows (the mobile replacement for a table) ----------------- */
.applist { display: flex; flex-direction: column; gap: 8px; }

.applist-item {
  display: block;
  background: var(--app-surface);
  border: 1px solid var(--app-line);
  border-radius: var(--radius);
  padding: 12px 14px;
  color: inherit;
  transition: transform .08s, background .12s;
}
a.applist-item:active { transform: scale(.99); background: #f8fafc; }

.applist-top {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
}
.applist-title { font-weight: 600; font-size: 15px; line-height: 1.3; }
.applist-sub   { font-size: 12.5px; color: var(--app-muted); margin-top: 2px; }
.applist-amount {
  text-align: right; flex: none;
  font-variant-numeric: tabular-nums;
}
.applist-amount .value { font-weight: 700; font-size: 16px; }
.applist-amount .label { font-size: 11px; color: var(--app-muted); }

.applist-meta {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid #f1f5f9;
  font-size: 12px; color: var(--app-muted);
}
.applist-meta b { color: var(--app-ink); font-weight: 600; }

/* ---- bottom sheet --------------------------------------------------- */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.45);
  z-index: 1055;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.sheet-backdrop.show { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 1060;
  background: var(--app-surface);
  border-radius: 18px 18px 0 0;
  transform: translateY(100%);
  transition: transform .24s cubic-bezier(.32,.72,0,1);
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -4px 24px rgba(15,23,42,.18);
}
.sheet.show { transform: translateY(0); }

.sheet-grab {
  width: 38px; height: 4px; border-radius: 999px;
  background: #cbd5e1;
  margin: 10px auto 4px;
  flex: none;
}
.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 18px 12px;
  border-bottom: 1px solid var(--app-line);
  font-weight: 600;
  flex: none;
}
.sheet-body { padding: 14px 18px 18px; overflow-y: auto; }

.sheet-link {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 4px;
  color: var(--app-ink);
  border-bottom: 1px solid #f1f5f9;
  font-size: 15px;
}
.sheet-link:last-child { border-bottom: 0; }
.sheet-link i { font-size: 19px; width: 24px; text-align: center; color: var(--app-muted); }
.sheet-link:active { background: #f8fafc; }
.sheet-link.is-danger, .sheet-link.is-danger i { color: var(--app-danger); }

/* Desktop keeps modals; sheets are a phone affordance. */
@media (min-width: 992px) {
  /* Closed, it must clear the 24px gap too, or its top edge peeks above the page bottom. */
  .sheet { max-width: 460px; left: 50%; transform: translate(-50%, calc(100% + 48px)); border-radius: 18px; bottom: 24px; }
  .sheet.show { transform: translate(-50%, 0); }
}

/* ---- floating action button ---------------------------------------- */
.fab {
  position: fixed;
  right: calc(16px + var(--safe-right));
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  z-index: 1035;
  width: 54px; height: 54px;
  border-radius: 50%;
  border: 0;
  background: var(--app-primary);
  color: #fff;
  font-size: 24px;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px rgba(29,78,216,.4);
}
.fab:active { transform: scale(.94); }

/* ---- toasts --------------------------------------------------------- */
.toast-stack {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  z-index: 1080;
  width: min(92vw, 460px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.app-toast {
  background: #0f172a;
  color: #fff;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(15,23,42,.28);
  animation: toast-in .22s cubic-bezier(.32,.72,0,1);
}
.app-toast.is-success { background: #14532d; }
.app-toast.is-danger  { background: #7f1d1d; }
.app-toast.is-warning { background: #7c2d12; }
.app-toast i { font-size: 17px; flex: none; margin-top: 1px; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- sticky form action bar ---------------------------------------- */
.form-actions {
  position: sticky;
  bottom: 0;
  background: var(--app-surface);
  border-top: 1px solid var(--app-line);
  padding: 12px 16px;
  padding-bottom: calc(12px + var(--safe-bottom));
  margin: 16px -16px 0;
  display: flex;
  gap: 10px;
  z-index: 1020;
}
.form-actions .btn { flex: 1 1 0; }

/* ---- segmented control (mobile tabs) -------------------------------- */
.segmented {
  display: flex;
  background: #e9edf3;
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.segmented button, .segmented a {
  flex: 1 1 0;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--app-muted);
  text-align: center;
}
.segmented .active { background: var(--app-surface); color: var(--app-ink); box-shadow: 0 1px 3px rgba(15,23,42,.12); }

/* ---- pull-to-refresh indicator -------------------------------------- */
.ptr {
  position: absolute;
  top: 0; left: 50%;
  transform: translate(-50%, -46px);
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--app-surface);
  box-shadow: 0 2px 10px rgba(15,23,42,.18);
  display: flex; align-items: center; justify-content: center;
  color: var(--app-primary);
  z-index: 1025;
  transition: transform .16s;
}
.ptr.spin i { animation: ptr-spin .8s linear infinite; }
@keyframes ptr-spin { to { transform: rotate(360deg); } }

/* =====================================================================
   PHONES AND SMALL TABLETS  (< 992px)
   The sidebar is replaced by a bottom tab bar, so the layout stops being
   a two-column shell and becomes a single scrolling column.
   ===================================================================== */
@media (max-width: 991.98px) {

  .lms-sidebar { display: none; }
  .lms-tabbar  { display: block; }
  .lms-back    { display: flex; }
  .fab         { display: flex; }

  .lms-shell { display: block; }
  .lms-main  { min-height: 100dvh; }

  /* Leave room for the tab bar so the last row is never trapped under it. */
  .lms-content {
    padding: 14px;
    padding-left:   calc(14px + var(--safe-left));
    padding-right:  calc(14px + var(--safe-right));
    padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
  }
  .lms-footer { display: none; }

  .form-actions {
    bottom: calc(var(--tabbar-h) + var(--safe-bottom));
    margin-left: -14px; margin-right: -14px;
    padding-bottom: 12px;
  }

  /* Comfortable one-handed targets, and 16px inputs so iOS does not zoom. */
  .btn { min-height: 46px; padding-left: 16px; padding-right: 16px; }
  .btn-sm { min-height: 38px; }
  .form-control, .form-select { min-height: 46px; font-size: 16px; }
  .form-check-input { width: 20px; height: 20px; margin-top: .15rem; }
  .form-check-label { padding-left: 4px; }

  .stat { padding: 12px 14px; border-radius: 12px; }
  .stat-value { font-size: 19px; }
  .stat-label { font-size: 10.5px; }

  .card { border-radius: 12px; }
  .lms-content > .card, .lms-content > .row { margin-bottom: 0; }

  /* Dense admin tables restack as labelled cards. Each cell carries its
     column name in data-label, so one rule covers every table. */
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr {
    background: var(--app-surface);
    border: 1px solid var(--app-line);
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 8px;
  }
  .table-cards td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    border: 0 !important;
    padding: 4px 0 !important;
    text-align: right;
  }
  .table-cards td::before {
    content: attr(data-label);
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--app-muted);
    text-align: left;
    flex: none;
  }
  .table-cards td:empty { display: none; }
  .table-cards .table-empty { display: block; text-align: center; }
  .table-cards .table-empty::before { content: none; }

  /* The card wrapper adds nothing once the rows are cards themselves. */
  .card > .table-responsive > .table-cards { background: transparent; }
  .card:has(> .table-responsive > .table-cards) {
    background: transparent; border: 0; box-shadow: none;
  }
  .card:has(> .table-responsive > .table-cards) > .card-header {
    background: transparent; border: 0; padding: 0 2px 8px;
    font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--app-muted);
  }

  /* Modals behave like sheets on a phone. */
  .modal-dialog {
    margin: 0;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    max-width: none;
  }
  .modal-content {
    border-radius: 18px 18px 0 0;
    border: 0;
    padding-bottom: var(--safe-bottom);
  }
  .modal.fade .modal-dialog { transform: translateY(100%); transition: transform .25s cubic-bezier(.32,.72,0,1); }
  .modal.show .modal-dialog { transform: translateY(0); }

  .pagination { justify-content: center; }
  .nav-tabs { flex-wrap: nowrap; overflow-x: auto; }
}

/* Very small phones: two stat tiles per row stay readable. */
@media (max-width: 380px) {
  .stat-value { font-size: 17px; }
  .lms-tab { font-size: 9.5px; }
  .lms-tab i { font-size: 18px; }
}

/* Desktop hides the mobile-only affordances. */
@media (min-width: 992px) {
  .mobile-only { display: none !important; }
}
@media (max-width: 991.98px) {
  .desktop-only { display: none !important; }
}

/* ---- print: receipts ------------------------------------------------ */
@media print {
  .lms-sidebar, .lms-topbar, .lms-tabbar, .lms-footer,
  .no-print, .fab, .form-actions { display: none !important; }
  .lms-content { padding: 0; }
  body { background: #fff; font-size: 12px; }
  .card { border: none; box-shadow: none; }
}

.receipt-58 { width: 58mm; margin: 0 auto; font-family: ui-monospace, Consolas, monospace; font-size: 11px; }
.receipt-a5 { width: 148mm; margin: 0 auto; }
@page { margin: 8mm; }

/* ---- 7-day trend chart ---------------------------------------------- */
.trend {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 180px;
}
.trend-col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
}
.trend-bar {
  width: 100%;
  min-height: 2px;
  background: var(--app-primary);
  border-radius: 5px 5px 0 0;
}
.trend-value, .trend-label {
  font-size: 10px;
  color: var(--app-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  text-align: center;
}
.trend-value { margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.trend-label { margin-top: 5px; }

@media (max-width: 575.98px) {
  .trend { height: 150px; gap: 4px; }
  .trend-value { font-size: 8.5px; }
  .trend-label { font-size: 9px; }
}

/* ---- collapsible filters -------------------------------------------- */
/* Filter panels are useful in the office and in the way on a phone, so on
   small screens everything but the search box folds behind a toggle. */
.filter-toggle {
  border: 1px solid #d5dae1;
  background: var(--app-surface);
  border-radius: 10px;
  color: var(--app-muted);
  min-height: 46px;
  padding: 0 14px;
  font-size: 13.5px;
  font-weight: 600;
  display: none;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.filter-toggle .count {
  background: var(--app-primary);
  color: #fff;
  border-radius: 999px;
  min-width: 18px; height: 18px;
  font-size: 11px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 5px;
}

@media (max-width: 991.98px) {
  .filter-toggle { display: inline-flex; }
  .filter-form.is-collapsed > .filter-extra { display: none; }
  .filter-form > .filter-first { flex: 1 1 auto; max-width: none; }
  /* Filter cards carry no visual weight of their own on a phone. */
  .card:has(> .card-body > .filter-form) {
    background: transparent; border: 0; box-shadow: none;
  }
  .card:has(> .card-body > .filter-form) > .card-body { padding: 0; }
}

@media (max-width: 991.98px) {
  /* An empty cell stacked as a bare label is just noise. */
  .table-cards td.is-blank { display: none; }
}

/* ---- compact tables --------------------------------------------------- */
/* A repayment schedule is a hundred short rows of dates and amounts. Stacking
   those as cards would be far worse than a tight table, so these keep their
   grid on a phone and simply get smaller and scrollable. */
@media (max-width: 991.98px) {
  .table-compact { font-size: 12.5px; }
  .table-compact > thead > tr > th { font-size: 10px; padding: 6px 6px; }
  .table-compact > tbody > tr > td { padding: 7px 6px; white-space: nowrap; }
  .table-compact .badge { font-size: 9.5px; padding: 3px 5px; }
}

/* On desktop these action rows sit in the sidebar column and must not stick. */
@media (min-width: 992px) {
  .form-actions {
    position: static;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    display: grid;
    gap: 10px;
  }
  .form-actions .btn { flex: none; }
}

/* Clickable rows/cards (data-href): whole row opens its detail. */
tr[data-href], [data-href].collect-card, [data-href].stat, [data-href].applist-item { cursor: pointer; }
tr[data-href]:hover { background: rgba(0,0,0,.03); }

/* ---- delete review + Deleted data ----------------------------------- */
.purge-intro .purge-icon {
  width: 44px; height: 44px; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: #fee2e2; color: var(--app-danger); font-size: 22px;
}
.purge-intro .purge-icon.is-safe { background: #dcfce7; color: var(--app-success); }
.purge-owner { font-size: 13.5px; background: #f8fafc; border: 1px solid var(--app-line); border-radius: 10px; padding: 8px 12px; }
.purge-master { border-top: 1px solid var(--app-line); padding-top: 12px; }

.purge-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.purge-tile {
  display: flex; flex-direction: column; background: var(--app-surface); color: inherit; text-decoration: none;
  border: 1px solid var(--app-line); border-radius: 12px; padding: 9px 12px;
}
.purge-tile:hover { border-color: #cbd5e1; color: inherit; }
.purge-tile .l { font-size: 12px; color: var(--app-muted); white-space: nowrap; }
.purge-tile .n { font-size: 20px; font-weight: 700; line-height: 1.2; }
.purge-tile .sel { font-size: 11.5px; font-weight: 600; color: var(--app-danger); min-height: 1.1em; }
.purge-tile.is-empty { opacity: .5; }

.purge-head { display: flex; align-items: center; gap: 10px; }
.purge-head .form-check-input { margin: 0; flex: none; }
.purge-head-label { display: flex; align-items: center; gap: 6px; margin: 0; cursor: pointer; font-weight: 600; min-width: 0; }
.purge-head-right { margin-left: auto; font-size: 12.5px; color: var(--app-muted); white-space: nowrap; }

.purge-list { display: flex; flex-direction: column; }
.purge-row { display: flex; align-items: flex-start; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--app-line); }
.purge-row:first-child { border-top: 0; }
.purge-row > .form-check-input { flex: none; margin-top: .2rem; cursor: pointer; }
.purge-row > .form-check-input:disabled { cursor: not-allowed; }
.purge-row.is-on { background: #fef2f2; }
.purge-row.is-forced > .form-check-input { opacity: .65; }
.purge-body { flex: 1 1 auto; min-width: 0; }
.purge-main { display: block; margin: 0; cursor: pointer; }
.purge-line { display: flex; justify-content: space-between; align-items: baseline; gap: 4px 10px; flex-wrap: wrap; }
.purge-sub { display: block; font-size: 12.5px; color: var(--app-muted); margin-top: 2px; overflow-wrap: anywhere; }
.purge-why {
  display: inline-block; margin-top: 4px; margin-right: 4px; padding: 1px 7px; border-radius: 6px;
  font-size: 11px; font-weight: 600; color: #b91c1c; background: #fee2e2;
}
.purge-why.is-admin { color: #475569; background: #e2e8f0; }
.purge-details { margin-top: 6px; }
.purge-details summary { font-size: 12.5px; color: var(--app-primary); cursor: pointer; width: fit-content; }
.purge-sched { max-height: 260px; overflow: auto; margin-top: 6px; border: 1px solid var(--app-line); border-radius: 8px; background: #fff; }
.purge-summary { padding-left: 1.2rem; margin-bottom: 12px; }
.purge-summary li { font-weight: 600; }

.purge-bar {
  position: sticky; bottom: 0; z-index: 1020;
  display: flex; align-items: center; gap: 12px;
  margin: 16px -16px 0; padding: 12px 16px calc(12px + var(--safe-bottom));
  background: var(--app-surface); border-top: 1px solid var(--app-line);
  box-shadow: 0 -4px 14px rgba(15, 23, 42, .06);
}
.purge-bar .purge-count { flex: 1 1 auto; min-width: 0; line-height: 1.3; }
@media (max-width: 991.98px) {
  .purge-bar {
    bottom: calc(var(--tabbar-h) + var(--safe-bottom));
    margin-left: -14px; margin-right: -14px; padding-bottom: 12px;
  }
}

.bin-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.bin-chip { font-size: 12px; background: #f1f5f9; border-radius: 999px; padding: 2px 10px; color: #334155; }
.bin-chip.is-money { background: #fee2e2; color: #991b1b; font-weight: 600; }
