:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --success: #16a34a;
  --bad: #fee2e2;
  --bad-b: #ef4444;
  --warn: #fef9c3;
  --warn-b: #eab308;
  --ok: #dcfce7;
  --ok-b: #22c55e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: #f1f5f9;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg);
  color: #fff;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.auth-box { display: flex; align-items: center; gap: 12px; }

.container { max-width: 1600px; margin: 0 auto; padding: 20px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.panel h2 { margin: 0 0 14px; font-size: 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.right { justify-content: flex-end; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }

input, select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
}
input:focus, select:focus { outline: 2px solid var(--primary); border-color: var(--primary); }

.btn {
  padding: 8px 14px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: .15s;
}
.btn:hover { background: #f8fafc; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-d); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { filter: brightness(.95); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--bad-b); color: #fff; border-color: var(--bad-b); }
.btn-danger:hover { filter: brightness(.9); }
.topbar .btn-ghost { color: #fff; border-color: #334155; }
.file-label { display: inline-block; }

.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
.hidden { display: none !important; }

.msg { margin-top: 10px; font-size: 14px; min-height: 18px; }
.msg.err { color: var(--bad-b); }
.msg.ok { color: var(--success); }

.banner {
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
}
.banner.err { background: var(--bad); color: #991b1b; border: 1px solid var(--bad-b); }
.banner.ok  { background: var(--ok); color: #14532d; border: 1px solid var(--ok-b); }
.warn-list { margin: 10px 0 0; padding-left: 20px; color: #92400e; font-size: 13px; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { font-size: 12px; padding: 4px 8px; border-radius: 6px; }
.chip-bad { background: var(--bad); color: #991b1b; }
.chip-warn { background: var(--warn); color: #854d0e; }
.chip-ok { background: var(--ok); color: #14532d; }

.freq-block { margin-bottom: 22px; }
.freq-title {
  font-size: 14px; font-weight: 600; margin: 0 0 8px;
  display: flex; align-items: center; gap: 8px;
}
.freq-badge {
  background: #e0e7ff; color: #3730a3; border-radius: 999px;
  padding: 2px 10px; font-size: 12px; font-weight: 600;
}

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { border: 1px solid var(--line); padding: 6px 10px; text-align: right; white-space: nowrap; }
thead th { background: #f8fafc; position: sticky; top: 0; }
.col-time { text-align: left; font-weight: 600; background: #f8fafc; position: sticky; left: 0; }
.series-head { text-align: left; min-width: 180px; }
.series-head .sel { margin-right: 6px; }
.series-name { cursor: default; }
.series-name.warn { background: var(--warn); border-left: 3px solid var(--warn-b); cursor: pointer; padding-left: 6px; }
.series-name.ok { background: var(--ok); border-left: 3px solid var(--ok-b); padding-left: 6px; }
.series-name.dup { background: var(--bad); border-left: 3px solid var(--bad-b); color: #991b1b; padding-left: 6px; cursor: not-allowed; }
.unit-cell { cursor: default; font-size: 12px; }
.unit-cell.bad { background: var(--bad); border-left: 3px solid var(--bad-b); cursor: pointer; color: #991b1b; padding-left: 6px; }
.unit-cell.ok { background: var(--ok); color: #14532d; padding-left: 6px; cursor: pointer; }
.groups-cell { font-size: 11px; }
/* Группы — компактно, в столбик с переносом, а не одной длинной строкой */
.groups-cell { white-space: normal; }
.groups-cell .group-tags {
  display: flex; flex-direction: column; gap: 2px; align-items: flex-start;
  max-width: 220px;
}
.group-tag {
  display: inline-flex; align-items: center; gap: 4px;
  background: #e2e8f0; border-radius: 6px;
  padding: 1px 6px; margin: 0; max-width: 100%;
}
.group-tag > span:first-child {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 190px;
}
.group-tag.new { background: #dbeafe; color: #1e40af; }
.tag-x {
  cursor: pointer; font-weight: 700; color: #64748b;
  line-height: 1; padding: 0 2px;
}
.tag-x:hover { color: #ef4444; }
.caret { color: var(--muted); font-size: 10px; margin-left: 4px; }

/* Popover */
.popover {
  position: absolute;
  z-index: 50;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.16);
  min-width: 240px;
  max-height: 320px;
  overflow-y: auto;
  padding: 6px;
}
.pop-item {
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
  display: flex; justify-content: space-between; gap: 10px; font-size: 13px;
}
.pop-item:hover { background: #eff6ff; }
.pop-item .score { color: var(--muted); font-size: 11px; }
.pop-empty { padding: 10px; color: var(--muted); font-size: 13px; }
.pop-head { padding: 6px 10px; font-size: 11px; color: var(--muted); text-transform: uppercase; }

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-card {
  background: #fff; border-radius: 12px; padding: 22px; width: min(520px, 92vw);
  /* Карточка не должна перерастать экран: она отцентрована флексом, и всё,
     что вылезло за границы, становится недостижимым — прокрутка страницы
     до него не добирается. */
  max-height: 88vh; overflow-y: auto;
}
/* Перечень выбранных рядов в диалоге группировки: своя прокрутка, чтобы
   длинный список не распирал карточку и не отжимал кнопки за экран. */
.grp-count { font-weight: 600; color: var(--ink); margin-bottom: 4px; }
.grp-list {
  max-height: 96px; overflow-y: auto; line-height: 1.5;
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px;
  background: rgba(127, 127, 127, .06); overflow-wrap: anywhere;
}
.modal-card h3 { margin: 0 0 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form-grid input, .form-grid select { color: var(--ink); }
.hint { font-size: 12px; color: var(--muted); }

/* Parser panel */
.seg { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
/* Комбобокс: input + выпадающий список под ним */
.combo { position: relative; flex: 1 1 320px; min-width: 240px; }
.combo input { width: 100%; box-sizing: border-box; }
.parser-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 50;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  max-height: 260px; overflow: auto; box-shadow: 0 8px 24px rgba(15,23,42,.12);
}
.parser-item {
  padding: 8px 12px; font-size: 13px; cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.parser-item:last-child { border-bottom: none; }
.parser-item:hover { background: #eff6ff; }
.small { font-size: 12px; }
.btn-danger { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.btn-danger:hover { background: #fecaca; }

/* Ignored series */
.series-head.ignored { opacity: .5; text-decoration: line-through; }
.parser-item.active { background: #dbeafe; font-weight: 600; }

/* ── Подсветка изменений при обновлении парсера ─────────────────────────── */
/* зелёный — новое, жёлтый — изменённое, красный — удалённое */
td.st-new,    th.series-head.st-new    { background: #dcfce7; }
td.st-changed,th.series-head.st-changed{ background: #fef9c3; }
td.st-deleted,th.series-head.st-deleted{ background: #fee2e2; }
th.series-head.st-deleted .series-name { text-decoration: line-through; color: #991b1b; }
td.st-deleted { color: #991b1b; text-decoration: line-through; }
.diff-badge {
  display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase;
  padding: 1px 5px; border-radius: 4px; margin-right: 6px; vertical-align: middle;
}
.diff-badge.st-new     { background: #16a34a; color: #fff; }
.diff-badge.st-changed { background: #ca8a04; color: #fff; }
.diff-badge.st-deleted { background: #dc2626; color: #fff; }
.chip-new { background: #dcfce7; color: #14532d; }
.chip-changed { background: #fef9c3; color: #854d0e; }
.chip-deleted { background: #fee2e2; color: #991b1b; }

/* Cascade group selector */
.block { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin: 6px 0; }
.cascade-label { font-size: 11px; color: var(--muted); text-transform: uppercase; margin-top: 8px; }
.cascade { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.cascade-step { color: var(--ink); padding: 4px; }
.newgrp { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 10px 0; }
.newgrp legend { font-size: 12px; color: var(--muted); padding: 0 6px; }

/* ── Вкладки (виджеты) ─────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; background: #1e293b; padding: 0 24px; }
.tab {
  background: transparent; border: none; color: #cbd5e1; cursor: pointer;
  padding: 12px 18px; font-size: 14px; border-bottom: 3px solid transparent;
}
.tab:hover { color: #fff; }
.tab.active { color: #fff; border-bottom-color: var(--primary); font-weight: 600; }
.tab-panel.hidden { display: none; }

/* ── Скрипт-парсер ─────────────────────────────────────────────────────── */
.code-editor {
  display: block;
  width: 100%;
  font-family: "Consolas", "Fira Mono", "Courier New", monospace;
  font-size: 13px;
  line-height: 1.5;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f172a;
  color: #e2e8f0;
  resize: vertical;
  margin-top: 4px;
  tab-size: 4;
}
.code-editor:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.code-editor::placeholder { color: #475569; }
#scriptPanel .block { color: var(--ink); }

/* Теги ряда в заголовке таблицы импорта */
.series-tags { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.series-tag-chip {
  font-size: 10px; font-weight: 500; line-height: 1.4;
  background: #e0e7ff; color: #3730a3;
  border-radius: 3px; padding: 0px 5px;
  white-space: nowrap; cursor: default;
}

/* ── Виджет 03: получение данных ───────────────────────────────────────── */
.ex-layout { display: grid; grid-template-columns: 292px 1fr; gap: 18px; align-items: start; }

/* Сайдбар прилипает: фильтры нужны и при прокрутке длинного списка */
.ex-sidebar {
  position: sticky; top: 12px; max-height: calc(100vh - 32px);
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px;
}
.ex-side-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.ex-side-head strong { font-size: 14px; }
.ex-side-head .spacer { flex: 1; }
.ex-count-badge {
  background: var(--primary); color: #fff; border-radius: 9px;
  padding: 0 6px; font-size: 11px; font-weight: 700;
}
.ex-quick { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.ex-quick label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.ex-quick select {
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px;
  font-size: 13px; color: var(--ink); background: #fff;
}
.ex-facets { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }

.ex-facet { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.ex-facet.has-selection { border-color: #93c5fd; background: #f8fbff; }
.ex-facet-head {
  width: 100%; display: flex; align-items: center; gap: 6px;
  padding: 7px 9px; background: #f8fafc; border: none; cursor: pointer;
  font: inherit; font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .03em; text-align: left;
}
.ex-facet-head:hover { background: #eff6ff; color: var(--ink); }
.ex-facet-chevron { font-size: 9px; width: 10px; }
.ex-facet-name { flex: 1; }
.ex-facet-badge {
  background: var(--primary); color: #fff; border-radius: 9px;
  padding: 0 6px; font-size: 10px; font-weight: 700;
}
.ex-facet-body { padding: 6px; background: #fff; }
.ex-facet-search {
  width: 100%; padding: 5px 8px; margin-bottom: 6px; font-size: 12px;
  border: 1px solid var(--line); border-radius: 6px;
}
.ex-facet-list { max-height: 230px; overflow-y: auto; }
.ex-facet-row { display: flex; align-items: baseline; gap: 2px; }
.ex-facet-item {
  display: flex; align-items: baseline; gap: 6px; padding: 3px 6px;
  font-size: 13px; cursor: pointer; border-radius: 5px; flex: 1; min-width: 0;
}
.ex-facet-item:hover { background: #eff6ff; }
.ex-facet-item input[type="checkbox"] { flex-shrink: 0; accent-color: var(--primary); cursor: pointer; }
.ex-node-toggle {
  border: none; background: none; cursor: pointer; color: var(--muted);
  font-size: 9px; width: 14px; padding: 0; line-height: 1.6; flex-shrink: 0;
}
.ex-node-toggle:hover { color: var(--primary); }
.ex-node-leaf { cursor: default; visibility: hidden; }
.ex-node-kids { color: #94a3b8; font-size: 11px; }
.ex-facet-empty { padding: 8px; color: var(--muted); font-size: 12px; text-align: center; }

/* ── Правая часть: поиск, чипы, список ─────────────────────────────────── */
.ex-main { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

.ex-searchbar { position: relative; display: flex; align-items: center; }
.ex-search-icon { position: absolute; left: 14px; font-size: 15px; opacity: .5; pointer-events: none; }
.ex-searchbar input {
  width: 100%; padding: 12px 76px 12px 42px; font-size: 15px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.ex-searchbar input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.ex-search-clear {
  position: absolute; right: 42px; border: none; background: none;
  color: var(--muted); cursor: pointer; font-size: 14px; padding: 4px 8px;
}
.ex-search-clear:hover { color: var(--ink); }
.ex-busy {
  position: absolute; right: 14px; width: 16px; height: 16px;
  border: 2px solid #cbd5e1; border-top-color: var(--primary);
  border-radius: 50%; animation: ex-spin .7s linear infinite;
}
@keyframes ex-spin { to { transform: rotate(360deg); } }

.ex-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ex-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: #eef2ff; border: 1px solid #c7d2fe; border-radius: 14px;
  padding: 3px 5px 3px 11px; font-size: 12px; color: #3730a3;
}
.ex-chip-x {
  border: none; background: transparent; cursor: pointer;
  color: #6366f1; font-size: 11px; padding: 0 4px; line-height: 1;
}
.ex-chip-x:hover { color: #b91c1c; }
.ex-chip-clear {
  padding: 3px 11px; cursor: pointer; background: #fff;
  border-color: var(--line); color: var(--muted); font: inherit; font-size: 12px;
}
.ex-chip-clear:hover { border-color: var(--bad-b); color: #b91c1c; }

.ex-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ex-toolbar .spacer { flex: 1; }
.ex-total { font-size: 14px; font-weight: 600; }
.ex-inline { display: inline-flex; align-items: center; gap: 5px; }
.ex-inline select { padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; }

.ex-selbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 12px; border-radius: 9px;
  background: #f0f9ff; border: 1px solid #bae6fd; font-size: 13px; color: #0c4a6e;
}
.ex-selbar .spacer { flex: 1; }

.ex-list { display: flex; flex-direction: column; gap: 6px; }
.ex-row {
  display: grid; grid-template-columns: 24px 1fr auto; gap: 10px; align-items: center;
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 13px;
  background: #fff; cursor: pointer; transition: .12s;
}
.ex-row:hover { border-color: #93c5fd; background: #f8fbff; }
.ex-row.selected { border-color: var(--primary); background: #eff6ff; }
.ex-row-check { accent-color: var(--primary); cursor: pointer; width: 15px; height: 15px; }
.ex-row-main { min-width: 0; }
.ex-row-name {
  font-weight: 600; font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ex-row-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ex-row-meta { display: flex; gap: 10px; align-items: center; white-space: nowrap; }
.ex-badge { background: #e0e7ff; color: #3730a3; border-radius: 4px; padding: 1px 7px; font-size: 11px; font-weight: 600; }
.ex-unit { font-size: 12px; color: #475569; }
/* Код единицы вместо обозначения — служебная информация, гасим её */
.ex-unit-code { color: #cbd5e1; font-family: ui-monospace, Consolas, monospace; font-size: 11px; }

.ex-empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.ex-empty-icon { font-size: 30px; opacity: .45; margin-bottom: 8px; }

.ex-pager { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 6px 0 2px; }

.ex-stats { display: flex; flex-wrap: wrap; gap: 10px; margin: 4px 0 12px; }
.ex-stat {
  background: #f8fafc; border: 1px solid var(--line); border-radius: 9px;
  padding: 7px 13px; min-width: 108px;
}
.ex-stat-t { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.ex-stat-v { font-size: 15px; font-weight: 600; margin-top: 2px; }
.ex-up { color: var(--success); }
.ex-down { color: #dc2626; }

.tag-action { cursor: pointer; font: inherit; font-size: 12px; }
.tag-action:hover { background: #dbeafe; border-color: var(--primary); color: #1e40af; }

.row.center { justify-content: center; align-items: center; gap: 10px; margin-top: 12px; }
.badge { background: #e0e7ff; color: #3730a3; border-radius: 4px; padding: 1px 6px; font-size: 11px; font-weight: 600; }

.detail-meta { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; font-size: 13px; margin-bottom: 10px; }
.src-parser { background: #ecfccb; color: #3f6212; border: 1px solid #bef264; border-radius: 4px; padding: 1px 8px; font-size: 12px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tag { background: #f1f5f9; border: 1px solid var(--line); border-radius: 12px; padding: 2px 10px; font-size: 12px; color: var(--muted); }
.tag-removable { display: inline-flex; align-items: center; gap: 4px; }
.tag-x { background: none; border: none; color: var(--bad-b); cursor: pointer; font-size: 14px; line-height: 1; padding: 0 2px; }
.tag-x:hover { color: #b91c1c; }

/* Группировка ряда */
.grouping { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin: 10px 0 14px; background: #f8fafc; }
.grouping-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.grouping-add { gap: 8px; flex-wrap: wrap; align-items: center; }
.grouping-add select, .newgrp select, .newgrp input { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; }
.chart-wrap { position: relative; height: 360px; }
.values-block { margin-top: 12px; }
.values-table { max-height: 320px; overflow: auto; margin-top: 8px; }
.values-table table { width: 100%; border-collapse: collapse; font-size: 13px; }
.values-table th, .values-table td { border: 1px solid var(--line); padding: 4px 10px; text-align: left; }
.values-table th { background: #f8fafc; position: sticky; top: 0; }

/* ── Виджет 03: доступ к проектам ──────────────────────────────────────── */
.access-table { display: flex; flex-direction: column; gap: 8px; }
.access-row {
  display: grid; grid-template-columns: 220px 1fr 120px; gap: 14px; align-items: center;
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px;
}
.ar-projects { display: flex; flex-wrap: wrap; gap: 12px; }
.chkbox { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; }

/* ── Импорт: степпер ──────────────────────────────────────────────────── */
.import-stepper {
  display: flex; gap: 0; margin-bottom: 20px;
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #f8fafc;
}
.imp-step {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 16px; font-size: 14px; font-weight: 500; color: var(--muted);
  border-right: 1px solid var(--line); cursor: pointer; transition: .2s;
  position: relative;
}
.imp-step:last-child { border-right: none; }
.imp-step:hover { background: #eff6ff; }
.imp-step.active { background: var(--primary); color: #fff; font-weight: 600; }
.imp-step.done { background: #dcfce7; color: #14532d; }
.imp-step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--line); color: var(--muted); font-size: 12px; font-weight: 700;
}
.imp-step.active .imp-step-num { background: rgba(255,255,255,.3); color: #fff; }
.imp-step.done .imp-step-num { background: #16a34a; color: #fff; }

/* ── Импорт: шаг-панели ──────────────────────────────────────────────── */
.step-panel { animation: fadeIn .2s ease; }
.step-panel.hidden { display: none !important; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.step-nav {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line);
}

/* ── Импорт: дроп-зона ───────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--line); border-radius: 14px;
  padding: 40px 20px; text-align: center; cursor: pointer;
  transition: .2s; background: #fafbfc;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--primary); background: #eff6ff;
}
.drop-zone-icon { font-size: 40px; margin-bottom: 10px; }
.drop-zone-text { font-size: 15px; color: var(--ink); line-height: 1.5; }
.drop-zone-hint { font-size: 12px; color: var(--muted); margin-top: 10px; }
.drop-zone.loading { opacity: .6; pointer-events: none; }
.drop-zone.loading .drop-zone-icon::after {
  content: " ⏳"; animation: pulse 1s infinite;
}
@keyframes pulse { 50% { opacity: .4; } }

/* ── Импорт: разделитель «или» ────────────────────────────────────────── */
.divider-or {
  display: flex; align-items: center; gap: 12px; margin: 24px 0 16px;
  color: var(--muted); font-size: 13px;
}
.divider-or::before, .divider-or::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}

/* ── Импорт: поиск существующего набора ───────────────────────────────── */
.search-existing { display: flex; gap: 10px; align-items: center; }
.parser-info {
  display: flex; align-items: center; gap: 12px; margin-top: 8px;
  padding: 10px 14px; background: #f0fdf4; border: 1px solid #bbf7d0;
  border-radius: 8px;
}

/* ── Импорт: расширенный режим ────────────────────────────────────────── */
.advanced-section { margin-top: 20px; border: 1px solid var(--line); border-radius: 8px; }
.advanced-section summary {
  padding: 10px 14px; cursor: pointer; font-size: 13px; color: var(--muted);
  font-weight: 500; list-style: none; user-select: none;
}
.advanced-section summary::-webkit-details-marker { display: none; }
.advanced-section summary::before { content: "▸ "; }
.advanced-section[open] summary::before { content: "▾ "; }
.advanced-section[open] { background: #fafbfc; }
.advanced-section > div { padding: 0 14px 14px; }

/* ── Импорт: summary-bar (шаг 2) ─────────────────────────────────────── */
.summary-bar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  padding: 12px 16px; margin-bottom: 14px;
  background: #f0f9ff; border: 1px solid #bae6fd; border-radius: 10px;
  font-size: 14px; font-weight: 500; color: #0c4a6e;
}
.summary-bar .sb-badge {
  background: #0ea5e9; color: #fff; border-radius: 6px;
  padding: 2px 8px; font-size: 12px; font-weight: 700;
}
.status-panel { margin-bottom: 14px; padding: 12px 16px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); }

/* ── Импорт: карточки рядов ───────────────────────────────────────────── */
.cards-grid { display: flex; flex-direction: column; gap: 8px; }
.series-card-item {
  display: grid; grid-template-columns: 32px 1fr 80px 36px; gap: 10px;
  align-items: center; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; transition: .15s;
}
.series-card-item:hover { border-color: #93c5fd; box-shadow: 0 2px 8px rgba(37,99,235,.08); }
.series-card-item.ignored { opacity: .5; background: #fafafa; }
.series-card-item.st-new { border-left: 4px solid #16a34a; }
.series-card-item.st-changed { border-left: 4px solid #ca8a04; }
.series-card-item.st-deleted { border-left: 4px solid #dc2626; opacity: .6; }

.card-check input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.card-body { min-width: 0; }
.card-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 400px; }
.card-name.warn { color: #92400e; cursor: pointer; }
.card-name.ok { color: #14532d; }
.card-name.dup { color: #991b1b; text-decoration: line-through; }
.card-meta { display: flex; gap: 8px; align-items: center; margin-top: 3px; flex-wrap: wrap; }
.card-unit {
  font-size: 12px; padding: 1px 6px; border-radius: 4px; cursor: pointer;
}
.card-unit.ok { background: #dcfce7; color: #14532d; }
.card-unit.bad { background: #fee2e2; color: #991b1b; }
.card-freq { font-size: 11px; color: var(--muted); }
.card-pts { font-size: 11px; color: var(--muted); }
.card-groups { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 3px; }
.card-groups .group-tag { font-size: 10px; }
.card-tags { display: flex; gap: 3px; flex-wrap: wrap; }

.sparkline { width: 80px; height: 24px; }
.sparkline polyline {
  fill: none; stroke: var(--primary); stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round;
}
.series-card-item.st-new .sparkline polyline { stroke: #16a34a; }
.series-card-item.st-deleted .sparkline polyline { stroke: #dc2626; }

.card-actions { display: flex; flex-direction: column; gap: 4px; }
.card-actions .btn-icon {
  background: none; border: 1px solid var(--line); border-radius: 6px;
  width: 28px; height: 28px; cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.card-actions .btn-icon:hover { background: #f8fafc; color: var(--ink); }

/* Карточка: раскрытая деталь */
.card-detail {
  grid-column: 1 / -1; padding: 10px 14px 6px;
  border-top: 1px solid var(--line); margin-top: 8px;
}
.card-detail table { font-size: 12px; width: 100%; }
.card-detail th, .card-detail td { padding: 3px 8px; border: 1px solid var(--line); }
.card-detail th { background: #f8fafc; }

/* Карточка: встроенная таблица значений */
.card-points { margin-top: 6px; }
.card-points summary {
  font-size: 11px; color: var(--primary); cursor: pointer; user-select: none;
}
.card-points summary:hover { text-decoration: underline; }
.card-sparkline { display: flex; align-items: center; margin-top: 4px; }
.pts-table { font-size: 11px; border-collapse: collapse; width: 100%; margin-top: 4px; }
.pts-table td { padding: 2px 6px; border-bottom: 1px solid var(--line); }
.pts-table td:first-child { color: var(--muted); white-space: nowrap; }
.pts-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.pts-table .pt-new td { background: #dcfce7; }
.pts-table .pt-changed td { background: #fef9c3; }
.pts-table .pt-deleted td { background: #fee2e2; text-decoration: line-through; }

/* ── Импорт: commit-summary (шаг 3) ──────────────────────────────────── */
.commit-summary { font-size: 14px; line-height: 1.8; }
.commit-summary .cs-row { display: flex; gap: 8px; align-items: center; }
.commit-summary .cs-num {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 24px; height: 24px; border-radius: 6px;
  background: var(--primary); color: #fff; font-size: 12px; font-weight: 700;
}
.commit-summary .cs-new { background: #16a34a; }
.commit-summary .cs-del { background: #dc2626; }

/* ── Импорт: auto-groups preview ──────────────────────────────────────── */
#autoGroupsList { display: flex; flex-direction: column; gap: 4px; }
.ag-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border: 1px solid #e2e8f0; border-radius: 6px;
  font-size: 13px; background: #f8fafc;
}
.ag-item .ag-path { color: var(--muted); font-size: 11px; }

/* ── Переключатель вида (карточки/таблица) ────────────────────────────── */
.btn-view { padding: 6px 10px; font-size: 16px; line-height: 1; }
.btn-view.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.toolbar-sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }

/* ── Сохранение формы ─────────────────────────────────────────────────── */
.save-form { margin-bottom: 14px; }
.save-form input { margin-top: 6px; }

/* ── Подвкладки внутри виджета ─────────────────────────────────────────── */
.sub-tabs {
  display: flex; gap: 0; margin-bottom: 20px;
  border-bottom: 2px solid var(--line);
}
.sub-tab {
  background: transparent; border: none; cursor: pointer;
  padding: 10px 20px; font-size: 14px; font-weight: 500; color: var(--muted);
  border-bottom: 3px solid transparent; margin-bottom: -2px; transition: .15s;
}
.sub-tab:hover { color: var(--ink); }
.sub-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.sub-panel.hidden { display: none !important; }

/* ── Заголовок секции (h2 + кнопка справа) ───────────────────────────── */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.section-head h2 { margin: 0; font-size: 16px; }

/* ── Сетка карточек парсеров ──────────────────────────────────────────── */
.parser-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}
.parser-card {
  border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px; background: #fff; cursor: pointer;
  transition: .15s; position: relative;
}
.parser-card:hover { border-color: #93c5fd; box-shadow: 0 4px 12px rgba(37,99,235,.08); }
.parser-card-title { font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.parser-card-meta { display: flex; gap: 12px; align-items: center; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.parser-card-meta .pc-badge {
  background: #e0e7ff; color: #3730a3; border-radius: 4px;
  padding: 1px 6px; font-size: 11px; font-weight: 600;
}
.parser-card-actions {
  position: absolute; top: 12px; right: 12px; display: flex; gap: 6px;
}
.parser-card-actions .btn-icon {
  background: none; border: 1px solid var(--line); border-radius: 6px;
  width: 28px; height: 28px; cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.parser-card-actions .btn-icon:hover { background: #fee2e2; color: #dc2626; border-color: #fca5a5; }
.parser-card-actions .btn-run:hover { background: #dcfce7; color: #16a34a; border-color: #86efac; }
.parser-card .pc-status { font-size: 11px; color: var(--muted); margin-top: 6px; }

/* ── Детальный просмотр парсера ───────────────────────────────────────── */
.detail-panel { animation: fadeIn .2s ease; }
.detail-header {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--line);
}
.detail-header h2 { margin: 0; font-size: 16px; flex: 1; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ══════════════════════════════════════════════════════════════
   Виджет 04 — Оценка проектов
   ══════════════════════════════════════════════════════════════ */

/* Карточки проектов */
.proj-card { cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.proj-card:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(37,99,235,.12); }
.proj-bar-wrap {
  height: 6px; background: var(--line); border-radius: 3px;
  overflow: hidden; margin: 10px 0 4px;
}
.proj-bar { height: 100%; background: var(--primary); border-radius: 3px; transition: width .3s; }

/* Модалки */
.modal-card-wide { max-width: 860px; width: 95vw; max-height: 88vh; overflow-y: auto; padding: 24px 28px; }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line);
}
.modal-header h3 { margin: 0; }

/* ── Passport table v2 ───────────────────────────────────── */
.proj-passport { margin-top: 12px; }

.pp-section {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  margin-bottom: 16px; overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.pp-sec-head {
  padding: 14px 20px; font-size: 14px; font-weight: 700; color: var(--ink);
  background: #f8fafc; border-bottom: 1px solid var(--line);
  letter-spacing: .01em;
}

.pp-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.pp-table thead th {
  font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); text-align: left; padding: 10px 14px;
  border-bottom: 2px solid var(--line); font-weight: 600;
  white-space: nowrap;
}
.pp-table tbody td {
  padding: 10px 14px; border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
.pp-table tbody tr:last-child td { border-bottom: none; }

.pp-th-num { width: 40px; text-align: center; }
.pp-th-name { min-width: 200px; }
.pp-th-value { width: 380px; }

.pp-td-num { text-align: center; color: var(--muted); font-weight: 600; font-size: 12px; }
.pp-fname { font-weight: 600; color: var(--ink); line-height: 1.4; }
.pp-fdesc { font-size: 11px; color: var(--muted); margin-top: 2px; line-height: 1.3; }
.pp-req { color: #ef4444; font-weight: 700; margin-left: 3px; }

.pp-precomputed { background: #fffbeb; }
.pp-precomputed .pp-fname::after {
  content: 'авто';
  display: inline-block; margin-left: 8px;
  font-size: 9px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: #d97706; background: rgba(217,119,6,.1); border: 1px solid rgba(217,119,6,.25);
  border-radius: 4px; padding: 1px 6px; vertical-align: middle;
}

.pf-input {
  width: 100%; padding: 7px 10px; border: 1px solid var(--line);
  border-radius: 6px; font-size: 13px; font-family: inherit;
  background: #fff; transition: border-color .15s, box-shadow .15s;
}
.pf-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.pf-input:disabled { background: #f8fafc; color: var(--muted); cursor: not-allowed; }
textarea.pf-input { resize: vertical; line-height: 1.5; }

.pf-unit {
  display: inline-block; margin-left: 6px; font-size: 11px; color: var(--muted);
  font-weight: 500; vertical-align: middle;
}
.pf-engine {
  display: inline-block; margin-left: 6px; font-size: 9px; font-weight: 600;
  letter-spacing: .05em; color: #7c3aed; background: rgba(124,58,237,.08);
  border: 1px solid rgba(124,58,237,.2); border-radius: 4px; padding: 1px 5px;
  vertical-align: middle;
}
.pp-src {
  display: inline-block; margin-left: 6px; font-size: 9px; color: var(--muted);
  background: rgba(100,116,139,.08); border: 1px solid rgba(100,116,139,.15);
  border-radius: 3px; padding: 1px 5px; vertical-align: middle;
}

/* ── Stages table ─────────────────────────────────────────── */
.pp-stages-table .pp-th-phase { width: 120px; }
.pp-stages-table .pp-th-stage { min-width: 200px; }
.pp-stages-table .pp-th-plan,
.pp-stages-table .pp-th-actual { width: 100px; text-align: center; }
.pp-stages-table .pp-th-delta { width: 90px; text-align: center; }
.pp-stages-table .pp-th-status { width: 130px; }

.pp-td-phase {
  font-weight: 700; font-size: 12px; color: var(--primary);
  text-transform: uppercase; letter-spacing: .05em;
  background: #f0f4ff; vertical-align: middle; text-align: center;
  border-right: 2px solid rgba(37,99,235,.15);
  line-height: 1.4; padding: 10px 8px;
}
.pp-td-stage { font-size: 13px; color: var(--ink); line-height: 1.4; }
.pp-td-est, .pp-td-actual { text-align: center; }
.pp-td-prob, .pp-td-delay, .pp-td-shift { text-align: center; font-weight: 600; font-size: 12px; white-space: nowrap; }

/* Calculated field colors */
.calc-good { color: #16a34a; }
.calc-warn { color: #b45309; }
.calc-bad { color: #ef4444; }
.calc-ok { color: var(--muted); }
.calc-none { color: #cbd5e1; }

/* Phase summary rows */
.st-phase-total {
  background: #f1f5f9; border-top: 2px solid #cbd5e1; border-bottom: 2px solid #cbd5e1;
}
.st-phase-total-label {
  font-weight: 700; font-size: 12px; color: #475569;
  text-align: right; padding-right: 16px; text-transform: uppercase; letter-spacing: .03em;
}
.st-phase-total-val {
  text-align: center; font-weight: 600; font-size: 12px; color: #334155;
}

/* Grand total row */
.st-grand-total {
  background: #e0e7ff; border-top: 3px solid #6366f1;
}
.st-gt-label {
  font-weight: 800; font-size: 13px; color: #312e81;
  text-align: right; padding-right: 16px;
}
.st-gt-val {
  text-align: center; font-weight: 700; font-size: 13px; color: #312e81;
}
.st-gt-status { color: #4f46e5; }

/* Stages table horizontal scroll */
.pp-stages-table { min-width: 900px; }
.pp-section:has(.pp-stages-table) { overflow-x: auto; }

.st-input {
  width: 70px; padding: 5px 8px; border: 1px solid var(--line);
  border-radius: 5px; font-size: 13px; font-family: inherit;
  text-align: center; background: #fff;
}
.st-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.1); }

.st-select {
  padding: 5px 8px; border: 1px solid var(--line);
  border-radius: 5px; font-size: 12px; font-family: inherit;
  cursor: pointer; font-weight: 600;
}
.st-sel-not_started { color: var(--muted); background: #f8fafc; }
.st-sel-in_progress { color: #b45309; background: #fef3c7; border-color: #fbbf24; }
.st-sel-completed { color: #166534; background: #dcfce7; border-color: #86efac; }

/* Stage row status coloring */
.st-row.st-completed { background: #f0fdf4; }
.st-row.st-in_progress { background: #fffbeb; }
.st-row.st-not_started { background: #fff; }


/* Lookup autocomplete */
.lu-wrap { position: relative; }
.lu-input { width: 100%; }
.lu-input.lu-filled { color: #1e40af; font-weight: 500; }
.lu-dropdown {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 50;
  max-height: 220px; overflow-y: auto;
  background: #fff; border: 1px solid #cbd5e1; border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
}
.lu-item {
  padding: 6px 10px; cursor: pointer; font-size: .88rem;
  border-bottom: 1px solid #f1f5f9;
}
.lu-item:last-child { border-bottom: none; }
.lu-item:hover { background: #eff6ff; }
.lu-code { font-weight: 600; color: #1e40af; }
.lu-empty { padding: 8px 10px; color: #94a3b8; font-size: .85rem; }

/* ── Выбор типа нового парсера ────────────────────────────────────────── */
.ptype-list { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 16px; }
.ptype-card {
  display: flex; align-items: flex-start; gap: 14px; width: 100%;
  padding: 14px 16px; text-align: left; cursor: pointer;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  font: inherit; color: var(--ink); transition: .15s;
}
.ptype-card:hover { border-color: var(--primary); box-shadow: 0 2px 10px rgba(37,99,235,.10); }
.ptype-icon { font-size: 26px; line-height: 1.1; }
.ptype-body { display: flex; flex-direction: column; gap: 3px; }

/* ── Мастер «Парсер данных ООН» ───────────────────────────────────────── */
.un-inline { display: flex; align-items: center; gap: 6px; }
.un-search-bar { display: flex; gap: 10px; align-items: center; margin: 10px 0; }
.un-search-bar input[type="search"] { flex: 1; padding: 9px 12px; font-size: 15px; }

.un-results {
  max-height: 440px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.un-row {
  display: grid; grid-template-columns: 90px 1fr 78px 84px; gap: 12px;
  align-items: baseline; padding: 9px 14px; cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
}
.un-row:last-child { border-bottom: none; }
.un-row:hover { background: #eff6ff; }
.un-row.selected { background: #dbeafe; }
.un-pick { font-size: 11px; color: var(--muted); text-align: right; white-space: nowrap; }
.un-row:hover .un-pick { color: var(--primary); }
.un-row.selected .un-pick { color: #1e40af; font-weight: 600; }

/* Уже загруженные показатели: приглушены, добавить нельзя */
.un-row-loaded { opacity: .62; background: #f8fafc; cursor: not-allowed; }
.un-row-loaded:hover { background: #f1f5f9; }
.un-row-loaded .un-name-ru { color: var(--muted); }
.un-pick-loaded { color: #64748b; font-weight: 600; cursor: not-allowed; }
.un-pick-loaded::before { content: "✓ "; color: #16a34a; }

/* Фильтры каталога (цель ЦУР, «скрыть загруженные») */
.src-filters { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center;
  margin: 4px 0 12px; padding: 8px 10px; background: #f8fafc;
  border: 1px solid var(--border); border-radius: 8px; }
.src-filter { display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--muted); }
.src-filter select { padding: 5px 8px; font-size: 13px; }
.src-filter-chk { cursor: pointer; }

/* Бейдж странового покрытия показателя */
.cov-badge { display: inline-block; margin-left: 8px; padding: 1px 7px;
  border-radius: 10px; font-size: 11px; font-weight: 600; white-space: nowrap;
  vertical-align: middle; }
.cov-global { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.cov-empty { background: #f1f5f9; color: #64748b; border: 1px solid #cbd5e1; }

/* Корзина товаров: остаётся на виду, пока ищешь следующий */
.un-basket {
  border: 1px solid #bae6fd; background: #f0f9ff;
  border-radius: 10px; padding: 10px 12px; margin: 10px 0;
}
.un-basket-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; }
.un-basket-head .spacer { flex: 1; }
.un-basket-list { display: flex; flex-wrap: wrap; gap: 6px; }
.un-basket-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid #7dd3fc; border-radius: 14px;
  padding: 3px 5px 3px 10px; font-size: 12px; color: #0c4a6e; max-width: 340px;
}
.un-basket-chip b { font-family: ui-monospace, Consolas, monospace; }
.un-basket-x {
  border: none; background: transparent; cursor: pointer;
  color: #0284c7; font-size: 11px; padding: 0 4px; line-height: 1;
}
.un-basket-x:hover { color: #b91c1c; }
.un-picked-item { margin-right: 12px; font-size: 13px; }

/* Раскладка по товарам на шаге калибровки */
.un-commodities { margin: 12px 0; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.un-com-row {
  display: grid; grid-template-columns: 78px 1.4fr 1.1fr 1fr 64px;
  gap: 10px; padding: 8px 12px; font-size: 13px; align-items: baseline;
  border-bottom: 1px solid #f1f5f9; background: #fff;
}
.un-com-row:last-child { border-bottom: none; }
.un-com-head {
  background: #f8fafc; font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .03em;
}
.un-com-row.un-com-empty { background: #fffbeb; }
.un-com-warn { color: #b45309; font-weight: 600; }
.un-code { font-weight: 700; color: #1e40af; font-family: ui-monospace, Consolas, monospace; }
.un-name-ru { display: block; }
.un-name-en { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.un-level { font-size: 11px; color: var(--muted); text-align: right; white-space: nowrap; }
.un-empty { padding: 18px; text-align: center; color: var(--muted); }

.un-params {
  display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; margin-bottom: 16px;
}
.un-params > label.block { flex: 0 0 130px; }
.un-fieldset {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px 12px;
  display: flex; flex-direction: column; gap: 5px;
}
.un-fieldset legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.un-fieldset label { font-size: 13px; display: flex; align-items: center; gap: 6px; }

.un-countries-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.un-countries-head .spacer { flex: 1; }
.un-countries {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 2px 10px; max-height: 260px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff;
}
.un-countries label {
  display: flex; align-items: center; gap: 6px; font-size: 13px;
  padding: 2px 0; cursor: pointer;
}
.un-countries label.un-nogeo { color: var(--muted); }
.un-countries .un-nogeo-mark { font-size: 11px; }

.un-llm {
  display: flex; gap: 10px; align-items: flex-start; margin-top: 16px;
  padding: 12px 14px; background: #f8fafc; border: 1px solid var(--line); border-radius: 10px;
}
.un-llm input { margin-top: 3px; }

.un-mapping { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.un-map-row { display: grid; grid-template-columns: 210px 1fr; gap: 12px; font-size: 14px; }
.un-map-row > span:first-child { color: var(--muted); }
.un-map-tag {
  display: inline-block; background: #eef2ff; border: 1px solid #c7d2fe;
  border-radius: 12px; padding: 1px 9px; font-size: 12px; margin: 0 4px 4px 0;
}
.un-sample {
  max-height: 300px; overflow: auto; font-size: 11px;
  background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 8px;
}

/* ── Прогресс фонового запуска скрипта ────────────────────────────────── */
.run-progress { margin-top: 12px; }
.run-progress-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.rp-stage {
  background: #0ea5e9; color: #fff; border-radius: 6px;
  padding: 2px 8px; font-size: 12px; font-weight: 700;
}
.rp-track { height: 8px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.rp-fill {
  height: 100%; width: 0; border-radius: 999px;
  background: linear-gradient(90deg, #2563eb, #0ea5e9);
  transition: width .3s ease;
}
/* Этап без известного числа шагов — бегущая полоса вместо процента */
.rp-fill.indeterminate {
  width: 35%; animation: rp-slide 1.4s ease-in-out infinite;
}
@keyframes rp-slide {
  0%   { margin-left: -35%; }
  100% { margin-left: 100%; }
}

@media (max-width: 1100px) {
  /* Узкий экран: фильтры уезжают наверх и перестают липнуть */
  .ex-layout { grid-template-columns: 1fr; }
  .ex-sidebar { position: static; max-height: none; }
  .ex-facet-list { max-height: 180px; }
  .ex-row { grid-template-columns: 24px 1fr; }
  .ex-row-meta { grid-column: 2; justify-content: flex-start; flex-wrap: wrap; }
}

@media (max-width: 900px) {
  .un-row { grid-template-columns: 70px 1fr; }
  .un-level, .un-pick { display: none; }
  .un-com-row { grid-template-columns: 70px 1fr; }
  .un-com-row > span:nth-child(n+3) { grid-column: 2; }
  .un-map-row { grid-template-columns: 1fr; gap: 2px; }
  .un-countries { grid-template-columns: 1fr; }
  .explore-layout { grid-template-columns: 1fr; }
  .access-row { grid-template-columns: 1fr; }
  .series-card-item { grid-template-columns: 28px 1fr 36px; }
  .series-card-item .sparkline { display: none; }
  .import-stepper { font-size: 12px; }
  .parser-grid { grid-template-columns: 1fr; }
  .detail-header { flex-direction: column; align-items: flex-start; }
  .proj-scheme { overflow-x: auto; }
  .proj-diag { min-width: 800px; }
  .proj-kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .res-kpi-row { grid-template-columns: repeat(2, 1fr); }
  .res-section { padding: 16px; }
  .pp-field-head { grid-template-columns: 24px 1fr; }
  .pp-field-input { padding-left: 34px; }
  .modal-card-wide { padding: 16px; }
}

/* Переключатель классификатора продукции: CPC 2.1 или HS 2022.
   Живёт внутри заголовка фасета «Продукт», поэтому клик по нему не должен
   сворачивать группу — это сделано в explore.js через stopPropagation. */
.ex-facet-switch { margin-left: auto; display: flex; gap: 4px; }

.ex-facet-switch-btn {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #64748b;
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 11px;
  line-height: 17px;
  cursor: pointer;
}

.ex-facet-switch-btn:hover { border-color: #94a3b8; color: #334155; }

.ex-facet-switch-btn.on {
  border-color: #2563eb;
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 600;
}

/* Вариант, несовместимый с выбранной частотой: виден, но недоступен —
   чтобы было понятно, что он есть и почему его нельзя взять. */
.src-opt { display: inline-flex; align-items: center; gap: 6px; margin-right: 14px; }
.src-opt-off { opacity: .45; text-decoration: line-through; }
.src-multi { margin: 10px 0; }
.src-opts { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-top: 4px; }

/* Быстрый выбор периода: кнопки стоят в одну строку с полями «с» и «по» */
.src-presets { display: flex; align-items: flex-end; gap: 6px; flex-wrap: wrap; }

/* Разметка источников контекстом фронта (админка) */
.sc-form { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.sc-form select, .sc-form input { padding: 6px 8px; }
.sc-form select { min-width: 220px; }
.sc-form input { flex: 1 1 200px; }
.sc-row { display: flex; align-items: center; gap: 12px; padding: 6px 0;
          border-bottom: 1px solid var(--border, #e5e7eb); }
.sc-row .sc-name { flex: 0 0 220px; font-weight: 600; }
.sc-row .sc-ctx { flex: 1 1 auto; }
.sc-chip { display: inline-flex; align-items: center; gap: 6px; margin: 2px 6px 2px 0;
           padding: 2px 8px; border-radius: 12px; background: rgba(127,127,127,.15);
           font-size: 12px; }
.sc-chip button { border: 0; background: none; cursor: pointer; font-size: 14px; line-height: 1; }

/* Панель автономного Java-клиента в обозревателе рядов. Код показываем
   моноширинным и со скроллом внутри панели: класс длиннее трёхсот строк,
   и без своего скролла он растягивает всю страницу. */
.ex-java {
  border: 1px solid var(--line); border-radius: 9px; background: #fff;
  overflow: hidden; margin-top: 8px;
}
.ex-java-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 12px; background: #f8fafc; border-bottom: 1px solid var(--line);
}
.ex-java-bar .spacer { flex: 1; }
.ex-java-bar input[type=text] {
  padding: 3px 7px; border: 1px solid var(--line); border-radius: 6px;
  font: inherit; font-size: 12px; margin-left: 4px;
}
.ex-java-note { padding: 7px 12px; border-bottom: 1px solid var(--line); }
.ex-java-note code { background: rgba(127,127,127,.15); padding: 1px 4px; border-radius: 3px; }
.ex-java-code {
  margin: 0; padding: 12px; max-height: 460px; overflow: auto;
  font-family: ui-monospace, Consolas, monospace; font-size: 12px; line-height: 1.5;
  white-space: pre; tab-size: 4;
}

/* Календарное допущение для выгрузок модели. Свёрнуто по умолчанию:
   для обычных Excel-файлов оно не нужно и только отвлекало бы. */
.vv-opts {
  margin: 10px auto 0; max-width: 640px;
  border: 1px solid var(--line); border-radius: 9px; background: #fff;
}
.vv-opts > summary {
  padding: 9px 13px; cursor: pointer; font-size: 13px; font-weight: 600;
  list-style: none;
}
.vv-opts > summary::before { content: "▸ "; color: var(--muted); }
.vv-opts[open] > summary::before { content: "▾ "; }
.vv-opts-body {
  display: flex; flex-wrap: wrap; gap: 12px;
  padding: 4px 13px 13px; border-top: 1px solid var(--line);
}
.vv-opts-body label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
.vv-opts-body input, .vv-opts-body select {
  padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; font-size: 13px;
}
.vv-opts-body input[type=number] { width: 100px; }
.vv-opts-body p { flex-basis: 100%; margin: 0; }
.vv-opts-body code { background: rgba(127,127,127,.15); padding: 1px 4px; border-radius: 3px; }

/* Ход разбора файла. Две формы: доля (ширина по проценту) и неопределённая
   бегущая полоса — для этапов, длительность которых заранее не known. */
.parse-progress { max-width: 640px; margin: 12px auto 0; }
.pp-head { display: flex; align-items: baseline; gap: 8px; font-size: 13px; margin-bottom: 5px; }
.pp-head .spacer { flex: 1; }
.pp-track {
  height: 6px; border-radius: 4px; overflow: hidden;
  background: rgba(127, 127, 127, .18);
}
.pp-bar {
  height: 100%; width: 0; border-radius: 4px;
  background: var(--accent, #2563eb);
  transition: width .25s ease;
}
.pp-bar.indeterminate {
  width: 35%;
  animation: pp-run 1.1s ease-in-out infinite;
}
@keyframes pp-run {
  0%   { margin-left: -35%; }
  100% { margin-left: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .pp-bar.indeterminate { animation: none; width: 100%; opacity: .45; }
}

/* Два шага Java-клиента: вызов (копируют каждый раз) и библиотека
   (заводится однажды, поэтому свёрнута). */
.ex-java-step { border-top: 1px solid var(--line); }
.ex-java-step > summary {
  padding: 9px 12px; cursor: pointer; font-size: 13px; list-style: none;
}
.ex-java-step > summary::before { content: "▸ "; color: var(--muted); }
.ex-java-step[open] > summary::before { content: "▾ "; }
.ex-java-step-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 12px; background: #f8fafc; border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.ex-java-step-head .spacer { flex: 1; }
.ex-java-warn {
  padding: 8px 12px; font-size: 12.5px; line-height: 1.5;
  background: #fef3c7; border-bottom: 1px solid #fcd34d; color: #78350f;
}
.ex-java-warn code { background: rgba(0, 0, 0, .08); padding: 1px 4px; border-radius: 3px; }

/* Верхняя панель записи на шаге проверки. Липкая: на сотнях рядов кнопка
   должна оставаться под рукой, пока прокручиваешь список. */
.save-top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 12px; margin-bottom: 10px;
  background: #fff; border: 1px solid var(--line); border-radius: 9px;
  box-shadow: 0 2px 8px -4px rgba(0,0,0,.25);
}
.save-top .spacer { flex: 1; }
.units-left {
  font-size: 12.5px; font-weight: 600; padding: 2px 9px; border-radius: 12px;
  background: #fef3c7; color: #92400e; border: 1px solid #fcd34d;
}
.btn.btn-warn { background: #d97706; border-color: #d97706; color: #fff; }
.btn.btn-warn:hover { background: #b45309; border-color: #b45309; }

/* Ряд, к которому подвели: подсветка держится, пока открыт список единиц —
   без неё после прокрутки непонятно, какой именно ряд от тебя ждут. */
.unit-wanted {
  outline: 2px solid #d97706; outline-offset: 2px; border-radius: 6px;
  animation: unit-pulse 1s ease-in-out 2;
}
@keyframes unit-pulse {
  0%, 100% { outline-color: #d97706; }
  50%      { outline-color: rgba(217, 119, 6, .25); }
}
@media (prefers-reduced-motion: reduce) { .unit-wanted { animation: none; } }
