/* Переиспользуемые виджеты: карточки, KPI, таблицы, формы, кнопки, бейджи,
   диалоги, chip-фильтры, паттерн «выбор точки», мастер-детейл. */

/* ---------- Cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px;
}
.card h2 { margin: 0 0 14px; font-size: var(--text-md); font-weight: var(--font-bold); }
.card h3 { margin: 18px 0 8px; font-size: var(--text-sm); color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fill, minmax(400px, 1fr)); align-items: start; }
.grid-2 .card { margin-bottom: 0; }
.grid-2 + .grid-2, .grid-2 ~ .card { margin-top: 18px; }

/* ---------- KPI ---------- */
.kpi { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.kpi .card { flex: 1; min-width: 170px; margin: 0; padding: 18px 20px; }
.kpi .val { font-size: var(--text-2xl); font-weight: var(--font-extrabold); letter-spacing: -.5px; color: var(--accent); }
.kpi .muted { margin-bottom: 2px; }
.kpi-compact { display: flex; gap: 26px; flex-wrap: wrap; padding: 10px 0 14px; font-size: 13px; }
.val-warn { color: var(--warn) !important; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .5px; }
tbody tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray-100); }
tr.low td { background: var(--danger-bg); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.table-head h2 { margin: 0; }
.table-tools { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

/* ---------- Forms ---------- */
form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
label { display: flex; flex-direction: column; gap: 5px; font-size: var(--text-xs); font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.lbl-plain { text-transform: none; font-size: 13px; color: var(--text); font-weight: 500; }
input, select, textarea {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px;
  font-size: 13.5px; font-family: inherit; min-width: 100px; background: #fff;
  color: var(--text); transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(14, 107, 96, .18);
}
textarea { min-width: 240px; resize: vertical; }
input.search { width: 220px; border-radius: var(--radius-full); padding: 8px 14px; }
.vform { flex-direction: column; align-items: stretch; }
.vform label input, .vform label select { width: 100%; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); min-width: 0; }
.checkline { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.pos-input { width: 84px !important; }
table.lines input.cell { width: 110px; text-align: right; padding: 6px 8px; }

/* ---------- Buttons ---------- */
button.primary, button.small, button.danger {
  all: unset; cursor: pointer; text-align: center; font-family: inherit;
  transition: filter .15s, background .15s, box-shadow .15s;
}
/* «опасная» кнопка без .small (подтверждения) — размер как у основной */
button.danger:not(.small) { font-size: 13.5px; padding: 10px 18px; border-radius: 9px; }
/* фокус с клавиатуры — мягкое кольцо вместо чёрной рамки браузера */
button.primary:focus-visible, button.small:focus-visible, button.danger:focus-visible {
  outline: none; box-shadow: 0 0 0 3px rgba(71, 106, 138, .35);
}
button.danger:focus-visible { box-shadow: 0 0 0 3px rgba(200, 60, 60, .25); }
button.primary {
  background: var(--accent); color: #fff; font-weight: 600; font-size: 13.5px;
  padding: 10px 18px; border-radius: 9px;
}
button.primary:hover { background: var(--accent-dark); }
button.small { padding: 5px 12px; font-size: 12px; border-radius: 7px;
  background: var(--gray-100); color: var(--text); font-weight: 500; }
button.small:hover { background: var(--gray-200); }
button.danger, button.small.danger { background: var(--danger-bg); color: var(--danger); font-weight: 600; }
button[disabled] { opacity: .45; cursor: not-allowed; filter: none; }
button.danger:hover { filter: brightness(.95); }
[data-add] { text-align: left !important; }


/* ---------- Chips (мульти-фильтр точек и т.п.) ---------- */
.chip-row { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  border: 1px solid var(--border); border-radius: 15px;
  background: var(--card); color: var(--text);
  padding: 4px 12px; font-size: 12.5px; cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Misc ---------- */
.muted { color: var(--muted); }
.danger-text { color: var(--danger); }
.badge {
  display: inline-block; padding: 3px 10px; border-radius: var(--radius-full); font-size: 11.5px;
  font-weight: 600; background: var(--sky-bg); color: var(--accent-dark);
}
.badge.red { background: var(--danger-bg); color: var(--danger); }
.badge.yellow { background: var(--warn-bg); color: var(--warn); }
.badge.green { background: var(--ok-bg); color: var(--ok); }
.msg { padding: 12px 16px; border-radius: 11px; margin: 0 0 16px; display: none;
  font-size: 13.5px; white-space: pre-wrap; }
.msg.error { display: block; background: var(--danger-bg); color: #b91c1c; border: 1px solid #f3c9c9; }
.msg.ok { display: block; background: var(--ok-bg); color: var(--ok); border: 1px solid #bfe4cd; }

pre.out {
  max-height: 260px; overflow: auto; background: var(--gray-900); color: #cfe3f5;
  border-radius: var(--radius-md); padding: 12px; font-size: 12px; white-space: pre-wrap;
  margin-top: 8px; min-height: 16px;
}
pre.out:empty::before { content: attr(data-placeholder); color: #8a8074; font-style: italic; }

/* ---------- Полосы запаса (Склад) ---------- */
.stockbar { background: var(--gray-100); border-radius: var(--radius-full); height: 8px; overflow: hidden; margin-top: 6px; }
.stockbar-fill { height: 100%; border-radius: var(--radius-full); background: var(--accent); }
.stockbar-fill.yellow { background: var(--warn); }
.stockbar-fill.red { background: var(--danger); }

/* ---------- LocationPicker variant="cards" + мастер-детейл (Склад/Приход) ---------- */
.loc-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.loc-card {
  border: 1px solid var(--border); border-radius: var(--radius-md); padding: 14px; cursor: pointer;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.loc-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.loc-card.current { background: var(--sky-bg); border-color: var(--accent); }
.loc-card-name { font-weight: 700; margin-bottom: 3px; }

.stock-layout { display: grid; grid-template-columns: 250px 1fr; gap: 16px; align-items: start; }
.loc-panel h2 { margin-bottom: 10px; }
.loc-item {
  border: 1px solid var(--border); border-radius: 11px; padding: 10px 12px; margin-bottom: 8px;
  cursor: pointer; transition: border-color .15s, background .15s;
}
.loc-item:hover { border-color: var(--accent); }
.loc-item.current { background: var(--sky-bg); border-color: var(--accent); }
.loc-item-name { font-weight: 700; font-size: 13.5px; }
.loc-item-stats { display: flex; align-items: center; justify-content: space-between; margin-top: 5px; font-size: 12.5px; }
.new-loc { margin-top: 10px; font-size: 13px; }
.new-loc summary { cursor: pointer; color: var(--accent-dark); font-weight: 600; }
.new-loc form { margin-top: 10px; }
@media (max-width: 860px) { .stock-layout { grid-template-columns: 1fr; } }

/* ---------- Компактный список категорий (панель «Товары») ----------
   В отличие от .loc-item (точки сети — крупные карточки со статистикой)
   категорий много и они однострочные: название + счётчик, кнопки правки
   появляются на наведении, чтобы список не рябил. */
.cat-list { display: flex; flex-direction: column; gap: 1px; }
.cat-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  border-radius: 8px; cursor: pointer; font-size: 13.5px;
  transition: background .12s;
}
.cat-row:hover { background: var(--gray-100); }
.cat-row.current { background: var(--sky-bg); font-weight: 600; }
.cat-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.cat-src { color: var(--muted); font-size: 11px; }
.cat-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.cat-row:hover .cat-actions, .cat-row.current .cat-actions { opacity: 1; }
.cat-actions button.small { padding: 1px 6px; font-size: 11px; border-radius: 6px; min-height: 0; }
.cat-rest { margin-top: 6px; }
.cat-rest > summary { cursor: pointer; color: var(--muted); font-size: 12.5px; padding: 4px 8px; }
.cat-rest > summary:hover { color: var(--text); }
@media (max-width: 760px) { .cat-actions { opacity: 1; } }

/* ---------- Точки сети (панель «Склад») ----------
   В отличие от категорий точек мало, но названия длинные: имя занимает до
   двух строк без обрезки, счётчики уходят на отдельную строку. */
.loc-row { flex-direction: column; align-items: stretch; gap: 2px; }
.loc-main { display: flex; align-items: flex-start; gap: 8px; }
.loc-row .cat-name {
  flex: 1; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  overflow: hidden; white-space: normal; line-height: 1.25;
}
.loc-meta { display: flex; gap: 6px; font-size: 12px; color: var(--muted); }

/* список инвентаризации в диалоге: изменённые факты подсвечены */
#inv-body tr.changed td { background: var(--warn-bg); }
#inv-body .inv-delta { white-space: nowrap; }

/* индикатор длительного OCR (диалог прихода) */
.ocr-status {
  display: flex; align-items: center; gap: 8px; margin-top: 10px;
  font-size: 12.5px; color: var(--muted);
}
.spin {
  flex-shrink: 0; width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--brand-500); border-top-color: transparent;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#btn-photo:disabled { opacity: .5; cursor: wait; }

/* выбор источника фото (камера / файл) */
.photo-src { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.photo-src-btn {
  all: unset; cursor: pointer; border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 16px 14px; text-align: center; display: flex; flex-direction: column; gap: 4px;
  transition: border-color .15s, box-shadow .15s;
}
.photo-src-btn:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.photo-src-icon { font-size: 26px; }
.cam-view {
  width: 100%; max-height: 60vh; background: #000; border-radius: var(--radius-md);
  transform: none; /* фронтальную камеру не зеркалим: снимаем документ */
}
@media (max-width: 600px) { .photo-src { grid-template-columns: 1fr; } }

/* ---------- Диалоги ---------- */
dialog.dlg {
  border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 22px 24px 16px; width: 380px;
  box-shadow: var(--shadow-lg);
  max-height: 88vh;          /* длинные диалоги (история покупок) — прокрутка внутри */
  overflow-y: auto;
}
dialog.dlg::backdrop { background: rgba(15, 14, 12, .55); }
dialog.dlg h2 { margin: 0; font-size: var(--text-md); }
/* прилипающая шапка с крестиком: закрыть можно с любой позиции прокрутки */
.dlg-head { position: sticky; top: -22px; z-index: 2; display: flex; align-items: flex-start;
  justify-content: space-between; gap: 12px; margin: -22px -24px 14px; padding: 18px 14px 10px 24px;
  background: var(--card, #fff); border-bottom: 1px solid var(--border); }
.dlg-x { border: none; background: transparent; cursor: pointer; font-size: 15px; line-height: 1;
  padding: 4px 8px; border-radius: var(--radius-full); color: var(--text-muted, #777); }
.dlg-x:hover { background: var(--gray-100, #f0eee9); color: var(--danger, #b3261e); }
dialog.dlg-wide { width: min(680px, 92vw); }
.dlg-scroll { max-height: 50vh; overflow: auto; margin-bottom: 8px; }
.dlg-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 12px; }
/* кнопки внизу окна — одного размера (раньше «Отмена» была мелкой рядом с крупной основной) */
.dlg-actions button.small, .dlg-actions button.primary, .dlg-actions button.danger {
  padding: 9px 18px; font-size: 13.5px; border-radius: 9px; min-height: 0; }
.dlg-x:focus { outline: none; }
.dlg-x:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(71, 106, 138, .35); border-radius: 8px; }

/* ---------- Приход: накладная, документы ---------- */
.receipt-foot { display: flex; align-items: center; gap: 14px; margin-top: 12px; }
.receipt-total { margin-left: auto; font-size: 15px; }
.doc-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border-top: 1px solid var(--border); padding: 10px 0;
}
.doc-row:first-of-type { border-top: none; }
.doc-main { min-width: 0; }
.doc-sum { white-space: nowrap; font-weight: 700; font-variant-numeric: tabular-nums; }
.unmatched-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.unmatched-row .u-name { flex: 1; }

/* ---------- Товары / Склад / Продажи: выбор строки ---------- */
#catalog-body tr, #stock-body tr { cursor: pointer; }
#catalog-body tr.selected td, #stock-body tr.selected td { background: var(--sky-bg); }
#catalog-body tr.selected td:first-child, #stock-body tr.selected td:first-child { border-radius: 8px 0 0 8px; }

/* «Продажи»: числа и кнопка чека — в одну строку, отступы чуть плотнее (10 колонок) */
#sales-body td.num, #sales-head th.num, #sales-body td:last-child { white-space: nowrap; }
#sales-body td, #sales-head th { padding-left: 9px; padding-right: 9px; }

/* клик по строке подсвечивает её — визуальный маркер, чтобы не терять место в списке */
#sales-body tr.marked td { background: var(--sky-bg); }
#sales-body tr.marked td:first-child { border-radius: 8px 0 0 8px; }
#sales-body tr.marked td:last-child { border-radius: 0 8px 8px 0; }

/* подпись под суммой чека: за счёт чего скидка (название акции — в title) */
.discount-note { font-size: 11px; font-weight: 400; white-space: nowrap; }
.hint { text-decoration: underline dotted var(--gray-400, #bbb) 1px; text-underline-offset: 2px; cursor: help; }

/* ---------- Segmented control (разделы внутри карточки) ---------- */
.seg { display: inline-flex; background: var(--gray-100); border-radius: var(--radius-full); padding: 3px; }
.seg button {
  border: none; background: transparent; padding: 7px 15px; border-radius: var(--radius-full);
  font: inherit; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer;
  white-space: nowrap; transition: background .15s, color .15s;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.seg .seg-count { opacity: .55; margin-left: 6px; font-weight: 500; }

/* ---------- Товары: панель фильтров и действия над выбранной строкой ---------- */
.catalog-filters {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.catalog-filters .chip-row { margin: 0; }
.row-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-actions .sel-name { font-size: 13px; font-weight: 600; margin-right: 2px; }
.row-actions.hidden { display: none; }

/* ---------- EmptyState ---------- */
.empty-state { padding: 18px 4px; text-align: center; }
.empty-state-icon { font-size: 22px; margin-bottom: 6px; opacity: .7; }
.empty-state-title { color: var(--muted); font-size: 13.5px; }

/* ---------- Form.js: FormRow ---------- */
.form-row { display: flex; gap: 10px; flex-wrap: wrap; width: 100%; }
@media (max-width: 600px) {
  form:not(.inline-force) { flex-direction: column; align-items: stretch; }
  form:not(.inline-force) input, form:not(.inline-force) select, form:not(.inline-force) textarea { width: 100%; }
  .form-row { flex-direction: column; }
  button.small, .chip, nav button { min-height: var(--tap-min); }
}
/* панель действий строкой под выделенной позицией (Товары) */
/* панель действий — продолжение выделенной строки: одна подсветка, общий блок */
tr.row-actions-tr > td { background: var(--sky-bg); padding: 2px 12px 10px; }
tr.row-actions-tr > td:first-child { border-radius: 0 0 0 8px; }
tr.row-actions-tr > td:last-child  { border-radius: 0 0 8px 0; }
tr.row-actions-tr .row-actions { justify-content: flex-end; }

/* ---------- График смен: сетка сотрудники × дни ---------- */
.sched-grid { width: 100%; border-collapse: collapse; }
.sched-grid th { text-align: center; padding: 6px 6px; }
.sched-grid th:first-child { text-align: left; }
.sched-grid .sched-daynum { font-weight: var(--font-bold); }
.sched-grid td { border-bottom: 1px solid var(--border); }
.sched-grid td.sched-cell { border: 1px solid var(--border); text-align: center; cursor: pointer;
  padding: 11px 4px; min-width: 56px; transition: background .12s; }
.sched-grid td.sched-cell:hover { background: var(--sky-bg); }
.sched-grid th.today { background: var(--sky-bg); border-radius: 8px 8px 0 0; }
.sched-grid td.today { background: var(--sky-bg); }
.sched-grid td:first-child { border: none; padding: 8px 10px 8px 2px; }
.sched-names { display: flex; flex-direction: column; gap: 4px; align-items: stretch; }
button.sched-chip { border: none; cursor: pointer; font: inherit; }
.sched-plus { visibility: hidden; color: var(--gray-500, #888); font-size: 12px; line-height: 1; }
.sched-cell:hover .sched-plus { visibility: visible; }

/* расшифровка дней сотрудника в отчёте по зарплате */
.inner-table { width: 100%; font-size: 12.5px; }
.inner-table th { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.inner-table td { padding: 4px 8px; border-bottom: 1px solid var(--border); }
.inner-table tr:last-child td { border-bottom: none; }

/* история покупок клиента: 7 колонок не влезали в стандартные 680px — кнопка
   «чек ⬇» обрезалась краем диалога */
dialog#dlg-cust { width: min(880px, 94vw); }
#dlg-cust-body td:nth-child(3) { max-width: 180px; }
#dlg-cust-body td:last-child { white-space: nowrap; }

/* попап клиента при наведении в чеках */
.cust-cell { cursor: help; text-decoration: underline dotted var(--gray-400, #bbb) 1px; text-underline-offset: 3px; }
.cust-pop {
  position: absolute; z-index: 50; width: 270px;
  background: var(--card, #fff); color: inherit;
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.14); padding: 12px 14px;
  font-size: 12.5px;
}
.cust-pop-name { font-weight: 700; margin-bottom: 8px; }
.cust-pop-grid { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; }
.cust-pop-grid b { text-align: right; }
.cust-pop { user-select: text; }
#dlg-cust-body > tr { cursor: pointer; }
#dlg-cust-body > tr { cursor: pointer; }

/* Интеграции → Telegram-бот: поля выбранного провайдера оплаты — отдельной строкой формы */
.prov-row { flex-basis: 100%; display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
