:root {
  --green: #4a9b2f;
  --green-dark: #3b7d25;
  --orange: #f07d1a;
  --ink: #24303d;
  --muted: #8a97a3;
  --line: #e3e8ec;
  --bg: #f6f8f6;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
}
a { color: var(--green-dark); }

/* ---------- шапка ---------- */
.topbar {
  background: #fff;
  border-bottom: 3px solid var(--green);
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand {
  font-weight: 800;
  font-size: 17px;
  color: var(--green);
  padding: 16px 0;
}
.topbar .brand span { color: var(--muted); font-weight: 500; font-size: 13px; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  padding: 18px 16px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 600;
  border-bottom: 3px solid transparent;
  margin-bottom: -3px;
}
.topbar nav a:hover { background: var(--bg); }
.topbar nav a.active { color: var(--green); border-bottom-color: var(--orange); }

.topbar nav a.nav-icon { font-size: 18px; padding: 16px 14px; }

/* кнопка выхода прижата к правому краю шапки */
.topbar .exit-form { margin-left: auto; }
.btn-exit {
  background: #fff;
  color: #d43b3b;
  border: 1px solid #f0c4c1;
  border-radius: 6px;
  padding: 7px 18px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.btn-exit:hover { background: #fdecea; border-color: #d43b3b; }

main { max-width: 1240px; margin: 0 auto; padding: 24px; }

/* таблица без рамок — для списков «поле → значение» */
table.plain { min-width: 0; background: none; }
table.plain td { border-bottom: 1px solid var(--line); padding: 8px 12px 8px 0; }
table.plain tr:last-child td { border-bottom: none; }
table.plain code { font-size: 12.5px; word-break: break-all; }

/* ---------- уведомления ---------- */
.flashes { margin-bottom: 16px; }
.flash {
  padding: 11px 16px;
  border-radius: 6px;
  margin-bottom: 8px;
  border-left: 4px solid;
}
.flash.ok { background: #eaf6e5; border-color: var(--green); }
.flash.error { background: #fdecea; border-color: #d43b3b; }

/* ---------- общие блоки ---------- */
.card-box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}
h1 { font-size: 22px; margin: 0 0 4px 0; }
h2 { font-size: 16px; margin: 0 0 14px 0; color: var(--green-dark); }
.subtitle { color: var(--muted); margin: 0 0 20px 0; }

.row-between { display: flex; justify-content: space-between; align-items: center; gap: 16px; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-block;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
}
.btn:hover { background: var(--green-dark); }
.btn.orange { background: var(--orange); }
.btn.orange:hover { background: #d66a10; }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--bg); }
.btn.danger { background: #fff; color: #d43b3b; border: 1px solid #f0c4c1; }
.btn.danger:hover { background: #fdecea; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn.big { padding: 13px 26px; font-size: 15px; }

/* ---------- формы ---------- */
label { display: block; font-weight: 600; margin-bottom: 5px; font-size: 13px; }
.hint { color: var(--muted); font-weight: 400; font-size: 12px; }
input[type=text], input[type=number], input[type=search], textarea, select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--green); border-color: var(--green); }
textarea { resize: vertical; min-height: 72px; }
input[type=color] { width: 54px; height: 38px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.field { margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.checkline { display: flex; align-items: center; gap: 8px; }
.checkline input { width: 17px; height: 17px; }
.checkline label { margin: 0; }

/* ---------- фильтры ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin: 0; }
.filters .grow { flex: 1; min-width: 220px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.chip {
  padding: 5px 12px;
  border-radius: 20px;
  background: #fff;
  border: 1px solid var(--line);
  text-decoration: none;
  color: var(--ink);
  font-size: 12.5px;
}
.chip.on { background: var(--green); border-color: var(--green); color: #fff; }

/* ---------- таблица ---------- */
.table-wrap {
  overflow-x: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
table { width: 100%; border-collapse: collapse; background: #fff; min-width: 760px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); background: #fafbfa; }
tr.hidden-row td { opacity: 0.45; }
td.num { text-align: right; white-space: nowrap; }
td.actions { text-align: right; white-space: nowrap; }
.thumb {
  width: 46px; height: 46px; object-fit: contain;
  background: var(--bg); border-radius: 4px; border: 1px solid var(--line);
}
.thumb.empty {
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; color: var(--muted); text-align: center; line-height: 1.1;
}
.price-new { font-weight: 700; color: var(--green-dark); }
.price-old { color: var(--muted); text-decoration: line-through; font-size: 12px; }
.tag {
  display: inline-block; padding: 2px 7px; border-radius: 3px;
  font-size: 11px; font-weight: 700; background: var(--orange); color: #fff;
}
.sku { color: var(--muted); font-size: 12.5px; font-family: Consolas, monospace; }

/* ---------- пагинация ---------- */
.pager { display: flex; gap: 6px; align-items: center; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.pager a, .pager span {
  padding: 7px 12px; border-radius: 6px; text-decoration: none;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
}
.pager .now { background: var(--green); color: #fff; border-color: var(--green); }
.pager .gap { border: none; background: none; color: var(--muted); }

/* ---------- прочее ---------- */
.photo-preview {
  width: 100%; height: 200px; object-fit: contain;
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
}
.log {
  background: #1e2a35; color: #d6e4ef; padding: 16px; border-radius: 6px;
  font-family: Consolas, monospace; font-size: 12.5px; white-space: pre-wrap;
  max-height: 320px; overflow: auto;
}
.stat-row { display: flex; gap: 28px; flex-wrap: wrap; }
.stat .value { font-size: 26px; font-weight: 800; color: var(--green); }
.stat .label { color: var(--muted); font-size: 12.5px; }
/* ---------- перетаскивание и выделение разделов ---------- */
.selection-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 12px 16px;
  position: sticky;
  top: 57px;
  z-index: 5;
}
.selection-bar .bar-spacer { flex: 1; }
.pick-cell { text-align: center; }
.pick-cell .pick { width: 17px; height: 17px; cursor: pointer; }
#sections-body tr { cursor: default; }
#sections-body tr.picked { background: #f2f9ef; }
#sections-body tr.dragging { opacity: 0.45; background: #eaf6e5; }
.order-cell { white-space: nowrap; }
.drag-handle {
  touch-action: none;
  display: inline-block;
  cursor: grab;
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
  padding: 4px 6px 4px 0;
  user-select: none;
}
.drag-handle:active { cursor: grabbing; }
#sections-body tr:hover .drag-handle { color: var(--green); }
.save-note { font-size: 13px; font-weight: 600; color: var(--muted); }
.save-note.ok { color: var(--green); }
.save-note.error { color: #d43b3b; }

.cut-all {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: 18px;
  padding-left: 18px;
  border-left: 1px solid var(--line);
}
.cut-all input { padding: 6px 8px; width: 78px; }
/* числовые поля со стрелками: держим их всегда видимыми, а не по наведению */
input.cut, input.qty {
  width: 78px;
  padding: 6px 8px;
  text-align: center;
}
input[type=number] { -moz-appearance: number-input; }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
  opacity: 1;
  height: 24px;
}

/* индикатор живого поиска */
.searching {
  display: none;
  color: var(--green);
  font-weight: 600;
  font-size: 12.5px;
}
.searching.on { display: inline; }

/* ---------- сведения о последней загрузке ---------- */
.last-import {
  background: #eaf6e5;
  border-color: var(--green);
}
.last-import h2 { color: var(--green-dark); }
.last-import .last-file {
  font-weight: 700;
  font-size: 15px;
  font-family: Consolas, monospace;
}

/* ---------- ход загрузки прайса ---------- */
.progress-stage {
  font-size: 17px;
  font-weight: 700;
  color: var(--green-dark);
  margin-bottom: 14px;
}
.progress-track {
  height: 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 2%;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--green), #6dbf46);
  background-size: 28px 28px;
  transition: width 0.5s ease;
  animation: progress-stripes 1s linear infinite;
  background-image: linear-gradient(45deg,
    rgba(255,255,255,0.22) 25%, transparent 25%,
    transparent 50%, rgba(255,255,255,0.22) 50%,
    rgba(255,255,255,0.22) 75%, transparent 75%, transparent);
}
.progress-fill.failed { background: #d43b3b; animation: none; }
@keyframes progress-stripes {
  from { background-position: 28px 0; }
  to { background-position: 0 0; }
}

/* затемнение на время отправки файла */
.sending-overlay {
  position: fixed;
  inset: 0;
  background: rgba(36, 48, 61, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.sending-overlay .box {
  background: #fff;
  border-radius: 10px;
  padding: 28px 36px;
  text-align: center;
  max-width: 420px;
}
.sending-overlay .spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto 14px;
  border: 4px solid var(--line);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- выбор формата и разделов ---------- */
.format-pick {
  flex: 1;
  min-width: 240px;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  cursor: pointer;
  font-weight: 400;
  margin: 0;
  transition: background 0.15s, border-color 0.15s;
}
.format-pick:hover { border-color: var(--green); }
.format-pick.on { background: #eaf6e5; border-color: var(--green-dark); }
.format-pick input { margin-right: 8px; }
.format-pick b { font-size: 15px; }
.format-pick .hint { display: block; margin-top: 5px; }

.sections-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 2px 16px;
}
.section-pick {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 5px;
  font-weight: 400;
  margin: 0;
  cursor: pointer;
}
.section-pick:hover { background: var(--bg); }
.section-pick input { width: 16px; height: 16px; flex: none; }
.section-pick .section-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inline-form { display: inline; }
.mini-input { display: inline-block; width: auto; min-width: 170px; }

/* поле с ошибкой: рамка и подпись под полем, чтобы ошибку было видно на месте */
.field input.bad {
  border-color: #d43b3b;
  background: #fff6f6;
}
.field-error {
  min-height: 0;
  margin-top: 4px;
  color: #d43b3b;
  font-size: 12px;
  line-height: 1.35;
}
.field-note {
  margin-top: 4px;
  color: var(--green);
  font-size: 12px;
}

/* технические описания: текст в таблице ограничиваем тремя строками */
.note-text {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.5;
}
.thumb.big { width: 120px; height: 120px; object-fit: contain; }
a.section-pick { text-decoration: none; color: inherit; display: block; }
a.section-pick:hover { border-color: var(--green); }

/* правка технического описания прямо в КП */
.note-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.note-block .row-between { margin-bottom: 8px; }
.note-area {
  width: 100%;
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  resize: vertical;
}
.tag-edited {
  display: inline-block;
  margin-left: 8px;
  background: #fff4e2;
  color: #a8600c;
  border-radius: 3px;
  padding: 1px 7px;
  font-size: 12px;
}

/* поиск по описаниям */
.search-box { display: flex; align-items: center; gap: 14px; }
.search-box input {
  flex: 1;
  font: inherit;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.search-box .hint { white-space: nowrap; }

/* вход и первая настройка */
body.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  margin: 0;
  background: #f4f7f5;
}
.auth-box {
  width: 380px;
  max-width: 92vw;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px 30px 30px;
  box-shadow: 0 8px 30px rgba(20, 40, 25, 0.07);
}
.auth-box.wide { width: 560px; }
.auth-brand {
  font-size: 21px;
  font-weight: 800;
  color: var(--green);
  letter-spacing: -0.2px;
}
.auth-brand span { color: #24303d; }
.auth-box .field { margin-top: 14px; }
.auth-box input[type=text], .auth-box input[type=password] { width: 100%; }

/* имя вошедшего в шапке */
.topbar .who {
  color: #5d6b62;
  font-size: 13px;
  margin-right: 10px;
  white-space: nowrap;
}

/* карточка сотрудника и галочки прав */
.staff-card { padding-bottom: 12px; }
.staff-extra {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.tag-on, .tag-off {
  border-radius: 3px;
  padding: 2px 9px;
  font-size: 12px;
}
.tag-on { background: #e8f5e9; color: #2f7d32; }
.tag-off { background: #fdecea; color: #c62828; }
.perm-box {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}
.perm-box.locked { opacity: 0.75; }
.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 8px;
}
.perm {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}
.perm.on { border-color: var(--green); background: #f3faf3; }
.perm input { margin-top: 3px; }
.perm b { display: block; font-weight: 600; font-size: 13px; }
.perm .hint { display: block; font-size: 12px; line-height: 1.35; }
