:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11,11,11,0.10);
  --shadow: 0 1px 2px rgba(11,11,11,.05), 0 8px 24px -12px rgba(11,11,11,.18);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --good: #0ca30c; --warning: #fab219; --critical: #d03b3b;
  --pos: #006300; --neg: #d03b3b;
  --accent: #2a78d6;
  --ghost: rgba(42,120,214,.08);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --plane: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255,255,255,0.10);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --pos: #0ca30c; --neg: #e66767;
  --accent: #3987e5;
  --ghost: rgba(57,135,229,.14);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--plane);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- каркас ---------- */
.app { display: flex; min-height: 100vh; }
.side {
  width: 232px; flex: 0 0 232px; background: var(--surface-1);
  border-right: 1px solid var(--border); padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--accent);
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px;
}
.brand-name { font-weight: 650; letter-spacing: -.01em; }
.brand-sub { font-size: 11px; color: var(--muted); }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  cursor: pointer; color: var(--text-secondary); border: 1px solid transparent;
}
.nav-item:hover { background: var(--ghost); }
.nav-item.active { background: var(--ghost); color: var(--text-primary); font-weight: 600; border-color: var(--border); }
.nav-item svg { width: 17px; height: 17px; opacity: .8; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }

.main { flex: 1; min-width: 0; padding: 22px 26px 60px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.02em; font-weight: 650; }
.sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---------- фильтры ---------- */
.filters {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 18px;
}
.seg { display: flex; background: var(--plane); border: 1px solid var(--border); border-radius: 9px; padding: 2px; }
.seg button {
  border: 0; background: transparent; padding: 5px 11px; border-radius: 7px; cursor: pointer;
  color: var(--text-secondary); font-size: 13px;
}
.seg button.on { background: var(--surface-1); color: var(--text-primary); font-weight: 600; box-shadow: var(--shadow); }
.field { display: flex; flex-direction: column; gap: 3px; }
.field label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
input, select, textarea {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 9px; outline: none; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ghost); }
.spacer { flex: 1; }
.btn {
  border: 1px solid var(--border); background: var(--surface-1); border-radius: 9px;
  padding: 7px 13px; cursor: pointer; font-weight: 550; white-space: nowrap;
}
.btn:hover { background: var(--ghost); }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--critical); }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }

/* ---------- карточки ---------- */
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow);
}
.card h2 { font-size: 14px; margin: 0 0 2px; font-weight: 620; letter-spacing: -.01em; }
.card .hint { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 14px; }
@media (max-width: 1340px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 900px)  { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi .k-label { font-size: 12px; color: var(--muted); }
.kpi .k-value { font-size: 26px; font-weight: 620; letter-spacing: -.02em; margin-top: 4px; white-space: nowrap; }
table.dense th, table.dense td { padding: 6px 8px; font-size: 12.5px; }
.kpi .k-note { font-size: 12px; color: var(--text-secondary); margin-top: 3px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.cols-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 1100px) { .cols-2 { grid-template-columns: 1fr; } }

/* ---------- таблицы ---------- */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 8px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  font-weight: 600; cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--surface-1);
}
th:hover { color: var(--text-primary); }
tbody tr:hover { background: var(--ghost); }
tfoot td { font-weight: 650; border-top: 2px solid var(--axis); border-bottom: 0; }
td.name { font-weight: 600; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px;
  padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-secondary);
}
.dot { width: 8px; height: 8px; border-radius: 3px; display: inline-block; }
.link { color: var(--accent); cursor: pointer; }
.link:hover { text-decoration: underline; }

/* ---------- графики ---------- */
.chart { width: 100%; overflow: visible; }
.chart text { font-family: inherit; }
.axis-label { fill: var(--muted); font-size: 11px; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.axis-line { stroke: var(--axis); stroke-width: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: 12px; color: var(--text-secondary); }
.legend .item { display: flex; align-items: center; gap: 6px; }
.tooltip {
  position: fixed; z-index: 60; pointer-events: none; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; box-shadow: var(--shadow);
  font-size: 12px; min-width: 150px; opacity: 0; transition: opacity .1s;
}
.tooltip .t-title { font-weight: 650; margin-bottom: 5px; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 14px; }
.tooltip .t-row span:last-child { font-variant-numeric: tabular-nums; }

/* ---------- модалка ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(11,11,11,.45); display: none;
  align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 80; overflow-y: auto;
}
.overlay.on { display: flex; }
.modal { background: var(--surface-1); border-radius: 16px; border: 1px solid var(--border);
  width: min(880px, 100%); box-shadow: 0 24px 64px -20px rgba(0,0,0,.5); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.x { border: 0; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--text-primary); color: var(--surface-1); padding: 9px 16px;
  border-radius: 999px; z-index: 100; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.bar-track { height: 6px; border-radius: 3px; background: var(--grid); overflow: hidden; min-width: 70px; }
.bar-fill { height: 100%; border-radius: 3px; }
.hidden { display: none !important; }
@media (max-width: 820px) {
  .app { flex-direction: column; }
  .side { width: 100%; flex: none; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .brand { padding-bottom: 0; }
  .side-foot { margin: 0; flex-direction: row; }
  .main { padding: 16px; }
}
