/* ══════════════════════════════════════════════
   EasyLedger Pro v2.0 – Main Stylesheet
   Mobile-first, fully responsive
   All new: Staff module, searchable dropdown,
   role-based button visibility, task comments
══════════════════════════════════════════════ */

/* ── CSS VARIABLES ───────────────────────────── */
:root{
  --primary:#1e3a5f;
  --primary-light:#2d5a8e;
  --accent:#0d6efd;
  --success:#198754;
  --danger:#dc3545;
  --warning:#d97706;
  --sidebar-w:240px;
  --card-shadow:0 2px 12px rgba(0,0,0,0.07);
  --radius:12px;
  --topbar-h:56px;
}

/* ── RESET ───────────────────────────────────── */
*{box-sizing:border-box;margin:0;padding:0;}
html,body{width:100%;height:100%;overflow-x:hidden;}
body{font-family:'Nunito',sans-serif;background:#eef2f7;color:#2d3748;font-size:14px;}
#mainApp{display:none;width:100%;min-height:100vh;}

/* ── ROLE-BASED VISIBILITY ───────────────────── */
/* Staff cannot see delete buttons */
body.role-staff .admin-action{display:none!important;}
body.role-staff .admin-only-nav{display:none!important;}
/* Admin-only nav hidden by default, shown via JS */
.admin-only-nav{display:none;}

/* ── AUTH ─────────────────────────────────────── */
#authSection{min-height:100vh;display:flex;align-items:center;justify-content:center;background:linear-gradient(135deg,#1e3a5f 0%,#1565c0 100%);padding:16px;}
.auth-card{background:#fff;border-radius:20px;padding:32px 28px;max-width:460px;width:100%;box-shadow:0 24px 64px rgba(0,0,0,0.22);}
.auth-logo{text-align:center;margin-bottom:24px;}
.auth-logo h2{color:var(--primary);font-weight:800;font-size:1.8rem;margin:0;}
.auth-logo h2 span{color:var(--accent);}
.auth-logo p{color:#6c757d;font-size:.875rem;margin:4px 0 0;}
.auth-tab-btns{display:flex;gap:0;background:#f0f4f8;border-radius:10px;padding:4px;margin-bottom:20px;}
.auth-tab-btns button{flex:1;border:none;background:transparent;padding:7px 4px;border-radius:8px;font-weight:700;font-size:.78rem;cursor:pointer;color:#6c757d;transition:.2s;}
.auth-tab-btns button.active{background:#fff;color:var(--primary);box-shadow:0 2px 6px rgba(0,0,0,.1);}

/* ── SIDEBAR ────────────────────────────────── */
#sidebar{position:fixed;top:0;left:0;height:100vh;width:var(--sidebar-w);background:var(--primary);overflow-y:auto;overflow-x:hidden;z-index:1050;transition:width .3s,left .3s;scrollbar-width:thin;scrollbar-color:rgba(255,255,255,.2) transparent;-webkit-overflow-scrolling:touch;display:flex;flex-direction:column;}
#sidebar.collapsed{width:64px;}
.sidebar-brand{padding:14px 16px;display:flex;align-items:center;gap:10px;border-bottom:1px solid rgba(255,255,255,.1);min-height:var(--topbar-h);flex-shrink:0;}
.brand-icon{background:var(--accent);width:34px;height:34px;border-radius:9px;display:flex;align-items:center;justify-content:center;color:#fff;font-size:.95rem;flex-shrink:0;}
.brand-text{color:#fff;font-weight:800;font-size:1rem;white-space:nowrap;overflow:hidden;}
.brand-text span{display:block;font-size:.68rem;font-weight:600;color:rgba(255,255,255,.5);}
.sidebar-user{padding:10px 16px;border-bottom:1px solid rgba(255,255,255,.1);display:flex;align-items:center;gap:10px;flex-shrink:0;}
.sidebar-user-avatar{width:32px;height:32px;border-radius:50%;background:rgba(255,255,255,.2);display:flex;align-items:center;justify-content:center;color:#fff;font-weight:700;font-size:.82rem;flex-shrink:0;}
.sidebar-user-info{overflow:hidden;flex:1;}
.sidebar-user-name{color:#fff;font-weight:700;font-size:.8rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.sidebar-user-email{color:rgba(255,255,255,.5);font-size:.68rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.sidebar-section-label{padding:14px 16px 4px;color:rgba(255,255,255,.35);font-size:.66rem;font-weight:700;text-transform:uppercase;letter-spacing:1px;white-space:nowrap;}
.sidebar-nav{flex:1;overflow-y:auto;overflow-x:hidden;padding-bottom:8px;}
.nav-link-item{display:flex;align-items:center;gap:12px;padding:10px 16px;color:rgba(255,255,255,.78);text-decoration:none;cursor:pointer;border-left:3px solid transparent;transition:.15s;position:relative;user-select:none;}
.nav-link-item:hover{background:rgba(255,255,255,.08);color:#fff;}
.nav-link-item.active{background:rgba(13,110,253,.25);color:#fff;border-left-color:var(--accent);}
.nav-link-item .ni{width:18px;text-align:center;font-size:.92rem;flex-shrink:0;}
.nav-link-item .nt{font-size:.84rem;font-weight:600;white-space:nowrap;}
.nav-badge{background:var(--accent);color:#fff;border-radius:20px;padding:1px 7px;font-size:.66rem;font-weight:700;margin-left:auto;}
.sidebar-footer{padding:12px 16px;border-top:1px solid rgba(255,255,255,.1);flex-shrink:0;}
.sidebar-footer button{width:100%;background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.15);color:rgba(255,255,255,.78);border-radius:8px;padding:8px;font-size:.84rem;font-weight:600;cursor:pointer;transition:.2s;display:flex;align-items:center;justify-content:center;gap:8px;}
.sidebar-footer button:hover{background:rgba(220,53,69,.3);color:#fff;}
.sidebar-role-badge{display:inline-block;background:rgba(255,255,255,.15);border-radius:20px;padding:1px 8px;font-size:.66rem;font-weight:700;color:rgba(255,255,255,.8);margin-left:6px;}

/* ── MAIN CONTENT ───────────────────────────── */
#mainContent{margin-left:var(--sidebar-w);min-height:100vh;min-width:0;width:calc(100% - var(--sidebar-w));transition:margin-left .3s,width .3s;display:flex;flex-direction:column;}
#mainContent.expanded{margin-left:64px;width:calc(100% - 64px);}
.topbar{background:#fff;padding:0 20px;height:var(--topbar-h);display:flex;align-items:center;justify-content:space-between;box-shadow:0 1px 4px rgba(0,0,0,.08);position:-webkit-sticky;position:sticky;top:0;z-index:900;gap:12px;}
.topbar-left{display:flex;align-items:center;gap:10px;}
#sidebarToggle{background:none;border:none;font-size:1.1rem;color:var(--primary);cursor:pointer;padding:6px;border-radius:8px;}
#sidebarToggle:hover{background:#f0f4f8;}
.topbar-title{font-size:1rem;font-weight:800;color:var(--primary);margin:0;}
.topbar-right:empty{display:none;}
.topbar-right{display:flex;align-items:center;gap:6px;}
.page-content{padding:20px;flex:1;}

/* ── STAT CARDS ─────────────────────────────── */
.stat-card{background:#fff;border-radius:var(--radius);padding:16px;box-shadow:var(--card-shadow);border:1px solid rgba(0,0,0,.04);}
.stat-icon{width:42px;height:42px;border-radius:11px;display:flex;align-items:center;justify-content:center;font-size:1.1rem;margin-bottom:10px;}
.stat-value{font-size:1.3rem;font-weight:800;color:var(--primary);}
.stat-label{font-size:.76rem;color:#6c757d;font-weight:600;}
.stat-sub{font-size:.73rem;color:#9ca3af;margin-top:2px;}

/* ── TABLE CARD ─────────────────────────────── */
.table-card{background:#fff;border-radius:var(--radius);box-shadow:var(--card-shadow);overflow:hidden;margin-bottom:16px;}
.tc-header{padding:12px 16px;border-bottom:1px solid #f0f0f0;display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:8px;}
.tc-header h6{margin:0;font-weight:800;color:var(--primary);font-size:.88rem;}
.tc-tabs{display:flex;gap:4px;flex-wrap:wrap;}
.tc-tab{border:none;background:#f0f4f8;color:#6c757d;border-radius:20px;padding:4px 10px;font-size:.75rem;font-weight:700;cursor:pointer;transition:.2s;}
.tc-tab.active{background:var(--accent);color:#fff;}
.filter-bar{padding:10px 16px;background:#f8f9fa;border-bottom:1px solid #e9ecef;display:flex;flex-wrap:wrap;gap:8px;align-items:center;}
.filter-bar input,.filter-bar select{border:1.5px solid #e5e7eb;border-radius:8px;padding:5px 10px;font-size:.82rem;font-family:inherit;background:#fff;}
.filter-bar input:focus,.filter-bar select:focus{outline:none;border-color:var(--accent);}

/* ── TABLE ───────────────────────────────────── */
table{width:100%;border-collapse:collapse;}
table thead th{background:#f8f9fa;padding:9px 13px;font-size:.74rem;font-weight:700;text-transform:uppercase;letter-spacing:.4px;color:#6c757d;border-bottom:2px solid #e9ecef;white-space:nowrap;cursor:pointer;user-select:none;}
table thead th:hover{background:#f0f0f0;}
table tbody td{padding:9px 13px;font-size:.845rem;border-bottom:1px solid #f5f5f5;vertical-align:middle;}
table tbody tr:last-child td{border-bottom:none;}
table tbody tr:hover{background:#f8f9fa;}
.sortable .sort-icon::before{content:'⇅';color:#ccc;font-size:.68rem;}
.sort-asc .sort-icon::before{content:'↑';color:var(--accent);}
.sort-desc .sort-icon::before{content:'↓';color:var(--accent);}

/* ── PAGINATION ─────────────────────────────── */
.pagination-bar{padding:8px 16px;background:#fafafa;border-top:1px solid #f0f0f0;display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:8px;}
.pagination-info{font-size:.78rem;color:#6c757d;font-weight:600;}
.pagination-controls{display:flex;align-items:center;gap:4px;flex-wrap:wrap;}
.pagination-controls button,.pag-btn{border:1.5px solid #e5e7eb;background:#fff;border-radius:7px;padding:5px 11px;font-size:.8rem;cursor:pointer;color:#495057;transition:.15s;font-weight:600;min-width:32px;}
.pagination-controls button:hover:not([disabled]),.pag-btn:hover:not([disabled]){border-color:var(--accent);color:var(--accent);}
.pagination-controls button[disabled],.pag-btn[disabled]{opacity:.35;cursor:not-allowed;pointer-events:none;}
.pagination-controls button.active-page,.pag-btn.pag-active{background:var(--accent);color:#fff;border-color:var(--accent);}
.per-page-select{border:1.5px solid #e5e7eb;border-radius:7px;padding:3px 7px;font-size:.78rem;cursor:pointer;}

/* ── BADGES ─────────────────────────────────── */
.badge{display:inline-block;padding:2px 9px;border-radius:20px;font-size:.71rem;font-weight:700;}
.b-upcoming{background:#dbeafe;color:#1d4ed8;}
.b-inprogress{background:#ede9fe;color:#6d28d9;}
.b-completed{background:#dcfce7;color:#15803d;}
.b-overdue{background:#fee2e2;color:#dc2626;}
.b-pending{background:#fef3c7;color:#92400e;}
.b-cancelled{background:#f3f4f6;color:#6b7280;}
.b-partpaid{background:#ffedd5;color:#c2410c;}
.b-dr{background:#dcfce7;color:#15803d;}
.b-cr{background:#fee2e2;color:#dc2626;}
.b-direct{background:#fef3c7;color:#92400e;}
.b-staff{background:#ede9fe;color:#5b21b6;}

/* ── ACTION BUTTONS ─────────────────────────── */
.action-btns{display:flex;gap:4px;flex-wrap:nowrap;}
.btn-xs{border:none;background:none;cursor:pointer;padding:5px 7px;border-radius:6px;font-size:.8rem;transition:.15s;line-height:1;}
.btn-view{color:var(--accent);}
.btn-view:hover{background:#dbeafe;}
.btn-edit{color:#6d28d9;}
.btn-edit:hover{background:#ede9fe;}
.btn-del{color:var(--danger);}
.btn-del:hover{background:#fee2e2;}
.btn-whatsapp{color:#25d366;}
.btn-whatsapp:hover{background:#dcfce7;}
.btn-key{color:#d97706;}
.btn-key:hover{background:#fef3c7;}

/* ── MODALS ─────────────────────────────────── */
.modal-header{background:var(--primary);color:#fff;}
.modal-title{font-weight:800;font-size:.95rem;}
.modal-header .btn-close{filter:invert(1) brightness(2);}
.form-label{font-weight:700;font-size:.82rem;color:#374151;}
.form-control,.form-select{border-radius:8px;border:1.5px solid #e5e7eb;font-size:.875rem;font-family:inherit;padding:7px 10px;}
.form-control:focus,.form-select:focus{border-color:var(--accent);box-shadow:0 0 0 3px rgba(13,110,253,.1);outline:none;}
.required-star{color:var(--danger);}
.bal-info{background:#dbeafe;border:1px solid #93c5fd;border-radius:8px;padding:7px 12px;font-size:.84rem;color:#1e40af;font-weight:700;}
.modal-footer{gap:8px;}

/* ── SEARCHABLE DROPDOWN (Custom) ───────────── */
.sdd-wrap{position:relative;width:100%;}
.sdd-search{width:100%;border:1.5px solid #e5e7eb;border-radius:8px;padding:7px 10px;font-size:.875rem;font-family:inherit;background:#fff;transition:.2s;}
.sdd-search:focus{border-color:var(--accent);box-shadow:0 0 0 3px rgba(13,110,253,.1);outline:none;}
.sdd-list{position:absolute;top:calc(100% + 4px);left:0;right:0;background:#fff;border:1.5px solid #e5e7eb;border-radius:10px;box-shadow:0 8px 24px rgba(0,0,0,.12);z-index:2000;display:none;max-height:220px;overflow-y:auto;}
.sdd-item{padding:8px 12px;font-size:.855rem;cursor:pointer;transition:.1s;border-bottom:1px solid #f5f5f5;}
.sdd-item:last-child{border-bottom:none;}
.sdd-item:hover{background:#dbeafe;color:var(--primary);}
.sdd-sub{display:block;font-size:.72rem;color:#9ca3af;margin-top:1px;}
.sdd-no-result{padding:10px 14px;font-size:.84rem;color:#9ca3af;text-align:center;}

/* ── COMM LOG ────────────────────────────────── */
.comm-log{max-height:240px;overflow-y:auto;display:flex;flex-direction:column;gap:6px;margin-bottom:10px;}
.comm-entry{background:#f8f9fa;border-left:3px solid var(--accent);border-radius:0 8px 8px 0;padding:8px 12px;}
.comm-meta{font-size:.72rem;color:#6c757d;font-weight:700;}
.comm-text{font-size:.845rem;margin-top:2px;}

/* ── TASK COMMENTS ───────────────────────────── */
.task-comment{background:#f8f9fa;border-left:3px solid #6d28d9;border-radius:0 8px 8px 0;padding:7px 12px;margin-bottom:5px;}
.tc-meta{font-size:.71rem;color:#6c757d;font-weight:700;display:block;margin-bottom:2px;}
.tc-text{font-size:.845rem;}
#taskCommentsLog{max-height:180px;overflow-y:auto;margin-bottom:10px;}

/* ── SUMMARY PILLS ───────────────────────────── */
.summary-row{display:flex;gap:8px;flex-wrap:wrap;margin-bottom:14px;}
.summary-pill{background:#fff;border-radius:10px;padding:10px 14px;box-shadow:var(--card-shadow);flex:1;min-width:110px;}
.sp-label{color:#6c757d;font-size:.71rem;font-weight:600;display:block;margin-bottom:2px;}
.sp-val{color:var(--primary);font-size:.95rem;font-weight:800;}
.text-success{color:#15803d!important;}
.text-danger{color:#dc2626!important;}
.text-muted{color:#6c757d!important;}
.text-warning{color:#d97706!important;}

/* ── ACCOUNT PILLS ───────────────────────────── */
.acc-pill-row{display:grid;grid-template-columns:repeat(auto-fill,minmax(140px,1fr));gap:10px;margin-bottom:14px;}
.acc-pill{background:#fff;border-radius:10px;padding:10px 13px;box-shadow:var(--card-shadow);border-left:4px solid #ccc;}
.ap-name{font-size:.71rem;font-weight:700;color:#6c757d;display:block;margin-bottom:2px;}
.ap-val{font-size:.92rem;font-weight:800;}
.ap-type{font-size:.67rem;color:#9ca3af;}

/* ── SVC INFO BLOCKS (service view modal) ────── */
.svc-info-block{background:#f8f9fa;border-radius:8px;padding:8px 12px;}
.sib-label{font-size:.71rem;font-weight:700;color:#6c757d;text-transform:uppercase;letter-spacing:.3px;}
.sib-val{font-size:.9rem;font-weight:700;color:#2d3748;margin-top:2px;}

/* ── EMPTY STATE ────────────────────────────── */
.empty-state{text-align:center;padding:48px 20px;color:#9ca3af;}
.empty-state i{font-size:2.6rem;margin-bottom:10px;display:block;}
.empty-state p{font-size:.88rem;margin:0;}

/* ── TOAST ──────────────────────────────────── */
#toastArea{position:fixed;top:14px;right:14px;z-index:9999;display:flex;flex-direction:column;gap:7px;max-width:320px;}
.toast-item{background:#fff;border-radius:10px;padding:11px 16px;box-shadow:0 6px 20px rgba(0,0,0,.15);border-left:4px solid var(--success);font-size:.855rem;font-weight:600;animation:slideIn .3s ease;word-break:break-word;}
.toast-item.error{border-left-color:var(--danger);}
.toast-item.warn{border-left-color:var(--warning);}
.toast-item.info{border-left-color:var(--accent);}
@keyframes slideIn{from{transform:translateX(60px);opacity:0;}to{transform:none;opacity:1;}}

/* ── SPINNER ─────────────────────────────────── */
.loading-overlay{position:fixed;inset:0;background:rgba(255,255,255,.7);z-index:9998;display:none;align-items:center;justify-content:center;}
.loading-overlay.active{display:flex!important;}
.spinner-ring{width:44px;height:44px;border:4px solid #e9ecef;border-top-color:var(--accent);border-radius:50%;animation:spin .7s linear infinite;}
@keyframes spin{to{transform:rotate(360deg);}}

/* ── PAGE SECTIONS ───────────────────────────── */
.page-section{display:none;}
.page-section.active{display:block;}
#overlay{display:none;position:fixed;inset:0;background:rgba(0,0,0,.35);z-index:1040;}

/* ── MISC ────────────────────────────────────── */
.fw-700{font-weight:700;}
.fw-800{font-weight:800;}
.col-5way{flex:0 0 auto;width:20%;}
.table-danger td{background:#fff5f5!important;}

/* ── DEMO BANNER ─────────────────────────────── */
#demoBanner{display:none;background:linear-gradient(90deg,#1e3a5f,#0d6efd);color:#fff;padding:7px 16px;font-size:.78rem;font-weight:700;text-align:center;position:sticky;top:0;z-index:1100;gap:8px;align-items:center;justify-content:center;flex-wrap:wrap;}
#demoBanner.show{display:flex;}

/* ════════════════════════════════════════
   RESPONSIVE — Tablet (max 1199px)
════════════════════════════════════════ */
@media(max-width:1199px){
  .col-5way{width:33.333%;}
}

/* ════════════════════════════════════════
   RESPONSIVE — Mobile (max 991px)
════════════════════════════════════════ */
@media(max-width:991px){
  /* Sidebar: slide in/out on mobile */
  #sidebar{
    position:fixed;
    left:calc(-1 * var(--sidebar-w));
    top:0;height:100%;
    transition:left .3s;
    z-index:1050;
  }
  #sidebar.mobile-open{left:0;}
  #mainContent{margin-left:0!important;width:100%!important;}

  /* Page padding tighter on mobile */
  .page-content{padding:12px;}
  .topbar{padding:0 12px;}

  /* Tables: horizontal scroll */
  .table-scroll{overflow-x:auto;-webkit-overflow-scrolling:touch;}

  /* Summary pills: 2 per row */
  .summary-pill{min-width:calc(50% - 8px);}

  /* Account pills: 2 per row */
  .acc-pill-row{grid-template-columns:repeat(2,1fr);}

  /* TC header: stack on mobile */
  .tc-header{padding:10px 12px;}
  .filter-bar{padding:8px 12px;}

  /* Auth card: no extra padding */
  .auth-card{padding:20px 16px;width:100%;max-width:100%;}
  .auth-logo h2{font-size:1.4rem;}
  .auth-logo p{font-size:.8rem;}

  /* Dashboard stat cols */
  .col-5way{width:50%!important;}

  /* Pagination: compact */
  .pagination-bar{padding:8px 12px;}
  .pagination-controls button{padding:3px 7px;font-size:.75rem;}

  /* Modal: full width on small */
  .modal-dialog{margin:8px;}

  /* Toast: full width */
  #toastArea{left:12px;right:12px;max-width:none;}
  .toast-item{min-width:0;}
}

/* ════════════════════════════════════════
   RESPONSIVE — Small mobile (max 576px)
════════════════════════════════════════ */
@media(max-width:576px){
  .auth-logo h2{font-size:1.5rem;}
  .auth-tab-btns button{font-size:.72rem;padding:6px 3px;}

  /* Summary: handled by new mobile grid rules below */

  /* Tables: minimum column widths */
  table thead th,table tbody td{padding:7px 10px;font-size:.78rem;}

  /* TC tabs: scrollable horizontally */
  .tc-tabs{overflow-x:auto;flex-wrap:nowrap;max-width:100%;}
  .tc-tab{flex-shrink:0;}

  /* Filter bar: stack */
  .filter-bar input,.filter-bar select{min-width:calc(50% - 4px);flex:1;}

  /* Modal full screen */
  .modal-dialog{margin:0;max-width:100%;height:100%;display:flex;align-items:flex-end;}
  .modal-content{border-radius:16px 16px 0 0;max-height:95vh;overflow-y:auto;}

  /* Action buttons: only show icons */
  .btn-xs span{display:none;}

  /* Staff table: hide less important cols */
  .staff-col-email{display:none;}
  .staff-col-resign{display:none;}

  /* Searchable dropdown list */
  .sdd-list{max-height:160px;}

  /* Page content */
  .page-content{padding:10px 8px;}

  /* Topbar title */
  .topbar-title{font-size:.88rem;}

  /* Sync btn text: icon only */

  /* Acc pills: handled in new mobile block */
}

/* ── Hide Type column in Ledgers table ────── */
#ledgersBody tr td:nth-child(2),
#ledgersTable thead tr th:nth-child(2) {
  display: none;
}

/* ── Mobile auth card full-width fix ─────── */
@media (max-width: 480px) {
  #authSection {
    padding: 12px;
    align-items: flex-start;
    padding-top: 40px;
  }
  .auth-card {
    padding: 20px 14px;
    border-radius: 14px;
  }
  .auth-logo { margin-bottom: 16px; }
  .auth-logo h2 { font-size: 1.3rem; }
}

/* ══════════════════════════════════════════════
   LEDGER VIEW — 3-TAB MODAL
══════════════════════════════════════════════ */

/* Header */
.ldv-header {
  background: var(--primary);
  color: #fff;
  padding: 10px 16px;
  align-items: flex-start;
}
.ldv-header-sub {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  opacity: .75;
  line-height: 1;
  margin-bottom: 2px;
}

/* ── Balance strip — always visible ── */
.ldv-bal-strip {
  display: flex;
  align-items: stretch;
  background: #f0f4ff;
  border-bottom: 1.5px solid #dde3f5;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.ldv-bal-item {
  flex: 1;
  min-width: 72px;
  padding: 8px 10px;
  text-align: center;
}
.ldv-bal-net {
  background: #e8f0fe;
}
.ldv-bal-label {
  font-size: .65rem;
  font-weight: 700;
  color: #6c757d;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
.ldv-bal-val {
  font-size: .88rem;
  font-weight: 700;
  color: var(--primary);
  margin-top: 1px;
  white-space: nowrap;
}
.ldv-bal-divider {
  width: 1px;
  background: #dde3f5;
  align-self: stretch;
  flex-shrink: 0;
}

/* ── Tab bar ── */
.ldv-tab-bar {
  display: flex;
  border-bottom: 2px solid #e9ecef;
  background: #fafafa;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex-shrink: 0;
}
.ldv-tab-btn {
  border: none;
  background: transparent;
  padding: 11px 16px;
  font-size: .83rem;
  font-weight: 700;
  color: #6c757d;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color .15s, border-color .15s, background .15s;
}
.ldv-tab-btn:hover:not(.active) {
  color: var(--primary);
  background: #f0f4f8;
}
.ldv-tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: #fff;
}
.ldv-tab-count {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 1px 6px;
  font-size: .66rem;
  font-weight: 800;
  margin-left: 4px;
  vertical-align: middle;
  min-width: 16px;
  text-align: center;
}

/* ── Tab panels ── */
.ldv-tab-panel { min-height: 180px; }

/* ── You Received / You Paid action buttons ── */
.ldv-action-bar {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  background: #f8f9fa;
  border-bottom: 1px solid #e9ecef;
}
.ldv-action-btn {
  flex: 1;
  border: none;
  border-radius: 10px;
  padding: 9px 8px;
  font-size: .88rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .15s;
}
.ldv-action-btn:hover { opacity: .88; }
.ldv-action-received {
  background: #16a34a;
  color: #fff;
}
.ldv-action-paid {
  background: #dc2626;
  color: #fff;
}

/* LDV payment/delete modals — stack above ledger view */
#modalLdvPayment       { z-index: 1060; }
#modalLdvDeleteConfirm { z-index: 1070; }

/* ── Mobile — fullscreen modal ── */
@media (max-width: 576px) {
  /* Balance strip: tighter on phone */
  .ldv-bal-item   { padding: 5px 7px; min-width: 56px; }
  .ldv-bal-label  { font-size: .58rem; }
  .ldv-bal-val    { font-size: .76rem; }
  .ldv-bal-val small { display: none; } /* hide Dr/Cr label on net balance to save space */

  /* Tabs: tighter */
  .ldv-tab-btn    { padding: 9px 11px; font-size: .76rem; }

  /* Action bar: bigger tap targets */
  .ldv-action-btn { padding: 12px 8px; font-size: .85rem; }

  /* LDV payment table — hide Notes column on mobile (save width for Actions) */
  #ldvPaymentsBody td:nth-child(5),
  #modalLedgerView .table thead tr th:nth-child(5) { display: none; }

  /* Compact table rows in LDV */
  #modalLedgerView table thead th,
  #modalLedgerView table tbody td {
    padding: 8px 8px;
    font-size: .78rem;
  }

  /* Keep action column always visible - pin to right */
  #ldvPaymentsBody td:last-child,
  #modalLedgerView .table thead tr th:last-child {
    position: sticky;
    right: 0;
    background: #fff;
    box-shadow: -2px 0 4px rgba(0,0,0,.06);
  }
}

/* ════════════════════════════════════════════════
   MOBILE-FIRST — All pages  (≤ 576px)
════════════════════════════════════════════════ */
@media (max-width: 576px) {

  /* ── Summary pills: 2-per-row grid (all pages) ── */
  .summary-row {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
    flex-wrap: unset !important;
  }
  .summary-pill {
    min-width: 0 !important;
    width: 100% !important;
    flex: unset !important;
    padding: 11px 12px !important;
    border-radius: 12px !important;
  }
  .summary-pill .sp-label {
    font-size: .7rem !important;
    margin-bottom: 3px;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .summary-pill .sp-val {
    font-size: .95rem !important;
    font-weight: 800 !important;
    display: block;
    line-height: 1.25;
    word-break: break-word;
  }

  /* ── Account pills: 2-per-row ── */
  .acc-pill-row { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
  .acc-pill { padding: 10px 11px !important; }
  .acc-pill .acc-name { font-size: .78rem !important; }
  .acc-pill .acc-bal  { font-size: .9rem !important; }

  /* ── Page padding ── */
  .page-content { padding: 8px 8px 24px !important; }

  /* ── Topbar ── */
  .topbar-title { font-size: .9rem; }

  /* ── Table card ── */
  .table-card { border-radius: 10px; margin-bottom: 10px; }

  /* ── TC header: allow scroll for tabs + button ── */
  .tc-header { padding: 8px 10px; gap: 6px; }
  .tc-tabs   { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .tc-tab    { flex-shrink: 0; font-size: .74rem; padding: 4px 9px; }

  /* ── Filter bar: 2-col grid ── */
  .filter-bar {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 8px 10px;
    align-items: center;
  }
  .filter-bar input,
  .filter-bar select  { font-size: .78rem; padding: 5px 8px; width: 100%; }
  /* full-width items inside filter bar */
  .filter-bar input[type="text"],
  .filter-bar input[id*="Search"] { grid-column: 1 / -1; }
  .filter-bar button              { font-size: .75rem; padding: 5px 10px; }

  /* ── Table: horizontal scroll + compact rows ── */
  .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table thead th, table tbody td {
    padding: 8px 9px !important;
    font-size: .77rem !important;
    white-space: nowrap;
  }

  /* ── Stat cards (inside modals / info tab) ── */
  .stat-card  { padding: 10px 12px; }
  .stat-label { font-size: .68rem; }
  .stat-value { font-size: 1rem; }

  /* ── Pagination ── */
  .pagination-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 8px 10px;
  }
  .pagination-controls { flex-wrap: wrap; gap: 3px; }
  .pagination-controls button,
  .pag-btn { padding: 4px 9px !important; font-size: .74rem !important; }
  .per-page-select { font-size: .74rem; }
}

/* ── Very small phones ≤ 400px ── */
@media (max-width: 400px) {
  .summary-pill .sp-val { font-size: .85rem !important; }
  .summary-pill .sp-label { font-size: .65rem !important; }
  table thead th, table tbody td { font-size: .72rem !important; padding: 6px 7px !important; }
}

/* ── Services & Payments pages: hide Add button + Action column ── */
/* Add Service button */
#page-services .btn[onclick*="openServiceModal()"] { display: none !important; }
/* Add Payment button */
#page-payments .btn[onclick*="openPaymentModal()"] { display: none !important; }
/* Action column header + cells in services table */
#servicesTable thead tr th:last-child,
#servicesBody  tr td:last-child { display: none !important; }
/* Action column in payments table */
#paymentsTable thead tr th:last-child,
#paymentsBody  tr td:last-child { display: none !important; }
