:root {
  --bg: #f5f6f8; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e5e7eb;
  --accent: #2563eb; --accent-2: #1d4ed8; --danger: #dc2626; --ok-bg: #ecfdf5; --ok: #047857;
  --err-bg: #fef2f2; --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111318; --card: #1b1e25; --text: #e5e7eb; --muted: #9ca3af; --line: #2c313b;
    --accent: #3b82f6; --accent-2: #60a5fa; --ok-bg: #0f2a22; --ok: #34d399; --err-bg: #2c1515; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 8px 0 16px; }
.big { font-size: 18px; font-weight: 700; }
h2 { font-size: 16px; margin: 0 0 12px; }
code, .mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12.5px; }
.small { font-size: 14px; font-weight: normal; }
.center { text-align: center; }
.pre { white-space: pre-wrap; margin: 0; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.spacer { flex: 1; }

.topbar { display: flex; align-items: center; gap: 20px; padding: 0 20px; height: 56px; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; font-size: 18px; color: var(--text); }
.topbar nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topbar nav a { padding: 8px 12px; border-radius: 8px; color: var(--text); white-space: nowrap; }
.topbar nav a:hover { background: var(--bg); text-decoration: none; }
.topbar nav a.active { background: var(--accent); color: #fff; }
.me { display: flex; gap: 14px; white-space: nowrap; }

.container { max-width: 1200px; margin: 0 auto; padding: 20px; }
.container.wide { max-width: 1500px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
table.card { padding: 0; overflow: hidden; }
.narrow { max-width: 520px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 { margin-bottom: 16px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; white-space: nowrap; }
.price { font-weight: 700; font-size: 16px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--bg); }
tfoot td { border-bottom: none; }
tfoot .total td { font-size: 18px; font-weight: 700; }

label { display: block; margin-bottom: 12px; font-size: 13.5px; color: var(--muted); }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 9px 11px; font: inherit; color: var(--text);
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
input[type=checkbox], input[type=radio] { width: auto; margin: 0; display: inline; flex: 0 0 auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.btn { display: inline-block; padding: 9px 16px; font: inherit; font-weight: 600; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); cursor: pointer; }
.btn:hover { background: var(--bg); text-decoration: none; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-2); }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn.big { padding: 14px; font-size: 17px; }
.link { background: none; border: none; cursor: pointer; font: inherit; color: var(--accent); padding: 4px; }
.link.danger { color: var(--danger); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: var(--ok-bg); color: var(--ok); }
.flash.error { background: var(--err-bg); color: var(--danger); }
.tag { white-space: nowrap; font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { color: var(--muted); font-size: 13px; }
.tile .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.tile .value.small { font-size: 16px; }
.bar { background: var(--bg); border-radius: 4px; height: 8px; min-width: 80px; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.tabs { display: flex; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.tabs a { padding: 6px 12px; border-radius: 6px; color: var(--text); }
.tabs a.active { background: var(--accent); color: #fff; }
.pager { display: flex; gap: 4px; flex-wrap: wrap; }
.pager a { padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); }
.pager a.active { background: var(--accent); color: #fff; }

.searchbar { display: flex; gap: 8px; margin-bottom: 8px; }
.searchbar input { margin: 0; font-size: 17px; padding: 12px 14px; }
.filters { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.filters label { margin: 0; min-width: 160px; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 360px; }
.login h1 { text-align: center; }

/* касса */
.pos { display: grid; grid-template-columns: 1fr 360px; gap: 16px; align-items: start; }
.pos-right { position: sticky; top: 72px; }
.pos-right h2 { margin-top: 4px; }
.scan { position: relative; }
.scan input { font-size: 19px; padding: 14px 16px; margin: 0; border: 2px solid var(--accent); }
.small-scan input { font-size: 15px; padding: 9px 11px; border-width: 1px; border-color: var(--line); }
.pos-tools { margin: 8px 0; }
.suggest { position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px; background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.15); max-height: 420px; overflow-y: auto; z-index: 20; }
.suggest .opt { display: flex; justify-content: space-between; gap: 12px; padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.suggest .opt:last-child { border-bottom: none; }
.suggest .opt.active, .suggest .opt:hover { background: var(--bg); }
.pad { padding: 10px 12px; }
.scan-msg { min-height: 22px; margin-bottom: 8px; font-size: 14px; color: var(--ok); }
.scan-msg.error { color: var(--danger); }
.cart input.cell { display: inline-block; width: 100px; margin: 0; padding: 5px 8px; text-align: right; }
.cart input.cell.short { width: 64px; text-align: center; }
.cart .qty button { width: 28px; height: 30px; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 6px; cursor: pointer; }
.cart td { vertical-align: middle; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 12px; }
.seg button { flex: 1; padding: 9px 4px; border: none; background: var(--card); color: var(--text); font: inherit; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--accent); color: #fff; }
.client-selected { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; }
#client-new { margin: 8px 0 16px; }
#client-new summary { cursor: pointer; color: var(--accent); margin-bottom: 6px; }
#client-new input { margin-bottom: 6px; }
.totals { border-top: 1px solid var(--line); margin: 8px 0 14px; padding-top: 10px; }
.totals .row { margin-bottom: 4px; }
.totals .grand { font-size: 22px; font-weight: 700; }
#done { margin: 12px 0 0; }

@media print {
  .topbar, .noprint { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border: none; }
}

/* ---------- v2: заказы, склад, ценники, телефон ---------- */
.burger, .nav-mobile { display: none; }
.burger { background: none; border: 1px solid var(--line); color: var(--text); font-size: 20px; border-radius: 8px; padding: 4px 12px; cursor: pointer; }
.row.nowrap { flex-wrap: nowrap; }
.row.nowrap > * { flex: 1; min-width: 0; }
.row.nowrap > .btn { flex: 0 0 auto; }
.actions { margin-bottom: 16px; }
.tile-link { color: var(--text); }
.tile-link:hover { text-decoration: none; border-color: var(--accent); }
.status { display: inline-block; font-size: 12.5px; font-weight: 600; padding: 2px 9px; border-radius: 20px; vertical-align: middle; white-space: nowrap; }
.status.new { background: #fef3c7; color: #92400e; }
.status.issued { background: var(--ok-bg); color: var(--ok); }
.status.cancelled { background: var(--err-bg); color: var(--danger); }
h1 .status { font-size: 14px; }
.scan-row { display: flex; gap: 8px; }
.scan-row input { flex: 1; min-width: 0; }
.cam-btn { font-size: 20px; padding: 6px 14px; }
.pos-step { margin-top: 4px; }
.pos-client .client-selected { margin-bottom: 0; }
.pos-client #client-new { margin-bottom: 0; }
.checkout-buttons { display: grid; gap: 8px; }
.wide-cell { width: 100% !important; text-align: left !important; }
.order-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; margin-bottom: 24px; }
.order-card { color: var(--text); margin: 0; display: grid; gap: 6px; border-left: 4px solid #f59e0b; }
.order-card:hover { text-decoration: none; border-color: var(--accent); }
.picklist { display: grid; gap: 8px; margin-bottom: 90px; }
.pick { display: flex; align-items: center; gap: 14px; margin: 0; cursor: pointer; user-select: none; }
.pick-check { font-size: 28px; line-height: 1; }
.pick-body { flex: 1; min-width: 0; }
.pick-name { font-weight: 600; }
.pick-qty { font-size: 18px; white-space: nowrap; }
.pick.done { background: var(--ok-bg); border-color: var(--ok); }
.pick.done .pick-check { color: var(--ok); }
.sticky-bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; display: flex; gap: 12px; align-items: center; justify-content: space-between;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(0,0,0,.08); }
.cam-overlay { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.8); display: grid; place-items: center; padding: 12px; }
.cam-box { background: var(--card); border-radius: 14px; padding: 12px; width: min(480px, 100%); display: grid; gap: 10px; }
#cam-reader { width: 100%; min-height: 240px; background: #000; border-radius: 8px; overflow: hidden; }
#cam-reader video { width: 100% !important; height: auto !important; display: block; }
.cam-hint { text-align: center; color: var(--muted); }
.cam-last { text-align: center; color: var(--ok); font-weight: 600; min-height: 1em; }

@media (max-width: 900px) {
  body { font-size: 16px; }
  .topbar { height: 54px; padding: 0 12px; gap: 10px; }
  .brand { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .burger { display: block; }
  .me { display: none; }
  .topbar nav { display: none; position: absolute; top: 54px; left: 0; right: 0; flex-direction: column; gap: 0;
    background: var(--card); border-bottom: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0,0,0,.15); padding: 6px; }
  .nav-open .topbar nav { display: flex; }
  .topbar nav a { padding: 13px 14px; font-size: 17px; }
  .nav-mobile { display: block; }
  .container { padding: 12px; }
  h1 { font-size: 21px; }
  .desktop-only { display: none; }
  input, select, textarea { font-size: 16px; } /* iOS не зумит поле при фокусе */
  .searchbar input { font-size: 16px; padding: 11px 12px; }
  .grid2 { grid-template-columns: 1fr; }
  .filters label { min-width: 0; flex: 1 1 140px; }

  /* таблицы → карточки */
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { border-bottom: 1px solid var(--line); padding: 8px 4px; }
  table.responsive td { border: none; padding: 2px 8px; text-align: left; }
  table.responsive td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 13px; }
  table.responsive td:empty, table.responsive td[data-label]:empty { display: none; }
  table.results tr { position: relative; padding-right: 64px; }
  table.results .r-name { font-weight: 600; }
  table.results .r-price { text-align: left; font-size: 20px; padding-top: 4px; }
  table.results .r-act { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: auto; }

  /* касса */
  .pos { grid-template-columns: 1fr; gap: 0; }
  .pos-right { position: static; margin-bottom: 150px; }
  .scan input { font-size: 17px; padding: 12px; }
  .cart thead { display: none; }
  .cart, .cart tbody { display: block; }
  .cart tr { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "name del" "price sum" "qty qty"; gap: 6px 10px;
    padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .cart td { display: block; border: none; padding: 0; }
  .cart .c-name { grid-area: name; font-weight: 600; }
  .cart .c-del { grid-area: del; }
  .cart .c-price { grid-area: price; text-align: left; }
  .cart .c-sum { grid-area: sum; align-self: center; font-size: 17px; }
  .cart .c-qty { grid-area: qty; text-align: left; display: flex; gap: 6px; }
  .cart .qty button { width: 44px; height: 40px; font-size: 20px; }
  .cart input.cell { width: 120px; padding: 8px; }
  .cart input.cell.short { width: 80px; }
  .labels-list tr { grid-template-areas: "name del" "price qty"; }
  .pos-checkout { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; background: var(--card); border-top: 1px solid var(--line);
    box-shadow: 0 -4px 16px rgba(0,0,0,.1); padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
  .pos-checkout .totals { margin: 0 0 6px; padding: 0; border: none; }
  .pos-checkout .totals .row:not(.grand) { display: none; }
  .pos-checkout .totals .grand { font-size: 20px; }
  .checkout-buttons { grid-template-columns: 1fr auto; }
  .checkout-buttons .btn.big { padding: 12px; font-size: 16px; }
  .suggest { max-height: 55vh; }
  .suggest .opt { padding: 12px; }
}
.rate-chip { font-weight: 600; font-size: 14px; padding: 4px 10px; border-radius: 20px; background: var(--bg); border: 1px solid var(--line); color: var(--text); white-space: nowrap; }
a.plain { color: inherit; }
@media (max-width: 900px) { .rate-chip { font-size: 13px; padding: 3px 8px; } }
.bind-head { background: #fef3c7; color: #92400e; border-bottom: 1px solid var(--line); }
.binding .pick:not(.done) { outline: 2px dashed #f59e0b; outline-offset: 2px; }
