:root {
  --red: #D7141A;
  --red-dark: #A80F14;
  --red-soft: #FDECEC;
  --black: #111111;
  --text: #1A1A1A;
  --muted: #6B6B6B;
  --line: #E6E6E6;
  --bg: #F6F6F6;
  --white: #FFFFFF;
  --ok: #1E7B34;
  --ok-soft: #E8F5EC;
  --warn: #8A5A00;
  --warn-soft: #FFF4DB;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { font-size: 15px; line-height: 1.4; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--red); }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 16px 0 8px; }

/* Шапка */
.top { position: sticky; top: 0; z-index: 10; background: var(--white); border-bottom: 1px solid var(--line); display: flex; align-items: center; flex-wrap: wrap; column-gap: 16px; padding: 8px 16px 0; }
.top .logo { order: 1; }
.top .who { order: 2; margin-left: auto; }
.top nav.main { order: 3; flex-basis: 100%; padding: 6px 0 6px; }
.logo { font-weight: 900; letter-spacing: 2px; font-size: 20px; color: var(--red); text-decoration: none; white-space: nowrap; }
.logo small { color: var(--black); font-weight: 600; letter-spacing: 0; font-size: 12px; margin-left: 6px; }
nav.main { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
nav.main a { padding: 8px 12px; border-radius: 8px; color: var(--text); text-decoration: none; white-space: nowrap; font-weight: 500; }
nav.main a.active { background: var(--red-soft); color: var(--red); }
nav.main a:hover { background: var(--bg); }
.who { display: flex; align-items: center; gap: 10px; white-space: nowrap; font-size: 13px; color: var(--muted); }
.who select { padding: 4px 6px; }
.mode-banner { background: var(--warn-soft); color: var(--warn); padding: 6px 16px; font-size: 13px; border-bottom: 1px solid #F0DDB0; }
.mode-banner.live { background: var(--ok-soft); color: var(--ok); border-color: #CDE7D4; }

main { padding: 16px; max-width: 1400px; margin: 0 auto; }

/* Элементы */
.btn { border: 1px solid var(--line); background: var(--white); border-radius: 8px; padding: 9px 14px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { border-color: #BDBDBD; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--red); border-color: var(--red); color: var(--white); }
.btn.primary:hover { background: var(--red-dark); }
.btn.dark { background: var(--black); border-color: var(--black); color: var(--white); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--red); padding: 6px 8px; }
.btn.big { padding: 16px 18px; font-size: 18px; border-radius: 10px; }
.btn.sm { padding: 5px 9px; font-size: 13px; }
.btn.danger { color: var(--red); border-color: #F3B5B7; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=tel], input:not([type]), select, textarea {
  border: 1px solid #D0D0D0; border-radius: 8px; padding: 9px 11px; background: var(--white); width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--red); outline-offset: 1px; border-color: var(--red); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
label.check { display: flex; align-items: flex-start; gap: 8px; color: var(--text); font-size: 14px; cursor: pointer; }
label.check input { margin-top: 3px; accent-color: var(--red); }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }
.row > .btn, .row > .shrink { flex: 0 0 auto; min-width: 0; }
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; overflow-x: auto; }
.grid > * { min-width: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.dark { background: var(--black); color: var(--white); }
.alert { padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 14px; margin-bottom: 12px; }
.alert.err { background: var(--red-soft); color: var(--red-dark); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.kpi .v { font-size: 24px; font-weight: 800; }
.kpi .l { font-size: 13px; color: var(--muted); }
.toolbar { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar > div { min-width: 140px; }
.spacer { flex: 1; }

/* Таблицы */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; background: #FAFAFA; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #FCF4F4; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.low td { background: #FFF8F8; }

/* Касса */
.pos { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
.scan { display: flex; gap: 8px; margin-bottom: 12px; }
.scan input { font-size: 18px; padding: 12px 14px; }
.results { border: 1px solid var(--line); border-radius: 8px; background: var(--white); max-height: 300px; overflow: auto; margin: -6px 0 12px; }
.results .it { padding: 9px 12px; display: flex; justify-content: space-between; gap: 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.results .it:last-child { border-bottom: 0; }
.results .it:hover, .results .it.sel { background: var(--red-soft); }
.cart td { vertical-align: middle; }
.qty { display: inline-flex; align-items: center; gap: 4px; }
.qty button { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--white); font-size: 18px; cursor: pointer; }
.qty input { width: 56px; text-align: center; padding: 6px; }
.side { position: sticky; top: 112px; display: grid; gap: 12px; }
.total-line { display: flex; justify-content: space-between; padding: 4px 0; }
.total-line.grand { font-size: 28px; font-weight: 900; border-top: 2px solid var(--black); margin-top: 6px; padding-top: 10px; }
.disc { color: var(--red); font-weight: 700; }
.pay { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cust-box { border: 2px dashed var(--line); border-radius: var(--radius); padding: 12px; }
.cust-box.has { border: 2px solid var(--red); background: var(--red-soft); }
.tier-big { font-size: 30px; font-weight: 900; color: var(--red); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }
kbd { border: 1px solid #CCC; border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 11px; background: #FFF; }

/* Карта лояльности */
.loyalty-card { width: 340px; max-width: 100%; aspect-ratio: 85.6/54; border-radius: 14px; background: var(--white); border: 1px solid var(--line); box-shadow: 0 4px 16px rgba(0,0,0,.08); padding: 14px 16px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.loyalty-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 10px; background: var(--red); }
.loyalty-card .brand { font-weight: 900; letter-spacing: 3px; color: var(--red); font-size: 20px; }
.loyalty-card .bc svg { width: 100%; height: auto; max-height: 92px; }

/* Модальные окна */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--white); border-radius: 12px; width: 100%; max-width: 560px; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 900px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.modal h2 { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

#toast-root { position: fixed; bottom: 16px; right: 16px; display: grid; gap: 8px; z-index: 60; max-width: calc(100vw - 32px); }
.toast { background: var(--black); color: var(--white); padding: 12px 16px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: 420px; }
.toast.err { background: var(--red); }
.toast.ok { background: var(--ok); }

.login { max-width: 380px; margin: 10vh auto; }
.login .logo { display: block; text-align: center; font-size: 36px; margin-bottom: 4px; }
.question { border-left: 4px solid var(--warn); background: var(--warn-soft); padding: 10px 12px; border-radius: 0 8px 8px 0; margin-bottom: 12px; }
.question.ok { border-color: var(--ok); background: var(--ok-soft); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--text); border-bottom: 3px solid transparent; white-space: nowrap; font-weight: 500; }
.tabs a.active { border-color: var(--red); color: var(--red); }
.bar { height: 8px; background: var(--red); border-radius: 4px; min-width: 2px; }

#print-root { display: none; }
@media print {
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block !important; }
  .loyalty-card { box-shadow: none; border: 1px solid #000; }
  @page { margin: 8mm; }
}
.print-receipt { width: 72mm; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.print-receipt .c { text-align: center; }
.print-receipt hr { border: 0; border-top: 1px dashed #000; }

@media (max-width: 600px) {
  .top .who { margin-left: 0; flex-basis: 100%; padding-top: 6px; }
  .scan input { font-size: 16px; }
}
@media (max-width: 960px) {
  .pos { grid-template-columns: 1fr; }
  .side { position: static; }
  .who-name, .keys { display: none; }
  .who { flex-wrap: wrap; }
  main { padding: 12px; }
}

/* Лист печати пачки карт: визитки 85×54 мм, 2 колонки на A4 */
.card-sheet { display: grid; grid-template-columns: repeat(2, 85.6mm); gap: 4mm; }
.card-sheet .print-card { width: 85.6mm; height: 54mm; box-sizing: border-box; break-inside: avoid; page-break-inside: avoid; }
