:root {
  --bg: #0f172a; --surface: #1e293b; --surface2: #334155; --line: #334155;
  --text: #f1f5f9; --muted: #94a3b8; --brand: #14b8a6; --brand-d: #0f766e;
  --green: #22c55e; --red: #ef4444; --amber: #f59e0b; --blue: #3b82f6;
  --r: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); overscroll-behavior-y: contain;
}
#app { max-width: 540px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }
button { font-family: inherit; cursor: pointer; border: none; }
input, select { font-family: inherit; font-size: 16px; }

/* Topbar */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--brand-d);
  padding: 14px 16px calc(14px + env(safe-area-inset-top)); display: flex; align-items: center; gap: 10px; }
.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; flex: 1; }
.topbar .chip { font-size: 12px; background: rgba(255,255,255,.15); padding: 4px 10px; border-radius: 999px; }
.offline-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); }
.offline-dot.off { background: var(--amber); }

/* Layout */
.page { flex: 1; padding: 14px 14px 90px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.card { background: var(--surface); border-radius: var(--r); padding: 14px; margin-bottom: 12px; }
.muted { color: var(--muted); }
.sub { font-size: 13px; color: var(--muted); }
h2 { font-size: 16px; margin: 4px 0 12px; }
.spacer { height: 10px; }

/* Forms */
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 5px; }
.field, input[type=text], input[type=number], input[type=password], input[type=search], select {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface2); color: var(--text); outline: none;
}
.field:focus, input:focus, select:focus { border-color: var(--brand); }

/* Buttons */
.btn { background: var(--brand); color: #042f2e; font-weight: 700; padding: 14px;
  border-radius: 12px; font-size: 16px; width: 100%; }
.btn:active { transform: scale(.98); }
.btn.sec { background: var(--surface2); color: var(--text); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn.danger { background: var(--red); color: #fff; }
.btn.sm { padding: 9px 12px; font-size: 14px; width: auto; }
.btn.block { width: 100%; }

/* Lists */
.list-item { display: flex; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: none; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.price { font-weight: 700; white-space: nowrap; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--surface2); color: var(--muted); }
.pill.low { background: #452; color: #fde68a; }
.pill.red { background: #512; color: #fca5a5; }

/* Stat grid */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface); border-radius: var(--r); padding: 14px; }
.stat .v { font-size: 22px; font-weight: 800; margin-top: 4px; }
.stat .v.g { color: var(--green); } .stat .v.r { color: var(--red); } .stat .v.b { color: var(--blue); }
.stat.wide { grid-column: span 2; }

/* Bottom nav */
.nav { position: fixed; bottom: 0; left: 0; right: 0; max-width: 540px; margin: 0 auto;
  background: var(--surface); border-top: 1px solid var(--line); display: flex;
  padding-bottom: env(safe-area-inset-bottom); z-index: 20; }
.nav button { flex: 1; background: none; color: var(--muted); padding: 10px 0 12px;
  font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.nav button.active { color: var(--brand); }
.nav .ic { font-size: 20px; }

/* Cart */
.cart-bar { position: fixed; bottom: calc(64px + env(safe-area-inset-bottom)); left: 0; right: 0;
  max-width: 540px; margin: 0 auto; padding: 0 14px; z-index: 15; }
.cart-bar .btn { box-shadow: 0 6px 20px rgba(0,0,0,.4); display: flex; justify-content: space-between; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 40; display: flex; align-items: flex-end; }
.modal { background: var(--surface); width: 100%; max-width: 540px; margin: 0 auto;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto; }
.modal h2 { margin-top: 0; }
.qty { display: flex; align-items: center; gap: 0; }
.qty button { width: 42px; height: 42px; font-size: 22px; background: var(--surface2); color: var(--text); border-radius: 10px; }
.qty input { width: 64px; text-align: center; margin: 0 8px; }

.pay-types { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
.pay-types button { padding: 14px; border-radius: 12px; background: var(--surface2); color: var(--text); font-weight: 600; border: 2px solid transparent; }
.pay-types button.on { border-color: var(--brand); background: #0f3f3a; }

.toast { position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #000d; color: #fff; padding: 12px 18px; border-radius: 12px; opacity: 0; transition: .25s;
  z-index: 60; pointer-events: none; max-width: 90%; text-align: center; font-size: 14px; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: #7f1d1dee; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.scan-box { background:#000; border-radius:12px; overflow:hidden; margin-bottom:10px; }
.scan-box video { width:100%; display:block; }

/* Login */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; }
.login .logo { text-align: center; margin-bottom: 20px; }
.login .logo .big { font-size: 30px; font-weight: 800; color: var(--brand); }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 18px 0; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; background: var(--surface2); }
.pin-dots i.on { background: var(--brand); }
.keypad { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; }
.keypad button { padding: 20px; font-size: 24px; font-weight: 600; background: var(--surface); color: var(--text); border-radius: 14px; }
.seg { display:flex; background:var(--surface2); border-radius:12px; padding:4px; gap:4px; margin-bottom:12px; }
.seg button { flex:1; padding:10px; border-radius:9px; background:none; color:var(--muted); font-weight:600; }
.seg button.on { background:var(--brand-d); color:#fff; }
