:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --brand-soft: #ccfbf1;
  --in: #15803d;
  --out: #b91c1c;
  --warn-bg: #fef3c7;
  --warn-text: #92400e;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --radius: 14px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b1114; --card: #151d22; --text: #e5e7eb; --muted: #9ca3af; --line: #26323a;
  --brand: #2dd4bf; --brand-ink: #042f2e; --brand-soft: #123d39; --in: #4ade80; --out: #f87171;
  --warn-bg: #3b2f0b; --warn-text: #fcd34d; --shadow: none; color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1114; --card: #151d22; --text: #e5e7eb; --muted: #9ca3af; --line: #26323a;
    --brand: #2dd4bf; --brand-ink: #042f2e; --brand-soft: #123d39; --in: #4ade80; --out: #f87171;
    --warn-bg: #3b2f0b; --warn-text: #fcd34d; --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--in); }
.neg { color: var(--out); }
.right { text-align: end; }

/* Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 10px 16px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--out); }
.btn.link { border: 0; background: none; color: var(--brand); font-weight: 500; }
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.btn-row .btn { flex: 1 1 auto; }
.icon-btn {
  border: 0; background: none; color: var(--text); font-size: 24px; min-width: 40px; height: 40px;
  border-radius: 10px; cursor: pointer;
}
.icon-btn:hover { background: var(--line); }
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 11px 12px; font: inherit; font-size: 16px;
  color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
input[type="checkbox"] { display: inline; width: auto; margin: 0 8px 0 0; transform: scale(1.3); vertical-align: middle; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: transparent; }
.check { display: flex; align-items: center; color: var(--text); font-size: 15px; }
.error { color: var(--out); font-size: 14px; margin: 0 0 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.with-btn { display: flex; gap: 6px; align-items: end; }
.with-btn > :first-child { flex: 1; }
.with-btn .btn { margin-bottom: 12px; height: 46px; }
.search { margin: 0 0 12px; }
.search input { margin: 0; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; text-align: center; padding: 28px 22px; }
.login-card label { text-align: start; }
.login-logo { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 8px; }
.login-card .muted { margin: 4px 0 20px; }
.demo-note { font-size: 13px; background: var(--warn-bg); color: var(--warn-text); padding: 10px; border-radius: 10px; margin: 12px 0 0; }

/* Shell */
#app-view { max-width: 820px; margin: 0 auto; padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; gap: 6px; padding: calc(10px + env(safe-area-inset-top)) 12px 6px 16px; min-height: 52px; }
.topbar h1 { font-size: 21px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#top-actions { display: flex; gap: 6px; }
.demo-banner { margin: 0 16px 8px; font-size: 13px; text-align: center; background: var(--warn-bg); color: var(--warn-text); padding: 6px; border-radius: 8px; }
.datebar { display: flex; align-items: center; gap: 4px; padding: 0 12px 8px; }
.date-pick { position: relative; flex: 1; margin: 0; text-align: center; font-size: 16px; color: var(--text); font-weight: 600; }
.date-pick input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
main { padding: 0 16px; }
html[dir="rtl"] .datebar [data-shift], html[dir="rtl"] #back-btn { transform: scaleX(-1); }
html[dir="rtl"] .amt > div:not(.s), html[dir="rtl"] .lt, html[dir="rtl"] .tbl td.n { direction: ltr; text-align: left; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 16px; margin-bottom: 12px; }
.card > h3 { font-size: 15px; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.card-head h3 { margin: 0; font-size: 15px; color: var(--muted); }
.card-head .total { font-weight: 700; font-size: 18px; }
.alert { background: var(--warn-bg); color: var(--warn-text); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; font-size: 14px; }
.alert a { color: inherit; font-weight: 700; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; min-width: 0; }
.stat .k { font-size: 13px; color: var(--muted); }
.stat .v { font-size: 21px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat.big { grid-column: 1 / -1; background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.stat.big .k { color: inherit; opacity: .85; }
.stat.big .v { font-size: 30px; }
@media (min-width: 640px) { .stats.four { grid-template-columns: repeat(4, 1fr); } }

/* Quick actions & menu grid */
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.quick a, .menu a {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-decoration: none; color: var(--text);
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 4px; font-size: 12px; font-weight: 600; text-align: center;
}
.quick a span, .menu a span { font-size: 22px; }
.menu { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.menu a { padding: 18px 6px; font-size: 13px; }
@media (min-width: 640px) { .menu { grid-template-columns: repeat(4, 1fr); } }

/* Bars */
.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: end; height: 140px; }
.bar { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; cursor: pointer; }
.bar .fill { width: 100%; max-width: 38px; background: var(--brand-soft); border-radius: 6px 6px 2px 2px; min-height: 3px; }
.bar.sel .fill { background: var(--brand); }
.bar .d { font-size: 11px; color: var(--muted); }
.bar .a { font-size: 10px; color: var(--muted); white-space: nowrap; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li.tap { cursor: pointer; }
.list li.tap:hover { background: color-mix(in srgb, var(--line) 40%, transparent); }
.list .main { flex: 1; min-width: 0; }
.list .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .s { font-size: 13px; color: var(--muted); }
.list .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: end; }
.list .amt .s { font-weight: 400; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
.pill { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--muted); }
.pill.in, .pill.ok { background: color-mix(in srgb, var(--in) 15%, transparent); color: var(--in); }
.pill.out, .pill.due { background: color-mix(in srgb, var(--out) 15%, transparent); color: var(--out); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.chips button { flex: none; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 99px; padding: 6px 14px; font: inherit; font-size: 14px; cursor: pointer; }
.chips button.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 8px 4px; border-bottom: 1px solid var(--line); text-align: start; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; }
.tbl td.n, .tbl th.n { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kv { display: flex; justify-content: space-between; padding: 6px 0; gap: 12px; }
.kv b { font-variant-numeric: tabular-nums; }
.kv.total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 10px; font-size: 18px; }

/* Bill editor */
.lines { list-style: none; margin: 0; padding: 0; }
.line { border-bottom: 1px solid var(--line); padding: 10px 0; }
.line:last-child { border-bottom: 0; }
.line-top { display: flex; align-items: center; gap: 8px; }
.line-top .nm { flex: 1; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.line-bot { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; margin-top: 6px; }
.qty { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.qty button { border: 0; background: var(--bg); color: var(--text); width: 36px; height: 40px; font-size: 20px; cursor: pointer; }
.qty input { width: 56px; margin: 0; border: 0; border-radius: 0; text-align: center; padding: 8px 2px; }
.line-bot .price { margin: 0; }
.line-bot .price input { margin: 0; padding: 9px 10px; }
.line-bot .lt { font-weight: 700; min-width: 80px; text-align: end; font-variant-numeric: tabular-nums; }
.x { border: 0; background: none; color: var(--muted); font-size: 22px; cursor: pointer; width: 34px; height: 34px; }
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--card); border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); display: flex; gap: 10px; align-items: center; justify-content: center;
}
.savebar .sum { flex: 1; max-width: 560px; font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.savebar .sum small { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }
body.editing .bottomnav, body.editing .fab { display: none; }

/* Invoice preview */
.doc { background: #fff; color: #111; border-radius: 12px; padding: 20px; border: 1px solid var(--line); margin-bottom: 12px; font-size: 14px; }
.doc .head { text-align: center; margin-bottom: 12px; }
.doc .head img { max-width: 90px; max-height: 70px; object-fit: contain; }
.doc .head h2 { font-size: 20px; margin: 4px 0 2px; }
.doc .head div { font-size: 12px; color: #444; }
.doc .head .slogan { font-size: 13px; font-style: italic; color: #0f766e; font-weight: 600; margin-bottom: 4px; }
.doc .meta { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; border-top: 1px dashed #999; border-bottom: 1px dashed #999; padding: 8px 0; margin-bottom: 8px; }
.doc table { width: 100%; border-collapse: collapse; font-size: 13px; }
.doc th, .doc td { padding: 5px 2px; text-align: start; border-bottom: 1px solid #eee; }
.doc th { font-size: 11px; color: #555; text-transform: uppercase; }
.doc .n { text-align: end; white-space: nowrap; font-variant-numeric: tabular-nums; }
.doc .tot { margin-top: 8px; }
.doc td .items { font-size: 12px; color: #555; margin-top: 2px; line-height: 1.35; }
.doc tbody td { vertical-align: top; }
.doc .tot div { display: flex; justify-content: space-between; padding: 2px 0; }
.doc .tot .grand { font-size: 17px; font-weight: 800; border-top: 1px dashed #999; margin-top: 4px; padding-top: 6px; }
.doc .foot { text-align: center; font-size: 12px; color: #555; margin-top: 14px; }
.doc h3 { font-size: 15px; margin: 12px 0 6px; }

/* FAB & nav */
.fab {
  position: fixed; inset-inline-end: max(16px, calc(50vw - 394px)); bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 10;
  width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--brand); color: var(--brand-ink);
  font-size: 30px; box-shadow: 0 4px 14px rgba(0,0,0,.25); cursor: pointer;
}
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  flex: 1; max-width: 160px; color: var(--muted); padding: 8px 0 10px; text-decoration: none;
  font-size: 12px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.bottomnav a b { font-weight: 500; }
.bottomnav a span { font-size: 20px; filter: grayscale(1); opacity: .7; }
.bottomnav a.active { color: var(--brand); }
.bottomnav a.active b { font-weight: 700; }
.bottomnav a.active span { filter: none; opacity: 1; }

/* Modal */
dialog {
  border: 0; border-radius: 18px; padding: 20px; width: min(460px, calc(100vw - 24px));
  background: var(--card); color: var(--text); max-height: calc(100vh - 40px);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { font-size: 20px; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; margin-top: 8px; }
.spacer { flex: 1; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }
.seg input { display: none; }
.seg label { margin: 0; text-align: center; padding: 10px; border: 1px solid var(--line); border-radius: 10px; font-weight: 600; cursor: pointer; color: var(--text); }
.seg input:checked + label.in { background: var(--in); border-color: var(--in); color: #fff; }
.seg input:checked + label.out { background: var(--out); border-color: var(--out); color: #fff; }
.calc { font-size: 14px; color: var(--muted); margin: -4px 0 12px; }
.calc b { color: var(--text); }
#reader { width: 100%; min-height: 240px; border-radius: 12px; overflow: hidden; background: #000; }

.toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 99px; font-size: 14px; z-index: 50;
}

/* Hide the "Powered by Netlify" badge that the free host injects */
#nl-badge-frame, iframe[title="Powered by Netlify"] { display: none !important; }

/* Printing */
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  #print-area .doc { border: 0; border-radius: 0; padding: 0; margin: 0; }
  body { background: #fff; }
}
#print-area.w80 .doc { width: 72mm; font-size: 12px; }
#print-area.w58 .doc { width: 50mm; font-size: 11px; }
#print-area.w80 .doc .head h2, #print-area.w58 .doc .head h2 { font-size: 15px; }
#print-area.w80 .doc .head img, #print-area.w58 .doc .head img { max-width: 60px; }
#print-area.w58 .doc th, #print-area.w58 .doc td { padding: 3px 1px; }

/* business switch (HK Sports / Garments) */
.biz-btn { border: 1px solid var(--line, #ccc); background: var(--card, #fff); color: inherit; border-radius: 999px; padding: 5px 10px; font: inherit; font-size: 13px; font-weight: 600; white-space: nowrap; cursor: pointer; }
.biz-btn.garments { background: #7c3aed; border-color: #7c3aed; color: #fff; }
body.biz-garments .topbar { box-shadow: inset 0 -3px 0 #7c3aed; }
.biz-card { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; margin-bottom: 12px; }
.biz-card > span { font-size: 28px; }
