:root {
  --paper: #f3f5f2;
  --card: #ffffff;
  --ink: #17201c;
  --muted: #5b665f;
  --line: #d3d9d4;
  --thread: #2c4fa3;
  --thread-ink: #ffffff;
  --ok: #1d7444;
  --ok-bg: #e3f2e8;
  --err: #b42318;
  --err-bg: #fbe9e7;
  --chalk: #f5d547;
  --r: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121614; --card: #1b201d; --ink: #edf1ee; --muted: #9aa49e; --line: #2e3531;
    --thread: #7f9cf0; --thread-ink: #0e1430; --ok: #6fd39a; --ok-bg: #173323; --err: #ff8a7a; --err-bg: #3a1b17;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper); color: var(--ink);
  font: 16px/1.45 "Golos Text", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
:root { padding-top: env(safe-area-inset-top, 0px); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--thread); outline-offset: 2px; }
.hidden { display: none !important; }

#app { max-width: 560px; margin: 0 auto; min-height: 100%; padding: 16px 16px calc(96px + env(safe-area-inset-bottom, 0px)); }
h1 { font-size: 22px; margin: 4px 0 16px; font-weight: 700; }
h2 { font-size: 17px; margin: 24px 0 8px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* Вход */
.login { min-height: 80vh; display: grid; place-content: center; text-align: center; gap: 12px; }
.login input { width: 220px; text-align: center; font-size: 28px; letter-spacing: 8px; }

/* Поля и кнопки */
input[type=text], input[type=tel], input[type=email], input[type=number], input[type=password], select {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--card);
}
input:focus, select:focus { border-color: var(--thread); outline: none; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 16px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--card);
  cursor: pointer; font-weight: 600; text-decoration: none; min-height: 48px; color: var(--ink);
}
.btn.primary { background: var(--thread); color: var(--thread-ink) !important; border-color: var(--thread); width: 100%; font-size: 18px; min-height: 58px; }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--thread); padding: 8px; min-height: 40px; }
.btn.danger { color: var(--err); }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.row > .btn { flex: 0 0 auto; }

/* Сумма продажи */
.total { display: flex; justify-content: space-between; align-items: baseline; margin: 0 0 16px; }
.total .sum { font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }

