:root {
  --bg: #f4f5f7; --panel: #ffffff; --panel-2: #f0f1f4; --text: #1b1d22; --muted: #646b78;
  --line: #e1e3e8; --accent: #4f5bd5; --accent-text: #fff; --good: #1e9e5a; --warn: #c27a10;
  --bad: #c9393e; --good-bg: #e3f5eb; --warn-bg: #fbf0dc; --bad-bg: #fbe5e6; --accent-bg: #e8eafb;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  --c-median: #4f5bd5; --c-min: #1e9e5a;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171c; --panel: #1d2027; --panel-2: #252932; --text: #e7e9ee; --muted: #9aa1ae;
    --line: #2f343e; --accent: #7c86f0; --accent-text: #0f1115; --good: #4cc68a; --warn: #e6a54a;
    --bad: #f07378; --good-bg: #1b3428; --warn-bg: #3a2e1a; --bad-bg: #3d2224; --accent-bg: #272c4a;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --c-median: #8b94f5; --c-min: #4cc68a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.topbar { position: sticky; top: 0; z-index: 10; background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; padding: 10px 20px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.status { color: var(--muted); font-size: 13px; flex: 1; min-width: 160px; }
.status .busy { color: var(--accent); font-weight: 600; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.btn { border: 1px solid var(--line); background: var(--panel); padding: 7px 12px; border-radius: 8px;
  cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }

.bell { position: relative; }
.bell .count { position: absolute; top: -6px; right: -6px; background: var(--bad); color: #fff; font-size: 11px;
  font-weight: 700; border-radius: 10px; padding: 1px 6px; }

.tabs { display: flex; gap: 4px; padding: 0 20px; background: var(--panel); border-bottom: 1px solid var(--line);
  overflow-x: auto; }
.tab { padding: 10px 14px; border: 0; background: none; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

main { max-width: 1240px; margin: 0 auto; padding: 20px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px;
  box-shadow: var(--shadow); margin-bottom: 16px; }
.panel h2 { margin: 0 0 12px; font-size: 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-head h2 { margin: 0; }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 28px; text-align: center; }

.alerts { display: grid; gap: 12px; }
.alert { display: grid; grid-template-columns: 84px 1fr auto; gap: 14px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; padding: 14px; box-shadow: var(--shadow); }
.alert.unread { border-left: 4px solid var(--accent); }
.alert img { width: 84px; height: 84px; object-fit: contain; background: #fff; border-radius: 8px; }
.alert .title { font-weight: 600; }
.alert .meta { color: var(--muted); font-size: 13px; margin-top: 4px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.alert .comment { margin-top: 8px; }
.alert .reasons { margin-top: 4px; color: var(--muted); font-size: 13px; font-style: italic; }
.alert .price-box { text-align: right; min-width: 150px; }
.price { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.delta { font-weight: 600; color: var(--good); }
.delta.up { color: var(--bad); }
@media (max-width: 640px) {
  .alert { grid-template-columns: 64px 1fr; }
  .alert img { width: 64px; height: 64px; }
  .alert .price-box { grid-column: 1 / -1; text-align: left; }
}

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.accent { background: var(--accent-bg); color: var(--accent); }

.groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin-bottom: 14px; }
.group { border: 1px solid var(--line); border-radius: 10px; padding: 12px; cursor: pointer; background: var(--panel); }
.group.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-bg); }
.group .cap { font-weight: 700; font-size: 18px; }
.group dl { margin: 6px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 13px; }
.group dt { color: var(--muted); }
.group dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.chart { width: 100%; overflow-x: auto; }
.chart svg { display: block; width: 100%; height: auto; min-width: 480px; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid { stroke: var(--line); }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 12px; height: 3px; vertical-align: middle; margin-right: 5px; border-radius: 2px; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel-2); }
tr.dim td { opacity: .55; }
.prod { max-width: 460px; }
.prod small { display: block; color: var(--muted); }

select, input[type=text], input[type=number], input[type=password], textarea {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 10px; }
textarea { width: 100%; min-height: 72px; resize: vertical; }
label.field { display: grid; gap: 4px; font-size: 13px; }
label.field span { color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.checks { display: flex; gap: 14px; flex-wrap: wrap; }
.checks label { display: flex; gap: 6px; align-items: center; }

.stores { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.store { border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.store .name { font-weight: 700; display: flex; justify-content: space-between; gap: 8px; }
.store .msg { color: var(--muted); font-size: 12px; margin-top: 6px; word-break: break-word; }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start;
  justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 14px; width: min(760px, 100%); padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal h3 { margin: 0 0 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

.toast-box { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; max-width: 360px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: 13px; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(360px, 100%); }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.login form { display: grid; gap: 12px; margin-top: 16px; }
.error { color: var(--bad); font-size: 13px; }
