:root {
  --bg: #0b0e14;
  --surface: #12161f;
  --surface-2: #181d28;
  --surface-3: #202634;
  --line: #262d3c;
  --line-strong: #343c4e;
  --text: #e8ebf1;
  --text-2: #a3abbb;
  --text-3: #6f7889;
  --accent: #ffc83d;
  --accent-hover: #ffd466;
  --on-accent: #1a1404;
  --series: #b88a10;
  --series-fill: rgba(184, 138, 16, 0.16);
  --good: #4cc38a;
  --bad: #ff6b6b;
  --warn: #f0a33a;
  --focus: #7aa2ff;
  --radius: 10px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f8;
    --surface: #ffffff;
    --surface-2: #f7f8fa;
    --surface-3: #eef0f4;
    --line: #e3e6ec;
    --line-strong: #cfd4dd;
    --text: #151922;
    --text-2: #4c5466;
    --text-3: #7c8496;
    --accent: #ffc83d;
    --accent-hover: #ffbb0f;
    --on-accent: #1a1404;
    --series: #a86b00;
    --series-fill: rgba(168, 107, 0, 0.12);
    --good: #18864f;
    --bad: #d33a3a;
    --warn: #b46a00;
    --focus: #2f5fd0;
    --shadow: 0 8px 30px rgba(20, 25, 35, 0.12);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }
.hidden { display: none !important; }

/* ---------- вход ---------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login form {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
}
.login h1 { margin: 0; font-size: 20px; display: flex; align-items: center; gap: 10px; }

/* ---------- каркас ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  height: 56px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; white-space: nowrap; }
.logo { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; flex: none; }
.logo svg { width: 16px; height: 16px; }
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.nav a {
  padding: 7px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-2);
  white-space: nowrap;
}
.nav a:hover { color: var(--text); background: var(--surface-3); }
.nav a.active { color: var(--text); background: var(--surface-3); font-weight: 600; }
.topbar .right { display: flex; align-items: center; gap: 8px; }

main { max-width: 1320px; margin: 0 auto; padding: 22px 20px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: 650; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card-pad { padding: 18px; }
.card h2 { margin: 0 0 4px; font-size: 15px; font-weight: 650; }
.card h3 { margin: 0 0 8px; font-size: 13px; font-weight: 650; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; }
.stack { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- элементы ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-3); color: var(--text); }
.btn.danger { color: var(--bad); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }

label.field { display: grid; gap: 5px; font-size: 13px; color: var(--text-2); }
label.field > span.hint { font-size: 12px; color: var(--text-3); }
.input, select.input, textarea.input {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--text);
}
textarea.input { height: auto; min-height: 90px; padding: 8px 10px; resize: vertical; }
.input:focus { border-color: var(--focus); outline: none; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; color: var(--text); font-size: 13.5px; }

.seg { display: inline-flex; max-width: 100%; overflow-x: auto; scrollbar-width: none; background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 9px; padding: 2px; }
.seg button { flex: none; }
.seg button {
  border: 0;
  background: transparent;
  color: var(--text-2);
  height: 28px;
  padding: 0 11px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}
.seg button.on { background: var(--surface-3); color: var(--text); font-weight: 600; box-shadow: 0 0 0 1px var(--line-strong); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 8px;
  border-radius: 99px;
  font-size: 12px;
  background: var(--surface-3);
  color: var(--text-2);
  white-space: nowrap;
}
.pill.good { color: var(--good); }
.pill.bad { color: var(--bad); }
.pill.warn { color: var(--warn); }
.pill.accent { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--text); }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--text-2); font-size: 12.5px; }
.kpi .value { font-size: 24px; font-weight: 650; margin-top: 2px; }
.kpi .sub { color: var(--text-3); font-size: 12px; margin-top: 2px; }

/* ---------- график ---------- */
.chart-wrap { position: relative; }
.chart { width: 100%; height: 220px; display: block; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--text-3); font-size: 11px; }
.chart .area { fill: var(--series-fill); }
.chart .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .cross { stroke: var(--line-strong); stroke-width: 1; }
.chart .dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12.5px;
  box-shadow: var(--shadow);
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 12px));
}

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { padding: 9px 12px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { font-size: 12px; font-weight: 600; color: var(--text-2); position: sticky; top: 0; background: var(--surface); }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tr.click { cursor: pointer; }
table.data tfoot td { font-weight: 650; border-bottom: 0; border-top: 1px solid var(--line-strong); }
table.data td.left, table.data th.left { text-align: left; }
table.data td.wrap { white-space: normal; min-width: 220px; }
.empty { padding: 36px 16px; text-align: center; color: var(--text-2); }

.crumbs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13.5px; }
.crumbs button { border: 0; background: none; color: var(--text-2); cursor: pointer; padding: 2px 4px; border-radius: 6px; }
.crumbs button:hover { color: var(--text); background: var(--surface-3); }
.crumbs .cur { font-weight: 600; }

.copy {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 4px 4px 10px;
  min-width: 0;
}
.copy code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
pre.code {
  margin: 0;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---------- модальные окна ---------- */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 12, 0.6);
  display: grid;
  place-items: start center;
  padding: 6vh 16px;
  overflow-y: auto;
  z-index: 50;
}
.modal {
  width: 100%;
  max-width: 760px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.modal header { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; font-size: 16px; flex: 1; }
.modal .body { padding: 18px; display: grid; gap: 16px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line); }

#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 100; }
.toast {
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--good);
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  max-width: 380px;
}
.toast.error { border-left-color: var(--bad); }

.note {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text-2);
  font-size: 13px;
}
.steps { margin: 0; padding-left: 18px; color: var(--text-2); display: grid; gap: 6px; }
.steps b { color: var(--text); font-weight: 600; }

@media (max-width: 720px) {
  .topbar { padding: 0 12px; gap: 10px; }
  .brand span { display: none; }
  main { padding: 16px 12px 48px; }
  .kpi .value { font-size: 20px; }
}
