:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #1c1f24;
  --text-muted: #6b7280;
  --accent: #2f5bea;
  --accent-hover: #2449c4;
  --accent-soft: #e9eefc;
  --danger: #d33f3f;
  --danger-hover: #b32f2f;
  --ok: #1e8e5a;
  --ok-soft: #e3f4ea;
  --warn: #b7791f;
  --warn-soft: #fbf0d9;
  --info: #2f5bea;
  --info-soft: #e9eefc;
  --bad: #d33f3f;
  --bad-soft: #fbe5e5;
  --muted-soft: #eceef1;
  --radius: 8px;
  --sidebar: 224px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }

/* --- каркас --- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: block;
  padding: 18px 20px 14px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.nav { display: flex; flex-direction: column; padding: 4px 10px; gap: 2px; flex: 1; }
.nav-item {
  display: block;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--text);
  font-weight: 500;
}
.nav-item:hover { background: var(--bg); text-decoration: none; }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent); }
.sidebar-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.who { display: flex; flex-direction: column; min-width: 0; }
.who-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.who-role { font-size: 12px; color: var(--text-muted); }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.link:hover { text-decoration: underline; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.page-title { font-size: 18px; }
.search input {
  width: 300px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: var(--bg);
}
.search input:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.content { padding: 24px 28px 48px; max-width: 1280px; width: 100%; }

/* --- карточки --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 14px; font-weight: 600; }
.card-body { padding: 18px; }
.card-body.is-flush { padding: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-main { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
@media (max-width: 1100px) {
  .grid-2, .grid-3, .grid-main { grid-template-columns: 1fr; }
  .search input { width: 200px; }
}

/* --- показатели --- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
@media (max-width: 1100px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
}
.kpi-label { font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px; }
.kpi-value { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* --- шапка объекта --- */
.object-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.object-title { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 600; }
.object-meta { color: var(--text-muted); margin-top: 4px; font-size: 13px; }
.object-meta a { color: inherit; text-decoration: underline; text-decoration-color: var(--border); }
.object-stats { display: flex; gap: 28px; }
.stat-label { font-size: 12px; color: var(--text-muted); }
.stat-value { font-size: 17px; font-weight: 600; }

/* --- таблицы --- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.table th { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; background: #fafbfc; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafbfc; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.wrap { white-space: normal; }
.table .muted { color: var(--text-muted); }
.row-link { color: inherit; font-weight: 500; }
.amount-pos { color: var(--ok); }
.amount-neg { color: var(--bad); }

/* --- фильтры --- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.filters .field { margin: 0; min-width: 140px; }
.filters .field label { font-size: 11.5px; }
.filters .btn { align-self: flex-end; }

/* --- бейджи --- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; line-height: 1.5; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-muted { background: var(--muted-soft); color: var(--text-muted); }

/* --- кнопки --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* --- блок действий --- */
.actions { display: flex; flex-direction: column; gap: 10px; }
.actions .btn { justify-content: flex-start; }
.actions-form { display: flex; flex-direction: column; gap: 8px; padding-top: 10px; border-top: 1px solid var(--border); margin-top: 4px; }
.actions-form .btn { align-self: flex-start; }

/* --- формы --- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 500; color: var(--text-muted); }
.field input, .field select, .field textarea {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: var(--surface);
  color: var(--text);
}
.field textarea { resize: vertical; font-family: inherit; }
.field textarea.mono { font-family: var(--mono); font-size: 12.5px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field-hint { font-size: 12px; color: var(--text-muted); }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.field-check { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.field-check input { width: 15px; height: 15px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.form-error { background: var(--bad-soft); color: var(--bad); padding: 9px 12px; border-radius: 6px; margin-bottom: 14px; }
.form-foot { display: flex; gap: 10px; align-items: center; padding-top: 6px; }

/* --- вкладки --- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); padding: 0 18px; }
.tab { padding: 10px 14px; margin-bottom: -1px; border-bottom: 2px solid transparent; color: var(--text-muted); font-weight: 500; cursor: pointer; background: none; border-top: 0; border-left: 0; border-right: 0; font: inherit; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

/* --- ключ-значение --- */
.kv { display: flex; flex-direction: column; }
.kv-row { display: flex; gap: 16px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.kv-row:last-child { border-bottom: 0; }
.kv-label { width: 160px; flex-shrink: 0; color: var(--text-muted); }
.kv-value { min-width: 0; word-break: break-word; }

/* --- пагинация --- */
.pagination { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 13px; }
.pagination-links { display: flex; align-items: center; gap: 10px; }

/* --- пустое состояние --- */
.empty { padding: 40px 18px; text-align: center; color: var(--text-muted); }
.empty-title { font-size: 28px; font-weight: 600; color: var(--text); margin: 0 0 6px; }
.empty .btn { margin-top: 10px; }

/* --- уведомление --- */
.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  font-weight: 500;
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
  z-index: 50;
  transition: opacity .3s;
}
.toast-bad { background: var(--danger); }
.toast.is-hiding { opacity: 0; }

/* --- модалка --- */
.modal { border: 0; border-radius: 10px; padding: 0; width: 440px; max-width: calc(100vw - 32px); box-shadow: 0 20px 50px rgba(0,0,0,0.25); }
.modal::backdrop { background: rgba(20, 23, 30, 0.45); }
.modal form { padding: 22px 24px; }
.modal-title { font-size: 16px; margin-bottom: 6px; }
.modal-text { color: var(--text-muted); margin: 0 0 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* --- вход --- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { width: 340px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 28px; }
.login-title { text-align: center; font-size: 20px; margin-bottom: 20px; }

/* --- прочее --- */
.muted { color: var(--text-muted); }
.small { font-size: 12.5px; }
.stack { display: flex; flex-direction: column; gap: 6px; }
.inline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.chart-box { position: relative; height: 240px; }
.attention-list { display: flex; flex-direction: column; }
.attention-row { display: flex; justify-content: space-between; padding: 10px 18px; border-bottom: 1px solid var(--border); color: inherit; }
.attention-row:last-child { border-bottom: 0; }
.attention-row:hover { background: #fafbfc; text-decoration: none; }
.attention-count { font-weight: 600; }
.attention-row.is-zero { color: var(--text-muted); }
.attention-row.is-zero .attention-count { font-weight: 400; }
.preview { max-width: 100%; max-height: 360px; border-radius: 6px; border: 1px solid var(--border); }
details.raw summary { cursor: pointer; color: var(--text-muted); }
details.raw pre { background: #fafbfc; border: 1px solid var(--border); border-radius: 6px; padding: 12px; overflow: auto; font-size: 12px; margin: 10px 0 0; }
.text-row td { white-space: normal; vertical-align: top; }
.text-cell { cursor: text; min-height: 20px; white-space: pre-wrap; }
.text-cell.is-changed { border-left: 3px solid var(--accent); padding-left: 8px; }
.text-key { font-family: var(--mono); font-size: 12px; color: var(--text-muted); }
.progress { height: 8px; background: var(--muted-soft); border-radius: 4px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); }
.segment-count { font-size: 13px; color: var(--text-muted); }
.sortable-move { display: inline-flex; gap: 4px; }
