/* =====================================================================
   POS Lite — app.css
   Material-style UI, light/dark themes, RTL, responsive, print (80mm/A4)
   ===================================================================== */

:root, [data-theme="light"] {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --border: #e4e6ef;
  --text: #1c2033;
  --text-2: #5a6072;
  --muted: #8a90a3;
  --primary: #4f46e5;
  --primary-2: #4338ca;
  --primary-soft: #eef0ff;
  --success: #16a34a;
  --success-soft: #e8f7ee;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --warn: #d97706;
  --warn-soft: #fdf3e3;
  --info: #0284c7;
  --info-soft: #e6f4fb;
  --shadow: 0 1px 2px rgba(20,24,50,.05), 0 6px 20px rgba(20,24,50,.06);
  --shadow-lg: 0 4px 12px rgba(20,24,50,.08), 0 18px 50px rgba(20,24,50,.18);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 236px;
  --topbar-h: 60px;
}

[data-theme="dark"] {
  --bg: #0f1120;
  --surface: #191c30;
  --surface-2: #20233c;
  --border: #2a2e4d;
  --text: #e8eaf6;
  --text-2: #b3b8d0;
  --muted: #7c82a3;
  --primary: #6d67ff;
  --primary-2: #5b54f5;
  --primary-soft: #242850;
  --success: #34d399;
  --success-soft: #14352a;
  --danger: #f87171;
  --danger-soft: #3c1f2a;
  --warn: #fbbf24;
  --warn-soft: #3a2f17;
  --info: #38bdf8;
  --info-soft: #132f45;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.4), 0 18px 50px rgba(0,0,0,.55);
}

* { box-sizing: border-box; }

* {
  scrollbar-width: thin;
  scrollbar-color: #2998d8 transparent;
}

*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #65d4ff 0%, #1684c5 100%);
  border: 2px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #86e0ff 0%, #0b6da8 100%);
  background-clip: padding-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[dir="rtl"] body, [dir="rtl"] .urdu, [lang="ur"] .urdu {
  font-family: "Noto Nastaliq Urdu", "Inter", "Segoe UI", serif;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

a { color: var(--primary); text-decoration: none; }

.muted { color: var(--muted); }
.t-right { text-align: right; }
.t-center { text-align: center; }
[dir="rtl"] .t-right { text-align: left; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.2;
  transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.is-loading { pointer-events: none; }
.btn.is-loading .btn-label { opacity: .65; }
.spinner {
  width: 14px; height: 14px; flex: 0 0 auto;
  border: 2px solid rgba(255,255,255,.45);
  border-top-color: #fff; border-radius: 50%;
  animation: spin .7s linear infinite; display: inline-block;
}
.spinner.dark { border-color: rgba(0,0,0,.18); border-top-color: var(--primary); }
.spinner-lg { width: 34px; height: 34px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* full-screen page loading overlay */
.global-loader {
  position: fixed; inset: 0; z-index: 9999;
  display: none; align-items: center; justify-content: center;
  background: rgba(255,255,255,.72);
  backdrop-filter: blur(1px);
}
.global-loader.show { display: flex; }
.global-loader .spinner { border-color: rgba(0,0,0,.15); border-top-color: var(--primary); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); box-shadow: 0 4px 14px rgba(79,70,229,.35); }
.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 7px; }
.btn-xs { padding: 4px 8px; font-size: 12px; border-radius: 6px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 9px; border: 1px solid transparent;
  background: transparent; color: var(--text-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; }
.chip-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
}
.chip-btn:hover { border-color: var(--primary); color: var(--primary); }
.chip-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip { display:inline-flex; align-items:center; gap:5px; padding:3px 9px; border-radius:999px; font-size:11.5px; font-weight:700; }
.chip.green { background: var(--success-soft); color: var(--success); }
.chip.red { background: var(--danger-soft); color: var(--danger); }
.chip.amber { background: var(--warn-soft); color: var(--warn); }
.chip.blue { background: var(--info-soft); color: var(--info); }
.chip.gray { background: var(--surface-2); color: var(--text-2); }

/* ---------- inputs ---------- */
.input, .select, .textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.input-xs { padding: 6px 10px; font-size: 13px; width: auto; }
.textarea { min-height: 72px; resize: vertical; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.field .req { color: var(--danger); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .span2 { grid-column: span 2; }

/* ---------- layout ---------- */
.dash { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 60;
}
[dir="rtl"] .sidebar { left: auto; right: 0; border-right: none; border-left: 1px solid var(--border); }
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-h);
  padding: 0 18px;
  font-size: 17px; font-weight: 700;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--primary); color: #fff;
}
.brand-mark svg { width: 18px; height: 18px; }
.side-nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.side-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 600; font-size: 13.5px;
  transition: background .15s, color .15s;
}
.side-link svg { width: 18px; height: 18px; flex-shrink: 0; }
.side-link:hover { background: var(--surface-2); color: var(--text); }
.side-link.active { background: var(--primary-soft); color: var(--primary); }
.sidebar-foot { padding: 12px 10px; border-top: 1px solid var(--border); }

