/* Ценовой радар.
   Макет: шапка со статусом магазинов → сводка → панель фильтров → (сравнение сетей) → таблица на всю ширину.
   Образ — магазинный ценник: скидка, подтверждённая историей, — жёлтый ценник, как на полке. */
:root {
  --bg: #f2f3f5; --surface: #ffffff; --surface-2: #f7f8fa; --line: #e3e5e9; --line-strong: #c9cdd3;
  --ink: #15171a; --ink-2: #3f444b; --muted: #6a7079;
  --tag: #ffd60a; --tag-ink: #1a1600; --tag-soft: #fff5c2;
  --good: #11743b; --good-soft: #e2f3e9; --bad: #b9342a; --bad-soft: #fbe8e6; --warn: #9a5800; --warn-soft: #fdefd9;
  --focus: #2457d6; --btn: #15171a; --btn-ink: #ffffff;
  --metro: #0b3d91; --magnit: #d52b1e; --vkusvill: #2b9348; --globus: #c98a00;
  --photo: #ffffff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .07);
  --shadow-pop: 0 20px 48px -12px rgba(16, 24, 40, .28);
  --font: "Onest", "Segoe UI", system-ui, -apple-system, sans-serif;
  --r: 12px; --r-sm: 8px; --r-xs: 5px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1113; --surface: #171a1d; --surface-2: #1d2125; --line: #2a2f35; --line-strong: #3b4148;
    --ink: #eceef0; --ink-2: #c6cbd1; --muted: #9aa1a9;
    --tag-soft: #3a3311; --good: #55c785; --good-soft: #14301f; --bad: #ff7d71; --bad-soft: #3a1a17;
    --warn: #f1aa4c; --warn-soft: #35270f; --focus: #8aa8ff; --btn: #eceef0; --btn-ink: #15171a;
    --metro: #7aa2ff; --magnit: #ff6f62; --vkusvill: #5fcb7d; --globus: #f2c14e; --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1113; --surface: #171a1d; --surface-2: #1d2125; --line: #2a2f35; --line-strong: #3b4148;
  --ink: #eceef0; --ink-2: #c6cbd1; --muted: #9aa1a9;
  --tag-soft: #3a3311; --good: #55c785; --good-soft: #14301f; --bad: #ff7d71; --bad-soft: #3a1a17;
  --warn: #f1aa4c; --warn-soft: #35270f; --focus: #8aa8ff; --btn: #eceef0; --btn-ink: #15171a;
  --metro: #7aa2ff; --magnit: #ff6f62; --vkusvill: #5fcb7d; --globus: #f2c14e; --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 14px/1.45 var(--font); }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.wrap { max-width: 1440px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px)); }

/* ---------- шапка */
.header { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.header .wrap { display: flex; align-items: center; gap: 12px 20px; min-height: 60px; flex-wrap: wrap; padding-block: 8px; }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.logo svg { width: 28px; height: 28px; flex: none; }
.stores-status { display: flex; gap: 6px; flex-wrap: wrap; }
.sstat { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line); font-size: 12.5px; color: var(--ink-2); white-space: nowrap; }
.sstat b { font-weight: 600; color: var(--ink); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.ok { background: var(--good); } .dot.run { background: var(--focus); animation: pulse 1.2s ease-in-out infinite; }
.dot.err, .dot.old { background: var(--bad); }
@keyframes pulse { 50% { opacity: .35; } }
.spacer { flex: 1; }
.hlinks { display: flex; align-items: center; gap: 4px; }
.hbtn { height: 34px; padding: 0 12px; border-radius: var(--r-sm); border: 1px solid transparent; background: transparent;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-weight: 500; }
.hbtn:hover { background: var(--surface-2); border-color: var(--line); color: var(--ink); }
.hbtn svg { width: 16px; height: 16px; }

/* ---------- сводка */
.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 20px 0 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow);
  display: grid; gap: 4px; text-align: left; }
