:root {
  --bg: #f4f6fb;
  --card: #fff;
  --text: #111827;
  --text-2: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-2: #f1f3f7;
  --primary: #4f46e5;
  --primary-2: #4338ca;
  --primary-soft: #eef2ff;
  --green: #059669;
  --green-soft: #ecfdf5;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --amber: #d97706;
  --sidebar: #0f172a;
  --sidebar-2: #1e293b;
  --sidebar-text: #94a3b8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --sb-w: 244px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14.5px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-2); }
h2 { margin: 4px 0 18px; font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; }
h3 { margin: 22px 0 12px; font-size: 1rem; font-weight: 650; color: var(--text-2); }
.card h3 { margin-top: 0; color: var(--text); }
.icon { width: 18px; height: 18px; flex: none; }

/* ===== Layout: sidebar + main ===== */
.layout { display: flex; min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sb-w); background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; z-index: 30; transition: transform .2s ease; }
.sb-brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 16px; border-bottom: 1px solid rgba(255, 255, 255, .06); }
.sb-logo { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 1.05rem; flex: none; }
.sb-name { color: #fff; font-weight: 650; font-size: .98rem; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.sb-nav { flex: 1; overflow-y: auto; padding: 8px 12px 16px; }
.sb-group { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: #64748b; padding: 16px 10px 6px; }
.sb-nav a, .sb-logout { display: flex; align-items: center; gap: 12px; padding: 9px 12px; margin: 2px 0; border-radius: 8px; color: var(--sidebar-text); font-weight: 500; font-size: .93rem; }
.sb-nav a:hover, .sb-logout:hover { background: var(--sidebar-2); color: #e2e8f0; }
.sb-nav a.active { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(79, 70, 229, .35); }
.sb-logout { margin: 0 12px 14px; border-top: 1px solid rgba(255, 255, 255, .06); border-radius: 0; padding-top: 14px; }
.sb-overlay { display: none; }

.main { flex: 1; min-width: 0; margin-left: var(--sb-w); display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; height: 60px; display: flex; align-items: center; gap: 12px; padding: 0 28px; background: rgba(255, 255, 255, .85); backdrop-filter: saturate(180%) blur(8px); border-bottom: 1px solid var(--line); }
.tb-date { color: var(--muted); font-size: .9rem; font-weight: 500; }
.tb-actions { margin-left: auto; display: flex; gap: 8px; }
.menu-btn { display: none; background: none; border: 0; padding: 6px; margin-left: -6px; color: var(--text); cursor: pointer; border-radius: 8px; }
.menu-btn .icon { width: 22px; height: 22px; }

.wrap { width: 100%; max-width: 1200px; margin: 0 auto; padding: 24px 28px 40px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; box-shadow: var(--shadow); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.row.between { justify-content: space-between; }
.row.between h2 { margin-bottom: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.muted { color: var(--muted); }
.green { color: var(--green); }
.red { color: var(--red); }

/* ===== Forms ===== */
label { display: block; font-size: .84rem; font-weight: 550; color: var(--text-2); margin-bottom: 14px; }
label.inline { display: inline-flex; gap: 8px; align-items: center; margin: 0; font-weight: 500; }
input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 9px; font-size: 15px; margin-top: 6px; background: #fff; color: var(--text); font-family: inherit; transition: border-color .15s, box-shadow .15s; }
input::placeholder, textarea::placeholder { color: #9ca3af; }
input:disabled { background: #f9fafb; color: var(--muted); }
input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); }
label.inline select { width: auto; margin: 0; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, .15); }
.form .grid2 { gap: 0 20px; }
.form h3 { padding-bottom: 8px; border-bottom: 1px solid var(--line-2); margin: 22px 0 14px; }
.form h3:first-of-type { margin-top: 0; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.filters input:not([type="checkbox"]), .filters select { width: auto; flex: 1 1 150px; margin: 0; }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border: 1px solid #d1d5db; background: #fff; color: var(--text-2); border-radius: 9px; font-size: .92rem; font-weight: 550; cursor: pointer; font-family: inherit; line-height: 1.3; box-shadow: 0 1px 2px rgba(16, 24, 40, .05); transition: background .15s, border-color .15s, color .15s; }
.btn:hover { background: #f9fafb; color: var(--text); border-color: #c4c8d0; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); border-color: var(--primary-2); }
.btn.danger { color: var(--red); border-color: #fecaca; }
.btn.danger:hover { background: var(--red-soft); }
.btn.sm { padding: 6px 11px; font-size: .84rem; }
.btn.sm .icon { width: 15px; height: 15px; }
.btn.big { padding: 14px 20px; font-size: 1rem; font-weight: 650; border-radius: 11px; }
.btn.full { width: 100%; }

.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; background: var(--green-soft); color: #065f46; border: 1px solid #a7f3d0; font-weight: 500; }
.alert.err { background: var(--red-soft); color: #991b1b; border-color: #fecaca; }

/* ===== Stats ===== */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat { position: relative; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); overflow: hidden; }
.stat::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--primary); opacity: .8; }
.stat:has(b.green)::before { background: var(--green); }
.stat:has(b.red)::before { background: var(--red); }
.stat span { display: block; color: var(--muted); font-size: .76rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.stat b { display: block; font-size: 1.45rem; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat b a { color: inherit; }
.stat small { color: var(--muted); font-size: .8rem; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .table-wrap { border: 0; border-radius: 0; box-shadow: none; }
.table { width: 100%; border-collapse: collapse; background: #fff; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 12px 14px; border-bottom: 1px solid var(--line-2); text-align: left; vertical-align: middle; }
.table th { font-size: .74rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; background: #f9fafb; border-bottom-color: var(--line); }
.table tbody tr:hover td, .table > tr:hover td { background: #fafbff; }
.table tr:last-child td { border-bottom: 0; }
.card .table th, .card .table td { padding-left: 4px; padding-right: 4px; }
.num { text-align: right !important; white-space: nowrap; }
.actions { white-space: nowrap; text-align: right; }
.actions form { display: inline; }
.table.pl td { font-size: .98rem; padding-top: 11px; padding-bottom: 11px; }
.table.pl tr.bold td { font-weight: 700; background: #f9fafb; }
.table.pl tr.big td { font-size: 1.2rem; }
.table.pl tr:hover td { background: transparent; }
.table.pl tr.bold:hover td { background: #f9fafb; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: .74rem; font-weight: 600; background: #f3f4f6; color: #374151; white-space: nowrap; }
.badge.received { background: #fef3c7; color: #92400e; }
.badge.in_progress { background: #dbeafe; color: #1e40af; }
.badge.ready { background: #d1fae5; color: #065f46; }
.badge.delivered { background: #f3f4f6; color: var(--muted); }
.badge.cancelled { background: #fee2e2; color: #991b1b; }

/* ===== Sale screen ===== */
.results { display: grid; gap: 8px; }
.result { display: flex; justify-content: space-between; align-items: center; padding: 11px 14px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; text-align: left; font: inherit; color: inherit; width: 100%; transition: border-color .15s, background .15s; }
.result:hover { border-color: var(--primary); background: var(--primary-soft); }
.result[disabled] { opacity: .5; cursor: not-allowed; }
.result small { color: var(--muted); }
#cart input { width: 90px; margin: 0; padding: 7px 9px; text-align: right; }
.totals { background: #f9fafb; border: 1px solid var(--line-2); border-radius: 10px; padding: 14px 16px; margin-bottom: 16px; font-variant-numeric: tabular-nums; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { font-size: 1.35rem; font-weight: 700; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; color: var(--primary); }

/* ===== Repairs ===== */
.print-only { display: none; }
.report-head { text-align: center; margin-bottom: 18px; padding-bottom: 12px; border-bottom: 2px solid #000; line-height: 1.6; }
.report-head h2 { margin: 0; }
.report-head h3 { margin: 8px 0 2px; font-size: 1.1rem; color: #000; }

.deliver { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line-2); }

/* ===== Login / Setup ===== */
.center-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; background: radial-gradient(1200px 600px at 10% -10%, #e0e7ff 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #ede9fe 0%, transparent 55%), var(--bg); }
.login-card { width: 100%; max-width: 400px; padding: 32px 28px; box-shadow: 0 10px 30px rgba(15, 23, 42, .08); }
.login-card h2 { text-align: center; margin-bottom: 22px; }
.login-card .btn { margin-top: 6px; padding: 12px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

/* ===== Invoice / receipt (kept black & white for printing) ===== */
.invoice { background: #fff; margin: 8px auto 0; padding: 24px; border: 1px solid var(--line); border-radius: 6px; color: #000; box-shadow: var(--shadow); }
.invoice.a4 { max-width: 800px; }
.invoice.receipt { max-width: 80mm; padding: 12px; font-size: 12px; }
.inv-head { text-align: center; border-bottom: 1px dashed #000; padding-bottom: 8px; margin-bottom: 8px; }
.inv-head h2 { margin: 0 0 4px; font-size: 1.4em; }
.inv-meta { margin-bottom: 8px; line-height: 1.5; }
.inv-table, .inv-totals { width: 100%; border-collapse: collapse; }
.inv-table th, .inv-table td { padding: 5px 3px; border-bottom: 1px dashed #999; text-align: left; }
.inv-totals td { padding: 3px; }
.inv-totals .grand td { font-weight: 700; font-size: 1.15em; border-top: 1px solid #000; }
.inv-note { text-align: center; margin-top: 12px; font-size: .9em; border-top: 1px dashed #000; padding-top: 8px; }
.invoice.a4 .inv-head h2 { font-size: 1.8rem; }
.inv-title { margin-top: 6px; font-weight: 700; letter-spacing: 1px; }
.inv-job { font-size: 1.4em; font-weight: 700; }
.inv-details { margin-bottom: 8px; }
.inv-details td { vertical-align: top; border-bottom: 1px dashed #999; }
.inv-details td:first-child { white-space: nowrap; color: #444; width: 1%; padding-right: 10px; }
.inv-tag { margin-top: 16px; text-align: center; line-height: 1.5; }
.inv-tag small { display: block; color: #666; margin-bottom: 6px; }

/* ===== Mobile: sidebar slides in ===== */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  body.nav-open .sidebar { transform: none; box-shadow: 8px 0 30px rgba(0, 0, 0, .25); }
  body.nav-open .sb-overlay { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 25; }
  body.nav-open { overflow: hidden; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 0 16px; }
  .wrap { padding: 18px 16px 32px; }
}
@media (max-width: 700px) {
  .grid2 { grid-template-columns: 1fr; gap: 12px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat b { font-size: 1.15rem; }
  .card { padding: 16px; }
  h2 { font-size: 1.3rem; }
  .tb-date { display: none; }
  .table th, .table td { padding: 10px 8px; font-size: .88rem; }
}

@media print {
  .no-print, .alert { display: none !important; }
  body { background: #fff; }
  .print-only { display: block; }
  body { font-size: 12px; color: #000; }
  .card, .table-wrap { box-shadow: none; border-color: #bbb; break-inside: avoid; }
  .table th { background: #f3f3f3 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .table th, .table td { padding: 6px 8px; }
  .green, .red { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .grid2 { grid-template-columns: 1fr 1fr; gap: 14px; }
  .main { margin: 0; }
  .wrap { padding: 0; max-width: none; }
  .invoice { border: 0; margin: 0; box-shadow: none; border-radius: 0; }
  .invoice.receipt { width: 72mm; max-width: 72mm; padding: 0; }
  @page { margin: 6mm; }
}
.login-logo { width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 14px; background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 1.4rem; box-shadow: 0 8px 20px rgba(99, 102, 241, .35); }
.login-card h2 + .login-sub { text-align: center; margin: -16px 0 22px; }

/* Text is saved in CAPITAL letters, so show it that way while typing (login page excluded) */
.wrap input:not([type]), .wrap input[type="text"], .wrap input[type="search"], .wrap input[type="tel"], .wrap textarea { text-transform: uppercase; }
.wrap input::placeholder, .wrap textarea::placeholder { text-transform: none; }

/* ===== WhatsApp button ===== */
.btn.wa { background: #25d366; border-color: #25d366; color: #fff; }
.btn.wa:hover { background: #1ebe5b; border-color: #1ebe5b; color: #fff; }
.btn.wa .icon { width: 17px; height: 17px; }

/* ===== Dashboard quick actions ===== */
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 700px) { .quick { grid-template-columns: 1fr 1fr; } .quick .btn.big { padding: 12px 10px; font-size: .92rem; } }

/* ===== Collapsible card (add customer, edit details) ===== */
details.card > summary { cursor: pointer; list-style: none; font-weight: 650; color: var(--primary); }
details.card > summary::-webkit-details-marker { display: none; }
details.card[open] > summary { color: var(--text); }

/* ===== Load / JazzCash service chips ===== */
.mm-services { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip { margin: 0; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip span { display: inline-block; padding: 8px 14px; border: 1px solid #d1d5db; border-radius: 99px; font-weight: 600; font-size: .85rem; color: var(--text-2); background: #fff; cursor: pointer; transition: all .15s; }
.chip input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 3px 10px rgba(79, 70, 229, .3); }
.chip input:focus-visible + span { box-shadow: 0 0 0 3px rgba(79, 70, 229, .25); }

/* ===== Daily cash (galla) ===== */
.galla-expected { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; padding: 14px 16px; background: var(--primary-soft); border-radius: 10px; }
.galla-expected span { font-weight: 600; color: var(--text-2); }
.galla-expected b { font-size: 1.4rem; color: var(--primary); font-variant-numeric: tabular-nums; }
.denoms { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px 12px; margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--line-2); }
.denoms label { margin: 0; font-size: .78rem; }
.denoms input { margin-top: 3px; padding: 7px 9px; }
@media (max-width: 700px) { .denoms { grid-template-columns: repeat(2, 1fr); } }
.galla-diff { margin: 0 0 14px; padding: 10px 14px; border-radius: 10px; font-weight: 650; display: none; }
.galla-diff.ok { display: block; background: var(--green-soft); color: #065f46; }
.galla-diff.short { display: block; background: var(--red-soft); color: #991b1b; }
.galla-diff.extra { display: block; background: #fffbeb; color: #92400e; }

/* ===== Mobile phones ===== */
.cnic-photos { display: flex; gap: 12px; margin-top: 12px; }
.cnic-photos a { flex: 1; max-width: 220px; text-align: center; font-size: .8rem; color: var(--muted); }
.cnic-photos img { display: block; width: 100%; aspect-ratio: 1.58; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); margin-bottom: 4px; }
.imei-hint { display: block; margin-top: 4px; font-weight: 500; }
.btn.active-doc { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.inv-declare { margin: 12px 0 0; font-size: .92em; line-height: 1.5; text-align: justify; }
.inv-sign { display: flex; justify-content: space-between; gap: 20px; margin-top: 40px; }
.inv-sign div { flex: 1; border-top: 1px solid #000; padding-top: 4px; text-align: center; font-size: .85em; }
.amber { color: var(--amber); }

/* ===== Dashboard / report tables ===== */
.table.biz th.grp { text-align: center !important; border-left: 1px solid var(--line); }
.table.biz thead tr:nth-child(2) th:nth-child(1), .table.biz thead tr:nth-child(2) th:nth-child(4),
.table.biz td:nth-child(2), .table.biz td:nth-child(5) { border-left: 1px solid var(--line); }
.table tr.total td { font-weight: 700; background: #f9fafb; border-top: 1px solid var(--line); }
.table tr.sub td { color: var(--muted); font-size: .9em; }
.table tr.sub td a { color: var(--muted); }