.dash-main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
[dir="rtl"] .dash-main { margin-left: 0; margin-right: var(--sidebar-w); }

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px;
  padding: 0 18px;
  position: sticky; top: 0; z-index: 50;
}
.topbar-title { display: flex; flex-direction: column; line-height: 1.2; }
.topbar-title > span:first-child { font-size: 15.5px; font-weight: 700; }
.topbar-biz { font-size: 12px; font-weight: 500; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
[dir="rtl"] .topbar-actions { margin-left: 0; margin-right: auto; }
.burger { display: none; }

.user-chip { display: flex; align-items: center; gap: 9px; padding: 4px 10px 4px 4px; border-radius: 999px; background: var(--surface-2); }
[dir="rtl"] .user-chip { padding: 4px 4px 4px 10px; }
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 12px; font-weight: 800;
}
.u-name { font-size: 13px; font-weight: 600; }

.content { padding: 20px; max-width: 1280px; width: 100%; margin: 0 auto; }

/* ---------- panels ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.panel-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.panel-body { padding: 16px 18px; }
.filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; }
[dir="rtl"] .filters { margin-left: 0; margin-right: auto; }

/* ---------- pagination ---------- */
.pager {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; border-top: 1px solid var(--border);
  font-size: 12.5px; color: var(--muted);
}
[dir="rtl"] .pager { flex-direction: row; }
.pager-btns { display: flex; gap: 6px; }
.pager-info { white-space: nowrap; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 700;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
[dir="rtl"] .table th { text-align: right; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
[dir="rtl"] .table .num { text-align: left; }
.table-empty { text-align: center; color: var(--muted); padding: 26px !important; }

/* ---------- stat cards ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.stat-card .k { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-card .v { font-size: 21px; font-weight: 800; margin-top: 5px; font-variant-numeric: tabular-nums; }
.stat-card .s { font-size: 12px; color: var(--muted); margin-top: 3px; }
.stat-card .ic { width: 38px; height: 38px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; margin-bottom: 8px; }
.stat-card .ic svg { width: 20px; height: 20px; }
.ic.blue { background: var(--info-soft); color: var(--info); }
.ic.green { background: var(--success-soft); color: var(--success); }
.ic.red { background: var(--danger-soft); color: var(--danger); }
.ic.amber { background: var(--warn-soft); color: var(--warn); }
.ic.indigo { background: var(--primary-soft); color: var(--primary); }

/* ---------- chart ---------- */
.chart { display: flex; align-items: flex-end; gap: 10px; height: 190px; padding: 10px 4px 0; }
.chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart .bars { display: flex; align-items: flex-end; gap: 3px; width: 100%; height: 100%; justify-content: center; }
.chart .bar { width: 40%; min-width: 6px; border-radius: 4px 4px 2px 2px; transition: height .4s; }
.chart .bar.sales { background: var(--primary); }
.chart .bar.purchases { background: var(--warn); }
.chart .bar-label { font-size: 10.5px; color: var(--muted); font-weight: 600; }
.chart .bar-val { font-size: 10.5px; font-weight: 700; color: var(--text-2); }
.chart .legend { display: flex; justify-content: center; gap: 18px; padding-top: 8px; font-size: 12px; color: var(--text-2); font-weight: 600; }
.chart .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 5px; }

/* ---------- products grid ---------- */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; padding: 16px; }
.pcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: box-shadow .15s, transform .1s, border-color .15s;
  display: flex; flex-direction: column;
}
.pcard:hover { box-shadow: var(--shadow-lg); border-color: var(--primary); transform: translateY(-2px); }
.pcard .thumb {
  height: 108px; background: var(--surface-2); display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.pcard .thumb img { width: 100%; height: 100%; object-fit: cover; }
.pcard .thumb .ph { font-size: 34px; font-weight: 800; color: var(--border); }
.pcard .meta { padding: 10px 12px 12px; }
.pcard .pname { font-weight: 700; font-size: 13.5px; line-height: 1.3; }
.pcard .pprice { color: var(--primary); font-weight: 700; font-size: 13.5px; margin-top: 2px; }
.pcard .pstock { font-size: 12px; color: var(--muted); margin-top: 4px; }
.pcard .pstock.low { color: var(--danger); font-weight: 700; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15,17,32,.5);
  display: none; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius);
  width: 100%; max-width: 560px; max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalIn .18s ease;
}
.modal.lg { max-width: 840px; }
.modal.sm { max-width: 420px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 15.5px; font-weight: 700; }
.modal-close { border: none; background: transparent; font-size: 22px; line-height: 1; color: var(--muted); border-radius: 6px; width: 32px; height: 32px; }
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 9px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- bill form (product picker + cart) ---------- */
.bill-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.bill-products { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.bill-search { width: 100%; }
.bill-invoice { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.bill-invoice .bill-cart { max-height: 320px; overflow-y: auto; }
.bill-products .bill-items { max-height: 460px; }
.bill-items { max-height: 320px; overflow-y: auto; border-radius: var(--radius-sm); }
.bill-item {
  display: flex; gap: 10px; align-items: center;
  padding: 8px 10px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.bill-item:hover { background: var(--surface-2); }
.bill-item img { width: 38px; height: 38px; border-radius: 7px; object-fit: cover; background: var(--surface-2); }
.bill-item .bi-ph { width: 38px; height: 38px; border-radius: 7px; background: var(--surface-2); display: inline-flex; align-items: center; justify-content: center; font-weight: 800; color: var(--border); font-size: 14px; flex-shrink: 0; }
.bill-item .bi-meta { flex: 1; min-width: 0; }
.bill-item .bi-name { font-weight: 600; font-size: 13px; line-height: 1.25; }
.bill-item .bi-sub { font-size: 11.5px; color: var(--muted); }
.bill-item .add-ic { color: var(--primary); font-size: 20px; font-weight: 800; }
.bill-card {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden; cursor: pointer; user-select: none;
  transition: border-color .12s ease, transform .12s ease, box-shadow .12s ease;
}
.bill-card:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.bill-card:active { transform: scale(.96); }
.bill-card .bc-img { position: relative; height: 74px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; }
.bill-card .bc-img img { width: 100%; height: 100%; object-fit: cover; }
.bill-card .bc-img .bc-ph { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 26px; color: var(--border); }
.bill-card .bc-img .bc-low { position: absolute; bottom: 3px; inset-inline-end: 4px; font-size: 12px; line-height: 1; }
.bill-card .bc-add { position: absolute; top: 4px; inset-inline-end: 4px; width: 20px; height: 20px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 800; line-height: 1; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.bill-card .bc-qty { position: absolute; top: 4px; inset-inline-start: 4px; background: var(--primary); color: #fff; border-radius: 999px; font-size: 10px; font-weight: 700; padding: 1px 7px; }
.bill-card .bc-name { font-size: 11.5px; font-weight: 600; line-height: 1.25; padding: 6px 7px 0; min-height: 2.5em; overflow: hidden; }
.bill-card .bc-price { display: flex; align-items: baseline; gap: 5px; font-size: 12px; font-weight: 700; color: var(--primary); padding: 3px 7px 7px; }
.bill-card .bc-stock { font-size: 10px; font-weight: 500; color: var(--muted); }
.bill-cart-item {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 8px 2px; border-bottom: 1px dashed var(--border);
}
.bill-cart-item .ci-ph { 
  width: 30px; 
  height: 30px; 
  border-radius: 6px; 
  object-fit: cover; 
  background: var(--surface); 
  flex-shrink: 0; 
  display: inline-flex; 
  align-items: center; 
  justify-content: center; 
  font-weight: 800; 
  color: var(--border); 
  font-size: 13px; 
}
.bill-cart-item .ci-ph img { 
  max-width: 100%; 
  height: auto; 
  width: auto\9; /* IE8 */ 
}
.bill-cart-item .ci-mid { flex: 1; min-width: 0; }
.bill-cart-item .ci-name { font-weight: 600; font-size: 12.5px; line-height: 1.2; margin-bottom: 4px; }
.bill-cart-item .ci-row { display: flex; align-items: center; gap: 6px; }
.qty-stepper { display: flex; align-items: center; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; background: var(--surface); flex-shrink: 0; }
.qty-stepper .stp { width: 26px; height: 27px; border: 0; background: none; color: var(--text); font-size: 16px; font-weight: 700; line-height: 1; cursor: pointer; }
.qty-stepper .stp:hover { background: var(--surface-2); }
.qty-stepper input { width: 44px; height: 27px; border: 0; border-inline: 1px solid var(--border); text-align: center; background: var(--surface); color: var(--text); font-size: 13px; -moz-appearance: textfield; appearance: textfield; }
.qty-stepper input::-webkit-outer-spin-button, .qty-stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.bill-cart-item .ci-rate { width: 70px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); font-size: 12.5px; text-align: right; flex-shrink: 0; }
.bill-cart-item .ci-total { min-width: 64px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 12.5px; }
.bill-cart-item .ci-x { color: var(--muted); background: none; border: none; font-size: 16px; line-height: 1; cursor: pointer; flex-shrink: 0; }
.bill-cart-item .ci-x:hover { color: var(--danger); }
.cart-total {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 2px 0; font-weight: 800; font-size: 15px; border-top: 1px solid var(--border); margin-top: 8px;
}
.cart-total .money { color: var(--primary); }

/* live invoice totals breakdown */
.live-totals { margin-top: 2px; }
.lt-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 12.5px; }
.lt-row span:last-child { font-weight: 600; font-variant-numeric: tabular-nums; }
.lt-grand { border-top: 1px solid var(--border); margin-top: 5px; padding-top: 7px; font-weight: 800; font-size: 15px; }

/* collapsible more options */
.more-options { margin-top: 4px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.more-options summary { padding: 8px 12px; font-size: 12.5px; font-weight: 700; color: var(--muted); cursor: pointer; list-style: none; }
.more-options summary::-webkit-details-marker { display: none; }
.more-options summary::after { content: "▾"; float: right; }
.more-options[open] summary::after { content: "▴"; }
[dir="rtl"] .more-options summary::after { float: left; }
.more-options[open] summary { color: var(--text); }
.more-options .form-grid { padding: 2px 12px 12px; }

/* ---------- toasts ---------- */
.toast-wrap { position: fixed; bottom: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
[dir="rtl"] .toast-wrap { right: auto; left: 18px; }
.toast {
  display: flex; align-items: center; gap: 9px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-inline-start: 4px solid var(--info);
  padding: 11px 15px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); font-weight: 600; font-size: 13.5px;
  max-width: 340px;
  animation: toastIn .2s ease;
  transition: opacity .3s, transform .3s;
}
.toast svg { width: 18px; height: 18px; flex-shrink: 0; }
.toast.ok { border-inline-start-color: var(--success); } .toast.ok svg { color: var(--success); }
.toast.err { border-inline-start-color: var(--danger); } .toast.err svg { color: var(--danger); }
.toast.out { opacity: 0; transform: translateY(8px); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- report tabs ---------- */
.report-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

/* ---------- sidebar backdrop (mobile) ---------- */
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; z-index: 55; background: rgba(15,17,32,.45);
}
.sidebar-backdrop.show { display: block; }

/* ---------- status pills ---------- */
.due-overdue { color: var(--danger); font-weight: 700; font-size: 11px; margin-inline-start: 6px; }

/* ---------- empty state ---------- */
.empty-box { text-align: center; color: var(--muted); padding: 40px 10px; }
.empty-box svg { width: 44px; height: 44px; opacity: .4; margin-bottom: 8px; }

/* ---------- helpers ---------- */
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; }
.hidden { display: none !important; }
.pointer { cursor: pointer; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }
.section-title { font-size: 15px; font-weight: 700; margin: 0 0 12px; }
.center { text-align: center; }

/* clickable text links (party / product / account ledger openers) */
.btn-link {
  background: none; border: 0; padding: 0; margin: 0;
  font: inherit; font-weight: 700; color: inherit; cursor: pointer;
  text-align: inherit; line-height: inherit;
  text-decoration: none;
}
.btn-link:hover { opacity: .8; }
.btn-link:visited { color: inherit; }
.pname-btn { display: block; text-align: left; }
[dir="rtl"] .pname-btn { text-align: right; }

/* ledger summary strip */
.ledger-sum { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.ledger-sum > div {
  display: flex; flex-direction: column; gap: 2px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 12px; font-size: 12.5px;
}
.ledger-sum span { color: var(--muted); }
.ledger-sum b { font-size: 14px; }

/* opening balance row in ledgers */
.ledger-open { background: var(--bg); }
.ledger-open td { border-top: 1px dashed var(--border); font-weight: 600; }
.ledger-open td:last-child { border-bottom: 1px dashed var(--border); }

/* balance sheet */
.bs-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.bs-col { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.bs-head { font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 8px; }
.bs-row { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 13.5px; font-variant-numeric: tabular-nums; }
.bs-row span:last-child { white-space: nowrap; }
.bs-total { border-bottom: 2px solid var(--border); font-weight: 800; }
.bs-sub { margin: 16px 0 4px; font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.bs-print-head { font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; margin: 6px 0 2px; }

/* ---------- auth / login ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow-lg); padding: 30px 28px; width: 100%; max-width: 400px;
}
.brand-lg { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.brand-mark-lg {
  display: inline-flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; border-radius: 13px; background: var(--primary); color: #fff;
}
.brand-mark-lg svg { width: 25px; height: 25px; }
.brand-title { font-size: 20px; font-weight: 800; line-height: 1.2; }
.brand-sub { font-size: 12.5px; color: var(--muted); }
.auth-head { font-size: 21px; font-weight: 800; margin: 4px 0 18px; }
.form-error {
  background: var(--danger-soft); color: var(--danger); border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 13px; font-weight: 600; margin-bottom: 14px;
}
.form-ok {
  background: var(--success-soft); color: var(--success); border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 13px; font-weight: 600; margin-bottom: 14px;
}
.auth-lead { font-size: 13.5px; color: var(--muted); margin: -10px 0 18px; line-height: 1.6; }
.auth-alt { margin-top: 18px; text-align: center; font-size: 13.5px; }
.auth-alt a { color: var(--primary); font-weight: 600; text-decoration: none; }
.auth-alt a:hover { text-decoration: underline; }
.btn-lg { padding: 12px 20px; font-size: 15px; border-radius: 10px; }
.btn-block { width: 100%; }
.demo-creds { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--muted); line-height: 1.9; }
.demo-creds b { color: var(--text-2); }
.demo-creds code { background: var(--surface-2); padding: 2px 6px; border-radius: 5px; font-size: 11.5px; }
.auth-corner { position: fixed; top: 14px; right: 14px; display: flex; gap: 6px; z-index: 30; }
[dir="rtl"] .auth-corner { right: auto; left: 14px; }

/* ---------- Windows-inspired dashboard refresh ---------- */
:root, [data-theme="light"] {
  --bg: #f3f3f3; --surface: #fff; --surface-2: #f7f7f7; --border: #e5e5e5;
  --text: #1f1f1f; --text-2: #5d5d5d; --muted: #777;
  --primary: #0067c0; --primary-2: #005a9e; --primary-soft: #e6f2ff;
  --success: #107c10; --success-soft: #e8f5e8; --danger: #c42b1c; --danger-soft: #fdecea;
  --warn: #9d5d00; --warn-soft: #fff4ce; --info: #0067c0; --info-soft: #e6f2ff;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.05);
  --shadow-lg: 0 8px 28px rgba(0,0,0,.14), 0 24px 60px rgba(0,0,0,.12);
  --radius: 8px; --radius-sm: 6px; --topbar-h: 68px;
}

[data-theme="dark"] {
  --bg: #202020; --surface: #292929; --surface-2: #323232; --border: #414141;
  --text: #f5f5f5; --text-2: #c8c8c8; --muted: #a0a0a0;
  --primary: #60cdff; --primary-2: #7bd7ff; --primary-soft: #183d52;
  --success: #6ccb5f; --success-soft: #214323; --danger: #ff99a4; --danger-soft: #54272c;
  --warn: #f7c64b; --warn-soft: #514218; --info: #60cdff; --info-soft: #183d52;
  --shadow: 0 1px 2px rgba(0,0,0,.25), 0 8px 24px rgba(0,0,0,.18);
  --shadow-lg: 0 10px 34px rgba(0,0,0,.4), 0 24px 60px rgba(0,0,0,.25);
}

body { font-family: "Segoe UI Variable", "Segoe UI", sans-serif; letter-spacing: 0; }
.dash-body {
  background: linear-gradient(135deg, #f7fbff 0%, #f3f3f3 48%, #eef5fb 100%);
  background-attachment: fixed;
  background-size: cover;
}
[data-theme="dark"] .dash-body {
  background: linear-gradient(135deg, #202020 0%, #252a2d 52%, #1e272d 100%);
  background-attachment: fixed;
  background-size: cover;
}
.dash { background: transparent; }
.sidebar { background: transparent; border-color: transparent; }
.sidebar { border: 0 !important; }
.sidebar-brand { height: 112px; padding: 14px 20px; flex-direction: column; justify-content: center; gap: 6px; font-size: 26px; text-align: center; }
.sidebar-brand { border: 0; }
.brand-mark { width: 38px; height: 38px; border-radius: 8px; background: var(--primary); }
.brand-mark svg { width: 21px; height: 21px; }
.profile-block { display: flex; align-items: center; gap: 12px; padding: 18px 22px 20px; }
.profile-avatar { width: 44px; height: 44px; font-size: 13px; background: linear-gradient(145deg, #33b5e5, #0067c0); }
.profile-copy { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.profile-copy strong { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-copy span { color: var(--muted); font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-block { margin-top: auto; border-top: 1px solid rgba(120,140,160,.16); }
.side-nav, .sidebar-foot, .profile-block { border: 0 !important; }
.side-nav { padding: 16px 10px; }
.side-link { min-height: 40px; border-radius: 5px; font-weight: 500; }
.side-link.active { box-shadow: none; font-weight: 600; }
[dir="rtl"] .side-link.active { box-shadow: none; }
.topbar { height: var(--topbar-h); background: rgba(255,255,255,.08); border-bottom: 1px solid transparent; box-shadow: none; backdrop-filter: blur(18px) saturate(115%); -webkit-backdrop-filter: blur(18px) saturate(115%); position: sticky; top: 0; z-index: 70; }
.topbar-title { display: flex; align-items: center; min-width: 0; }
.topbar-title h1 { margin: 0; font-size: 24px; line-height: 1.1; font-weight: 600; letter-spacing: 0; }
.topbar-title > span:first-child { font-size: 20px; font-weight: 600; }
.topbar-context { font-size: 15px !important; font-weight: 500 !important; }
.topbar-title, .topbar-business { display: none; }
.topbar .topbar-title { display: flex; }
.settings-search { position: absolute; left: 50%; transform: translateX(-50%); width: min(520px, 42vw); height: 42px; display: flex; align-items: center; gap: 10px; padding: 0 15px; border: 1px solid var(--border); border-radius: 24px; background: rgba(255,255,255,.66); box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.settings-search svg { width: 19px; height: 19px; flex: none; }
.settings-search input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 16px; }
.topbar-business { margin-inline-start: 0; font-size: 12px; }
.user-menu { position: relative; }
.user-chip { border: 0; color: var(--text); cursor: pointer; }
.user-chevron { color: var(--muted); font-size: 16px; line-height: 1; margin-inline-start: 2px; }
.user-dropdown { display: none; position: absolute; top: calc(100% + 8px); right: 0; min-width: 180px; padding: 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow-lg); z-index: 80; }
[dir="rtl"] .user-dropdown { right: auto; left: 0; }
.user-menu.open .user-dropdown { display: flex; flex-direction: column; }
.user-dropdown button, .user-dropdown a { display: block; width: 100%; border: 0; border-radius: 5px; padding: 9px 11px; background: transparent; color: var(--text-2); text-align: start; font: inherit; font-size: 13px; text-decoration: none; cursor: pointer; }
.user-dropdown button:hover, .user-dropdown a:hover { background: var(--surface-2); color: var(--text); }
.content { max-width: 1440px; padding: 28px 32px 44px; }
.panel, .stat-card { border-radius: 6px; box-shadow: var(--shadow); }
.panel { margin-bottom: 20px; }
.panel-head { padding: 16px 20px; }
.panel-head h3 { font-size: 16px; font-weight: 600; }
.stat-card { padding: 18px; }
.stat-card .v { font-size: 24px; font-weight: 600; }
.btn { border-radius: 4px; font-weight: 600; }
.btn-primary { box-shadow: none; }
.btn-primary:hover { box-shadow: 0 3px 10px rgba(0,103,192,.2); }
.btn-ghost { background: var(--surface); }
.input, .select, .textarea { border-radius: 4px; }
.input:focus, .select:focus, .textarea:focus { box-shadow: 0 0 0 2px var(--primary-soft); }
.table th { letter-spacing: .02em; text-transform: none; font-size: 12px; }
.table td { padding-block: 13px; }
.section-enter { animation: sectionEnter .22s ease both; }
@keyframes sectionEnter { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.modal { border-radius: 8px; }
.modal-backdrop { background: rgba(0,0,0,.32); backdrop-filter: blur(4px); }
.modal.bill-modal {
  width: min(1240px, 100%);
  max-width: none;
  height: min(900px, calc(100vh - 32px));
  max-height: none;
  border: 1px solid rgba(255,255,255,.7);
  box-shadow: 0 20px 60px rgba(0,45,85,.18);
}
.bill-modal .modal-head { padding: 20px 28px; background: color-mix(in srgb, var(--surface) 90%, var(--primary-soft)); }
.bill-modal .modal-head h3 { font-size: 21px; }
.bill-modal .modal-body { padding: 24px 28px; }
.bill-modal .modal-foot { padding: 16px 28px; }
.bill-modal .bill-layout { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); gap: 24px; }
.bill-modal .bill-items, .bill-modal .bill-cart { background: var(--surface-2); border-radius: 8px; }
.bill-modal .bill-items { padding: 10px; background: transparent; display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; align-content: start; }
.bill-modal .bill-items .empty-box { grid-column: 1 / -1; }
.bill-modal .bill-item { padding: 12px 14px; }
.bill-modal .bill-cart { min-height: 220px; padding: 8px 14px; }
.bill-modal .cart-total { font-size: 18px; padding: 16px 2px 0; }

/* payment method block inside the invoice panel */
.pay-block { border-top: 1px dashed var(--border); padding-top: 8px; }
.pay-block .pay-row { display: flex; align-items: center; gap: 8px; }
.pay-block .pay-label { font-size: 12.5px; font-weight: 700; color: var(--muted); }
#paidField { margin: 6px 0 0; }

@media (max-width: 900px) {
  .content { padding: 24px 16px 32px; }
  .topbar-title h1 { font-size: 21px; }
  .sidebar { width: min(286px, 86vw); }
  .sidebar.open { background: rgba(247,251,255,.98); border-inline-end: 1px solid rgba(100,130,160,.18); }
  [data-theme="dark"] .sidebar.open { background: rgba(32,32,32,.98); }
}

@media (max-width: 520px) {
  .settings-search { left: 50%; width: 42vw; min-width: 140px; }
  .settings-search input { font-size: 13px; }
  .content { padding: 20px 10px 28px; }
  .panel-head { padding: 14px; }
  .panel-head h3 { flex: 1 1 100%; }
  .filters { width: 100%; margin-inline-start: 0; }
  .filters .input, .filters .select { flex: 1 1 120px; min-width: 0; }
  .filters .btn { flex: 1 1 auto; }
  .stat-grid { gap: 8px; }
  .stat-card { padding: 13px; }
  .stat-card .v { font-size: 18px; }
  .topbar { padding-inline: 10px; }
  .topbar-actions .user-chip { background: transparent; }
  .user-dropdown { right: -4px; }
  [dir="rtl"] .user-dropdown { right: auto; left: -4px; }
  .modal.bill-modal { width: 100%; height: 100%; border-radius: 0; }
  .bill-modal .modal-head, .bill-modal .modal-body, .bill-modal .modal-foot { padding-inline: 16px; }
  .bill-modal .modal-head h3 { font-size: 18px; }
  .bill-modal .bill-layout { grid-template-columns: 1fr; gap: 16px; }
}

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

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-105%); transition: transform .22s ease; box-shadow: var(--shadow-lg); }
  [dir="rtl"] .sidebar { transform: translateX(105%); }
  .sidebar.open { transform: translateX(0); }
  .dash-main { margin-left: 0; }
  [dir="rtl"] .dash-main { margin-right: 0; }
  .burger { display: inline-flex; }
  .u-name { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .bill-layout { grid-template-columns: 1fr; }
  .content { padding: 14px; }
  .user-chip { padding: 4px; }
  .avatar { width: 30px; height: 30px; }
}

@media (max-width: 520px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-card .v { font-size: 17px; }
  .panel-head { padding: 12px 14px; }
  .topbar { padding: 0 12px; }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
  .modal-body { padding: 14px; }
  .topbar-actions { gap: 4px; }
}

/* Final Settings-shell responsive overrides */
@media (max-width: 900px) {
  .content { padding-top: 24px; }
}
@media (max-width: 520px) {
  .content { padding-top: 20px; }
  .settings-search { width: 42vw; min-width: 140px; }
  .settings-search input { font-size: 13px; }
}

/* =====================================================================
   PRINT — hidden by default, shown when .print-area active
   ===================================================================== */
.print-area { display: none; }

@media print {
  body.printing-invoice { background: #fff; }
  body.printing-invoice .dash,
  body.printing-invoice .toast-wrap,
  body.printing-invoice .modal-backdrop { display: none !important; }
  body.printing-invoice .print-area { display: block !important; }
  body.printing-invoice .print-area * { visibility: visible; }
}

/* ---------- A4 invoice ---------- */
.invoice-a4 { background: #fff; color: #000; padding: 26px; font-size: 13px; max-width: 760px; margin: 0 auto; }
.invoice-a4 .inv-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid #000; padding-bottom: 14px; margin-bottom: 14px; }
.invoice-a4 .inv-biz h1 { margin: 0; font-size: 22px; font-weight: 800; }
.invoice-a4 .inv-biz p { margin: 2px 0; font-size: 12px; color: #333; }
.invoice-a4 .inv-meta { text-align: right; font-size: 12.5px; }
.invoice-a4 .inv-meta b { display: block; font-size: 15px; }
.invoice-a4 .inv-party { display: grid; grid-template-columns: 1fr auto; gap: 20px; margin-bottom: 12px; font-size: 12.5px; }
.invoice-a4 table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.invoice-a4 table th { background: #f1f1f4; border: 1px solid #000; padding: 6px 8px; text-align: left; font-size: 11.5px; }
.invoice-a4 table td { border: 1px solid #000; padding: 6px 8px; }
.invoice-a4 .num { text-align: right; }
.invoice-a4 .inv-total { margin-inline-start: auto; width: 260px; margin-top: 12px; }
.invoice-a4 .inv-total div { display: flex; justify-content: space-between; padding: 4px 8px; font-size: 12.5px; }
.invoice-a4 .inv-total .grand { font-weight: 800; border-top: 2px solid #000; margin-top: 4px; }
.invoice-a4 .inv-foot { margin-top: 28px; display: flex; justify-content: space-between; font-size: 12px; }

/* ---------- A4 ledger ---------- */
.ledger-a4 { background: #fff; color: #000; padding: 26px; font-size: 13px; max-width: 760px; margin: 0 auto; }
.ledger-a4 .inv-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid #000; padding-bottom: 14px; margin-bottom: 14px; }
.ledger-a4 .inv-biz h1 { margin: 0; font-size: 22px; font-weight: 800; }
.ledger-a4 .inv-biz p { margin: 2px 0; font-size: 12px; color: #333; }
.ledger-a4 .inv-meta { text-align: right; font-size: 12.5px; }
.ledger-a4 .inv-meta b { display: block; font-size: 15px; }
.ledger-a4 table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ledger-a4 table th { background: #f1f1f4; border: 1px solid #000; padding: 6px 8px; text-align: left; font-size: 11.5px; }
.ledger-a4 table td { border: 1px solid #000; padding: 5px 8px; }
.ledger-a4 table .num { text-align: right; }
.ledger-a4 .ledger-open td { background: #f9f9fb; font-style: italic; }
.ledger-a4 .inv-total { margin-inline-start: auto; width: 260px; margin-top: 12px; }
.ledger-a4 .inv-total div { display: flex; justify-content: space-between; padding: 4px 8px; font-size: 12.5px; }
.ledger-a4 .inv-total .grand { font-weight: 800; border-top: 2px solid #000; margin-top: 4px; }
.ledger-a4 .inv-foot { margin-top: 28px; display: flex; justify-content: space-between; font-size: 12px; }

/* ---------- A4 landscape: invoice + gate pass side by side ---------- */
.invoice-combo { background: #fff; color: #000; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.invoice-combo .invoice-half.invoice-a4 { max-width: none; margin: 0; padding: 14px; border: 1px solid #b6bcc4; }
.invoice-combo .invoice-half .inv-head { padding-bottom: 10px; margin-bottom: 10px; }
.invoice-combo .invoice-half .inv-biz h1 { font-size: 18px; }
.invoice-combo .invoice-half .inv-party { margin-bottom: 8px; }
.invoice-combo .invoice-half .inv-total { width: 210px; margin-top: 10px; }
.invoice-combo .invoice-half .inv-foot { margin-top: 16px; }
@media print {
  .invoice-combo .invoice-half.invoice-a4 { border: 1px solid #999; }
}

/* ---------- 80mm thermal ---------- */
.invoice-80 { background: #fff; color: #000; font-family: "Consolas", "Courier New", monospace; font-size: 11px; line-height: 1.35; padding: 6px; width: 300px; margin: 0 auto; }
.invoice-80 .center { text-align: center; }
.invoice-80 .biz-name { font-size: 15px; font-weight: 800; }
.invoice-80 .hr { border-top: 1px dashed #000; margin: 6px 0; }
.invoice-80 .row2 { display: flex; justify-content: space-between; }
.invoice-80 table { width: 100%; border-collapse: collapse; }
.invoice-80 table td { padding: 2px 0; vertical-align: top; }
.invoice-80 table td:last-child { text-align: right; white-space: nowrap; }
.invoice-80 .total-row { font-size: 13px; font-weight: 800; border-top: 1px solid #000; }
.invoice-80 .barcode { text-align: center; font-size: 26px; letter-spacing: 2px; margin: 6px 0; }
.invoice-80 .barcode-caption { text-align: center; font-size: 10px; letter-spacing: 6px; }
.invoice-80 .stamp { text-align: center; font-weight: 800; font-size: 12px; margin-top: 4px; }

@page { margin: 10mm; }
.invoice-80 { width: 80mm; }
@media print {
  .invoice-a4 { max-width: none; }
  .invoice-a4 table th,
  .invoice-a4 table td { padding: 4.8px 6.4px; }
  .ledger-a4 { max-width: none; }
  .ledger-a4 table th,
  .ledger-a4 table td { padding: 4px 6px; }
  .invoice-80 { width: 72mm; padding: 0; }
  .invoice-80 table td { padding: 1.6px 0; }
  .invoice-80 .barcode { display: none; }
}