button.kpi { cursor: pointer; font: inherit; color: inherit; }
button.kpi:hover { border-color: var(--line-strong); }
button.kpi[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.kpi .k { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.kpi .v { font-size: 28px; line-height: 34px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12.5px; color: var(--muted); }
.kpi .bar { height: 6px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; margin-top: 4px; }
.kpi .bar i { display: block; height: 100%; background: var(--ink); }

/* ---------- ценник */
.tag { display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 9px 0 13px; position: relative;
  background: var(--tag); color: var(--tag-ink); border-radius: 4px 6px 6px 4px; font-weight: 700; font-size: 14px;
  font-variant-numeric: tabular-nums; white-space: nowrap; }
.tag::before { content: ""; position: absolute; left: 5px; top: 50%; width: 4px; height: 4px; margin-top: -2px;
  border-radius: 50%; background: var(--surface); }
.tag.soft { background: var(--tag-soft); color: var(--ink); }
.tag.plain { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); font-weight: 600; }
.tag.plain::before { background: var(--line-strong); }

/* ---------- фильтры */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.filters { padding: 16px; display: grid; gap: 14px; }
.frow { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; }
.field { display: grid; gap: 6px; min-width: 0; }
.flabel { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.input, .select { height: 40px; border-radius: var(--r-sm); border: 1px solid var(--line-strong); background: var(--surface);
  padding: 0 12px; min-width: 0; }
.input:hover, .select:hover { border-color: var(--muted); }
.search { flex: 1 1 320px; position: relative; }
.search .input { width: 100%; padding-left: 38px; font-size: 15px; }
.search svg { position: absolute; left: 12px; bottom: 12px; width: 16px; height: 16px; color: var(--muted); }
.search kbd { position: absolute; right: 10px; bottom: 10px; font: 500 11px var(--font); padding: 1px 6px; border-radius: 4px;
  border: 1px solid var(--line-strong); color: var(--muted); }
.fsel { flex: 0 1 230px; }
.fsel .select { width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; display: inline-flex; align-items: center; gap: 7px; height: 40px; padding: 0 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--surface); cursor: pointer; user-select: none; font-weight: 500; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:has(input:checked) { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.chip:has(input:not(:checked)) { color: var(--muted); }
.chip:has(input:not(:checked)) .dot { opacity: .35; }
.chip:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { height: 32px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent; cursor: pointer;
  color: var(--ink-2); font-weight: 500; white-space: nowrap; }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow), 0 0 0 1px var(--line); font-weight: 600; }
.range { display: flex; align-items: center; gap: 10px; height: 40px; }
.range input { width: 150px; accent-color: var(--ink); }
.range output { min-width: 40px; font-weight: 600; font-variant-numeric: tabular-nums; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; min-height: 40px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; color: var(--ink-2); }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--ink); }
.hint { font-size: 12.5px; color: var(--muted); margin: 0; max-width: 90ch; }

/* ---------- сравнение сетей */
.compare { margin-top: 16px; padding: 16px; display: grid; gap: 12px; }
.compare h3 { margin: 0; font-size: 15px; font-weight: 600; }
.cmp-rows { display: grid; gap: 8px; }
.cmp { display: grid; grid-template-columns: 120px 1fr 300px; gap: 12px; align-items: center; }
.cmp .track { position: relative; height: 22px; background: var(--surface-2); border-radius: 4px; border: 1px solid var(--line); }
.cmp .range-bar { position: absolute; top: 4px; bottom: 4px; border-radius: 3px; opacity: .28; }
.cmp .mark { position: absolute; top: 1px; bottom: 1px; width: 3px; border-radius: 2px; }
.cmp .val { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--ink-2); text-align: right; }
.cmp .val b { color: var(--ink); }
.cmp-axis { display: grid; grid-template-columns: 120px 1fr 300px; gap: 12px; font-size: 11.5px; color: var(--muted); }
.cmp-axis div:nth-child(2) { display: flex; justify-content: space-between; }

