:root {
  --bg: #f4f6f8; --panel: #ffffff; --ink: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --accent: #0f766e; --accent-ink: #ffffff; --accent-soft: #ccfbf1;
  --danger: #dc2626; --warn: #b45309; --ok: #15803d;
  --radius: 14px; --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.06);
  --nav-w: 220px; --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0b1220; --panel: #121a2b; --ink: #e5e9f0; --muted: #94a3b8; --line: #23304a;
  --accent: #2dd4bf; --accent-ink: #042f2e; --accent-soft: #123b3a;
  --danger: #f87171; --warn: #fbbf24; --ok: #4ade80;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Sinhala", sans-serif;
  background: var(--bg); color: var(--ink); -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1 { font-size: 24px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 19px; margin: 0; }
h3 { font-size: 15px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* layout */
.app { display: flex; height: 100vh; height: 100dvh; }
.nav {
  width: var(--nav-w); flex: none; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 16px 12px; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 18px; padding: 4px 8px 18px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; border: 0; background: none; padding: 11px 12px;
  border-radius: 10px; font-weight: 550; color: var(--muted); text-align: left;
}
.nav-item .ico { font-size: 18px; width: 22px; text-align: center; }
.nav-item:hover { background: var(--bg); color: var(--ink); }
.nav-item.on { background: var(--accent-soft); color: var(--ink); }
.nav-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.lic { font-size: 13px; padding: 8px 10px; border-radius: 10px; text-align: center; border: 0; }
.lic.ok { color: var(--ok); }
.lic.trial { background: #fef3c7; color: #92400e; font-weight: 600; }
.main { flex: 1; min-width: 0; overflow: auto; }

/* buttons */
.btn {
  border: 1px solid var(--line); background: var(--panel); padding: 10px 16px; border-radius: 10px;
  font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 10px; font-size: 13px; }
.btn.big { padding: 15px 18px; font-size: 17px; }
.btn.block { width: 100%; }
.btn.grow { flex: 1; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; margin: 12px 0; }
.btn-row.wrap { flex-wrap: wrap; }
.btn-row .btn { flex: 1; }
.icon-btn { border: 0; background: var(--bg); width: 36px; height: 36px; border-radius: 50%; font-size: 15px; flex: none; }
.link { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 4px; }

/* sell */
.sell { display: flex; height: 100%; }
.catalog { flex: 1; min-width: 0; overflow: auto; padding: 18px 20px 100px; }
.search-row input, .page-search {
  width: 100%; padding: 13px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel);
  outline: none; font-size: 16px;
}
.search-row input:focus, .page-search:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0; scrollbar-width: none; }
.chip { border: 1px solid var(--line); background: var(--panel); padding: 7px 14px; border-radius: 999px; white-space: nowrap; font-weight: 550; }
.chip.on { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile {
  position: relative; text-align: left; border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius);
  padding: 14px 14px 12px 18px; min-height: 104px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow);
  overflow: hidden; transition: transform .06s;
}
.tile::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--c); }
.tile:active { transform: scale(.97); }
.tile:hover { border-color: var(--c); }
.t-name { font-weight: 650; line-height: 1.25; }
.t-price { margin-top: auto; font-weight: 750; font-size: 16px; }
.t-stock { font-size: 12px; color: var(--muted); }
.t-stock.warn { color: var(--warn); font-weight: 600; }
.t-stock.bad { color: var(--danger); font-weight: 600; }
.tile.out { opacity: .55; }

