:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #14211f;
  --muted: #5d6b68;
  --line: #dde3e1;
  --primary: #0f766e;
  --primary-2: #0d5f59;
  --primary-soft: #d9f0ec;
  --danger: #c2410c;
  --warn: #b45309;
  --ok: #15803d;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 22, .06), 0 4px 16px rgba(16, 24, 22, .06);
  --nav-w: 92px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1514; --surface: #172120; --surface-2: #1f2b29; --text: #e7efed; --muted: #9aaba7;
    --line: #2b3936; --primary: #2bb3a3; --primary-2: #4cc7b8; --primary-soft: #173a36;
    --danger: #f08a5d; --warn: #f0b45d; --ok: #5fd08a; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err-t { color: var(--danger); }
.danger-t { color: var(--danger) !important; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.nav {
  width: var(--nav-w); flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: stretch; gap: 4px; padding: 12px 8px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; margin-bottom: 14px; }
.brand strong { font-size: 13px; display: block; }
.brand small { font-size: 11px; color: var(--muted); }
.nav-btn {
  position: relative; border: 0; background: none; border-radius: 12px; padding: 10px 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--muted);
}
.nav-btn:hover { background: var(--surface-2); }
.nav-btn.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.ico { display: inline-flex; }
.badge {
  position: absolute; top: 4px; right: 14px; background: var(--danger); color: #fff; border-radius: 10px;
  font-size: 11px; padding: 0 6px; min-width: 18px; text-align: center;
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { margin: 0; font-size: 20px; }
.topbar p { margin: 0; font-size: 13px; }
.view { padding: 20px 24px; flex: 1; }
.pill {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.pill.ok { color: var(--ok); border-color: currentColor; }
.pill.warn { color: var(--warn); border-color: currentColor; }
.pill.err { color: var(--danger); border-color: currentColor; }
.pill.busy { color: var(--primary); }

/* ---------- Kontrol ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: var(--surface); border-radius: 10px; padding: 10px 16px; cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text);
  min-height: 42px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; min-height: 32px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.grow { flex: 1; }
.icon-btn { border: 0; background: var(--surface-2); border-radius: 10px; width: 36px; height: 36px; cursor: pointer; }
input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 12px; min-height: 42px;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .pcard:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 12px; align-items: center; }
.toolbar.wrap, .actions.wrap { flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: thin; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 14px; cursor: pointer; white-space: nowrap; font-size: 14px;
}
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.actions { display: flex; gap: 10px; margin-top: 14px; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; grid-column: 1 / -1; }
.empty .btn { margin-top: 12px; }
.empty.small { padding: 24px 8px; }
.note { background: var(--primary-soft); padding: 10px 14px; border-radius: 10px; font-size: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; font-size: 16px; }

/* ---------- Kasir ---------- */
.pos { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.pcard {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 8px; cursor: pointer; text-align: left;
  display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow); transition: transform .08s;
}
.pcard:active { transform: scale(.97); }
.pcard.out { opacity: .5; }
.thumb { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: var(--surface-2); display: block; }
.thumb.ph { display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 26px; color: var(--primary); background: var(--primary-soft); }
.thumb.sm { width: 52px; height: 52px; font-size: 16px; flex-shrink: 0; }
.thumb.lg { width: 120px; height: 120px; font-size: 32px; }
.pname { font-weight: 600; font-size: 14px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pprice { color: var(--primary); font-weight: 700; }
.pstock { font-size: 12px; color: var(--muted); }
.pstock.low { color: var(--warn); }
.cart {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  position: sticky; top: 84px; display: flex; flex-direction: column; max-height: calc(100vh - 104px);
}
.cart-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 6px; }
.cart-head h2 { margin: 0; font-size: 17px; }
.cart-items { overflow-y: auto; padding: 0 16px; flex: 1; }
.citem { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.cinfo { display: flex; flex-direction: column; font-size: 14px; }
.csub { text-align: right; align-self: center; }
.qty { display: flex; align-items: center; gap: 4px; }
.qty button { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; font-size: 18px; }
.qty input { width: 56px !important; text-align: center; min-height: 34px !important; padding: 4px !important; }
.cart-foot { padding: 12px 16px 16px; border-top: 1px solid var(--line); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.big { font-size: 22px; }
.cart-fab {
  position: fixed; left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 20; border: 0; border-radius: 14px;
  background: var(--primary); color: #fff; padding: 14px 18px; display: none; align-items: center; gap: 10px; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.cart-fab strong { margin-left: auto; font-size: 17px; }
.mobile-only { display: none; }

/* ---------- Produk ---------- */
.plist { display: flex; flex-direction: column; gap: 8px; }
.prow { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.pinfo { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pinfo strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pinfo span, .pnums span { font-size: 13px; }
.pnums { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.pact { display: flex; gap: 6px; }
.photo-pick { display: flex; gap: 16px; align-items: center; }

/* ---------- Form & Modal ---------- */
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 14px; font-weight: 500; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; }
.form label.btn { flex-direction: row; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 12px; padding: 4px; }
.seg label { flex-direction: row; justify-content: center; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; width: 100%; text-align: center; padding: 10px; border-radius: 9px; cursor: pointer; font-weight: 600; }
.seg input:checked + span { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }
.seg input:focus-visible + span { outline: 2px solid var(--primary); }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.summary { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.summary .total { font-size: 20px; font-weight: 700; border-top: 1px dashed var(--line); padding-top: 6px; margin-top: 4px; }
.modal { position: fixed; inset: 0; background: rgba(8, 14, 13, .5); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card {
  background: var(--surface); border-radius: 18px; width: 100%; max-width: 440px; max-height: calc(100vh - 32px); overflow-y: auto; padding: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-card.wide { max-width: 620px; }
.modal-card.small { max-width: 380px; }
.modal-card h2 { margin: 0 0 14px; font-size: 19px; }
.modal.layer { z-index: 55; background: rgba(8, 14, 13, .35); align-items: center; padding: 16px; }
.modal.layer .modal-card { border-radius: 18px; max-width: 380px; padding-bottom: 20px; }
.modal.layer p { margin: 0; color: var(--muted); }
.actions.stack { flex-direction: column; }
.actions.stack .btn { width: 100%; }
.draft-note { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 0 0 12px; }
.draft-status { margin: -4px 0 0; min-height: 1em; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none; z-index: 60;
  background: #14211f; color: #fff; padding: 12px 18px; border-radius: 12px; transition: .2s; max-width: calc(100vw - 32px); box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #9a3412; }

/* ---------- Struk ---------- */
.receipt {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; background: #fff; color: #000;
  border: 1px dashed #bbb; border-radius: 8px; padding: 14px; max-width: 320px; margin: 0 auto;
}
.receipt hr { border-top: 1px dashed #999; margin: 8px 0; }
.r-center { text-align: center; }
.r-store { font-size: 16px; }
.r-row { display: flex; justify-content: space-between; gap: 8px; }
.r-total { font-weight: 700; font-size: 15px; }

/* ---------- Pesanan ---------- */
.orders { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.order { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow); }
.ohead { display: flex; justify-content: space-between; gap: 8px; }
.ohead div { display: flex; flex-direction: column; font-size: 14px; }
.ohead .muted { font-size: 12px; }
.tag { background: var(--primary-soft); color: var(--primary); border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600; height: fit-content; }
.obody { font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
.ofoot { display: flex; align-items: center; gap: 8px; }
.ofoot strong { margin-right: auto; }
.ofoot select { width: auto; min-height: 34px; padding: 4px 8px; }

/* ---------- Laporan ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 4px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); }
.stat span { color: var(--muted); font-size: 13px; }
.stat strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.stat small { color: var(--danger); font-size: 12px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-top: 16px; align-items: start; }
.cols .card { margin-bottom: 0; }
.cols.settings { margin-top: 0; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.bar { margin-bottom: 10px; }
.bl { display: flex; justify-content: space-between; font-size: 13px; gap: 8px; }
.bt { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.bt i { display: block; height: 100%; background: var(--primary); border-radius: 4px; }
.top { margin: 0; padding-left: 20px; }
.top li { padding: 4px 0; }
.top li span:last-child { float: right; color: var(--muted); font-size: 13px; }
.dates { display: flex; align-items: center; gap: 8px; }
.dates input { width: auto; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
tr.cancel td { color: var(--muted); text-decoration: line-through; }
tr.cancel td:last-child { text-decoration: none; }
.nowrap { display: flex; gap: 6px; }
.guide { background: var(--primary-soft); border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px; }
.guide summary { cursor: pointer; font-weight: 600; }
.guide ol { margin: 10px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.copy { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.copy code { word-break: break-all; }
.status-list { padding-left: 18px; margin: 14px 0 0; font-size: 14px; display: flex; flex-direction: column; gap: 4px; }

/* ---------- HP / Tablet ---------- */
@media (max-width: 1100px) {
  .pos { grid-template-columns: minmax(0, 1fr) 320px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 820px) {
  .app { flex-direction: column; }
  .nav {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto; width: auto; flex-direction: row; z-index: 30;
    border-right: 0; border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); gap: 2px;
  }
  .brand { display: none; }
  .nav-btn { flex: 1; padding: 6px 2px; font-size: 11px; }
  .badge { right: calc(50% - 22px); }
  .topbar { padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); }
  .topbar h1 { font-size: 18px; }
  .view { padding: 14px 16px 150px; }
  .pos { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
  .cart {
    display: none; position: fixed; inset: 0; top: auto; max-height: 85vh; border-radius: 18px 18px 0 0; z-index: 40;
    padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -10px 40px rgba(0,0,0,.3);
  }
  .cart.open { display: flex; }
  .cart-fab { display: flex; }
  .cart-fab.hidden { display: none; }
  .mobile-only { display: inline-block; }
  .prow { flex-wrap: wrap; }
  .pact { width: 100%; justify-content: flex-end; }
  .grid2 { grid-template-columns: 1fr; }
  .cols.settings { grid-template-columns: 1fr; }
  .modal { align-items: flex-end; padding: 0; }
  .modal-card, .modal-card.wide { max-width: none; border-radius: 18px 18px 0 0; max-height: 92vh; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
}
@media (max-width: 420px) {
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat strong { font-size: 18px; }
}

/* ---------- Cetak struk ---------- */
#printArea { display: none; }
@media print {
  @page { margin: 4mm; size: auto; }
  body.printing > *:not(#printArea) { display: none !important; }
  body.printing #printArea { display: block; }
  body.printing { background: #fff; }
  #printArea .receipt { border: 0; max-width: 72mm; padding: 0; margin: 0; font-size: 12px; }
}
