:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e3e6ea;
  --text: #16181d;
  --muted: #6b7280;
  --brand: #2563eb;
  --brand-soft: #eff4ff;
  --ok: #15803d;
  --ok-soft: #e9f7ee;
  --warn: #b45309;
  --warn-soft: #fef5e7;
  --danger: #b91c1c;
  --danger-soft: #fdeceb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- каркас ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.topbar-inner {
  max-width: 1360px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 22px; min-height: 58px;
}
.logo { font-weight: 700; font-size: 16px; color: var(--text); white-space: nowrap; }
.logo span { color: var(--brand); }
.nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
.nav a {
  padding: 7px 12px; border-radius: 8px; color: var(--muted);
  font-weight: 500; font-size: 14px; white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.userbox { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.userbox b { color: var(--text); font-weight: 600; }

.wrap { max-width: 1360px; margin: 0 auto; padding: 22px 20px 60px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.2px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 10px; }
.sub { color: var(--muted); font-size: 13px; margin: 0; }

/* ---------- карточки ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px;
}
.card.pad0 { padding: 0; overflow: hidden; }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-side { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px 16px; box-shadow: var(--shadow);
}
.kpi .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -.5px; }
.kpi .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.accent { background: var(--brand-soft); border-color: #cddcfb; }
.kpi.accent .value { color: var(--brand); }

/* ---------- таблицы ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600; padding: 10px 14px; background: var(--surface-2);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.nowrap { white-space: nowrap; }
.table-scroll { overflow-x: auto; }

/* ---------- бейджи ---------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px;
  font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: #c9ead6; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: #f5e0bb; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: #f5c9c6; }
.badge.brand { background: var(--brand-soft); color: var(--brand); border-color: #cddcfb; }

/* ---------- формы ---------- */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--text); }
input[type=text], input[type=password], input[type=number], input[type=date],
input[type=email], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1; min-width: 130px; margin-bottom: 0; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 8px; }
.check input { width: auto; }
.check label { margin: 0; font-weight: 500; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #1d4fd8; }
.btn.danger { color: var(--danger); border-color: #f0c8c5; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.big { padding: 15px 20px; font-size: 16px; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
form.inline { display: inline; }

/* ---------- сообщения ---------- */
.alert { padding: 11px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 16px; border: 1px solid; }
.alert.ok { background: var(--ok-soft); color: var(--ok); border-color: #c9ead6; }
.alert.err { background: var(--danger-soft); color: var(--danger); border-color: #f5c9c6; }
.alert.info { background: var(--brand-soft); color: var(--brand); border-color: #cddcfb; }
.empty { padding: 34px 18px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---------- прочее ---------- */
.muted { color: var(--muted); }
.small { font-size: 13px; }
.xs { font-size: 12px; }
.strong { font-weight: 700; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
details.box { border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; background: var(--surface-2); margin-bottom: 12px; }
details.box summary { cursor: pointer; font-weight: 600; font-size: 14px; }
details.box[open] summary { margin-bottom: 12px; }

.bar { height: 7px; background: var(--border); border-radius: 4px; overflow: hidden; min-width: 70px; }
.bar > i { display: block; height: 100%; background: var(--brand); }
.bar.ok > i { background: var(--ok); }

.chart { display: flex; align-items: flex-end; gap: 5px; height: 110px; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 5px; }
.chart .col i { display: block; width: 100%; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; }
.chart .col span { font-size: 10px; color: var(--muted); }

/* ---------- логин ---------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-box { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 30px; box-shadow: 0 8px 30px rgba(16,24,40,.08); }
.login-box h1 { text-align: center; margin-bottom: 4px; }
.login-box .sub { text-align: center; margin-bottom: 22px; }

/* ---------- сканер ---------- */
.scanner { max-width: 620px; margin: 0 auto; }
#preview { width: 100%; border-radius: 12px; background: #000; display: block; aspect-ratio: 4/3; object-fit: cover; }
.scan-frame { position: relative; }
.scan-frame::after {
  content: ''; position: absolute; inset: 22% 10%; border: 2px solid rgba(255,255,255,.85);
  border-radius: 10px; pointer-events: none;
}
.scan-result { padding: 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); margin-top: 14px; }
.scan-result.hit { border-color: #c9ead6; background: var(--ok-soft); }
.scan-result.miss { border-color: #f5c9c6; background: var(--danger-soft); }
.qty-row { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.qty-row input { text-align: center; font-size: 22px; font-weight: 700; padding: 10px; }
.qty-btn { width: 52px; height: 52px; font-size: 24px; flex: none; }

@media (max-width: 1080px) {
  .g-side, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .wrap { padding: 16px 14px 50px; }
  .g2, .g3, .g4, .g-side { grid-template-columns: 1fr; }
  .topbar-inner { flex-wrap: wrap; padding: 8px 14px; gap: 8px; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  th, td { padding: 9px 10px; }
  .kpi .value { font-size: 22px; }
}

@media print {
  .topbar, .no-print, .actions { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; }
}
