/* Общий макет: светлая спокойная тема. Таск 04 дополняет, а не переделывает. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #667085;
  --border: #e3e6ea;
  --accent: #2f5fd0;
  --accent-soft: #e8eefb;
  --ok: #1e7f4f;
  --ok-soft: #e6f4ec;
  --warn: #8a5a00;
  --warn-soft: #fdf3dc;
  --error: #b42318;
  --error-soft: #fdecea;
  --good-cell: #d9f2e3;
  --equal-cell: #fff3c4;
  --bad-cell: #fbe0dd;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }
code { background: var(--accent-soft); padding: 1px 4px; border-radius: 4px; }
.muted { color: var(--muted); }

/* Шапка */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; color: var(--text); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  padding: 6px 12px;
  border-radius: var(--radius);
  color: var(--muted);
}
.nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.logout { margin: 0; }

.page { max-width: 1440px; margin: 0 auto; padding: 24px; }

/* Карточки, кнопки, формы */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.button {
  display: inline-block;
  padding: 8px 16px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font: inherit;
  cursor: pointer;
}
.button:hover { filter: brightness(1.05); text-decoration: none; }
.button-secondary { background: var(--surface); color: var(--accent); }
.link-button {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
}
.link-button.danger { color: var(--error); }

label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }
input[type="text"], input[type="password"], input[type="date"], select {
  font: inherit;
  color: var(--text);
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  min-width: 160px;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

/* Сообщения */
.flashes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.flash { padding: 10px 14px; border-radius: var(--radius); border: 1px solid transparent; }
.flash-ok { background: var(--ok-soft); color: var(--ok); border-color: #bfe3cf; }
.flash-info { background: var(--accent-soft); color: var(--accent); border-color: #c9d7f5; }
.flash-warn { background: var(--warn-soft); color: var(--warn); border-color: #f1dca6; }
.flash-error { background: var(--error-soft); color: var(--error); border-color: #f5c2bd; }

/* Пустое состояние */
.empty-state {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  margin-bottom: 16px;
  max-width: 720px;
}
.actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 16px; }

/* Вход */
.page-login { display: flex; justify-content: center; padding-top: 12vh; }
.login-card { width: 340px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin-bottom: 4px; }

/* Выгрузки */
.upload-form { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
.upload-form .wide { flex-basis: 100%; }
.category-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.rename summary { cursor: pointer; color: var(--accent); }
.rename form { display: flex; gap: 8px; margin-top: 8px; }

/* Таблицы */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.table th { color: var(--muted); font-weight: 500; font-size: 13px; background: var(--surface); }
.table td.num, .table th.num { text-align: right; }
.table tbody tr:hover { background: #fafbfc; }
.row-actions { text-align: right; width: 1%; white-space: nowrap; }
.row-actions form { margin: 0; }

/* ===== Экраны: сравнение, динамика, анализ ниши, настройка расширения ===== */
.page-wide { max-width: none; }
.notice {
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid #f1dca6;
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 12px;
}
.warn-text { color: var(--warn); }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin: 0 0 12px; }
input[type="text"]:not([size]) { min-width: 160px; }
.chip {
  display: inline-block;
  padding: 1px 8px;
  margin: 0 4px 2px 0;
  border-radius: 999px;
  background: var(--ok-soft);
  color: var(--ok);
  font-size: 13px;
}
.chip-skipped { background: var(--warn-soft); color: var(--warn); }
.range-info p { margin: 4px 0; }

/* Выбор области просмотра */
.scope { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; padding: 14px 16px; }
.scope [hidden] { display: none !important; }
.scope .range-fields { display: flex; gap: 12px; align-items: flex-end; }
.scope select { min-width: 200px; }
.mode-switch { display: flex; gap: 4px; border: 0; padding: 0; margin: 0; }
.mode-switch legend { color: var(--muted); font-size: 13px; padding: 0 0 4px; float: left; width: 100%; }
.mode-switch .radio {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
}
.mode-switch .radio:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* Панель над таблицей */
.toolbar { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; padding: 14px 16px; }
.toolbar-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.button[disabled] { opacity: .5; cursor: default; }
.search-box { position: relative; flex: 1 1 360px; max-width: 520px; }
.search-box input { width: 100%; }
.search-results {
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  margin: 4px 0 0;
  padding: 4px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(16, 24, 40, .12);
  max-height: 320px;
  overflow: auto;
}
.search-results li { display: flex; align-items: center; gap: 4px; padding: 2px 6px; }
.search-results .result-pick {
  flex: 1;
  display: flex;
  flex-direction: column;
  text-align: left;
  border: 0;
  background: none;
  font: inherit;
  padding: 6px 4px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
}
.search-results .result-pick:hover { background: var(--accent-soft); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0, 0, 0, .1); vertical-align: -2px; margin-right: 4px; }

/* Таблица сравнения: шапка и первый столбец закреплены */
.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 170px);
  min-height: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.compare-table { border-collapse: separate; border-spacing: 0; font-size: 13px; width: max-content; min-width: 100%; }
.compare-table th, .compare-table td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid #eef0f3;
  background: var(--surface);
  text-align: right;
  white-space: nowrap;
}
.compare-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f9fafb;
  border-bottom: 2px solid var(--border);
  white-space: normal;
  vertical-align: top;
  text-align: left;
  font-weight: 400;
}
.compare-table .metric-col {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 250px;
  max-width: 250px;
  text-align: left;
  font-weight: 500;
  white-space: normal;
  box-shadow: 1px 0 0 var(--border);
}
.compare-table thead .metric-col { z-index: 4; background: #f9fafb; vertical-align: bottom; color: var(--muted); }
.compare-table .stat-col { min-width: 96px; color: var(--muted); background: #fafbfc; }
.compare-table thead .stat-col { background: #f9fafb; vertical-align: bottom; text-align: right; }
.compare-table .sku-col { min-width: 176px; max-width: 176px; }
.compare-table .sku-col.is-mine { background: var(--accent-soft); }
.compare-table td.text-cell { white-space: normal; text-align: left; }
.compare-table .group-row th, .compare-table .group-row td {
  background: #eef1f6;
  color: var(--accent);
  font-size: 12px;
  letter-spacing: .03em;
  text-transform: uppercase;
  padding: 4px 10px;
}
.compare-table tbody tr:hover td:not(.cell-good):not(.cell-equal):not(.cell-bad) { background: #f7f9fc; }
.cell-good { background: var(--good-cell) !important; }
.cell-equal { background: var(--equal-cell) !important; }
.cell-bad { background: var(--bad-cell) !important; }
.swatch.cell-good, .swatch.cell-equal, .swatch.cell-bad { background-color: inherit; }

.sku-head { display: flex; flex-direction: column; gap: 2px; min-height: 124px; }
.sku-tools { display: flex; justify-content: space-between; align-items: center; min-height: 24px; }
.sku-name { font-weight: 500; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.sku-meta { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sku-id { color: var(--muted); font-size: 11px; }
.absent { color: var(--warn); font-size: 12px; font-weight: 500; }
.star, .remove {
  border: 0;
  background: none;
  cursor: pointer;
  font: inherit;
  font-size: 18px;
  line-height: 1;
  color: #98a2b3;
  padding: 2px 4px;
  border-radius: 4px;
}
.star:hover, .remove:hover { background: rgba(0, 0, 0, .06); color: var(--text); }
.star.on { color: #d98a00; }
.remove { font-size: 20px; }

/* Планируемый заказ */
.plan-form { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: flex-end; }
.plan-form input[type="text"] { min-width: 0; width: 110px; }
.plan-result { min-width: 90px; padding-bottom: 8px; font-size: 16px; }
.plan-days { font-weight: 600; }

/* Графики */
.chart-title { display: flex; align-items: baseline; gap: 12px; }
.chart-box { position: relative; height: 460px; }
.chart-box.chart-short { height: 300px; }
.dynamics-controls { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
.sku-picker {
  list-style: none;
  margin: 0;
  padding: 0;
  columns: 3 320px;
  column-gap: 24px;
}
.sku-picker li { break-inside: avoid; padding: 2px 0; }
.check { flex-direction: row; align-items: baseline; gap: 8px; color: var(--text); font-size: 14px; cursor: pointer; }
.check .is-mine { font-weight: 600; }

/* Анализ ниши */
.niche-source { margin: 0 0 12px; }
.niche-table { font-size: 13px; }
.niche-table th[scope="row"] { font-weight: 400; color: var(--text); background: transparent; font-size: 14px; }
.niche-table tfoot td { font-weight: 600; background: #fafbfc; }
.kv-table th[scope="row"] { width: 52%; }
.niche-table tr.is-mine td, .niche-table tr.is-mine th { background: var(--good-cell); font-weight: 600; }
.my-seller p { margin: 8px 0 0; }

/* Страница расширения */
.steps { padding-left: 22px; }
.steps li { margin-bottom: 12px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 4px 12px; margin: 8px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.kv-table { max-width: 820px; }
.kv-table td.num[colspan] { text-align: left; }
