:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --grid: #ebeae6;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7973;
  --accent: #2a78d6;
  --s-normal: #2a78d6;
  --s-new: #eb6834;
  --s-flag: #a3a29b;
  --good: #0ca30c;
  --good-text: #006300;
  --warn: #fab219;
  --crit: #d03b3b;
  --crit-bg: #fbe9e9;
  --new-bg: #fdeee7;
  --fav: #c98500;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2f2f2c;
    --grid: #2a2a27;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #3987e5;
    --s-normal: #3987e5;
    --s-new: #d95926;
    --s-flag: #6b6a64;
    --good-text: #4cc94c;
    --crit-bg: #3a1e1e;
    --new-bg: #3a2418;
    --fav: #eda100;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c; --grid: #2a2a27;
  --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e86; --accent: #3987e5;
  --s-normal: #3987e5; --s-new: #d95926; --s-flag: #6b6a64; --good-text: #4cc94c;
  --crit-bg: #3a1e1e; --new-bg: #3a2418; --fav: #eda100;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
button, input, select { font: inherit; color: inherit; }
input, select { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; }
input[type=number] { width: 7em; }

.top { position: sticky; top: 0; z-index: 5; display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.tab { border: 1px solid transparent; background: none; padding: 5px 12px; border-radius: 999px; cursor: pointer; color: var(--text-2); }
.tab[aria-selected=true] { background: var(--surface-2); border-color: var(--border); color: var(--text); font-weight: 600; }
.tab .off { font-size: 11px; color: var(--muted); }
.run { display: flex; gap: 12px; align-items: center; }
.btn { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 6px 14px; cursor: pointer; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn:disabled { opacity: .6; cursor: default; }

main { padding: 16px 24px 40px; max-width: 1500px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }

.runlog pre { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px;
  font-size: 12px; max-height: 220px; overflow: auto; white-space: pre-wrap; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; }
.kpi .label { color: var(--text-2); font-size: 12px; }
.kpi .value { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi .sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.filters { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; color: var(--text-2); }
.filters label { display: inline-flex; gap: 6px; align-items: center; }
.filters .chk input { margin: 0; }
.more summary { cursor: pointer; }
.more[open] { display: inline-flex; gap: 14px; }

.grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; }
.side { display: flex; flex-direction: column; gap: 16px; }
.side .card label { display: flex; gap: 6px; align-items: center; margin: 4px 0; }
.chart { width: 100%; height: 380px; }
.chart svg { width: 100%; height: 100%; display: block; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.hint { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.ref-price { font-size: 22px; font-weight: 600; }
#checklist ul { margin: 0; padding-left: 18px; color: var(--text-2); }
#checklist li { margin: 4px 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: left; font-weight: 600; font-size: 12px; color: var(--text-2); padding: 6px 8px; border-bottom: 1px solid var(--border);
  white-space: nowrap; cursor: pointer; user-select: none; }
th.num, td.num { text-align: right; }
th[aria-sort=ascending]::after { content: " ▲"; }
th[aria-sort=descending]::after { content: " ▼"; }
td { padding: 7px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
tbody tr.row { cursor: pointer; }
tbody tr.row:hover { background: var(--surface-2); }
tr.is-new td:first-child { box-shadow: inset 3px 0 0 var(--s-new); }
tr.is-removed { opacity: .55; }
tr.is-removed .price { text-decoration: line-through; }
tr.is-ref { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.cfg { min-width: 220px; }
.cfg .gpu { font-weight: 600; }
.cfg .rest { color: var(--text-2); font-size: 12px; }
.title-sm { color: var(--muted); font-size: 12px; max-width: 360px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.old { color: var(--muted); text-decoration: line-through; font-size: 12px; margin-left: 4px; }
.delta-down { color: var(--good-text); font-size: 12px; }
.delta-up { color: var(--crit); font-size: 12px; }
.badge { display: inline-block; font-size: 11px; line-height: 1; padding: 3px 6px; border-radius: 4px; margin: 0 4px 3px 0;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.badge.new { background: var(--new-bg); color: var(--text); border-color: var(--s-new); }
.badge.crit { background: var(--crit-bg); color: var(--crit); border-color: var(--crit); }
.badge.good { color: var(--good-text); border-color: var(--good); }
.seller.low { color: var(--crit); font-weight: 600; }
.value-bar { display: inline-flex; align-items: center; gap: 6px; justify-content: flex-end; }
.value-bar b { font-weight: 600; min-width: 3ch; }
.value-bar i { display: inline-block; height: 6px; border-radius: 3px; background: var(--s-normal); }
.value-bar.better b { color: var(--good-text); }
.act { white-space: nowrap; }
.icon-btn { border: none; background: none; cursor: pointer; padding: 2px 4px; font-size: 16px; color: var(--muted); border-radius: 4px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.on { color: var(--fav); }
tr.detail td { background: var(--surface-2); }
.detail-grid { display: grid; grid-template-columns: 280px 1fr; gap: 16px; }
.detail-grid .desc { white-space: pre-wrap; color: var(--text-2); font-size: 13px; max-height: 220px; overflow: auto; }
.detail-grid textarea { width: 100%; min-height: 54px; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px; font: inherit; }
.runs td, .runs th { font-size: 12px; }
.st-ok { color: var(--good-text); }
.st-blocked, .st-error { color: var(--crit); }

.tip { position: fixed; z-index: 20; pointer-events: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgb(0 0 0 / .15); max-width: 300px; }
.tip b { font-size: 13px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

@media (max-width: 1000px) {
  .grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .top, main { padding-left: 16px; padding-right: 16px; }
  .chart { height: 300px; }
  .kpi .value { font-size: 22px; }
}
[hidden] { display: none !important; }
td.num, td.nw { white-space: nowrap; }
.msgr { display: flex; gap: 8px; align-items: center; }
.tpls { margin: 4px 0 6px; }
.tpl { cursor: pointer; font: inherit; font-size: 11px; }
.tpl:hover { border-color: var(--accent); color: var(--text); }
.msg-actions { display: flex; gap: 10px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.msgs { margin-bottom: 6px; font-size: 13px; }
.msg { padding: 3px 0; }
.msg .err { color: var(--crit); font-size: 12px; }
.badge.warn { border-color: var(--warn); color: var(--text); white-space: normal; }
.offline { background: var(--crit-bg); border: 1px solid var(--crit); border-radius: 10px; padding: 10px 14px; }

body[data-mode="public"] #runBtn, body[data-mode="admin"] #runBtn,
body:not([data-mode="local"]) #schedCard, body:not([data-mode="local"]) #recheckBtn { display: none !important; }
.msgr a.btn { text-decoration: none; color: var(--text); }
.panel { position: fixed; inset: 0; z-index: 30; background: rgb(0 0 0 / .45); display: flex; justify-content: center; align-items: flex-start; padding: 40px 16px; overflow: auto; }
.panel-box { width: min(900px, 100%); }
.form-grid { display: grid; grid-template-columns: minmax(180px, 260px) 1fr; gap: 6px 14px; align-items: center; margin: 6px 0 14px; }
.form-grid label { color: var(--text-2); font-size: 13px; }
.form-grid textarea { width: 100%; min-height: 70px; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px; font: inherit; }
.form-grid input[type=text] { width: 100%; }
fieldset { border: 1px solid var(--border); border-radius: 8px; margin: 10px 0; padding: 6px 12px; }
legend { color: var(--text-2); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 0 6px; }
.login { max-width: 360px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.changed { border-color: var(--warn) !important; }
