/* ReMatrix — дизайн-система */
:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --line: #e3e7ec;
  --line-strong: #c9d0d8;
  --text: #1c2430;
  --muted: #77808c;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #eaf1fe;
  --ok: #0b7a3e;
  --ok-bg: #e9f7ee;
  --ok-line: #b9e4c8;
  --warn: #8a6100;
  --warn-bg: #fff6df;
  --warn-line: #eeddA6;
  --err: #bb2424;
  --err-bg: #fdeceb;
  --err-line: #f6c6c3;
  --best: #0b7a3e;
  --best-bg: #def2e5;
  --missing-bg: #fdf3cd;
  --empty-bg: #fdeceb;
  --empty-line: #f3c4c0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(23, 32, 44, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.55 var(--font);
  color: var(--text);
  background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; line-height: 1.25; margin: 0 0 6px; }
h2 { font-size: 17px; margin: 0; }
h3 { font-size: 15px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.spacer { flex: 1; }

/* шапка админки */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.topbar-in {
  max-width: 1280px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 18px; height: 54px;
}
.brand { font-size: 18px; font-weight: 800; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-accent { color: #dc2626; }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.nav a {
  color: var(--muted); font-weight: 500; padding: 6px 12px;
  border-radius: 8px; white-space: nowrap;
}
.nav a:hover { color: var(--text); background: var(--bg); text-decoration: none; }
.nav a.is-active { color: var(--accent); background: var(--accent-soft); }
.nav-logout { margin-left: auto; }

.page { max-width: 1280px; margin: 0 auto; padding: 20px 16px 80px; }
.footer {
  text-align: center; color: var(--muted); font-size: 12.5px;
  padding: 18px 16px 28px;
}

/* сообщения */
.flash { border-radius: 10px; padding: 10px 14px; margin: 0 0 14px; border: 1px solid; }
.flash-ok   { background: var(--ok-bg);   border-color: var(--ok-line);   color: var(--ok); }
.flash-warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.flash-err  { background: var(--err-bg);  border-color: var(--err-line);  color: var(--err); }

/* карточки */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 16px;
}
.card-narrow { max-width: 560px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.center { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; }

/* шапка страницы */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head p { margin: 0; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* статистика */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat-num { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 13px; }

/* кнопки */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  font: inherit; font-weight: 500;
  border: 1px solid var(--line-strong); background: var(--card); color: var(--text);
  border-radius: 9px; padding: 8px 14px; cursor: pointer;
  transition: background .12s, border-color .12s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-danger { color: var(--err); }
.btn-danger:hover { background: var(--err-bg); }
.btn-ghost { border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 7px; }
.btn-lg { padding: 11px 22px; font-size: 16px; }
.btn-block { width: 100%; justify-content: center; }
.inline { display: inline; }

/* поля */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
.field input[type=text], .field input[type=password], .sel {
  font: inherit; width: 100%; padding: 9px 12px;
  border: 1px solid var(--line-strong); border-radius: 9px; background: var(--card);
  color: var(--text);
}
.field input:focus, .sel:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.field-inline { display: flex; align-items: center; gap: 10px; margin: 0; }
.field-inline > span { margin: 0; white-space: nowrap; }
.field-inline input { margin: 0; width: 220px; }
.field-grow { flex: 1; }
.form-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.form-row .field { margin-bottom: 0; }
.form-row .btn { margin-bottom: 1px; }
.form-row .field input { width: 100%; min-width: 160px; }

/* таблицы */
.table-wrap { overflow: auto; border-radius: 10px; }
.tbl { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 640px; }
.tbl th, .tbl td {
  padding: 8px 12px; border-bottom: 1px solid var(--line);
  text-align: left; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.tbl thead th {
  position: sticky; top: 0; z-index: 5;
  background: #f4f6f9; font-size: 12.5px; text-transform: uppercase;
  letter-spacing: .03em; color: var(--muted); font-weight: 600;
}
.tbl thead th:first-child { border-radius: 10px 0 0 0; }
.tbl thead th:last-child { border-radius: 0 10px 0 0; }
.tbl tbody tr:hover td { background: #f7f9fc; }
.td-strong { font-weight: 600; }
.td-num, .th-num { text-align: right; }
.td-mine { color: var(--muted); }
.td-link { max-width: 380px; }
.td-link code {
  font-size: 12px; background: var(--bg); padding: 3px 8px; border-radius: 6px;
  display: inline-block; max-width: 250px; overflow: hidden;
  text-overflow: ellipsis; vertical-align: middle;
}
.td-acts, .th-acts { text-align: right; }
.td-acts .btn, .td-acts form { margin-left: 4px; }

/* прогресс */
.progress { height: 6px; background: #e8ecf1; border-radius: 99px; overflow: hidden; min-width: 90px; }
.progress span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.progress-big { height: 10px; }
.progress-big span { background: linear-gradient(90deg, #22c55e, #16a34a); }

/* значки */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 99px;
  font-size: 12px; font-weight: 600; background: var(--bg); color: var(--muted);
  border: 1px solid var(--line);
}
.badge-ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-line); }
.badge-warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.legend { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.chip { font-size: 12.5px; padding: 3px 11px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); color: var(--muted); }
.chip-green { background: var(--best-bg); color: var(--best); border-color: #bfe4cc; }
.chip-red { background: var(--err-bg); color: var(--err); border-color: var(--err-line); }
.chip-yellow { background: var(--missing-bg); color: #8a6d00; border-color: #eadfa4; }

/* матрица: жёлтая — цены нет, красная — дороже нашей, зелёная — дешевле нашей.
   Колонки фиксированной ширины: трое поставщиков влезают в стандартное окно.
   Скролл нативный: полоса появляется сама, когда таблица шире окна */
.matrix-wrap { overflow-x: auto; }
.matrix { min-width: 0; }
.matrix td.td-empty { background: var(--missing-bg); }
.matrix tbody tr:hover td.td-empty { background: #ffefad; }
.matrix td.td-over { background: var(--err-bg); color: #a11f1f; }
.matrix tbody tr:hover td.td-over { background: #fbd9d6; }
.matrix td.td-under { background: var(--best-bg); color: var(--best); }
.matrix tbody tr:hover td.td-under { background: #cdeeda; }
.matrix th, .matrix td { padding: 6px 8px; }
.matrix .th-grp, .matrix .td-grp { color: var(--muted); min-width: 84px; white-space: nowrap; }
.matrix .td-grp { font-weight: 700; }
.matrix td.td-strong { font-weight: 400; }
.matrix td.td-mine { color: var(--text); }
.matrix th:nth-child(2), .matrix td:nth-child(2) { min-width: 180px; max-width: 230px; white-space: normal; overflow-wrap: break-word; }
.matrix .th-num, .matrix .td-num { width: 1%; white-space: nowrap; }
.matrix th.th-sup { min-width: 135px; max-width: 135px; }
.matrix td:not(.td-grp):not(:nth-child(2)) { white-space: nowrap; }
.sup-total { font-size: 11px; font-weight: 400; color: var(--muted); font-variant-numeric: tabular-nums; }
.sup-total.best { color: #7c3aed; font-weight: 500; }
.th-best-total {
  box-shadow: inset 0 0 0 2px rgba(139, 92, 246, .55);
  border-radius: 8px;
}

/* редактор */
.editor-form .toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; margin-bottom: 12px;
}
.toolbar.sticky { position: sticky; top: 64px; z-index: 30; box-shadow: 0 4px 14px rgba(23,32,44,.08); }
.toolbar.bottom { margin-top: 12px; margin-bottom: 0; }
.editor .cell {
  width: 100%; border: 1px solid transparent; background: transparent;
  font: inherit; color: inherit; padding: 6px 8px; border-radius: 6px;
}
.editor .cell:focus { outline: none; border-color: var(--accent); background: #fff; box-shadow: 0 0 0 2px var(--accent-soft); }
.editor .cell-name { min-width: 240px; font-weight: 500; }
.editor .cell-num { text-align: right; width: 110px; }
.th-chk, .td-chk { width: 36px; text-align: center; }
.th-del, .td-del { width: 40px; }
.rowdel {
  border: 0; background: none; color: #c3cbd4; font-size: 20px; cursor: pointer;
  padding: 2px 8px; line-height: 1; border-radius: 6px;
}
.rowdel:hover { color: var(--err); background: var(--err-bg); }
tr.row-off td { opacity: .38; }
tr.row-new td { background: var(--accent-soft); }

/* загрузка файла */
.upload-form .dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  border: 2px dashed var(--line-strong); border-radius: var(--radius);
  padding: 34px 20px; margin-bottom: 14px; cursor: pointer;
  color: var(--muted); transition: border-color .15s, background .15s;
  text-align: center;
}
.upload-form .dropzone:hover, .upload-form .dropzone.is-drag {
  border-color: var(--accent); background: var(--accent-soft); color: var(--accent);
}
.dz-title { font-weight: 600; }
.dz-sub { font-size: 13px; }
.upload-form input[type=file] { width: 1px; height: 1px; opacity: 0; position: absolute; }
.steps { color: var(--muted); padding-left: 20px; margin: 0; }
.steps li { margin-bottom: 6px; }

/* всплывающая правка поставщика */
.pop { position: relative; display: inline-block; }
.pop summary { list-style: none; }
.pop summary::-webkit-details-marker { display: none; }
.pop-body {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50;
  background: var(--card); border: 1px solid var(--line-strong); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(23,32,44,.14); padding: 14px; width: 260px;
}

/* страница поставщика */
.pub { background: #eef1f5; }
.offer-wrap { max-width: 1400px; margin: 0 auto; padding: 22px 18px 90px; }
.offer-head { margin-bottom: 14px; }
/* текстовые блоки — читабельной ширины, таблица — во всю ширину */
.offer-head, .offer-progress, .offer-wrap > .flash { max-width: 860px; }
.offer-brand { font-weight: 800; font-size: 17px; margin-bottom: 10px; }
.offer-hello { font-size: 20px; }
.offer-round { color: var(--muted); margin-top: 2px; }
.offer-emoji { font-size: 40px; margin-bottom: 6px; }
.offer-progress { margin-bottom: 14px; }
.offer-progress-label { color: var(--muted); font-size: 13.5px; margin-top: 6px; }
.offer-form .toolbar {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.offer-form .toolbar.sticky { position: sticky; top: 8px; z-index: 30; }
.offer-group { padding-bottom: 8px; }
.group-title {
  font-size: 13px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); margin: 4px 2px 8px; font-weight: 700;
}
.offer-table th { position: static; background: transparent; padding-bottom: 4px; }
.offer-table-wrap { border-radius: 8px; }
/* таблица вписывается в экран: названия переносятся, числа компактны */
.offer-table { min-width: 0; }
.offer-table td:first-child, .offer-table th:first-child {
  white-space: normal; min-width: 180px; max-width: 420px;
  overflow-wrap: break-word;
}
.offer-table .th-num, .offer-table td[data-label="Кол-во"],
.offer-table td[data-label="За 1 сейчас"], .offer-table td[data-label="За всё сейчас"] { white-space: nowrap; }
.offer-table .td-num { padding-left: 8px; padding-right: 8px; }
.td-price { min-width: 104px; }
.price-input {
  font: inherit; width: 100%; padding: 8px 10px; text-align: right;
  border: 1px solid var(--line-strong); border-radius: 8px;
  font-variant-numeric: tabular-nums; background: var(--card);
}
.price-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.price-input.is-invalid { border-color: var(--err); background: var(--err-bg); box-shadow: 0 0 0 3px #fdeceb; }
tr.is-invalid-row td { background: var(--err-bg); }
.total-input { color: var(--muted); }
.total-input.auto { color: var(--muted); font-style: italic; }
#unsaved-note { color: var(--warn); }
.flash-hint { background: var(--accent-soft); border: 1px solid #c8dbfb; color: #1e4fbb; }

/* логин */
.login-wrap { min-height: 92vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--card);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 12px 40px rgba(23,32,44,.10);
  padding: 34px 30px; text-align: center;
}
.login-logo { font-size: 26px; font-weight: 800; }
.login-sub { color: var(--muted); margin: 2px 0 18px; }
.login-form { text-align: left; }

/* мобильная */
@media (max-width: 720px) {
  .topbar-in { gap: 10px; height: auto; padding: 8px 12px; flex-wrap: wrap; }
  .nav { order: 3; width: 100%; padding-bottom: 2px; }
  .nav-logout { margin-left: 0; }
  .page { padding: 14px 10px 70px; }
  .toolbar.sticky { top: 8px; }
  .editor-form .toolbar.sticky { top: 8px; }
  .matrix thead th { position: static; }
  .page-head { flex-direction: column; }
  .td-link { max-width: 220px; }
  .td-link code { max-width: 130px; }
  .offer-wrap { padding: 14px 8px 80px; }
  .offer-table thead { display: none; }
  .offer-table tr { display: block; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; background: var(--card); }
  .offer-table td { display: flex; justify-content: space-between; align-items: center; border: 0; border-bottom: 1px dashed var(--line); padding: 7px 10px; }
  .offer-table td::before { content: attr(data-label); color: var(--muted); font-size: 12.5px; }
  .offer-table td:last-child { border-bottom: 0; }
  .offer-table .td-price { width: 100%; }
  .price-input { max-width: 160px; }
}