.cart {
  width: 380px; flex: none; background: var(--panel); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; height: 100%;
}
.cart-head { display: flex; align-items: center; gap: 8px; padding: 18px 18px 10px; }
.cart-head h2 { flex: 1; }
.cart-items { flex: 1; overflow: auto; padding: 0 12px; }
.cart-empty { color: var(--muted); text-align: center; padding: 50px 10px; }
.ci { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 10px 6px; border-bottom: 1px solid var(--line); align-items: center; }
.ci-name { font-weight: 600; }
.ci-sub { font-size: 12px; color: var(--muted); }
.ci-total { grid-column: 2; grid-row: 1; text-align: right; font-weight: 650; }
.qty { grid-column: 2; display: flex; align-items: center; gap: 2px; justify-self: end; }
.qty button { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); font-size: 17px; line-height: 1; }
.qty span { min-width: 30px; text-align: center; font-weight: 650; }
.ci-main { grid-row: 1 / span 2; }
.cart-foot { border-top: 1px solid var(--line); padding: 14px 18px calc(16px + var(--safe-b)); display: flex; flex-direction: column; gap: 6px; }
.disc-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.disc-row label { flex: 1; color: var(--muted); }
.disc-row input { width: 90px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.disc-row select { padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.sum { display: flex; justify-content: space-between; color: var(--muted); }
.sum.total { color: var(--ink); font-size: 20px; font-weight: 750; margin: 4px 0 10px; }
.cart-bar { display: none; }
.only-mobile { display: none; }

/* pages */
.page { padding: 22px 24px 110px; max-width: 980px; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-search { margin-bottom: 14px; }
.list { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px 16px; border: 0; border-bottom: 1px solid var(--line);
  background: none; text-align: left;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--bg); }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-main small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-stock { color: var(--muted); font-size: 13px; white-space: nowrap; }
.row-stock.warn { color: var(--warn); font-weight: 600; }
.row-price { font-weight: 700; white-space: nowrap; min-width: 80px; text-align: right; }
.badge { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: var(--bg); }
.badge.bad { color: var(--danger); }
.group { display: flex; justify-content: space-between; margin: 20px 4px 8px; font-size: 14px; color: var(--muted); }
.group small { font-size: 14px; color: var(--ink); }
.empty { grid-column: 1 / -1; text-align: center; padding: 50px 20px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty .big { font-size: 44px; }

.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 7px 12px; border-radius: 8px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card.wide { grid-column: 1 / -1; }
.stat small { color: var(--muted); display: block; }
.stat b { font-size: 24px; letter-spacing: -.01em; }
.pos { color: var(--ok); } .neg { color: var(--danger); } .warn { color: var(--warn); }
.kv { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.kv:last-child { border-bottom: 0; }
.kv small { color: var(--muted); }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 170px; padding-top: 8px; }
.bar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; min-width: 0; }
.bar i { width: 100%; max-width: 42px; background: var(--accent); border-radius: 6px 6px 2px 2px; }
.bar span { font-size: 11px; color: var(--muted); }

.settings .card { margin-bottom: 14px; }
.settings form.card h3:not(:first-child) { margin-top: 18px; }
.ok-text { color: var(--ok); }
.howto { padding-left: 18px; margin: 8px 0 0; }
.howto li { margin: 4px 0; }

/* forms */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); outline: none; width: 100%; font-size: 16px;
}
.field textarea { font-family: ui-monospace, monospace; font-size: 13px; word-break: break-all; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; margin: 4px 0 16px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.sw input { position: absolute; opacity: 0; }
.sw i { display: block; width: 30px; height: 30px; border-radius: 50%; background: var(--c); cursor: pointer; border: 3px solid transparent; }
.sw input:checked + i { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--c); }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(2,6,23,.5); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { background: var(--panel); border-radius: 18px; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-box.narrow { max-width: 430px; }
.m-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.methods { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.method { border: 1px solid var(--line); background: var(--bg); padding: 12px 4px; border-radius: 10px; font-weight: 650; }
.method.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin: -4px 0 10px; }
.change { font-size: 17px; margin-bottom: 14px; }
.change-big { background: var(--accent-soft); border-radius: 12px; padding: 12px; text-align: center; margin-bottom: 12px; font-size: 16px; }
.change-big b { display: block; font-size: 28px; }
.setup-hero { text-align: center; margin-bottom: 16px; }
.setup-hero img { border-radius: 16px; }
.setup-hero h2 { margin-top: 8px; font-size: 22px; }

/* plans */
.plans { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.plan { border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-align: center; display: flex; flex-direction: column; background: var(--bg); }
.plan small { color: var(--muted); font-weight: 600; }
.plan b { font-size: 20px; }
.plan span { font-size: 12px; color: var(--muted); }
.btn.wa { background: #25d366; border-color: #25d366; color: #fff; text-decoration: none; }
.device { font-size: 13px; margin: 12px 0 0; }
.device b { font-family: ui-monospace, Consolas, monospace; letter-spacing: .04em; }
.or { text-align: center; color: var(--muted); font-size: 13px; margin: 14px 0 6px; }

/* receipt */
.receipt-wrap { background: var(--bg); border-radius: 12px; padding: 14px; display: flex; justify-content: center; }
.receipt { background: #fff; color: #000; width: 100%; max-width: 300px; padding: 14px; font: 13px/1.4 ui-monospace, "Courier New", monospace; }
.r-center { text-align: center; }
.r-shop { font-size: 16px; font-weight: 700; }
.r-line { border-top: 1px dashed #000; margin: 8px 0; }
.r-row { display: flex; justify-content: space-between; gap: 8px; }
.r-item { margin-bottom: 4px; }
.r-total { font-weight: 700; font-size: 15px; margin: 4px 0; }
.r-refund { font-weight: 700; margin-top: 6px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); z-index: 60;
  background: #0f172a; color: #fff; padding: 11px 18px; border-radius: 12px; box-shadow: var(--shadow); max-width: 90vw; text-align: center;
}
.toast[hidden] { display: none; }
#print-area { display: none; }

/* mobile */
@media (max-width: 860px) {
  .app { flex-direction: column-reverse; }
  .nav {
    width: 100%; flex-direction: row; border-right: 0; border-top: 1px solid var(--line); padding: 4px 4px calc(4px + var(--safe-b));
    justify-content: space-around; gap: 0; z-index: 20;
  }
  .brand, .nav-foot { display: none; }
  .nav-item { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; flex: 1; align-items: center; }
  .nav-item.on { background: none; color: var(--accent); }
  .catalog { padding: 12px 12px 150px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
  .cart {
    position: fixed; inset: 0; width: 100%; z-index: 30; transform: translateY(100%); transition: transform .22s ease;
    border-left: 0;
  }
  .cart.open { transform: none; }
  .only-mobile { display: inline-block; }
  .cart-bar {
    position: fixed; left: 12px; right: 12px; bottom: calc(70px + var(--safe-b)); z-index: 25; display: flex; justify-content: space-between;
    align-items: center; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 14px; padding: 15px 18px;
    font-size: 16px; box-shadow: 0 8px 24px rgba(15,118,110,.35);
  }
  .cart-bar[hidden] { display: none; }
  .page { padding: 16px 14px 100px; }
  .two { grid-template-columns: 1fr; gap: 0; }
  .modal { align-items: flex-end; padding: 0; }
  .modal-box, .modal-box.narrow { max-width: none; border-radius: 20px 20px 0 0; padding-bottom: calc(20px + var(--safe-b)); }
  .row-stock { display: none; }
  .toast { bottom: calc(84px + var(--safe-b)); }
}

/* print: only the receipt */
@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { display: block; position: absolute; left: 0; top: 0; }
  #print-area .receipt { max-width: none; padding: 0; }
  .app, .modal, .toast { display: none !important; }
}
