:root {
  color-scheme: light;
  --plane: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #101828;
  --ink-2: #475467;
  --muted: #8a94a6;
  --hairline: #e8ebf1;
  --baseline: #cfd5e0;
  --accent: #2563eb;
  --accent-soft: #eef3ff;
  --good: #12b76a;
  --good-soft: #e9faf1;
  --seeding: #2a78d6;
  --target: #eb6834;
  /* one hue per product, validated for colour-blind separation in both themes */
  --p-green: #008300;
  --p-blue: #2a78d6;
  --p-compost: #eb6834;
  --p-scent: #4a3aa7;
  --p-other: #8a94a6;
  --tint-blue: #eef3ff;
  --tint-green: #e9faf1;
  --tint-violet: #f2f1fe;
  --tint-orange: #fff2ea;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .04);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane: #0c0f14;
    --surface: #161a21;
    --surface-2: #1b2028;
    --ink: #f5f7fa;
    --ink-2: #b9c1cf;
    --muted: #8a94a6;
    --hairline: #262c36;
    --baseline: #39404c;
    --accent: #4b86f7;
    --accent-soft: #1b2740;
    --good: #2ecb84;
    --good-soft: #14301f;
    --seeding: #3987e5;
    --target: #d95926;
    --p-green: #008300;
    --p-blue: #3987e5;
    --p-compost: #d95926;
    --p-scent: #9085e9;
    --p-other: #8a94a6;
    --tint-blue: #18233a;
    --tint-green: #14301f;
    --tint-violet: #221f3a;
    --tint-orange: #33221a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0c0f14;
  --surface: #161a21;
  --surface-2: #1b2028;
  --ink: #f5f7fa;
  --ink-2: #b9c1cf;
  --muted: #8a94a6;
  --hairline: #262c36;
  --baseline: #39404c;
  --accent: #4b86f7;
  --accent-soft: #1b2740;
  --good: #2ecb84;
  --good-soft: #14301f;
  --seeding: #3987e5;
  --target: #d95926;
  --p-green: #008300;
  --p-blue: #3987e5;
  --p-compost: #d95926;
  --p-scent: #9085e9;
  --p-other: #8a94a6;
  --tint-blue: #18233a;
  --tint-green: #14301f;
  --tint-violet: #221f3a;
  --tint-orange: #33221a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.sprite { position: absolute; }
.icon {
  width: 16px; height: 16px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.muted { color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card--pad { padding: 20px 22px 18px; }
.card__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 14px;
}

/* ---------- header ---------- */
.topbar {
  display: flex; flex-wrap: wrap; gap: 10px 24px;
  align-items: center; justify-content: space-between;
  padding: 20px 28px 14px; max-width: 1400px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand__mark {
  width: 34px; height: 34px; border-radius: 11px; background: var(--tint-blue);
  display: grid; place-items: center;
}
.brand__mark span {
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent); box-shadow: inset -4px -4px 0 rgba(255, 255, 255, .55);
}
h1 { font-size: 19px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
.topbar__meta { display: flex; flex-wrap: wrap; gap: 20px; font-size: 13px; color: var(--ink-2); }
.meta { display: inline-flex; align-items: center; gap: 7px; }
.meta .icon { color: var(--muted); }

/* ---------- tabs ---------- */
.tabs {
  display: flex; gap: 10px; flex-wrap: wrap;
  padding: 6px 28px 16px; max-width: 1400px; margin: 0 auto;
}
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  appearance: none; font: inherit; font-size: 14px; cursor: pointer;
  background: var(--surface); color: var(--ink-2);
  border: 1px solid var(--hairline); border-radius: 11px;
  padding: 9px 16px; box-shadow: var(--shadow);
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] {
  background: var(--accent); color: #fff; border-color: transparent; font-weight: 600;
}
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- filters ---------- */
.filterbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; font-size: 13px;
  max-width: 1400px; margin: 0 auto 18px; width: calc(100% - 56px);
}
.filterbar__label {
  font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.filterbar__actions { display: inline-flex; gap: 14px; margin-left: auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  appearance: none; font: inherit; font-size: 13px; cursor: pointer;
  border: 1px solid var(--hairline); background: var(--surface-2); color: var(--ink-2);
  border-radius: 9px; padding: 4px 11px; white-space: nowrap;
}
.chip:hover { border-color: var(--baseline); }
.chip[aria-pressed="true"] {
  background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600;
}
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dategroup { display: inline-flex; gap: 12px; }
.dateinput { color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.dateinput input {
  font: inherit; font-size: 13px; color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--hairline); border-radius: 8px; padding: 4px 8px;
}
.linkbtn {
  appearance: none; border: 0; background: none; font: inherit; font-size: 13px;
  color: var(--accent); cursor: pointer; padding: 2px;
}
.linkbtn:hover { text-decoration: underline; }

/* ---------- layout ---------- */
main { padding: 0 28px 60px; max-width: 1400px; margin: 0 auto; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 18px; align-items: start; }
.aside { display: grid; gap: 18px; }
@media (max-width: 1080px) { .split { grid-template-columns: 1fr; } }

h2 {
  font-size: 15px; font-weight: 620; color: var(--ink); margin: 0; letter-spacing: -0.005em;
}
h2.mt { margin-top: 26px; margin-bottom: 12px; }

/* ---------- kpi ---------- */
.kpis {
  display: grid; gap: 16px; margin-bottom: 18px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}
.kpi {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px;
}
.kpi__icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.kpi__icon .icon { width: 20px; height: 20px; }
.kpi__label { font-size: 13px; color: var(--ink-2); }
.kpi__value {
  font-size: 24px; font-weight: 650; letter-spacing: -0.02em; margin-top: 2px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.kpi__value.is-good { color: var(--good); }

/* ---------- aside summary cards ---------- */
.sum { padding: 16px 18px 18px; }
.sum__head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.sum__icon { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.sum__title { font-size: 15px; font-weight: 620; }
.sum__title small { color: var(--muted); font-weight: 400; font-size: 13px; }
.sum__more {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px;
  color: var(--accent); font-size: 13px; background: none; border: 0; cursor: pointer; font-family: inherit;
}
.sum__more:hover { text-decoration: underline; }
.grid {
  display: grid; border: 1px solid var(--hairline); border-radius: 10px; overflow: hidden;
}
.grid + .grid { margin-top: 10px; }
.grid--4 { grid-template-columns: repeat(4, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.cell { padding: 9px 12px; border-right: 1px solid var(--hairline); min-width: 0; }
.cell:last-child { border-right: 0; }
.cell__k { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.cell__v {
  /* narrow cells: let a long compact number wrap instead of running into its neighbour */
  font-size: 14.5px; font-weight: 600; margin-top: 3px;
  /* wrap between number and unit, never inside "тыс." */
  font-variant-numeric: tabular-nums; white-space: normal; overflow-wrap: normal;
  letter-spacing: -0.01em;
}
.cell__v.is-good { color: var(--good); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--hairline); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 11px 14px; text-align: right; white-space: nowrap; }
thead th { background: var(--surface-2); color: var(--muted); font-weight: 500; font-size: 12.5px; }
tbody td { border-top: 1px solid var(--hairline); font-size: 14px; }
th:first-child, td:first-child { text-align: left; }
tbody tr:hover td { background: var(--surface-2); }
tr.is-off td { color: var(--muted); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--good-soft); color: var(--good);
  border-radius: 999px; padding: 3px 10px; font-size: 12.5px; font-weight: 600;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge {
  display: inline-block; margin-left: 8px; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--hairline);
  font-size: 11.5px; color: var(--muted);
}
.swatch { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 8px; }

/* ---------- charts ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--hairline); stroke-width: 1; }
.chart .axis { stroke: var(--baseline); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .bar { rx: 5; }
.chart .crosshair { stroke: var(--baseline); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hit { fill: transparent; cursor: crosshair; }
/* neutral, so it never competes with a product that is literally green */
.chart .target-line { stroke: var(--baseline); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .target-label { fill: var(--muted); font-size: 11px; font-weight: 600; }
.chart .value { fill: var(--ink-2); font-size: 12px; font-weight: 600; }

.tip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 10px;
  padding: 9px 11px; font-size: 12.5px; white-space: nowrap;
  box-shadow: 0 8px 26px rgba(16, 24, 40, .14);
  font-variant-numeric: tabular-nums;
}
.tip__head { color: var(--muted); font-size: 11.5px; margin-bottom: 5px; }
.tip__row { display: flex; gap: 14px; justify-content: space-between; }
.tip__row b { font-weight: 600; }

.scatters {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}
.scatter { border: 1px solid var(--hairline); border-radius: 10px; padding: 12px 14px 10px; }
.scatter__head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.scatter__name { font-size: 13.5px; font-weight: 600; }
.scatter__note { font-size: 12px; color: var(--muted); margin-top: 8px; line-height: 1.4; }
.scatter__note b { color: var(--ink-2); font-weight: 600; }
.scatter__warn { color: #b25f00; }
.chart .point { stroke: var(--surface); stroke-width: 1.5; }
.chart .trend { stroke-width: 2; stroke-dasharray: 6 4; fill: none; opacity: .75; }

.legend { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; }

.toggle { display: inline-flex; gap: 8px; align-items: center; font-size: 13px; color: var(--ink-2); }
.hint {
  display: flex; gap: 9px; align-items: flex-start;
  margin: 18px 0 0; padding: 11px 13px; border-radius: 10px;
  background: var(--accent-soft); color: var(--ink-2); font-size: 12.5px; line-height: 1.45;
}
.hint .icon { color: var(--accent); margin-top: 1px; }
.error { margin: 24px 28px; color: #d03b3b; }
.empty { color: var(--muted); font-size: 13.5px; padding: 22px 0; }

@media (max-width: 640px) {
  .topbar, .tabs, main { padding-left: 16px; padding-right: 16px; }
  .filterbar { width: calc(100% - 32px); }
  .card--pad { padding: 16px 14px; }
  h1 { font-size: 17px; }
}
