:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2430;
  --line: #2b3648;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #4ea1ff;
  --accent-ink: #04101f;
  --good: #43c59e;
  --warn: #f2b64a;
  --bad: #ff6b6b;
  --radius: 14px;
  --tap: 52px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  overscroll-behavior-y: contain;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ------------------------------------------------------------- верх */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: rgba(13, 17, 23, .94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 38px; height: 38px; flex: 0 0 38px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: linear-gradient(145deg, #2b6cb0, #4ea1ff);
  color: #fff; font-weight: 800; font-size: 20px;
}
.brand-text { min-width: 0; }
.brand-text b { display: block; font-size: 15px; white-space: nowrap; }
.brand-text small { display: block; color: var(--muted); font-size: 11px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 42vw; }
.top-actions { display: flex; align-items: center; gap: 8px; }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 9px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel-2);
  color: var(--muted); font-size: 11px; white-space: nowrap;
}
.pill.online { color: var(--good); border-color: #255c4c; }
.pill.offline { color: var(--warn); border-color: #6b5626; }
.pill.warn { color: var(--warn); border-color: #6b5626; }
.pill.good { color: var(--good); border-color: #255c4c; }

.icon {
  width: 42px; height: 42px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--panel-2);
  color: var(--text); font-size: 19px;
}
.icon:active { transform: scale(.96); }

/* ------------------------------------------------------------- экраны */
main {
  flex: 1;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 14px 14px 96px;
}
.screen { display: none; }
.screen.active { display: block; animation: fade .16s ease-out; }
@keyframes fade { from { opacity: .4; } to { opacity: 1; } }

.hero { padding: 4px 4px 14px; }
.hero h1 { margin: 0 0 4px; font-size: 22px; }
.hero p { margin: 0; color: var(--muted); font-size: 13px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 { margin: 0 0 12px; font-size: 15px; }
.muted-card { background: linear-gradient(180deg, var(--panel), #121821); }
.muted-card p { margin: 0; color: var(--muted); font-size: 13px; }

label {
  display: block;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .03em;
}
input, select {
  display: block;
  width: 100%;
  margin-top: 5px;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px;
  text-transform: none;
  letter-spacing: normal;
}
input:focus, select:focus { outline: 2px solid rgba(78, 161, 255, .55); border-color: var(--accent); }
input[readonly] { color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.btn {
  display: flex; align-items: center; justify-content: center;
  width: 100%; min-height: var(--tap);
  padding: 12px 16px; margin-top: 10px;
  border-radius: 12px; border: 1px solid transparent;
  font-size: 15px; font-weight: 650;
  transition: transform .08s ease, filter .15s ease;
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.secondary { background: #24415f; color: #dcecff; border-color: #2f5a86; }
.btn.ghost { background: transparent; color: var(--accent); border-color: var(--line); }
.btn.danger { background: #4a2030; color: #ffd7df; border-color: #743246; }
.btn.big { min-height: 60px; font-size: 17px; margin-top: 14px; }
.btn.small { width: auto; min-height: 38px; padding: 6px 12px; font-size: 13px; margin: 0; }

.hint { min-height: 18px; margin-top: 10px; color: var(--muted); font-size: 12px; }
.hint.ok { color: var(--good); }
.hint.err { color: var(--bad); }

/* ------------------------------------------------------------- продажа */
.session-bar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.searchrow input { margin: 0; }
.scan-hint { margin-top: 6px; color: var(--muted); font-size: 11px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0;
  scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 9px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel-2);
  color: var(--muted); font-size: 13px; white-space: nowrap;
}
.chip.active { background: rgba(78, 161, 255, .16); color: #cfe6ff;
  border-color: #2f5a86; }

.products { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.product {
  text-align: left;
  min-height: 132px;
  padding: 12px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel-2), #151d28);
  color: var(--text);
  display: flex; flex-direction: column; justify-content: space-between;
  gap: 8px;
}
.product:active { transform: scale(.98); border-color: var(--accent); }
.product .name { font-size: 13px; line-height: 1.3; font-weight: 600;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden; }
.product .meta { display: flex; align-items: end; justify-content: space-between; gap: 6px; }
.product .price { font-size: 18px; font-weight: 750; font-variant-numeric: tabular-nums; }
.product .unit { color: var(--muted); font-size: 11px; }
.product .vat { font-size: 10px; color: var(--muted); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

.cart-fab-wrap {
  position: fixed; left: 0; right: 0; bottom: calc(66px + env(safe-area-inset-bottom));
  padding: 0 14px; z-index: 15; pointer-events: none;
}
.cart-fab {
  pointer-events: auto;
  width: 100%; max-width: 952px; margin: 0 auto;
  display: flex; align-items: center; gap: 10px;
  min-height: 58px; padding: 10px 18px;
  border-radius: 16px; border: 0;
  background: var(--accent); color: var(--accent-ink);
  font-size: 16px; font-weight: 750;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .45);
}
.cart-fab span { flex: 1; text-align: left; }
.cart-fab b { font-variant-numeric: tabular-nums; }
.cart-fab b:first-of-type {
  min-width: 26px; height: 26px; border-radius: 50%;
  background: rgba(4, 16, 31, .18);
  display: grid; place-items: center; font-size: 13px;
}

/* ------------------------------------------------------------- нижние вкладки */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(13, 17, 23, .97);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.tab {
  min-height: 62px; border: 0; background: transparent;
  color: var(--muted); font-size: 12px; font-weight: 600;
}
.tab.active { color: var(--accent); }
.tab.active::before {
  content: ""; display: block; width: 26px; height: 3px;
  margin: 0 auto 4px; border-radius: 3px; background: var(--accent);
}

/* ------------------------------------------------------------- шторки */
.sheet {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-end;
  background: rgba(0, 0, 0, .55);
}
.sheet-panel {
  width: 100%; max-width: 680px; max-height: 92vh; max-height: 92dvh;
  margin: 0 auto; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--panel); border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--line);
  overflow-y: auto;
  animation: sheet-up .18s ease-out;
}
@keyframes sheet-up { from { transform: translateY(28px); opacity: .6; }
  to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 18px; }

.cart-lines { display: flex; flex-direction: column; gap: 10px; }
.cart-line {
  padding: 12px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel-2);
}
.cart-line .top { display: flex; justify-content: space-between; gap: 10px; }
.cart-line .title { font-size: 13px; font-weight: 600; }
.cart-line .sum { font-weight: 750; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cart-line .controls { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.stepper { display: flex; align-items: center; gap: 0; border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden; }
.stepper button { width: 40px; height: 40px; border: 0; background: #223044;
  color: var(--text); font-size: 20px; }
.stepper input {
  width: 66px; min-height: 40px; margin: 0; border: 0; border-radius: 0;
  text-align: center; background: var(--panel); font-size: 15px;
}
.cart-line select { width: auto; min-height: 40px; margin: 0; padding: 6px 10px; font-size: 13px; }
.link-danger { border: 0; background: transparent; color: var(--bad); font-size: 12px;
  padding: 8px; }
.sheet-total { display: flex; justify-content: space-between; align-items: baseline;
  margin: 16px 0 4px; padding-top: 12px; border-top: 1px solid var(--line); }
.sheet-total b { font-size: 24px; font-variant-numeric: tabular-nums; }

.pay-total { text-align: center; padding: 8px 0 16px; color: var(--muted); }
.pay-total b { display: block; color: var(--text); font-size: 34px;
  font-variant-numeric: tabular-nums; }
.pay-methods { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.pay-method {
  min-height: 54px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-weight: 650;
}
.pay-method.active { background: rgba(78, 161, 255, .18); border-color: var(--accent);
  color: #cfe6ff; }
.quick-cash { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 4px; }
.quick-cash button {
  flex: 1 1 30%; min-height: 42px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  font-size: 13px;
}
.change { display: flex; justify-content: space-between; margin-top: 10px;
  color: var(--muted); }
.change b { color: var(--good); font-size: 20px; font-variant-numeric: tabular-nums; }

.receipt { max-width: 520px; }
.receipt-body { font-size: 13px; }
.receipt-body .r-line { display: flex; justify-content: space-between; gap: 10px;
  padding: 6px 0; border-bottom: 1px dashed var(--line); }
.receipt-body .r-total { display: flex; justify-content: space-between;
  margin-top: 12px; font-size: 20px; font-weight: 750; }
.receipt-note { color: var(--warn); font-size: 11px; margin: 14px 0 0; }

/* ------------------------------------------------------------- сводка */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.metric { background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; }
.metric .k { font-size: 22px; font-weight: 750; font-variant-numeric: tabular-nums; }
.metric .l { color: var(--muted); font-size: 11px; text-transform: uppercase;
  letter-spacing: .04em; margin-top: 4px; }
.metric.good .k { color: var(--good); }
.metric.warn .k { color: var(--warn); }
.metric.bad .k { color: var(--bad); }
details.handover {
  margin: 12px 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
}
details.handover summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 14px;
  font-weight: 650;
}
details.handover label { margin-top: 10px; }
.cash-check {
  margin: 10px 0 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
}
.cash-check .diag { margin-top: 8px; }
.cash-check .diag b.ok { color: var(--good); }
.cash-check .diag b.err { color: var(--bad); }
.queue-list { display: grid; gap: 6px; margin: 8px 0 14px; }
.queue-item {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 8px 10px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--panel-2);
  font-size: 12px;
}
.queue-item b { text-align: right; font-weight: 600; word-break: break-word; }
.queue-retry {
  align-self: center;
  padding: 3px 8px; font-size: 11px;
  border: 1px solid var(--accent); border-radius: 6px;
  background: transparent; color: var(--accent);
}
.queue-retry:hover { background: rgba(78, 161, 255, .12); }

.receipt-list { display: flex; flex-direction: column; gap: 10px; }
.receipt-item {
  text-align: left; width: 100%;
  padding: 14px; border-radius: 13px;
  border: 1px solid var(--line); background: var(--panel);
  color: var(--text);
}
.receipt-item:active { border-color: var(--accent); }
.receipt-item .row { display: flex; justify-content: space-between; gap: 10px; }
.receipt-item .row + .row { margin-top: 6px; color: var(--muted); font-size: 12px; }
.receipt-item .sum { font-weight: 750; font-variant-numeric: tabular-nums; }
.receipt-item .items { margin-top: 8px; color: var(--muted); font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.diag { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.diag div { display: flex; justify-content: space-between; gap: 10px;
  border-bottom: 1px solid var(--line); padding-bottom: 5px; }
.diag b { color: var(--text); font-weight: 600; text-align: right; word-break: break-all; }
.diag-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.diag-actions .btn { width: auto; flex: 1 1 150px; margin-top: 0; }

/* ------------------------------------------------------------- тост */
.toast {
  position: fixed; left: 50%; bottom: calc(140px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(92vw, 560px);
  padding: 12px 16px;
  border-radius: 12px;
  background: #223044; color: var(--text);
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  font-size: 13px;
  text-align: center;
}
.toast.good { border-color: #255c4c; color: #c9f5e6; }
.toast.bad { border-color: #6b3030; color: #ffd7df; }

@media (min-width: 640px) {
  .products { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cards { grid-template-columns: repeat(4, 1fr); }
  main { padding-left: 20px; padding-right: 20px; }
}
@media (min-width: 900px) {
  .products { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