/* ---------- результаты */
.results { margin: 16px 0 40px; overflow: hidden; }
.rhead { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.rhead h2 { font-size: 15px; margin: 0; font-weight: 600; }
.rhead .count { color: var(--muted); font-variant-numeric: tabular-nums; }
.notice { margin: 12px 16px 0; padding: 10px 14px; border-radius: var(--r-sm); background: var(--tag-soft); color: var(--ink);
  font-size: 13px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.notice .pbar { width: 140px; height: 6px; border-radius: 3px; background: rgba(0,0,0,.08); overflow: hidden; }
.notice .pbar i { display: block; height: 100%; background: var(--ink); }
.tscroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1040px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 0; background: var(--surface-2);
  border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; }
th > button, th > span { display: flex; align-items: center; gap: 4px; width: 100%; padding: 10px 12px; border: 0; background: none;
  color: inherit; font: inherit; text-align: left; cursor: pointer; }
th > span { cursor: default; }
th.r > button, th.r > span { justify-content: flex-end; }
th > button:hover { color: var(--ink); }
th > button::after { content: "↕"; opacity: .4; }
th[aria-sort] > button { color: var(--ink); }
th[aria-sort="ascending"] > button::after { content: "↑"; opacity: 1; }
th[aria-sort="descending"] > button::after { content: "↓"; opacity: 1; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
td.r { text-align: right; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr.sel td { background: var(--tag-soft); }
tr.out td { opacity: .55; }
.prod { display: flex; gap: 12px; align-items: center; min-width: 300px; }
.thumb { width: 48px; height: 48px; flex: none; border-radius: var(--r-xs); background: var(--photo); object-fit: contain;
  border: 1px solid var(--line); padding: 2px; }
.pname { font-weight: 500; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.psub { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.store { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.price { font-weight: 700; font-size: 15px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.old { display: block; font-size: 12px; color: var(--muted); text-decoration: line-through; font-weight: 400; }
.unitp { white-space: nowrap; font-variant-numeric: tabular-nums; }
.unitp small { color: var(--muted); }
.disc { display: grid; gap: 3px; justify-items: end; }
.disc small { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.mkt { display: grid; gap: 4px; min-width: 170px; }
.mbar { position: relative; height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--good-soft), var(--surface-2) 50%, var(--bad-soft));
  border: 1px solid var(--line); }
.mbar i { position: absolute; top: -4px; width: 4px; height: 12px; margin-left: -2px; border-radius: 2px; background: var(--ink); }
.mkt small { font-size: 12px; color: var(--muted); white-space: nowrap; }
.mkt small.warn { color: var(--warn); font-weight: 500; }
.pills { display: flex; flex-wrap: wrap; gap: 4px; max-width: 260px; }
.pill { font-size: 11.5px; line-height: 20px; padding: 0 7px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line);
  color: var(--ink-2); white-space: nowrap; }
.pill.good { background: var(--good-soft); border-color: transparent; color: var(--good); }
.pill.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.pill.bad { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.more { display: flex; justify-content: center; padding: 16px; }
.btn { height: 40px; padding: 0 16px; border-radius: var(--r-sm); border: 1px solid var(--line-strong); background: var(--surface);
  cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--btn); color: var(--btn-ink); border-color: var(--btn); }
.btn.primary:hover { opacity: .9; }
.btn:disabled { opacity: .5; cursor: default; }
.empty { padding: 56px 16px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 6px; }

/* ---------- карточка товара */
.scrim { position: fixed; inset: 0; background: rgba(15, 17, 19, .35); z-index: 30; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--surface); z-index: 31;
  box-shadow: var(--shadow-pop); display: flex; flex-direction: column; }
.drawer header { display: flex; gap: 14px; padding: 18px 18px 14px; border-bottom: 1px solid var(--line); align-items: flex-start; }
.drawer header .thumb { width: 84px; height: 84px; }
.drawer h2 { font-size: 17px; line-height: 1.3; margin: 0 0 6px; font-weight: 600; text-wrap: balance; }
.drawer .body { padding: 16px 18px 24px; overflow-y: auto; display: grid; gap: 20px; }
.close { margin-left: auto; width: 36px; height: 36px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; display: grid; place-items: center; flex: none; }
.close:hover { background: var(--surface-2); }
.kvs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.kv .k { font-size: 12.5px; color: var(--muted); }
.kv .v { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kv .s { font-size: 12.5px; color: var(--muted); }
.sect h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font: 400 11px var(--font); font-variant-numeric: tabular-nums; }
.elsewhere { display: grid; gap: 6px; }
.elsewhere div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 12px; border-radius: var(--r-sm); background: var(--surface-2); }
.changes { display: grid; gap: 4px; font-size: 13px; }
.changes div { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border-bottom: 1px solid var(--line); }

/* ---------- вход */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: min(400px, 100%); padding: 28px; display: grid; gap: 18px; }
.login h1 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
.login p { margin: 0; color: var(--muted); }
.login .input { width: 100%; }
.login .btn { width: 100%; justify-content: center; height: 44px; }
.alert { padding: 10px 12px; border-radius: var(--r-sm); background: var(--bad-soft); color: var(--bad); font-size: 13px; }

/* ---------- админка */
.admin { display: grid; gap: 16px; margin: 20px 0 40px; }
.admin .panel { padding: 16px; }
.admin h2 { margin: 0 0 12px; font-size: 16px; }
.admin table { min-width: 760px; }
.admin td, .admin th > span { font-size: 13.5px; }
.log { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px; max-height: 360px; overflow: auto;
  font: 12px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace; white-space: pre-wrap; margin: 0; }
.form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.form-row .field { flex: 1 1 220px; }
.ok-msg { color: var(--good); font-size: 13px; }
.err-msg { color: var(--bad); font-size: 13px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

@media (max-width: 1000px) {
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .summary { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi .v { font-size: 22px; line-height: 28px; }
  .fsel { flex: 1 1 100%; }
  .cmp, .cmp-axis { grid-template-columns: 84px 1fr; }
  .cmp .val, .cmp-axis div:nth-child(3) { grid-column: 1 / -1; text-align: left; }
  .kvs { grid-template-columns: 1fr; }
  .header .stores-status { order: 3; width: 100%; }
  .sstat .t { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
