:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #0f766e;
  --accent-2: #115e59;
  --accent-soft: #ccfbf1;
  --gw: #c2410c;
  --gw-soft: #ffedd5;
  --pos: #15803d;
  --neg: #b91c1c;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --radius: 14px;
  --tab-h: 62px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f14;
    --card: #151b23;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --line: #263040;
    --accent: #14b8a6;
    --accent-2: #2dd4bf;
    --accent-soft: #134e4a;
    --gw: #fb923c;
    --gw-soft: #431407;
    --pos: #4ade80;
    --neg: #f87171;
    --warn: #fbbf24;
    --warn-soft: #422006;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 12px);
}
a { color: inherit; text-decoration: none; }
h2 { margin: 0 0 6px; font-size: 1.25rem; }
h3 { margin: 18px 0 8px; font-size: 1rem; }
p { margin: 6px 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.pad { padding: 12px 14px; }
.pad-x { padding-left: 14px; padding-right: 14px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn-text { color: var(--warn); font-weight: 600; }

/* top + tab bars */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 8px) 14px 8px;
  background: var(--accent); color: #fff;
}
.topbar h1 { flex: 1; margin: 0; font-size: 1.1rem; }
.topbar .brand, .topbar .gear { font-size: 1.4rem; width: 32px; text-align: center; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 0.72rem; color: var(--muted); }
.tabbar a span { font-size: 1.3rem; line-height: 1.2; }
.tabbar a.active { color: var(--accent); font-weight: 600; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 10px 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-align: center;
}
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary.alt { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn.big { min-height: 60px; font-size: 1.1rem; }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: 0.9rem; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--neg); }
.btn.danger:not(.ghost) { border-color: var(--neg); }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-size: 0.85rem; text-decoration: underline; }
.filebtn { position: relative; overflow: hidden; }

/* cards, lists */
.card {
  display: flex; flex-direction: column; gap: 2px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
}
.card.row { flex-direction: row; }
.linklike { text-align: left; font: inherit; color: inherit; cursor: pointer; }
.live-card { border: 2px solid var(--neg); }
.warn-card { background: var(--warn-soft); border-color: var(--warn); }
.list { background: var(--card); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%;
  padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line); background: none;
  color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.item:last-child { border-bottom: 0; }
.item .right { text-align: right; white-space: nowrap; }
.badge { align-self: flex-start; display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; background: var(--line); }
.badge.live { background: var(--neg); color: #fff; }
.badge.ok { background: var(--accent-soft); color: var(--accent-2); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.note { background: var(--card); border-left: 4px solid var(--accent); padding: 8px 10px; border-radius: 6px; font-size: 0.9rem; }
.note.warn { border-left-color: var(--warn); background: var(--warn-soft); }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; }
.tile span { font-size: 0.8rem; color: var(--muted); }
.tile b { font-size: 1.25rem; }
.tile em { font-style: normal; font-size: 0.8rem; color: var(--muted); }
.tile.hl { border: 2px solid var(--accent); }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(4, 1fr); } }

/* scanner */
.scanner { position: relative; margin: 0 14px; border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 4 / 3; max-height: 38vh; width: calc(100% - 28px); }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; left: 10%; right: 10%; top: 30%; bottom: 30%; border: 3px solid rgba(255,255,255,0.85); border-radius: 12px; box-shadow: 0 0 0 999px rgba(0,0,0,0.25); }
.scan-msg { position: absolute; left: 0; right: 0; bottom: 0; padding: 6px 10px; background: rgba(0,0,0,0.55); color: #fff; font-size: 0.85rem; text-align: center; }
.scan-flash { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity 0.3s; }
.scan-flash.ok { background: rgba(34,197,94,0.45); opacity: 1; transition: none; }
.scan-tools { display: flex; gap: 8px; justify-content: center; padding: 8px 14px 0; }

/* selling */
.segmented { display: flex; background: var(--line); border-radius: 12px; padding: 3px; }
.segmented button { flex: 1; min-height: 44px; border: 0; border-radius: 10px; background: none; font: inherit; font-weight: 700; color: var(--muted); }
.segmented button.on { background: var(--card); color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,0.15); }
.segmented button.on.gw { color: #fff; background: var(--gw); }
.next { margin-top: 10px; display: flex; align-items: baseline; justify-content: space-between; padding: 10px 16px; border-radius: var(--radius); background: var(--accent-soft); color: var(--accent-2); }
.next span { font-weight: 600; }
.next b { font-size: 3rem; line-height: 1; }
.next.gw { background: var(--gw-soft); color: var(--gw); }
.next.gw b { font-size: 1.4rem; }
.lastscan { min-height: 1.5em; margin-top: 8px; font-size: 1.1rem; text-align: center; }
.sticker { min-width: 52px; padding: 6px; border-radius: 8px; background: var(--accent-soft); color: var(--accent-2); font-weight: 800; text-align: center; }
.sticker.gw { background: var(--gw-soft); color: var(--gw); }
table.summary { width: 100%; border-collapse: collapse; }
table.summary td { padding: 5px 0; border-bottom: 1px solid var(--line); }
table.summary .num { text-align: right; white-space: nowrap; }
table.summary tr.total td { border-bottom: 0; padding-top: 10px; font-size: 1.2rem; font-weight: 800; }

/* sheets */
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,0); display: flex; align-items: flex-end; justify-content: center; transition: background 0.2s; }
.sheet-backdrop.show { background: rgba(0,0,0,0.45); }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform 0.2s ease-out;
}
.sheet-backdrop.show .sheet { transform: none; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted); }
.field input, input.search, .custom input, .feegrid input, .moneyin input {
  font: inherit; font-size: 17px; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px; width: 100%;
}
input.search { margin: 6px 0 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 0.85rem; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.picklist { max-height: 45vh; overflow-y: auto; margin-bottom: 10px; border-radius: 12px; background: var(--card); }
.pick { display: flex; flex-direction: column; align-items: flex-start; width: 100%; padding: 12px; border: 0; border-bottom: 1px solid var(--line); background: none; color: inherit; font: inherit; text-align: left; }

/* number pad */
.numfields { display: flex; gap: 8px; margin: 10px 0; }
.numfield { flex: 1; display: flex; flex-direction: column; align-items: flex-start; padding: 10px 12px; border: 2px solid var(--line); border-radius: 12px; background: var(--card); color: inherit; font: inherit; }
.numfield .lbl { font-size: 0.8rem; color: var(--muted); }
.numfield .val { font-size: 1.8rem; font-weight: 800; }
.numfield.active { border-color: var(--accent); }
.numfield.fresh .val { color: var(--muted); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.key { min-height: 56px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text); font: inherit; font-size: 1.5rem; font-weight: 600; }
.key:active { background: var(--accent-soft); }

/* reports */
.scroll-x { overflow-x: auto; background: var(--card); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
table.data { border-collapse: collapse; width: 100%; font-size: 0.88rem; white-space: nowrap; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: right; }
table.data th:first-child, table.data td:first-child, table.data td.nm { text-align: left; }
table.data td.nm { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
table.data th { color: var(--muted); font-weight: 600; background: var(--bg); }
.custom { margin-top: 8px; }
.feegrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.feegrid label { display: flex; flex-direction: column; font-size: 0.85rem; color: var(--muted); }
.pctin, .moneyin { display: flex; align-items: center; gap: 4px; color: var(--text); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px); z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; transition: all 0.25s;
  max-width: 90vw; padding: 10px 16px; border-radius: 12px; background: #111827; color: #fff; font-weight: 600;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast-ok { background: var(--pos); }
.toast-error { background: var(--neg); }
