:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --line: #cdd4db;
  --ink: #1f2a33;
  --muted: #66747f;
  --accent: #1f6feb;
  --accent-dark: #1858bd;
  --danger: #c0392b;
  --ok: #1e8449;
  --shadow: 0 2px 10px rgba(20, 35, 50, .10);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.4 "Segoe UI", Roboto, Arial, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- Шапка ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 30;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.logo { font-size: 18px; font-weight: 700; letter-spacing: .5px; color: var(--accent-dark); }
.ver { font-size: 11px; color: var(--muted); }

.mix-picker { display: flex; gap: 8px; align-items: center; flex: 1 1 420px; min-width: 320px; }
.mix-picker input[type="search"] { flex: 1 1 160px; min-width: 120px; }
.mix-picker select { flex: 2 1 260px; min-width: 180px; }

.top-actions { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.mix-label { font-size: 12px; color: var(--muted); max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-box { position: relative; display: flex; align-items: center; gap: 6px; }
.user-name { font-weight: 600; }

.dropdown {
  position: absolute; right: 0; top: 34px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); min-width: 220px; padding: 6px; z-index: 40;
}
.dropdown button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 8px 10px; border-radius: 6px; cursor: pointer; font: inherit;
}
.dropdown button:hover { background: #eef3fa; }

/* ---------- Поля и кнопки ---------- */
input, select {
  font: inherit; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 8px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(31,111,235,.15); }
input[type="number"] { width: 92px; }

.btn {
  font: inherit; cursor: pointer; border: 1px solid var(--line); background: #f7f9fb;
  color: var(--ink); border-radius: 6px; padding: 7px 12px;
}
.btn:hover { background: #eaf0f7; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { background: #fdecea; border-color: #f3b6ae; color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.wide { width: 100%; margin-bottom: 8px; }
.btn:disabled { opacity: .55; cursor: default; }

/* ---------- Каркас ---------- */
#app { zoom: var(--ui-zoom, 1); }
.layout {
  display: grid; grid-template-columns: 250px minmax(0, 1fr);
  gap: 12px; padding: 12px; align-items: start;
  height: calc(100vh / var(--ui-zoom, 1) - 57px);
}
.side { display: flex; flex-direction: column; font-size: 12.5px; }
.side .btn { padding: 5px 10px; font-size: 12.5px; }
.side .btn.wide { margin-bottom: 6px; }
.side .card { padding: 8px 10px; margin-top: 8px; }
.side .card-title { font-size: 10.5px; margin-bottom: 6px; }
.side .metrics dl { font-size: 12px; gap: 2px 8px; }
.side .metrics dd { font-size: 12px; }
.side-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 2px 0 6px; }
.content { display: flex; flex-direction: column; gap: 12px; min-width: 0; height: 100%; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin-top: 10px; box-shadow: var(--shadow);
}
.card-title { font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 8px; }

.metrics dl { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; margin: 0; }
.metrics dt { color: var(--muted); }
.metrics dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }

.side .progress-text { font-size: 11px; margin: 5px 0 6px; min-height: 26px; }
.side .issues ul { font-size: 11px; }
.chart-wrap {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px; box-shadow: var(--shadow); flex: 0 0 auto;
}
.chart-wrap img { width: 100%; height: auto; display: block; border-radius: 6px; }

