:root {
  --bg: #f4f2ee; --panel: #ffffff; --ink: #1f2024; --muted: #6b6d75; --line: #e3e0da;
  --side: #2b2c31; --side-ink: #d9d6cf; --gold: #c9924a; --gold-d: #a8742f; --gold-l: #f6ead8;
  --ok: #2f7d4f; --ok-l: #e3f2e8; --bad: #b3372f; --bad-l: #f9e3e1; --warn: #9a6a00; --warn-l: #fbf0d4;
  --r: 10px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  font-family: "Segoe UI", "Iskoola Pota", "Noto Sans Sinhala", system-ui, -apple-system, sans-serif;
  color: var(--ink); background: var(--bg); font-size: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #18191c; --panel: #222327; --ink: #ecebe7; --muted: #a3a29c; --line: #34353a;
    --side: #111214; --gold-l: #3a2f20; --ok-l: #1d3326; --bad-l: #3d2220; --warn-l: #3a3018;
  }
}
:root[data-theme="dark"] { --bg: #18191c; --panel: #222327; --ink: #ecebe7; --muted: #a3a29c; --line: #34353a; --side: #111214; --gold-l: #3a2f20; --ok-l: #1d3326; --bad-l: #3d2220; --warn-l: #3a3018; }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--gold-d); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.boot img { width: 96px; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 16px 14px; border-bottom: 1px solid #ffffff14; }
.brand img { width: 40px; height: 40px; }
.brand b { display: block; color: #fff; font-size: 15px; line-height: 1.15; }
.brand small { color: var(--gold); font-size: 11px; letter-spacing: .04em; }
.nav { padding: 8px; flex: 1; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--side-ink); text-decoration: none; margin: 1px 0; }
.nav a:hover { background: #ffffff10; }
.nav a.on { background: var(--gold); color: #1d1408; font-weight: 600; }
.nav .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #8d8b85; padding: 12px 10px 4px; }
.side-foot { padding: 12px; border-top: 1px solid #ffffff14; font-size: 12px; }
.sync { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #888; display: inline-block; }
.dot.ok { background: #4cc77a; } .dot.bad { background: #e2574c; } .dot.warn { background: #e8b13b; }
.main { padding: 20px 24px 40px; min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.top h1 { font-size: 21px; margin: 0; flex: 1; }
.menu-btn { display: none; }

/* components */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat small { color: var(--muted); display: block; margin-bottom: 4px; }
.stat b { font-size: 22px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.btn { border: 1px solid var(--line); background: var(--panel); padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--gold); }
.btn.pri { background: var(--gold); border-color: var(--gold); color: #1d1408; font-weight: 600; }
.btn.pri:hover { background: var(--gold-d); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.big { padding: 14px 18px; font-size: 17px; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: -1px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.f > input, label.f > select, label.f > textarea { font-size: 14px; color: var(--ink); }
label.chk { display: flex; gap: 8px; align-items: center; }
.form { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form .wide { grid-column: 1 / -1; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--gold-l); color: var(--gold-d); }
.badge.ok { background: var(--ok-l); color: var(--ok); } .badge.bad { background: var(--bad-l); color: var(--bad); } .badge.warn { background: var(--warn-l); color: var(--warn); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button { border: 1px solid var(--line); background: var(--panel); padding: 7px 12px; border-radius: 99px; cursor: pointer; }
.tabs button.on { background: var(--ink); color: var(--panel); border-color: var(--ink); }

/* tables */
.tbl-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; background: var(--panel); font-size: 12px; color: var(--muted); font-weight: 600; z-index: 1; cursor: pointer; user-select: none; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--gold-l); }
tfoot td { font-weight: 700; }
.si { font-size: 15px; }
.en { color: var(--muted); font-size: 12px; }

/* POS */
.pos { display: grid; grid-template-columns: minmax(0, 1fr) minmax(380px, 46%); gap: 16px; height: calc(100vh - 92px); }
.pos-left, .pos-right { display: flex; flex-direction: column; min-height: 0; gap: 10px; }
.scan { font-size: 18px; padding: 12px 14px; }
.results { overflow: auto; flex: 1; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; align-content: start; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.tile:hover, .tile.sel { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold-l); }
.tile .p { font-weight: 700; font-size: 15px; }
.tile .s { font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; }
.cart { flex: 1; overflow: auto; }
.cart td { padding: 6px 6px; }
.cart td:first-child { min-width: 140px; }
.cart input { width: 58px; padding: 4px 6px; text-align: right; }
.totals { font-size: 15px; }
.totals div { display: flex; justify-content: space-between; padding: 3px 0; }
.totals .grand { font-size: 26px; font-weight: 800; border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 6px; }
.cust { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pay-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pay-grid input { font-size: 18px; text-align: right; }
.change { font-size: 28px; font-weight: 800; text-align: center; padding: 10px; border-radius: 10px; background: var(--ok-l); color: var(--ok); }
.kbd { font-size: 11px; color: var(--muted); }

/* modal and toasts */
.modal-bg { position: fixed; inset: 0; background: rgba(15,15,18,.55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; width: min(680px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { width: min(1000px, 100%); }
.modal header { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.modal header h2 { margin: 0; font-size: 17px; flex: 1; }
.modal .body { padding: 16px 18px; overflow: auto; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: var(--ink); color: var(--panel); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; }
.toast.bad { background: var(--bad); color: #fff; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; background: var(--side); padding: 16px; }
.login .card { width: min(400px, 100%); }
.login .logo { text-align: center; margin-bottom: 10px; }
.login .logo img { width: 92px; }
.login h1 { text-align: center; font-size: 20px; margin: 4px 0 2px; }
.login p.sub { text-align: center; color: var(--muted); margin: 0 0 16px; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.err { color: var(--bad); min-height: 1.2em; }

/* charts */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; }
.bars div { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bars i { display: block; width: 100%; max-width: 34px; background: var(--gold); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars span { font-size: 10px; color: var(--muted); }

/* labels */
.labels { display: flex; flex-wrap: wrap; gap: 6px; }
.label { border: 1px dashed var(--line); width: 50mm; height: 25mm; padding: 1mm 2mm; display: flex; flex-direction: column; align-items: center; justify-content: space-between; overflow: hidden; background: #fff; color: #000; }
.label .n { font-size: 9px; line-height: 1.1; text-align: center; max-height: 2.2em; overflow: hidden; }
.label img { height: 9mm; max-width: 100%; image-rendering: pixelated; }
.label .pr { font-size: 11px; font-weight: 800; display: flex; justify-content: space-between; width: 100%; }
.label.qr { flex-direction: row; gap: 2mm; }
.label.qr img { height: 21mm; width: 21mm; }

#print { display: none; }
@media print {
  @page { margin: 0; }
  body > *:not(#print) { display: none !important; }
  #print { display: block; color: #000; background: #fff; }
  .receipt { width: var(--rw, 80mm); padding: 3mm 4mm; font-family: "Segoe UI", "Iskoola Pota", sans-serif; font-size: 11px; }
  .receipt h3 { margin: 0; text-align: center; font-size: 15px; }
  .receipt .c { text-align: center; }
  .receipt table td { padding: 1px 0; border: 0; font-size: 11px; }
  .receipt hr { border: 0; border-top: 1px dashed #000; margin: 4px 0; }
  .receipt img { display: block; margin: 0 auto 2px; width: 38px; }
  .print-labels .labels { gap: 0; } .print-labels .label { border: 0; page-break-inside: avoid; }
  .print-page { padding: 10mm; font-size: 11px; } .print-page table td, .print-page table th { padding: 3px 5px; }
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 40; width: 240px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .menu-btn { display: inline-block; }
  .main { padding: 14px 16px 40px; }
  .pos { grid-template-columns: 1fr; height: auto; }
  .grid2, .form { grid-template-columns: 1fr; }
  .results { max-height: 40vh; }
}

.tile .thumb { width: 100%; height: 90px; object-fit: cover; border-radius: 6px; background: var(--bg); }
img.mini { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; display: block; }
.photos { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; align-items: center; }
.photos .ph { position: relative; }
.photos .ph img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.photos .ph button { position: absolute; top: 4px; right: 4px; }
.hbars { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.hb { display: grid; grid-template-columns: minmax(0, 1.2fr) 2fr auto; gap: 8px; align-items: center; font-size: 13px; }
.hb .l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hb .b { background: var(--bg); border-radius: 4px; height: 10px; overflow: hidden; }
.hb .b i { display: block; height: 100%; background: var(--gold); border-radius: 4px; }
.hb .v { font-variant-numeric: tabular-nums; color: var(--muted); }
.stat.warn { border-color: var(--gold); }
