/*
  Касса — рабочее место кассира (pos.html, docs/pos.md в sales_agent).

  Экран под планшет у прилавка: крупные цели под палец, итог читается издалека,
  поиск всегда под сканером. Светлая тема всегда — как вход в панель: у прилавка
  яркий свет, и тёмный экран там читается хуже.
*/
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  color-scheme: light;
  --bg:       #ffffff;
  --surface:  #f4f4f4;
  --surface2: #e8e8e8;
  --border:   #e0e0e0;
  --accent:   #0f62fe;
  --accent-h: #0050e6;
  --text:     #161616;
  --muted:    #525252;
  --danger:   #da1e28;
  --ok:       #198038;
  --warn:     #8a6100;
  --radius:   6px;
}
html, body { height: 100%; }
body {
  font-family: 'IBM Plex Sans', 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px; letter-spacing: 0.16px;
  background: var(--surface); color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
button:disabled { opacity: .45; cursor: not-allowed; }
input { font: inherit; color: inherit; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ─── Кнопки ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px; border-radius: var(--radius);
  background: var(--surface2); color: var(--text); font-weight: 400;
  transition: background .12s;
}
.btn:hover:not(:disabled) { background: #d6d6d6; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-h); }
.btn-danger { background: rgba(218,30,40,.1); color: var(--danger); }
.btn-ghost { background: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--surface2); }
.btn-lg { min-height: 56px; font-size: 18px; padding: 12px 22px; }
.btn-block { width: 100%; }

.input {
  width: 100%; min-height: 48px; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  outline: none; font-size: 16px; transition: border-color .12s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.hint { font-size: 13px; color: var(--muted); line-height: 1.45; }

/* ─── Вход ───────────────────────────────────────────────────────────────── */
.center-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px 28px; width: 100%; max-width: 420px; }
.card h1 { font-size: 24px; font-weight: 300; margin-bottom: 6px; }
.card .sub { color: var(--muted); font-size: 14px; margin-bottom: 24px; }
.brand { text-align: center; margin-bottom: 24px; }
.brand img { height: 20px; width: auto; }
.error-box { background: rgba(218,30,40,.07); border-left: 3px solid var(--danger); color: var(--danger); padding: 10px 14px; font-size: 14px; margin-bottom: 16px; }

/* Касса ещё не обкатана на живом клиенте — помечена, как прочие новые функции панели. */
.beta-tag { display: inline-block; padding: 1px 5px; font-size: 10px; font-weight: 600; line-height: 14px; letter-spacing: .04em; color: #78a9ff; border: 1px solid currentColor; vertical-align: 2px; }

/* ─── Шапка ──────────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: #161616; color: #f4f4f4;
}
.topbar .title { font-size: 17px; font-weight: 600; margin-right: auto; display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.topbar .title .org { font-weight: 300; color: #c6c6c6; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .who { font-size: 13px; color: #c6c6c6; }
.topbar .btn { background: #393939; color: #f4f4f4; min-height: 40px; padding: 8px 14px; font-size: 14px; }
.topbar .btn:hover:not(:disabled) { background: #4c4c4c; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 13px; background: #393939; color: #f4f4f4; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: #42be65; }

/* ─── Рабочая область ────────────────────────────────────────────────────── */
/* Шапка на планшете переносится на вторую строку — высоту отдаём флексу, а не вычитаем руками. */
#screenPos:not(.hidden) { display: flex; flex-direction: column; height: 100vh; }
.work { display: grid; grid-template-columns: minmax(0, 1fr) 400px; flex: 1; min-height: 0; }
.catalog { display: flex; flex-direction: column; min-width: 0; padding: 14px 16px 0; overflow: hidden; }
.scanrow { display: flex; gap: 8px; }
.scanrow .input { font-size: 18px; min-height: 54px; background: var(--bg); }
.scanrow .btn { min-height: 54px; min-width: 54px; padding: 0 14px; background: var(--bg); border: 1px solid var(--border); }
.cats { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0; scrollbar-width: none; }
.cats::-webkit-scrollbar { display: none; }
.cat {
  flex: 0 0 auto; padding: 8px 14px; min-height: 40px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--border); font-size: 14px; white-space: nowrap;
}
.cat.active { background: var(--text); border-color: var(--text); color: #fff; }
.tiles {
  flex: 1; overflow-y: auto; padding-bottom: 16px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-content: start;
}
.tile {
  display: flex; flex-direction: column; text-align: left; min-height: 120px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; transition: border-color .12s, transform .06s;
}
.tile:hover { border-color: var(--accent); }
.tile:active { transform: scale(.98); }
.tile .ph { height: 84px; background: var(--surface) center/cover no-repeat; }
.tile .body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.tile .name { font-size: 14px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile .meta { margin-top: auto; display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.tile .price { font-weight: 600; }
.tile .stock { font-size: 12px; color: var(--muted); }
.tile.out { opacity: .5; }
.tile.out .stock { color: var(--danger); }
.empty { color: var(--muted); padding: 24px 4px; grid-column: 1 / -1; }

/* ─── Чек ────────────────────────────────────────────────────────────────── */
.ticket { display: flex; flex-direction: column; background: var(--bg); border-left: 1px solid var(--border); min-height: 0; }
.ticket-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.ticket-head h2 { font-size: 17px; font-weight: 600; }
.lines { flex: 1; overflow-y: auto; position: relative; }
.line { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; padding: 10px 16px; border-bottom: 1px solid var(--surface2); }
.line.flash { animation: flash .6s ease-out; }
@keyframes flash { from { background: rgba(15,98,254,.16); } to { background: transparent; } }
.line .lname { font-size: 15px; line-height: 1.3; }
.line .lsum { font-weight: 600; text-align: right; }
.line .lprice { font-size: 13px; color: var(--muted); }
.qty { display: flex; align-items: center; gap: 4px; justify-self: end; }
.qty button { width: 40px; height: 40px; border-radius: var(--radius); background: var(--surface); font-size: 20px; line-height: 1; }
.qty button:hover { background: var(--surface2); }
.qty .q { min-width: 36px; text-align: center; font-weight: 600; }
.qty .rm { color: var(--danger); font-size: 16px; }
.ticket-empty { color: var(--muted); padding: 32px 16px; text-align: center; line-height: 1.5; }
.ticket-foot { border-top: 1px solid var(--border); padding: 14px 16px 16px; }
.total { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.total .lbl { font-size: 16px; color: var(--muted); }
.total .sum { font-size: 32px; font-weight: 600; }
.foot-actions { display: grid; grid-template-columns: auto 1fr; gap: 8px; }
.fiscal-note { margin-top: 10px; font-size: 12px; color: var(--muted); line-height: 1.4; }

/* ─── Окна ───────────────────────────────────────────────────────────────── */
.overlay { position: fixed; inset: 0; background: rgba(22,22,22,.5); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: var(--bg); border-radius: var(--radius); width: 100%; max-width: 480px; max-height: calc(100vh - 32px); overflow-y: auto; padding: 22px; }
.modal.wide { max-width: 640px; }
.modal h3 { font-size: 20px; font-weight: 400; margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.pay-methods { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.pay-method { min-height: 64px; border-radius: var(--radius); border: 2px solid var(--border); background: var(--bg); font-size: 15px; }
.pay-method.active { border-color: var(--accent); background: rgba(15,98,254,.06); color: var(--accent); font-weight: 600; }
.pay-due { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 0; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.pay-due .sum { font-size: 28px; font-weight: 600; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.quick button { padding: 8px 12px; min-height: 40px; border-radius: var(--radius); background: var(--surface); font-size: 14px; }
.quick button:hover { background: var(--surface2); }
.change { display: flex; justify-content: space-between; align-items: baseline; margin-top: 14px; padding: 12px 14px; border-radius: var(--radius); background: var(--surface); }
.change .sum { font-size: 26px; font-weight: 600; color: var(--ok); }
.change.short .sum { color: var(--danger); }
.done-big { text-align: center; padding: 8px 0 4px; }
.done-big .ok { font-size: 44px; color: var(--ok); }
.done-big .t { font-size: 20px; margin-top: 4px; }
.done-big .chg { font-size: 34px; font-weight: 600; margin-top: 10px; }
.variants { display: grid; gap: 8px; }
.variant { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 56px; padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg); text-align: left; }
.variant:hover:not(:disabled) { border-color: var(--accent); }
.variant .vs { font-size: 13px; color: var(--muted); }
.report { width: 100%; border-collapse: collapse; }
.report td { padding: 8px 0; border-bottom: 1px solid var(--surface2); }
.report td:last-child { text-align: right; font-weight: 600; }
.report tr.strong td { font-size: 17px; border-bottom: 2px solid var(--border); }
.diff-ok { color: var(--ok); }
.diff-bad { color: var(--danger); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; }
.seg button { padding: 10px 18px; min-height: 44px; }
.seg button.active { background: var(--text); color: #fff; }
.sales { width: 100%; border-collapse: collapse; font-size: 14px; }
.sales th { text-align: left; font-weight: 400; color: var(--muted); padding: 6px 4px; border-bottom: 1px solid var(--border); }
.sales td { padding: 9px 4px; border-bottom: 1px solid var(--surface2); }
.sales td.r, .sales th.r { text-align: right; }
.sales tr.cancelled td { color: var(--muted); text-decoration: line-through; }
video.cam { width: 100%; border-radius: var(--radius); background: #000; aspect-ratio: 4 / 3; object-fit: cover; }

/* ─── Тосты ──────────────────────────────────────────────────────────────── */
#toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; width: min(92vw, 420px); pointer-events: none; }
.toast { padding: 12px 16px; border-radius: var(--radius); background: #161616; color: #fff; font-size: 15px; box-shadow: 0 4px 16px rgba(0,0,0,.25); opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: none; }
.toast.err { background: var(--danger); }

/* ─── Узкий экран: телефон и планшет в портрете ──────────────────────────── */
@media (max-width: 900px) {
  #screenPos:not(.hidden) { height: auto; }
  .work { grid-template-columns: 1fr; }
  .catalog { overflow: visible; padding: 12px 16px 0; }
  .tiles { overflow: visible; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .ticket { border-left: none; border-top: 1px solid var(--border); padding-bottom: 150px; }
  .lines { overflow: visible; }
  .ticket-foot { position: fixed; left: 0; right: 0; bottom: 0; background: var(--bg); box-shadow: 0 -4px 16px rgba(0,0,0,.08); z-index: 20; }
  .total .sum { font-size: 26px; }
  .fiscal-note { display: none; }
  .topbar .who { display: none; }
  .pay-methods { grid-template-columns: 1fr; }
}
