:root{
  --brand:#ff6b35; --brand-dark:#b8431a; --brand-soft:#fff1ec; --gold:#c8963e;
  --ink:#1f2430; --muted:#6b7280; --line:#e7e3da; --bg:#f6f5f1; --card:#fff;
  --ok:#16a34a; --ok-soft:#e8f6ed; --danger:#dc2626; --danger-soft:#fdecec;
  --warn:#b45309; --warn-soft:#fff6e6;
}
*{box-sizing:border-box;}
body{margin:0;font-family:'Cairo',system-ui,Arial,sans-serif;background:var(--bg);color:var(--ink);font-size:14px;}
h1,h2,h3{font-weight:600;margin:0;}
a{color:inherit;text-decoration:none;}
button{font-family:inherit;cursor:pointer;}

/* Header */
.app-header{background:var(--brand);color:#fff;padding:12px 20px;display:flex;align-items:center;justify-content:space-between;gap:12px;}
.brand{display:flex;align-items:center;gap:12px;}
.brand-title{font-weight:600;font-size:16px;}
.brand-sub{font-size:12px;color:#ffe3d6;}
.header-actions{display:flex;align-items:center;gap:10px;font-size:12.5px;}
.user-chip{background:#ffffff22;padding:5px 12px;border-radius:20px;}
.today{opacity:.9;}
.back-link{background:#fff;color:var(--brand-dark);padding:6px 12px;border-radius:7px;font-weight:500;}

/* Tabs */
.tab-bar{display:flex;gap:6px;padding:10px 16px;background:var(--card);border-bottom:1px solid var(--line);flex-wrap:wrap;}
.tab-btn{background:transparent;border:1px solid var(--line);color:var(--muted);padding:8px 14px;border-radius:8px;font-size:13.5px;display:flex;align-items:center;gap:6px;}
.tab-btn:hover{background:var(--bg);}
.tab-btn.active{background:var(--brand-soft);color:var(--brand-dark);border-color:var(--brand);font-weight:500;}
.badge{background:var(--brand);color:#fff;font-size:11px;padding:1px 7px;border-radius:20px;}

/* Layout */
.content{padding:18px;max-width:1200px;margin:0 auto;}
.panel{display:none;}
.panel.active{display:block;}
.section-title{font-size:14px;font-weight:600;margin:0 0 8px;display:flex;align-items:center;gap:6px;}

/* Cards & metrics */
.metric-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:12px;margin-bottom:18px;}
.metric{background:var(--card);border:1px solid var(--line);border-radius:12px;padding:14px;border-top:3px solid var(--brand);}
.metric.red{border-top-color:var(--danger);} .metric.gold{border-top-color:var(--gold);} .metric.ok{border-top-color:var(--ok);}
.metric .label{font-size:12.5px;color:var(--muted);}
.metric .value{font-size:23px;font-weight:600;margin-top:2px;}
.metric .value small{font-size:12px;color:var(--muted);font-weight:400;}
.card{background:var(--card);border:1px solid var(--line);border-radius:12px;padding:16px;}

/* ── Mobile-first KPI dashboard ─────────────────────────── */
.dash{display:flex;flex-direction:column;gap:12px;}
.kpi{display:flex;align-items:center;gap:14px;background:var(--card);border:1px solid var(--line);
  border-radius:16px;padding:16px 18px;text-align:right;width:100%;border:0;position:relative;
  box-shadow:0 1px 2px rgba(0,0,0,.04);transition:transform .12s,box-shadow .12s;cursor:default;}
a.kpi{cursor:pointer;}
a.kpi:active{transform:scale(.985);}
a.kpi:hover{box-shadow:0 4px 14px rgba(0,0,0,.08);}
.kpi-ic{flex:0 0 auto;width:52px;height:52px;border-radius:14px;display:flex;align-items:center;
  justify-content:center;font-size:22px;background:var(--brand-soft);color:var(--brand);}
.kpi-body{display:flex;flex-direction:column;gap:3px;min-width:0;flex:1;}
.kpi-label{font-size:13px;color:var(--muted);font-weight:500;}
.kpi-val{font-size:30px;font-weight:700;line-height:1.1;color:var(--ink);letter-spacing:-.5px;}
.kpi-val small{font-size:14px;color:var(--muted);font-weight:500;}
.kpi-go{color:var(--muted);font-size:15px;flex:0 0 auto;}
/* primary = receivables hero */
.kpi-primary{background:linear-gradient(135deg,var(--brand),var(--brand-dark));border:0;}
.kpi-primary .kpi-label{color:rgba(255,255,255,.85);}
.kpi-primary .kpi-val{color:#fff;}
.kpi-primary .kpi-val small{color:rgba(255,255,255,.8);}
.kpi-primary .kpi-ic{background:rgba(255,255,255,.2);color:#fff;}
.kpi-primary .kpi-go{color:rgba(255,255,255,.85);}
/* secondary tints */
.kpi-gold .kpi-ic{background:#fbf2df;color:var(--gold);}
.kpi-warn .kpi-ic{background:var(--warn-soft);color:var(--warn);}
.kpi-warn .kpi-val{color:var(--warn);}
.kpi-row{display:grid;grid-template-columns:1fr 1fr;gap:12px;}
.kpi-row .kpi{padding:14px;gap:11px;}
.kpi-row .kpi-ic{width:42px;height:42px;font-size:18px;border-radius:12px;}
.kpi-row .kpi-val{font-size:24px;}

/* dashboard block (top debtors) */
.dash-block{background:var(--card);border:1px solid var(--line);border-radius:16px;overflow:hidden;}
.dash-block-head{display:flex;justify-content:space-between;align-items:center;gap:8px;
  padding:13px 16px;border-bottom:1px solid var(--line);font-weight:600;font-size:14px;}
.dash-block-head > span{display:flex;align-items:center;gap:7px;}
.dash-block-head i.fa-triangle-exclamation{color:var(--warn);}
.debtor-list{display:flex;flex-direction:column;}
.debtor{display:flex;align-items:center;gap:12px;padding:12px 16px;border-bottom:1px solid var(--line);
  text-align:right;transition:background .12s;}
.debtor:last-child{border-bottom:0;}
a.debtor{cursor:pointer;}
a.debtor:active{background:var(--brand-soft);}
a.debtor:hover{background:var(--brand-soft);}
.debtor-rank{flex:0 0 auto;width:26px;height:26px;border-radius:50%;background:var(--bg);color:var(--muted);
  font-size:12px;font-weight:700;display:flex;align-items:center;justify-content:center;}
.debtor:nth-child(1) .debtor-rank{background:#fde8e8;color:var(--danger);}
.debtor:nth-child(2) .debtor-rank{background:#fdf0e3;color:var(--warn);}
.debtor:nth-child(3) .debtor-rank{background:#fbf2df;color:var(--gold);}
.debtor-main{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px;}
.debtor-name{font-weight:600;font-size:14.5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.debtor-sub{font-size:11.5px;color:var(--muted);display:flex;align-items:center;gap:5px;}
.debtor-sub i{font-size:10px;}
.debtor-bal{flex:0 0 auto;font-weight:700;font-size:15px;color:var(--danger);}
.dash-empty{padding:22px;text-align:center;color:var(--muted);font-size:13px;}
.dash-empty i{color:var(--ok);margin-left:6px;}
/* widen the KPI hero into a row on desktop */
@media (min-width:720px){
  .dash{display:grid;grid-template-columns:2fr 1fr 1fr;gap:14px;align-items:start;}
  .kpi-primary{grid-column:1;grid-row:1;}
  .kpi-row{display:contents;}
  .kpi-row .kpi{grid-row:1;}
  .dash-block{grid-column:1 / -1;}
}

/* Tables */
table{width:100%;border-collapse:collapse;font-size:13px;}
th,td{padding:9px 8px;text-align:right;border-bottom:1px solid var(--line);}
th{color:var(--muted);font-weight:500;font-size:12px;white-space:nowrap;}
tbody tr:hover{background:var(--brand-soft);}
.clickable{cursor:pointer;}
.num{font-variant-numeric:tabular-nums;}

/* ── Universal scrollable table: pins header + totals, keeps page chrome visible ─ */
/* The table scrolls INSIDE this box (capped height) so the cards / filters / totals
   above and below it stay in view no matter how long the history is. */
.table-scroll{max-height:calc(100vh - 250px);overflow:auto;border:1px solid var(--line);
  border-radius:12px;background:var(--card);-webkit-overflow-scrolling:touch;}
.table-scroll table{border:0;}
.table-scroll thead th{position:sticky;top:0;z-index:3;background:var(--card);
  box-shadow:inset 0 -1px 0 var(--line);}
.table-scroll tfoot td{position:sticky;bottom:0;z-index:2;background:var(--brand-soft);
  box-shadow:inset 0 1px 0 var(--brand);font-weight:700;}
.table-scroll tbody tr:last-child td{border-bottom:none;}
/* inside a card the card already frames it — drop the extra border, shorter cap */
.card .table-scroll{border:0;border-radius:0;max-height:46vh;}

/* Chips */
.chip{font-size:11.5px;padding:2px 9px;border-radius:20px;display:inline-block;white-space:nowrap;}
.chip.draft{background:var(--brand-soft);color:var(--brand-dark);}
.chip.issued{background:var(--ok-soft);color:var(--ok);}
.chip.cancelled{background:#eee;color:#777;}
.chip.overdue{background:var(--danger-soft);color:var(--danger);}
.chip.paid{background:var(--ok-soft);color:var(--ok);}
.chip.partial{background:var(--warn-soft);color:var(--warn);}
.chip.unpaid{background:var(--danger-soft);color:var(--danger);}

/* Buttons */
.btn{border:1px solid #cdc6b6;background:#efece4;color:var(--ink);padding:7px 12px;border-radius:7px;font-size:12.5px;font-weight:600;display:inline-flex;align-items:center;gap:5px;cursor:pointer;box-shadow:0 1px 1px rgba(0,0,0,.04);}
.btn:hover{background:#e3dfd3;border-color:#bfb7a3;}
.btn-primary{background:var(--brand);color:#fff;border-color:var(--brand);box-shadow:0 1px 2px rgba(0,0,0,.12);}
.btn-primary:hover{background:var(--brand-dark);}
.btn-danger{color:var(--danger);background:#fdecec;border-color:#f3c0c0;}
.btn-danger:hover{background:#fbdcdc;border-color:#e89a9a;}
.toolbar{display:flex;gap:8px;margin-bottom:12px;flex-wrap:wrap;align-items:center;}
input,select,textarea{font-family:inherit;font-size:13px;padding:7px 10px;border:1px solid var(--line);border-radius:7px;background:#fff;color:var(--ink);}
input:focus,select:focus,textarea:focus{outline:none;border-color:var(--brand);box-shadow:0 0 0 3px var(--brand-soft);}
.grow{flex:1;min-width:160px;}
/* statement filter date pairs (label + date kept together) */
.stmt-date{display:flex;align-items:center;gap:6px;}
.stmt-date label{flex:0 0 auto;}
.stmt-date input{min-width:0;}
/* customer profile header — prominent name + action row */
.cust-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:12px;gap:10px;flex-wrap:wrap;}
.cust-title{font-size:21px;font-weight:700;color:var(--ink);}
.cust-actions{display:flex;gap:8px;flex-wrap:wrap;}
/* print-statement button: distinct from the orange table header (outline style) */
.stmt-print{background:#fff;color:var(--brand-dark);border:1.5px solid var(--brand);box-shadow:none;}
.stmt-print:hover{background:var(--brand-soft);}

/* Two-column splits */
.split{display:grid;grid-template-columns:300px 1fr;gap:14px;}
.list-pane{background:var(--card);border:1px solid var(--line);border-radius:12px;overflow:hidden;max-height:70vh;overflow-y:auto;}
.list-item{padding:10px 12px;border-bottom:1px solid var(--line);cursor:pointer;}
.list-item:hover{background:var(--bg);}
.list-item.active{background:var(--brand-soft);border-right:3px solid var(--brand);}
.list-item .li-title{font-size:13px;font-weight:500;}
.list-item .li-sub{font-size:11.5px;color:var(--muted);}

.acct-cards{display:flex;gap:10px;margin-bottom:12px;flex-wrap:wrap;}
.acct-card{flex:1;min-width:120px;background:var(--bg);border-radius:9px;padding:10px 12px;}
.acct-card .label{font-size:11.5px;color:var(--muted);}
.acct-card .value{font-size:18px;font-weight:600;}
.acct-card.ok{background:var(--ok-soft);}
.acct-card .label i{font-size:11px;opacity:.75;margin-left:2px;}
.acct-card.accent-bal{background:#fff;border:1px solid var(--line);border-top:3px solid var(--brand);}
.acct-card.accent-bal .value{color:var(--brand-dark);}
.acct-card.accent-due{background:var(--danger-soft);border-top:3px solid var(--danger);}

/* ── Account statement table ──────────────────────────── */
.stmt-wrap{border:1px solid var(--line);border-radius:12px;overflow:auto;background:var(--card);
  max-height:calc(100vh - 330px);-webkit-overflow-scrolling:touch;}
.stmt-notice{padding:8px 14px;background:#fff8e1;border-bottom:1px solid #ffe082;font-size:12px;color:#7a5c00;display:flex;gap:6px;align-items:center;}
table.stmt-table{width:100%;border-collapse:collapse;font-size:13px;}
table.stmt-table thead th{position:sticky;top:0;z-index:1;background:var(--brand);color:#fff;font-weight:600;font-size:11.5px;
  padding:10px 12px;text-align:right;white-space:nowrap;letter-spacing:.2px;}
/* keep all header labels white — override the per-column color classes (date/debit/credit) */
table.stmt-table thead th,
table.stmt-table thead th.st-date,
table.stmt-table thead th.st-desc,
table.stmt-table thead th.st-debit,
table.stmt-table thead th.st-credit,
table.stmt-table thead th.st-bal{color:#fff;}
table.stmt-table thead th.num{text-align:right;}
table.stmt-table tbody td{padding:9px 12px;border-bottom:1px solid var(--line);vertical-align:middle;}
table.stmt-table tbody tr:nth-child(even){background:#faf9f6;}
table.stmt-table tbody tr:hover{background:var(--brand-soft);}
table.stmt-table .num{text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap;}
table.stmt-table tbody tr.st-clickable{cursor:pointer;}
table.stmt-table tbody tr.st-clickable:hover{background:var(--brand-soft);}
table.stmt-table tbody tr.st-clickable:hover .doc-tag{text-decoration:underline;}
table.stmt-table .st-date{color:var(--muted);font-size:12.5px;white-space:nowrap;width:1%;}
table.stmt-table .st-desc{width:40%;}
table.stmt-table .st-desc{color:var(--ink);}
.st-note{color:#64748b;font-size:12px;font-style:italic;}
.stmt-table .doc-tag{display:inline-flex;align-items:center;gap:6px;font-weight:600;font-size:12px;color:var(--brand-dark);
  background:var(--brand-soft);border:1px solid #f3d9cd;border-radius:6px;padding:2px 8px;white-space:nowrap;}
.stmt-table .doc-tag i{font-size:10px;opacity:.8;}
.stmt-table .st-debit{color:var(--danger);font-weight:600;}
.stmt-table .st-credit{color:var(--ok);font-weight:600;}
.stmt-table .dash{color:#cfcabd;font-weight:400;}
/* invoice row paid badge */
.st-paid-badge{display:inline-flex;align-items:center;gap:4px;font-size:11px;font-weight:600;color:#166534;background:#dcfce7;border:1px solid #bbf7d0;border-radius:20px;padding:1px 8px;margin-right:6px;vertical-align:middle;}
.st-paid-badge i{font-size:10px;}
/* payment row → invoice chip */
.st-inv-chip{display:inline-flex;align-items:center;gap:4px;font-size:11px;font-weight:600;color:#1e40af;background:#dbeafe;border:1px solid #bfdbfe;border-radius:6px;padding:1px 8px;margin-right:6px;cursor:pointer;vertical-align:middle;transition:background .15s;}
.st-inv-chip:hover{background:#bfdbfe;}
.st-inv-chip i{font-size:10px;}
/* invoice editor — linked payments label */
.linked-pay-label{color:var(--ok);}
.stmt-table .st-bal b{font-weight:700;}
.stmt-table .st-bal b.pos{color:var(--ink);}
.stmt-table .st-bal b.neg{color:var(--ok);}
.stmt-table tfoot td{position:sticky;bottom:0;z-index:1;background:var(--brand-soft);border-top:2px solid var(--brand);font-weight:700;font-size:13px;padding:11px 12px;}
.stmt-table tfoot .st-debit{color:var(--danger);} .stmt-table tfoot .st-credit{color:var(--ok);}
.stmt-table tbody tr:last-child td{border-bottom:none;}

.muted{color:var(--muted);}
.right{text-align:left;}
.empty{padding:30px;text-align:center;color:var(--muted);}

/* Modal */
.modal-overlay{position:fixed;inset:0;background:rgba(0,0,0,.45);display:flex;align-items:center;justify-content:center;z-index:50;padding:20px;}
.modal{background:var(--card);border-radius:12px;max-width:560px;width:100%;max-height:88vh;overflow-y:auto;}
.modal-head{padding:14px 18px;border-bottom:1px solid var(--line);display:flex;justify-content:space-between;align-items:center;}
.modal-body{padding:18px;}
.modal-foot{padding:14px 18px;border-top:1px solid var(--line);display:flex;gap:8px;justify-content:flex-start;}
.field{margin-bottom:12px;}
.field label{display:block;font-size:12px;color:var(--muted);margin-bottom:4px;}
.field input,.field select,.field textarea{width:100%;}
.row2{display:grid;grid-template-columns:1fr 1fr;gap:10px;}
.icon-btn{background:transparent;border:none;font-size:18px;color:var(--muted);}

/* Toast */
.toast{position:fixed;bottom:20px;right:20px;background:var(--ink);color:#fff;padding:11px 16px;border-radius:8px;font-size:13px;opacity:0;transform:translateY(10px);transition:.25s;z-index:60;}
.toast.show{opacity:1;transform:translateY(0);}
.toast.err{background:var(--danger);}

/* Login gate */
.login-gate{position:fixed;inset:0;background:var(--bg);display:flex;align-items:center;justify-content:center;z-index:100;}
.login-card{background:var(--card);border:1px solid var(--line);border-radius:12px;padding:36px;text-align:center;}
.login-card i{font-size:40px;color:var(--brand);}
.login-card p{margin:14px 0;}

.banner{background:var(--danger-soft);color:var(--danger);padding:8px 12px;border-radius:8px;font-size:12.5px;margin-bottom:12px;}
.banner.info{background:var(--warn-soft);color:var(--warn);}
.line-note{font-size:11.5px;color:var(--muted);margin-top:8px;}

/* disabled buttons (e.g. اعتماد locked until the review walkthrough is done) */
.btn:disabled{opacity:.5;cursor:not-allowed;box-shadow:none;}

/* ── Review navigator: one floating speech-bubble caption at a time ── */
.rev-spot{outline:2px solid var(--brand)!important;outline-offset:2px;border-radius:6px;
  box-shadow:0 0 0 4px rgba(255,107,53,.18);transition:outline-color .15s,box-shadow .15s;}
.rev-bubble{position:fixed;z-index:9000;width:300px;max-width:calc(100vw - 16px);
  background:#fff;border:1.5px solid var(--brand);border-radius:14px;
  box-shadow:0 10px 30px rgba(0,0,0,.18);padding:12px 13px;animation:revPop .16s ease-out;}
@keyframes revPop{from{opacity:0;transform:scale(.94);}to{opacity:1;transform:scale(1);}}
.rev-bubble-arrow{position:absolute;width:14px;height:14px;background:#fff;
  border:1.5px solid var(--brand);transform:rotate(45deg);}
.rev-bubble[data-side="bottom"] .rev-bubble-arrow{top:-8px;border-left:none;border-bottom:none;}
.rev-bubble[data-side="top"]    .rev-bubble-arrow{bottom:-8px;border-right:none;border-top:none;}
.rev-bubble[data-side="left"]   .rev-bubble-arrow{right:-8px;border-left:none;border-top:none;}
.rev-bubble-top{display:flex;justify-content:space-between;align-items:center;margin-bottom:6px;}
.rev-bubble-step{background:var(--brand-soft);color:var(--brand-dark);border-radius:999px;
  padding:2px 9px;font-size:11.5px;font-weight:700;direction:ltr;}
.rev-bubble-skip{background:none;border:none;color:var(--muted);font-size:11.5px;font-weight:600;
  cursor:pointer;padding:2px 4px;}
.rev-bubble-skip:hover{color:var(--danger);}
.rev-bubble-title{display:flex;align-items:center;gap:7px;font-weight:700;font-size:14px;color:var(--ink);margin-bottom:3px;}
.rev-bubble-num{flex:0 0 auto;width:22px;height:22px;border-radius:50%;background:var(--brand);
  color:#fff;font-size:12px;font-weight:700;display:flex;align-items:center;justify-content:center;}
.rev-bubble-text{font-size:12.5px;color:var(--muted);line-height:1.5;margin-bottom:11px;}
.rev-bubble-actions{display:flex;justify-content:space-between;gap:8px;}
.rev-bubble-actions .btn.xs{padding:5px 12px;}

/* Similar-name warning in the new-customer modal */
.nc-warn{background:#fff8ec;border:1px solid #f5d58a;border-radius:8px;padding:8px 10px;margin-bottom:12px;}
.nc-warn-title{font-size:12.5px;font-weight:600;color:#b8860b;margin-bottom:6px;}
.nc-warn-title i{margin-left:4px;}
.nc-warn-item{display:flex;flex-direction:column;align-items:flex-start;gap:1px;width:100%;text-align:right;
  background:#fff;border:1px solid #eee;border-radius:6px;padding:6px 9px;margin-top:5px;cursor:pointer;transition:.12s;}
.nc-warn-item:hover{background:var(--warn-soft);border-color:var(--gold,#c8963e);}
.nc-warn-name{font-weight:600;font-size:13px;color:var(--text,#333);}
.nc-warn-phone{font-size:11.5px;color:var(--muted);direction:ltr;}

/* Client search dropdown (settlement picker) */
.client-results{position:absolute;top:100%;right:0;left:0;z-index:50;display:none;max-height:220px;overflow-y:auto;
  background:#fff;border:1px solid var(--line);border-radius:8px;box-shadow:0 8px 24px rgba(0,0,0,.12);margin-top:3px;}
.client-result-item{display:flex;flex-direction:column;align-items:flex-start;gap:1px;padding:8px 11px;cursor:pointer;border-bottom:1px solid #f1f1f1;}
.client-result-item:last-child{border-bottom:none;}
.client-result-item:hover{background:var(--brand-soft);}
.client-result-item .cr-name{font-weight:600;font-size:13px;color:var(--ink);}
.client-result-item .cr-phone{font-size:11.5px;color:var(--muted);direction:ltr;}
.client-empty{padding:9px 11px;color:var(--muted);font-size:12.5px;}

.unit-lbl{font-size:11px;color:var(--muted);}

/* ── Compact invoice editor / builder ─────────────────── */
.btn.xs{padding:4px 7px;font-size:12px;line-height:1;}

/* sticky action bar */
.ed-bar{position:sticky;top:0;z-index:5;display:flex;justify-content:space-between;align-items:center;gap:8px;
  background:var(--card);border-bottom:1px solid var(--line);padding:8px 0 10px;margin:-4px 0 10px;flex-wrap:wrap;}
.ed-bar-id{display:flex;align-items:center;gap:8px;font-size:15px;}
.ed-bar-id strong{font-size:16px;}
.ed-bar-actions{display:flex;gap:6px;flex-wrap:wrap;}

/* compact meta line */
.ed-meta{display:flex;gap:18px;flex-wrap:wrap;background:var(--bg);border:1px solid var(--line);border-radius:9px;padding:8px 12px;margin-bottom:10px;}
.ed-meta .m{display:flex;align-items:center;gap:6px;}
.ed-meta .k{font-size:11px;color:var(--muted);}
.ed-meta .v{font-weight:500;display:flex;align-items:center;gap:6px;}

/* dense payments mini-table */
table.mini{width:100%;border-collapse:collapse;}
table.mini th,table.mini td{padding:5px 7px;font-size:12px;}
table.mini thead th{position:sticky;top:0;z-index:1;background:#f4f1ec;font-weight:600;font-size:11.5px;border-bottom:2px solid var(--line);white-space:nowrap;}
table.mini tbody tr:nth-child(even){background:#faf9f6;}
table.mini tbody tr:hover{background:var(--brand-soft);}
.mini-scroll{max-height:210px;overflow-y:auto;border:1px solid var(--line);border-radius:8px;}
.ed-pay-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px;}
.ed-pay-head strong{font-size:13px;display:flex;align-items:center;gap:6px;}

/* ── ERP invoice editor / builder ─────────────────────── */
.inv-editor.erp, .inv-builder{font-size:13px;}
.inv-editor.erp .doc-no{font-size:13px;color:var(--muted);font-weight:600;}

/* header band: customer prominent + balance, compact fields */
.ed-head{display:flex;justify-content:space-between;align-items:flex-start;gap:16px;flex-wrap:wrap;
  background:linear-gradient(0deg,var(--bg),#fff);border:1px solid var(--line);border-radius:10px;padding:10px 14px;margin-bottom:10px;}
.ed-head-cust .cust-name{font-size:20px;font-weight:700;display:flex;align-items:center;gap:10px;line-height:1.2;flex-wrap:wrap;}
.ed-head-cust .cust-bal{font-size:12px;color:var(--muted);margin-top:3px;}
.ed-head-cust .cust-bal b{color:var(--ink);font-size:13px;}
.ed-head-cust .cust-bal b.neg{color:var(--danger);}
.no-cust-label{font-size:15px;color:var(--muted);font-weight:500;}
.btn-cust-link{font-size:11.5px;font-weight:600;padding:3px 10px;border-radius:20px;border:1.5px solid var(--brand);color:var(--brand);background:#fff;cursor:pointer;display:inline-flex;align-items:center;gap:5px;transition:background .15s,color .15s;white-space:nowrap;}
.btn-cust-link:hover{background:var(--brand);color:#fff;}
.ed-head-fields{display:flex;gap:16px;flex-wrap:wrap;}
.ed-head-fields .f{display:flex;flex-direction:column;gap:2px;}
.ed-head-fields .f label{font-size:10.5px;color:var(--muted);}
.ed-head-fields .f input{padding:4px 8px;}
.ed-head-fields .f span{font-weight:500;padding:4px 0;}

/* the items grid — the focus of the screen */
.ed-grid-wrap{border:1px solid var(--line);border-radius:10px;overflow:auto;max-height:48vh;}
table.ed-grid{width:100%;border-collapse:collapse;font-size:12.5px;}
table.ed-grid th{position:sticky;top:0;z-index:2;background:var(--brand);color:#fff;font-weight:600;font-size:11.5px;padding:7px 8px;text-align:right;white-space:nowrap;}
table.ed-grid td{padding:3px 6px;border-bottom:1px solid var(--line);border-left:1px solid #f1efe9;}
table.ed-grid td:last-child{border-left:none;}
table.ed-grid tbody tr:nth-child(even){background:#fbfaf7;}
table.ed-grid tbody tr:hover{background:var(--brand-soft);}
table.ed-grid .c-desc{width:34%;}
table.ed-grid input{width:100%;border:1px solid transparent;background:transparent;padding:5px 6px;border-radius:5px;}
table.ed-grid input:hover{border-color:var(--line);background:#fff;}
table.ed-grid input:focus{border-color:var(--brand);background:#fff;box-shadow:0 0 0 2px var(--brand-soft);}
table.ed-grid .it-line{font-weight:600;white-space:nowrap;}
table.ed-grid .empty{text-align:center;color:var(--muted);padding:18px;}

.grid-tools{display:flex;align-items:center;gap:14px;flex-wrap:wrap;margin:8px 0;}
.grid-tools .bulk-tax{font-size:12px;color:var(--muted);display:flex;align-items:center;gap:6px;}
.grid-tools .bulk-tax input{padding:4px 6px;}
.tax-toggle{display:flex;align-items:center;gap:6px;font-size:13px;font-weight:600;color:var(--ink);cursor:pointer;user-select:none;}
.tax-toggle input[type=checkbox]{width:16px;height:16px;accent-color:var(--brand);cursor:pointer;}
.postdisc-toggle{display:flex;align-items:center;gap:6px;font-size:13px;font-weight:600;color:var(--ink);user-select:none;}
.postdisc-toggle input{width:90px;padding:4px 6px;text-align:right;font-variant-numeric:tabular-nums;}
.ed-summary .r.postdisc b{color:var(--brand-dark);}

/* bottom: summary (left) + payments & notes (right) */
.ed-bottom{display:grid;grid-template-columns:300px 1fr;gap:14px;align-items:start;}
.ed-summary{border:1px solid var(--line);border-radius:10px;overflow:hidden;}
.ed-summary .r{display:flex;justify-content:space-between;align-items:center;padding:7px 12px;border-bottom:1px solid var(--line);font-size:13px;}
.ed-summary .r span{color:var(--muted);}
.ed-summary .r b{font-variant-numeric:tabular-nums;}
.ed-summary .r.grand{background:var(--brand-soft);}
.ed-summary .r.grand span,.ed-summary .r.grand b{color:var(--brand-dark);font-size:16px;font-weight:700;}
.ed-summary .r.paid b{color:var(--ok);}
.ed-summary .r.rem{border-bottom:none;background:#faf9f6;}
.ed-summary .r.rem b{font-weight:700;}
.ed-side{display:flex;flex-direction:column;gap:10px;}
.ed-paybox{border:1px solid var(--line);border-radius:10px;padding:10px 12px;}
.ed-notes-box label{display:block;font-size:11px;color:var(--muted);margin-bottom:4px;}
.ed-notes-box textarea{width:100%;resize:vertical;}

@media (max-width:760px){
  .content{padding:12px;}

  /* Header: compact, hide the secondary subtitle on phones */
  .app-header{padding:10px 14px;}
  .brand-sub{display:none;}
  .brand-title{font-size:15px;}
  /* Tab bar: one clean horizontal swipe row instead of a tall wrap */
  .tab-bar{flex-wrap:nowrap;overflow-x:auto;-webkit-overflow-scrolling:touch;scrollbar-width:none;
    padding:8px 12px;gap:8px;}
  .tab-bar::-webkit-scrollbar{display:none;}
  .tab-btn{flex:0 0 auto;padding:9px 14px;font-size:14px;}

  /* Touch-friendly controls — 16px font on inputs stops iOS zoom-on-focus */
  input,select,textarea{font-size:16px;padding:9px 11px;}
  .btn{padding:9px 13px;font-size:13.5px;}
  .icon-btn{width:38px;height:38px;}

  /* Section titles wrap their action buttons */
  .section-title{flex-wrap:wrap;}

  /* Data tables: scroll sideways instead of crushing columns */
  .table-scroll{max-height:64vh;}
  .card .table-scroll{max-height:64vh;}
  .table-scroll th,.table-scroll td{white-space:nowrap;}
  .stmt-wrap{max-height:64vh;}
  table.stmt-table th,table.stmt-table td{white-space:nowrap;}

  /* Toolbars: search gets its own full-width row, filters wrap to halves below */
  .toolbar{gap:8px;}
  .toolbar .grow{flex:1 1 100%;min-width:0;}
  .toolbar input[type="date"],.toolbar select{flex:1 1 44%;min-width:0;}
  /* Statement filter (client profile): من|إلى side-by-side, تطبيق|الكل paired,
     طباعة on its own full-width row — instead of 5 stacked rows */
  .stmt-toolbar .stmt-date{flex:1 1 calc(50% - 4px);min-width:0;}
  .stmt-toolbar .stmt-date input{flex:1 1 0;}
  .stmt-toolbar .btn{flex:1 1 calc(50% - 4px);justify-content:center;}
  .stmt-toolbar .stmt-print{flex:1 1 100%;}
  /* Customer profile: all 4 action buttons in one row, equal width */
  .cust-actions{width:100%;gap:6px;}
  .cust-actions .btn{flex:1 1 0;min-width:0;padding:8px 4px;font-size:11.5px;gap:4px;justify-content:center;text-align:center;}
  .cust-title{font-size:19px;}

  /* Customers split: stack list above the detail card */
  .split{grid-template-columns:1fr;min-width:0;}
  .list-pane{max-height:38vh;}
  /* Let containers shrink so wide tables scroll INSIDE their own box instead of
     stretching the page (which forced the whole profile to need a zoom-out). */
  .split > *,.panel,.card,#custDetail{min-width:0;}
  .stmt-wrap,.table-scroll,.ed-grid-wrap{max-width:100%;}
  /* Guaranteed safety: the customers/profile screen can never push the page wide
     (no sticky elements here, so clipping page-level overflow is safe — the
     statement still scrolls inside .stmt-wrap). */
  #panel-customers{overflow-x:hidden;}

  /* Modals: use more of the screen, big tappable footer buttons */
  .modal-overlay{padding:10px;}
  .modal{max-width:none;max-height:92vh;}
  .modal-body{padding:16px;}
  .modal-foot{padding:12px 16px;}
  .modal-foot .btn{flex:1 1 auto;justify-content:center;padding:11px 14px;}
  .row2{grid-template-columns:1fr;}

  /* Invoice editor / builder / return */
  .ed-bottom{grid-template-columns:1fr;}
  .ed-head{flex-direction:column;}
  .ed-head-fields{gap:12px;}
  .ed-grid-wrap{max-height:none;}
  .ed-grid th,.ed-grid td{white-space:nowrap;}
  .ed-bar{flex-wrap:wrap;}
  .ed-bar-actions{width:100%;justify-content:flex-start;}

  /* KPI sizing for small screens — big but not overflowing */
  .kpi-val{font-size:27px;}
  .kpi-row .kpi-val{font-size:21px;}
  .kpi-ic{width:46px;height:46px;font-size:20px;}
}
@media (max-width:380px){
  .kpi-row{grid-template-columns:1fr;}
  .kpi-val{font-size:25px;}
}

/* ── Pagination ──────────────────────────────────────────── */
.pager-wrap{display:flex;justify-content:center;padding:14px 0 4px;}
.pager{display:flex;align-items:center;gap:12px;}
.pager-btn{padding:6px 16px;border:1px solid var(--line);border-radius:8px;background:var(--card);color:var(--ink);font-size:13px;font-family:inherit;cursor:pointer;transition:background .15s;}
.pager-btn:hover:not([disabled]){background:var(--brand-soft);border-color:var(--brand);color:var(--brand);}
.pager-btn[disabled]{opacity:.4;cursor:default;}
.pager-info{font-size:13px;color:var(--muted);font-weight:600;}

/* ── Return / credit-note chip ───────────────────────────── */
.chip.ret{background:#fff4ef;color:#c0392b;border:1px solid #f0c0aa;}
.chip.audit-created{background:#e8f6ed;color:#1d8a4e;}
.chip.audit-updated{background:#eef2ff;color:#3b5bdb;}
.chip.audit-issued{background:#e8f6ed;color:#1d8a4e;}
.chip.audit-cancelled,.chip.audit-deleted{background:#fdecea;color:#c0392b;}
.chip.audit-printed{background:#f5f0ff;color:#6741d9;}

/* ── Reports grid ────────────────────────────────────────── */
.rpt-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:14px;}
@media (max-width:900px){.rpt-grid{grid-template-columns:1fr;}}
.rpt-grid .card .section-title{margin-bottom:10px;}
td.debit{color:var(--danger);font-weight:600;}

/* ── Editor meta row (return builder) ───────────────────── */
.ed-meta{display:flex;flex-wrap:wrap;gap:14px;padding:10px 12px;border-bottom:1px solid var(--line);background:var(--bg);}
.ed-meta .m{display:flex;align-items:center;gap:6px;font-size:13px;}
.ed-meta .k{color:var(--muted);font-size:11px;}
.ed-meta .v{font-weight:600;}

/* ── Custom confirm / alert dialogs ──────────────────────── */
.cdlg-overlay{position:fixed;inset:0;background:rgba(31,36,48,.55);display:flex;align-items:center;justify-content:center;z-index:80;padding:20px;opacity:0;transition:opacity .16s ease;}
.cdlg-overlay.show{opacity:1;}
.cdlg{background:var(--card);border-radius:16px;width:100%;max-width:400px;padding:26px 24px 20px;text-align:center;box-shadow:0 20px 60px rgba(0,0,0,.25);transform:translateY(8px) scale(.97);transition:transform .18s cubic-bezier(.2,.8,.3,1);}
.cdlg-overlay.show .cdlg{transform:translateY(0) scale(1);}
.cdlg-icon{width:58px;height:58px;border-radius:50%;display:flex;align-items:center;justify-content:center;font-size:25px;margin:0 auto 14px;}
.cdlg-icon.danger{background:var(--danger-soft);color:var(--danger);}
.cdlg-icon.warning{background:var(--warn-soft);color:var(--warn);}
.cdlg-icon.primary{background:var(--brand-soft);color:var(--brand);}
.cdlg-icon.info{background:#eef2ff;color:#3b5bdb;}
.cdlg-icon.success{background:var(--ok-soft);color:var(--ok);}
.cdlg-title{margin:0 0 8px;font-size:17px;font-weight:700;color:var(--ink);}
.cdlg-msg{margin:0 0 20px;font-size:13.5px;line-height:1.7;color:var(--muted);}
.cdlg-actions{display:flex;gap:10px;justify-content:center;}
.cdlg-actions .btn{min-width:104px;justify-content:center;padding:9px 16px;font-size:13px;font-weight:600;}
.btn-danger-solid{background:var(--danger);color:#fff;border-color:var(--danger);}
.btn-danger-solid:hover{background:#b91c1c;}

/* ── Toast with icon (success / error / info / warning) ──── */
.toast{display:flex;align-items:center;gap:9px;}
.toast i{font-size:15px;flex:0 0 auto;}
.toast.ok{background:var(--ok);}
.toast.info{background:#3b5bdb;}
.toast.warn{background:var(--warn);}