/* Сканирование */
.scan { display: flex; gap: 8px; }
.scan input { font-size: 15px; }
.scan.flash input { background: var(--chalk); color: #17201c; transition: background .05s; }

/* Позиции */
.lines { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 10px; }
.line { background: var(--card); border: 1.5px solid var(--line); border-radius: var(--r); padding: 12px; display: grid; gap: 8px; }
.line.bad { border-color: var(--err); }
.line-top { display: flex; gap: 8px; align-items: center; }
.line-top select, .line-top .title { flex: 1; }
.line-top .title { font-weight: 600; }
.line .price { width: 120px; flex: 0 0 120px; text-align: right; font-variant-numeric: tabular-nums; }
.kiz { font-size: 13px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.kiz code { font-size: 13px; color: var(--muted); }
.chip { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 13px; font-weight: 600; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.err { background: var(--err-bg); color: var(--err); }
.chip.wait { background: var(--line); color: var(--muted); }
.x { border: 0; background: none; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px 8px; }
.empty { border: 2px dashed var(--line); border-radius: var(--r); padding: 22px; text-align: center; color: var(--muted); margin-top: 16px; }

.contact { display: grid; gap: 8px; }
.footer-action { margin-top: 20px; }
.error { background: var(--err-bg); color: var(--err); border-radius: 10px; padding: 10px 12px; margin-top: 12px; font-size: 15px; }

/* Чек-билет: строчка-стежок по краю — как пришитая бирка */
.ticket {
  position: relative; background: var(--card); border-radius: 18px; padding: 22px 20px; text-align: center;
  box-shadow: 0 1px 0 var(--line);
}
.ticket::before {
  content: ""; position: absolute; inset: 8px; border: 2px dashed var(--thread); border-radius: 12px; pointer-events: none; opacity: .55;
}
.ticket .amount { font-size: 52px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -1px; margin: 4px 0 2px; }
.ticket .qr { width: min(78vw, 300px); aspect-ratio: 1; margin: 12px auto; background: #fff; border-radius: 10px; padding: 8px; }
.ticket .qr svg { width: 100%; height: 100%; display: block; }
.status { font-size: 18px; font-weight: 600; margin: 8px 0 4px; }
.status.ok { color: var(--ok); }
.status.err { color: var(--err); }
.pay-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.pay-actions .wide { grid-column: 1 / -1; }
.done-mark { width: 84px; height: 84px; margin: 6px auto; border-radius: 50%; background: var(--ok-bg); color: var(--ok); display: grid; place-items: center; font-size: 46px; }
@media (prefers-reduced-motion: no-preference) {
  .done-mark { animation: pop .35s ease-out; }
  @keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
}
.items-mini { text-align: left; margin: 14px 0 0; padding: 0; list-style: none; font-size: 15px; }
.items-mini li { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-top: 1px solid var(--line); }

/* Журнал */
.orders { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.orders button { width: 100%; text-align: left; background: var(--card); border: 1.5px solid var(--line); border-radius: var(--r); padding: 12px; cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
.orders .sum { font-weight: 700; font-variant-numeric: tabular-nums; }

/* Товары */
.cat { display: grid; gap: 10px; }
.cat-item { background: var(--card); border: 1.5px solid var(--line); border-radius: var(--r); padding: 12px; display: grid; gap: 8px; }
.cat-item label { font-size: 13px; color: var(--muted); display: grid; gap: 4px; }

/* Нижнее меню */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line);
  display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom, 0px); z-index: 10;
}
nav.tabs button { flex: 1; max-width: 186px; border: 0; background: none; padding: 12px 4px 14px; font-weight: 600; color: var(--muted); cursor: pointer; border-top: 3px solid transparent; }
nav.tabs button[aria-current=page] { color: var(--thread); border-top-color: var(--thread); }

/* Камера */
.cam { position: fixed; inset: 0; background: #000; z-index: 30; display: flex; flex-direction: column; }
.cam video { flex: 1; width: 100%; object-fit: cover; }
.cam .frame { position: absolute; left: 50%; top: 42%; width: 62vmin; height: 62vmin; transform: translate(-50%, -50%); border: 3px solid var(--chalk); border-radius: 16px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); }
.cam .bar { position: absolute; bottom: 0; left: 0; right: 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px)); display: flex; gap: 8px; justify-content: space-between; align-items: center; color: #fff; }
.cam .bar .btn { background: #fff; color: #17201c; }
.banner { background: var(--chalk); color: #17201c; border-radius: 10px; padding: 8px 12px; font-size: 14px; margin-bottom: 12px; }

/* Режим продажи */
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--card); border: 1.5px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: none; padding: 10px; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; min-height: 44px; }
.seg button[aria-checked=true] { background: var(--thread); color: var(--thread-ink); }
.mode-hint { margin: 8px 2px 14px; }

.cashier { display: flex; align-items: center; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.cashier span:nth-child(2) { font-weight: 600; }
.line-sub { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.qty { display: inline-flex; align-items: center; gap: 6px; }
.qty input { width: 72px; padding: 8px 10px; text-align: center; }
.mark { display: inline-flex; align-items: center; gap: 6px; }
.check { flex-direction: row !important; align-items: center; display: flex !important; gap: 8px; }
.err-text { color: var(--err); }

/* Выдача и возврат на экране заказа */
.panel { text-align: left; margin-top: 18px; padding-top: 6px; border-top: 2px dashed var(--line); }
.panel h2 { margin-top: 10px; }
.issue-list, .refund-list, .receipts { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; text-align: left; }
.issue-list li, .refund-list li, .receipts li { display: flex; align-items: center; gap: 8px; justify-content: space-between; flex-wrap: wrap; padding: 8px 0; border-top: 1px solid var(--line); font-size: 15px; }
.refund-list label { display: flex; gap: 8px; align-items: center; flex: 1; min-width: 60%; }
.refund-list input[type=checkbox], .mark input, .check input { width: 20px; height: 20px; accent-color: var(--thread); }
.refund-list .rq { width: 72px; padding: 6px 8px; }
.receipts { margin-top: 14px; }
.receipts a { color: var(--thread); }