.table-block {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column;
}
.block-head { position: relative; display: flex; justify-content: space-between; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.hint { color: #8a97a1; }
.table-scroll { overflow: auto; }

/* ---------- Таблица ---------- */
table.mix-table { border-collapse: collapse; width: max-content; min-width: 100%; font-size: var(--tbl-font, 14px); line-height: 1.18; }
.mix-table th, .mix-table td { border: 1px solid #dde3e9; padding: 0 2px; text-align: center; white-space: nowrap; }
.mix-table thead th { position: sticky; top: 0; background: #f2f5f8; z-index: 3; font-weight: 600; font-size: calc(var(--tbl-font, 14px) - 0.5px); padding: 1px 2px; }
.mix-table th.name, .mix-table td.name { text-align: left; min-width: calc(var(--tbl-font, 14px) * 12); }
.mix-table td.name { position: sticky; left: 0; background: #fff; z-index: 2; }
.mix-table th.name { left: 0; z-index: 4; }
.mix-table input {
  border: 1px solid #cfd8e0; background: #fff; padding: 0 2px; width: 100%;
  border-radius: 3px; font-size: calc(var(--tbl-font, 14px) - 0.5px); line-height: 1.2;
}
.mix-table input:hover { border-color: #9fb4c8; background: #fbfdff; }
.mix-table input:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 2px rgba(31,111,235,.18); }
.mix-table tr.min-row input, .mix-table tr.max-row input { background: #fffdf6; border-color: #e3d6b0; }
.mix-table tr.min-row td, .mix-table tr.max-row td { background: #fbfcfd; }
.mix-table td.num input { width: calc(var(--tbl-font, 14px) * 4.6); text-align: right; font-variant-numeric: tabular-nums; }
.mix-table td.name input { width: calc(var(--tbl-font, 14px) * 11.5); }
.btn.tiny { padding: 1px 7px; font-size: 11px; border-radius: 4px; }
.zoom { display: inline-flex; gap: 4px; align-items: center; }
.zoom-label { font-size: 11px; color: var(--muted); min-width: 34px; text-align: center; }
.head-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; row-gap: 4px; }
.sum { font-weight: 600; color: var(--ok); }
.sum.bad { color: var(--danger); }
.mix-table tr.fakt-row td { background: #f4faf6; font-variant-numeric: tabular-nums; }
.mix-table .row-label { text-align: left; font-weight: 600; color: var(--muted); }
.mix-table .total-cell { font-weight: 600; }

/* ---------- Прогресс ---------- */
.progress { height: 10px; background: #e6ebf0; border-radius: 6px; overflow: hidden; }
.progress-bar { height: 100%; width: 0%; background: linear-gradient(90deg, #1f6feb, #4a9bff); transition: width .25s linear; }
.progress-text { font-size: 12px; color: var(--muted); margin: 6px 0 8px; min-height: 32px; }

.issues ul { margin: 0; padding-left: 18px; color: #a1541a; font-size: 12px; }

/* ---------- Оверлеи ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(24, 36, 46, .45);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 100;
}
.dialog {
  background: var(--panel); border-radius: 12px; box-shadow: 0 18px 50px rgba(0,0,0,.25);
  padding: 18px; width: min(720px, 96vw); max-height: 92vh; overflow: auto;
}
.dialog.small { width: min(380px, 94vw); }
.dialog.wide { width: min(1080px, 96vw); }
.dialog h2, .dialog h3 { margin: 0 0 12px; }
.dialog label { display: block; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.dialog label input, .dialog label select { display: block; width: 100%; margin-top: 4px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.check { display: flex !important; align-items: center; gap: 8px; }
.check input { width: auto; margin: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.row input[type="text"], .row input[type="password"] { flex: 1 1 150px; }
.error { color: var(--danger); font-size: 13px; margin-bottom: 8px; }

.list { list-style: none; margin: 0; padding: 0; max-height: 46vh; overflow: auto; }
.list li { display: flex; align-items: center; gap: 10px; padding: 8px; border-bottom: 1px solid #eef1f4; }
.list li .grow { flex: 1; }
.list li .when { color: var(--muted); font-size: 12px; }

.result-head { display: flex; justify-content: space-between; align-items: center; }
.result-body { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 12px; align-items: start; }
.result-body img { width: 100%; border: 1px solid var(--line); border-radius: 8px; }
.report { margin: 0; font: 12px/1.45 Consolas, "Courier New", monospace; white-space: pre-wrap; max-height: 60vh; overflow: auto; background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 10px; }

.limits-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }.limits-table th { text-align: left; font-weight: 600; color: var(--muted); padding: 4px 6px; border-bottom: 1px solid var(--line); }
.limits-table td { padding: 3px 6px; border-bottom: 1px solid #eef1f4; }
.limits-table td:nth-child(2), .limits-table td:nth-child(3) { width: 90px; }
.limits-table input { width: 80px; text-align: right; font-variant-numeric: tabular-nums; }
.limits-sums { margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.limits-sums b { color: var(--ink); }
.limits-sums.bad b { color: var(--danger); }
.vis-block { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 12.5px; }.vis-block > label { display: block; margin-bottom: 8px; color: var(--muted); }
.vis-block select { display: block; width: 100%; margin-top: 4px; }
.users-box { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin: 4px 0 10px; font-size: 12.5px; }
.users-box label { display: inline-flex; align-items: center; gap: 5px; margin: 0; color: var(--ink); }
.users-box input { width: auto; margin: 0; }
.creds { margin: 8px 0 12px; padding: 10px 12px; border: 1px solid #cfe3cf; background: #f3faf3; border-radius: 8px; font-size: 13px; }
.creds b { font-family: Consolas, "Courier New", monospace; font-size: 14px; }
.creds .muted { margin: 6px 0 8px; }
.dialog h4 { margin: 16px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.admin-summary { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.admin-summary .stat { background: #f6f8fa; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; font-size: 12px; color: var(--muted); }
.admin-summary .stat b { display: block; font-size: 18px; color: var(--ink); }
.list li .bad { color: var(--danger); }
.list li .good { color: var(--ok); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #1f2a33; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 90vw;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 240px minmax(0, 1fr); }
  .result-body { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .side { order: 2; }
  .content { height: auto; }
  .top-actions { width: 100%; margin-left: 0; }
}

/* Плотность в расчёте и редактор материалов */
.density-toggle { position: absolute; top: 7px; display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--muted); white-space: nowrap; cursor: pointer; z-index: 6; }
.density-toggle input { margin: 0; }
.mix-table td.density-off { background: #e7ecf4; }
.mix-table td.density-off input { background: transparent; color: #8a94a3; }
.wide-label { display: block; margin: 10px 0; font-size: 12.5px; color: var(--muted); }
.wide-label textarea { display: block; width: 100%; margin-top: 4px; font: inherit; padding: 6px 8px;
  border: 1px solid var(--line); border-radius: 6px; resize: vertical; color: var(--ink); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.mat-desc { display: block; font-size: 12px; color: var(--muted); }

@media (max-width: 1200px) {
  .density-text { display: none; }
}
