:root {
  color-scheme: light;
  --bg: #f3f7fa;
  --surface: #ffffff;
  --surface-2: #f8fbfd;
  --text: #132a3a;
  --muted: #5b7083;
  --faint: #8ea1b1;
  --line: #dde7ee;
  --line-strong: #c7d5df;
  --accent: #1f6fa8;
  --accent-hover: #175a8b;
  --accent-soft: #e7f2fa;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --success: #137a3a;
  --success-soft: #e6f6ec;
  --warn: #a15c07;
  --warn-soft: #fff4e0;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(19, 42, 58, .06), 0 4px 16px rgba(19, 42, 58, .05);
  --font: "Wix Madefor Text", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { display: block; max-width: 100%; }
h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 650; }
h1 { font-size: 24px; letter-spacing: -.01em; }
h2 { font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px;
  border: 1px solid var(--line-strong); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font: 600 14px/1 var(--font); cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--faint); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); border-color: #f1c2bd; }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--accent-soft); border-color: transparent; }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1;
}
.icon-btn:hover { color: var(--text); border-color: var(--line-strong); }
.icon-btn:disabled { opacity: .35; cursor: default; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span, .label { font-size: 13px; font-weight: 600; color: var(--text); }
.field .hint { font-size: 12.5px; color: var(--muted); font-weight: 400; }
.req::after { content: " *"; color: var(--danger); }
input[type=text], input[type=search], input[type=number], input[type=password], select, textarea {
  width: 100%; min-height: 42px; padding: 9px 12px;
  border: 1px solid var(--line-strong); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font: 400 15px/1.4 var(--font);
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31, 111, 168, .15); }
input[readonly] { background: var(--surface-2); color: var(--muted); }
select { appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%235b7083' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.check:hover { border-color: var(--line-strong); }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.check b { display: block; font-weight: 600; font-size: 14px; }
.check small { color: var(--muted); font-size: 12.5px; }

/* ---------- каркас ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 60px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 15px; }
.brand small { font-weight: 500; color: var(--muted); font-size: 13px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 8px 12px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 14px; }
.nav a:hover { background: var(--accent-soft); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.user-chip { font-size: 13px; color: var(--muted); }

.page { max-width: 1240px; margin: 0 auto; padding: 24px 24px 120px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card + .card { margin-top: 16px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-title p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* ---------- фильтры ---------- */
.filters { display: grid; grid-template-columns: minmax(200px, 2fr) repeat(3, minmax(150px, 1fr)); gap: 10px; padding: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 14px 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2);
  font: 600 13px/1.2 var(--font); color: var(--muted); cursor: pointer;
}
.chip b { color: var(--text); font-weight: 700; }
.chip:hover { border-color: var(--line-strong); }
.chip.active { background: var(--accent-soft); border-color: #b7d6ec; color: var(--accent); }

/* ---------- список товаров ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover td { background: #f6fafd; }
.table th:first-child { border-top-left-radius: var(--radius); }
.table th:last-child { border-top-right-radius: var(--radius); }
.thumb { width: 52px; height: 52px; border-radius: 9px; border: 1px solid var(--line); background: #fff; object-fit: contain; flex: none; }
.thumb-empty { display: grid; place-items: center; color: var(--faint); font-size: 11px; }
.p-name { font-weight: 600; line-height: 1.3; color: var(--text); }
.p-name:hover { color: var(--accent); }
.p-code { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.price { font-weight: 700; white-space: nowrap; }
.price small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.price-none { color: var(--muted); font-weight: 500; font-size: 13px; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-ok { background: var(--success-soft); color: var(--success); }
.badge-order { background: var(--warn-soft); color: var(--warn); }
.badge-hit { background: #fff1d6; color: #8a5300; }
.badge-hidden { background: #eef1f4; color: #55636f; }
.badge-photo { background: var(--accent-soft); color: var(--accent); }
.toggles { display: flex; gap: 6px; justify-content: flex-end; }
.toggle {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface);
  color: var(--faint); cursor: pointer; display: grid; place-items: center; font-size: 16px;
}
.toggle:hover { border-color: var(--line-strong); color: var(--muted); }
.toggle.on-hit { color: #d48806; border-color: #f3d9a4; background: #fff8e8; }
.toggle.on-hidden { color: #55636f; border-color: var(--line-strong); background: #eef1f4; }
.toggle svg { width: 18px; height: 18px; }

.pcards { display: none; }
.pcard { display: flex; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); align-items: center; color: inherit; }
.pcard:last-child { border-bottom: 0; }
.pcard:hover { text-decoration: none; background: #f6fafd; }
.pcard-body { flex: 1; min-width: 0; }
.pcard-body .p-name { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pcard-meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }

/* ---------- форма товара ---------- */
.form-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.form-side { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 16px; }
.price-result { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); }
.price-result b { font-size: 20px; color: var(--accent); }
.price-result.none b { font-size: 15px; color: var(--muted); }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 12px; }
.photo { position: relative; border: 1px solid var(--line); border-radius: 10px; background: #fff; overflow: hidden; }
.photo img { width: 100%; aspect-ratio: 1; object-fit: contain; }
.photo-main { position: absolute; top: 6px; left: 6px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; }
.photo-shared { position: absolute; top: 6px; right: 6px; background: rgba(255,255,255,.92); color: var(--warn); font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px; border: 1px solid #f1d39b; }
.photo-tools { display: flex; justify-content: space-between; gap: 4px; padding: 6px; border-top: 1px solid var(--line); background: var(--surface-2); }
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  aspect-ratio: 1; border: 1.5px dashed var(--line-strong); border-radius: 10px; background: var(--surface-2);
  color: var(--muted); font-size: 13px; text-align: center; padding: 10px; cursor: pointer;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.dropzone b { font-size: 26px; line-height: 1; font-weight: 400; }

.specs { display: flex; flex-direction: column; gap: 8px; }
.spec-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr) auto; gap: 8px; align-items: center; }
.spec-tools { display: flex; gap: 4px; }

.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); box-shadow: 0 -4px 18px rgba(19, 42, 58, .06);
}
.savebar-inner { max-width: 1240px; width: 100%; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.savebar .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.dirty-note { font-size: 13px; color: var(--warn); font-weight: 600; }

/* ---------- категории ---------- */
.cat-row { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto auto; gap: 14px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.cat-row:last-child { border-bottom: 0; }
.cat-icon { width: 44px; height: 44px; }
.cat-count { font-size: 13px; color: var(--muted); white-space: nowrap; text-align: right; }
.cat-actions { display: flex; gap: 6px; }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 8px; max-height: 240px; overflow: auto; padding: 2px; }
.icon-choice { border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 4px; cursor: pointer; }
.icon-choice img { width: 100%; }
.icon-choice.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(31, 111, 168, .25); }

/* ---------- журнал ---------- */
.log { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.log td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.log tr:last-child td { border-bottom: 0; }

/* ---------- вход ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 500px at 50% -10%, #dcecf7, transparent), var(--bg); }
.login-card { width: 100%; max-width: 380px; padding: 28px; }
.login-card .brand { margin-bottom: 20px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.error-box { padding: 10px 12px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); font-size: 14px; font-weight: 500; }

/* ---------- диалоги и уведомления ---------- */
.dialog { border: 0; padding: 0; border-radius: 16px; width: min(520px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(19, 42, 58, .25); color: var(--text); }
.dialog::backdrop { background: rgba(19, 42, 58, .35); }
.dialog-body { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 16px 16px; }
.toasts { position: fixed; right: 16px; bottom: 84px; z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast { pointer-events: auto; max-width: 360px; padding: 12px 16px; border-radius: 12px; background: #132a3a; color: #fff; font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); animation: toast-in .2s ease-out; }
.toast-error { background: var(--danger); }
.toast-ok { background: var(--success); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- адаптив ---------- */
@media (max-width: 980px) {
  .form-layout { grid-template-columns: 1fr; }
  .form-side { position: static; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .f-search { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .topbar { height: auto; padding: 10px 16px 0; flex-wrap: wrap; gap: 10px; }
  .brand small { display: none; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; padding-bottom: 8px; }
  .user-chip { display: none; }
  .page { padding: 16px 16px 120px; }
  h1 { font-size: 21px; }
  .table-wrap { display: none; }
  .pcards { display: block; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .filters { padding: 12px; }
  .chips { padding: 0 12px 12px; }
  .spec-row { grid-template-columns: 1fr auto; }
  .spec-row .spec-val { grid-column: 1 / 2; }
  .spec-row .spec-tools { grid-row: 1 / 3; grid-column: 2; flex-direction: column; }
  .savebar { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
  .savebar .dirty-note { display: none; }
  .cat-row { grid-template-columns: 40px minmax(0, 1fr) auto; }
  .cat-row .cat-count { display: none; }
  .photos { grid-template-columns: repeat(2, 1fr); }
  .toasts { left: 16px; right: 16px; align-items: stretch; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
