/* ============================================================
   Mesh Viewer — engineering / blueprint aesthetic
   ============================================================ */

:root {
  /* palette */
  --bg:        #0a0d10;
  --bg-2:      #0f1318;
  --surface:   #14191f;
  --surface-2: #1a2027;
  --border:    #232c35;
  --border-2:  #2d3741;

  --fg:        #e8ebef;
  --fg-2:      #b6bec7;
  --muted:     #6b7682;
  --muted-2:   #4a535d;

  --accent:    #ff8a3d;     /* signal amber */
  --accent-2:  #ffb27a;
  --accent-dim:#3a2519;

  --good:      #6ad28a;
  --warn:      #ffcb5c;
  --bad:       #ff5a5a;
  --info:      #35c2ff;     /* blueprint cyan (= внешний контур крыш) */
  --info-2:    #7ad4ff;

  /* typography */
  --ff-sans: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --ff-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* shape */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;

  /* z layers */
  --z-hud: 10;
  --z-overlay: 50;
  --z-drop: 60;
}

* { box-sizing: border-box; }

/* The `hidden` attribute is toggled from JS to show/hide the overlays
   (.empty / .loading / .dropzone) and sidebar panels. Those rules set
   `display: flex`, which would otherwise beat the user-agent `[hidden]`
   rule in the cascade and leave the elements visible. Force it. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--ff-sans);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

body {
  display: grid;
  grid-template-rows: 44px 1fr 24px;
  height: 100vh;
}

code, .mono { font-family: var(--ff-mono); font-size: 0.92em; }
.muted { color: var(--muted); }
.muted.small { font-size: 11px; }

/* ===== Toolbar ============================================ */

.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  -webkit-app-region: drag;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--ff-mono);
  letter-spacing: 0.04em;
}
.brand__mark {
  width: 10px;
  height: 10px;
  background: var(--accent);
  display: inline-block;
  align-self: center;
  box-shadow: 0 0 12px var(--accent);
}
.brand__title {
  font-weight: 600;
  font-size: 12px;
  color: var(--fg);
}
.brand__subtitle {
  font-size: 11px;
  color: var(--muted);
}
/* Источник загруженной модели — в верхнем баре после логотипа. Отделён вертикальной
   чертой; длинное имя усекается многоточием, чтобы не распирать тулбар. */
.brand__source {
  margin-left: 4px;
  padding-left: 12px;
  border-left: 1px solid var(--border-2);
  font-size: 11px;
  color: var(--fg-2);
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.brand__source[hidden] { display: none; }

.toolbar__actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
  -webkit-app-region: no-drag;
}

.btn {
  appearance: none;
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--fg);
  font-family: var(--ff-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 120ms, border-color 120ms, color 120ms;
}
.btn:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--accent);
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn--ghost {
  background: transparent;
}
/* Кнопка-тоггл во включённом состоянии (напр. «Кластеризация поверхностей»). */
.btn.is-on {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
/* Компактная кнопка-иконка (undo/redo): квадратная, крупный глиф. */
.btn--icon {
  padding: 6px 9px;
  font-size: 15px;
  line-height: 1;
}
/* Перетаскивание файла(ов) прямо на кнопку «Открыть / загрузить». */
.btn.is-dragover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}
.btn__kbd {
  font-size: 10px;
  color: var(--muted);
}

/* ===== Layout ============================================= */

.layout {
  display: grid;
  /* Ширина боковой панели регулируется перетаскиванием сплиттера (--sidebar-w). */
  grid-template-columns: var(--sidebar-w, 280px) 6px 1fr;
  min-height: 0;
}

/* Вертикальный разделитель: ухватка ресайза левой панели. */
.sidebar-resizer {
  cursor: col-resize;
  background: var(--border);
  transition: background 100ms;
  touch-action: none;
}
.sidebar-resizer:hover,
.sidebar-resizer.is-dragging { background: var(--accent); }
/* Во время перетаскивания глушим выделение текста и события на канвасе. */
body.is-resizing { cursor: col-resize; user-select: none; }
body.is-resizing .canvas-host { pointer-events: none; }

/* ===== Sidebar ============================================ */

.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
.sidebar::-webkit-scrollbar-thumb:hover { background: var(--border-2); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.panel__title {
  margin: 0;
  padding: 10px 12px 8px;
  font-size: 10px;
  font-family: var(--ff-mono);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
}
.panel__count {
  margin-left: auto;
  font-weight: 400;
  color: var(--muted-2);
  font-size: 10px;
}
.panel__actions {
  display: flex;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
}
.link {
  background: none;
  border: none;
  color: var(--muted);
  font-family: var(--ff-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  padding: 2px 0;
  transition: color 100ms;
}
.link:hover { color: var(--accent); }

/* ===== Level editor (panel-levels-edit) ================== */
.lvled__group-title {
  padding: 8px 12px 4px;
  font-size: 9px;
  font-family: var(--ff-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted-2);
}
.lvled-row {
  display: grid;
  grid-template-columns: 1fr 64px 18px;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
}
.lvled-row.is-top { background: rgba(255, 255, 255, 0.03); }
.lvled-row.is-excluded { opacity: 0.5; }
.lvled-row { cursor: pointer; }
.lvled-row.is-selected {
  background: rgba(224, 64, 251, 0.16);
  box-shadow: inset 2px 0 0 #e040fb;
}
.lvled-row__name {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm, 4px);
  color: var(--text);
  font-size: 12px;
  padding: 3px 6px;
  min-width: 0;
}
.lvled-row__name[readonly] { background: transparent; border-color: transparent; }
.lvled-row__num {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm, 4px);
  color: var(--text);
  font-family: var(--ff-mono);
  font-size: 11px;
  padding: 3px 4px;
  text-align: right;
  /* Прячем стрелки спиннера — отметку вводят точным числом. */
  -moz-appearance: textfield;
  appearance: textfield;
}
.lvled-row__num::-webkit-outer-spin-button,
.lvled-row__num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.lvled-row__num:disabled { opacity: 0.4; }
.lvled-row__del {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  transition: color 100ms;
}
.lvled-row__del:hover { color: var(--danger, #e53935); }
.lvled-row__unit {
  grid-column: 1 / -1;
  font-size: 9px;
  color: var(--muted-2);
  font-family: var(--ff-mono);
  text-align: right;
  margin-top: -2px;
}

/* Segmented control (e.g. horizontal-element filter) */
.segmented {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
/* Inline toggle row inside the horizontal-filter panel: a checkbox label
   that doesn't need the grid alignment of the storey/type list rows. */
.row--toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding: 6px 2px;
  cursor: pointer;
  font-size: 11px;
  font-family: var(--ff-mono);
  letter-spacing: 0.03em;
  color: var(--fg-2);
  user-select: none;
}
.row--toggle:hover { color: var(--fg); }
/* toolbar dropdown (e.g. projection picker) */
.select {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--border-2);
  background-color: var(--surface);
  color: var(--fg);
  font-family: var(--ff-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 6px 26px 6px 12px;
  border-radius: var(--r-sm);
  cursor: pointer;
  -webkit-app-region: no-drag;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='6' viewBox='0 0 8 6' fill='none'%3E%3Cpath d='M1 1l3 3 3-3' stroke='%236b7682' stroke-width='1.4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
}
.select:hover {
  background-color: var(--surface-2);
  border-color: var(--accent);
  color: var(--accent);
}
.select:focus { outline: none; border-color: var(--accent); }
.select option {
  background: var(--surface);
  color: var(--fg);
}
/* Text input — same visual language as `.select`, just no chevron. Used by
   the «Выбор» panel for the glob-style name filter. */
.input {
  display: block;
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--border-2);
  background-color: var(--surface);
  color: var(--fg);
  font-family: var(--ff-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 6px 10px;
  border-radius: var(--r-sm);
}
.input::placeholder { color: var(--muted-2); }
.input:focus { outline: none; border-color: var(--accent); }
.input:hover { border-color: var(--accent); }
/* Stack of action buttons used inside `.panel__body` (e.g. Выбрать / К выбору /
   Сброс). Distinct from `.panel__actions`, which lives in the panel header. */
.panel__actions--btns {
  border-bottom: none;
  padding: 0;
  flex-wrap: wrap;
  gap: 6px;
}
.btn--sm {
  padding: 6px 10px;
  font-size: 10px;
  letter-spacing: 0.05em;
}
/* Panels in the sidebar use a one-column `.panel__body`. The Выбор panel
   stacks input + select + buttons + hint, so give them consistent breathing
   room without touching every other panel. */
#panel-select .panel__body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
}
.seg {
  appearance: none;
  text-align: left;
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--fg-2);
  font-family: var(--ff-mono);
  font-size: 11px;
  letter-spacing: 0.03em;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background 120ms, border-color 120ms, color 120ms;
}
.seg:hover { background: var(--surface-2); color: var(--fg); }
.seg.is-on {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.panel__body {
  padding: 10px 12px;
}
.panel__body.list {
  padding: 4px 0;
  max-height: 280px;
  overflow-y: auto;
}
.panel__body.list::-webkit-scrollbar { width: 6px; }
.panel__body.list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* List rows (storeys / types) */
.row {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 12px;
  user-select: none;
  transition: background 100ms;
}
.row:hover { background: var(--surface-2); }
.row__swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  border: 1px solid rgba(255,255,255,0.18);
  flex-shrink: 0;
}
.row__check {
  appearance: none;
  width: 12px;
  height: 12px;
  border: 1px solid var(--border-2);
  border-radius: 2px;
  background: var(--bg);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}
.row__check:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.row__check:checked::after {
  content: "";
  position: absolute;
  left: 2px; top: -0.5px;
  width: 4px; height: 7px;
  border: solid var(--bg);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}
.row__label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--fg-2);
}
.row.is-off .row__label { color: var(--muted-2); }
/* Значок якорного уровня (определён по пространствам) — в списке этажей и редакторе. */
.anchor-badge {
  margin-left: 4px;
  color: var(--accent);
  font-size: 10px;
  opacity: 0.95;
  white-space: nowrap;
}

/* «Типы» panel — row layout: swatch · name · count · 3-state visibility icons.
   Override the default `.row` grid since this row doesn't have a checkbox. */
.row--type {
  grid-template-columns: 10px 1fr auto auto;
  cursor: default;
}
.row--type:hover { background: transparent; }
/* Three-state visibility group (visible / translucent / hidden). The active
   button gets `.is-on`. Keys use simple unicode glyphs — see VIS_GLYPH in
   ui.js — so we don't need an SVG sprite. */
.vis {
  display: inline-flex;
  gap: 2px;
  margin-left: 6px;
}
.vis__btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted-2);
  font-size: 13px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: color 100ms, background 100ms, border-color 100ms;
}
.vis__btn:hover { color: var(--fg); background: var(--surface-2); }
.vis__btn.is-on {
  color: var(--accent);
  border-color: var(--border-2);
  background: var(--surface-2);
}

/* «Назначить тип» — row inside the Select panel: label + dropdown stacked. */
.select-assign {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 2px;
}
.select-assign__label {
  font-family: var(--ff-mono);
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Type rows: swatch + name share the middle (1fr) column */
.row__typename {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;            /* let the name shrink so ellipsis works */
}
.row__name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--fg-2);
}
.row.is-off .row__name { color: var(--muted-2); }
.row__meta {
  font-family: var(--ff-mono);
  font-size: 10px;
  color: var(--muted);
}

/* Info table */
.kv {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 4px 10px;
  font-size: 11px;
}
.kv dt {
  color: var(--muted);
  font-family: var(--ff-mono);
  text-transform: lowercase;
}
.kv dd {
  margin: 0;
  color: var(--fg-2);
  font-family: var(--ff-mono);
  word-break: break-word;
}

/* ===== Stage / canvas ===================================== */

.stage {
  position: relative;
  background:
    radial-gradient(ellipse at 50% 100%, #182028 0%, var(--bg) 70%);
  overflow: hidden;
}
.canvas-host {
  position: absolute;
  inset: 0;
}
.canvas-host canvas {
  display: block;
}

/* ===== Индикатор режима изоляции ========================== */

/* Рамка-«обводка» вьюпорта (как в Revit): не перехватывает мышь, кроме бейджа. */
.isolate-frame {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: var(--z-overlay);
  border: 3px solid var(--info);
  box-shadow: inset 0 0 0 1px rgba(53, 194, 255, 0.25),
              inset 0 0 24px rgba(53, 194, 255, 0.18);
  border-radius: 2px;
}
.isolate-frame[hidden] { display: none; }
.isolate-frame__badge {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px 5px 12px;
  background: var(--surface-2);
  border: 1px solid var(--info);
  border-radius: var(--r-md);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  font-size: 12px;
  font-weight: 600;
  color: var(--info-2);
  letter-spacing: 0.02em;
}
.isolate-frame__icon { font-size: 14px; line-height: 1; }
.isolate-frame__text { white-space: nowrap; }
.isolate-frame__exit {
  pointer-events: auto;
  background: var(--info);
  color: #04141d;
  border: none;
  border-radius: var(--r-sm);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  padding: 3px 10px;
}
.isolate-frame__exit:hover { background: var(--info-2); }

/* ===== View shortcuts (top-right of stage) ================ */

.viewcube {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  /* Крестовина видов: 3 колонки × 4 ряда. Позиции задают классы кнопок. */
  grid-template-columns: repeat(3, 62px);
  grid-template-rows: repeat(4, auto);
  gap: 4px;
  padding: 8px;
  background: rgba(10, 13, 16, 0.72);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  z-index: var(--z-hud);
}
.viewcube__btn {
  appearance: none;
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--fg-2);
  font-family: var(--ff-sans);
  font-size: 11px;
  letter-spacing: 0.01em;
  padding: 6px 0;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background 120ms, border-color 120ms, color 120ms;
}
.viewcube__btn:hover {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--accent);
}
.viewcube__btn:active { transform: translateY(1px); }

/* Раскладка «крестовина»: сверху / (слева · спереди · справа) / сзади / ISO. */
.viewcube__btn--top   { grid-area: 1 / 2 / 2 / 3; }
.viewcube__btn--left  { grid-area: 2 / 1 / 3 / 2; }
.viewcube__btn--front { grid-area: 2 / 2 / 3 / 3; }
.viewcube__btn--right { grid-area: 2 / 3 / 3 / 4; }
.viewcube__btn--back  { grid-area: 3 / 2 / 4 / 3; }
.viewcube__btn--iso   { grid-area: 4 / 1 / 5 / 4; font-family: var(--ff-mono); letter-spacing: 0.06em; }

/* ===== Drop overlay ======================================= */

.dropzone {
  position: absolute;
  inset: 0;
  background: rgba(10, 13, 16, 0.88);
  backdrop-filter: blur(4px);
  z-index: var(--z-drop);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--accent);
  outline: 16px solid var(--accent-dim);
  outline-offset: -16px;
  pointer-events: none;
  animation: dz-pulse 1.4s ease-in-out infinite;
}
.dropzone__inner {
  text-align: center;
  color: var(--accent-2);
}
.dropzone__icon {
  font-size: 56px;
  line-height: 1;
  color: var(--accent);
  margin-bottom: 12px;
}
.dropzone__text {
  font-family: var(--ff-mono);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 13px;
  margin-bottom: 6px;
}
.dropzone__hint {
  font-family: var(--ff-mono);
  font-size: 11px;
  color: var(--muted);
}
@keyframes dz-pulse {
  0%,100% { outline-color: var(--accent-dim); }
  50%     { outline-color: rgba(255, 138, 61, 0.35); }
}

/* ===== Warning banner ===================================== */

.warnbar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(720px, calc(100% - 24px));
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--warn);
  border-radius: var(--r-md);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  font-size: 13px;
  color: var(--fg-2);
}
.warnbar[hidden] { display: none; }
.warnbar__icon { color: var(--warn); flex: 0 0 auto; }
.warnbar__text { flex: 1 1 auto; line-height: 1.35; }
.warnbar__close {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.warnbar__close:hover { color: var(--fg); }

/* Красный значок «!» — индикатор наличия предупреждений в модели.
   На триггере-шестерёнке (угловой бейдж) и инлайн перед пунктом меню. */
.warn-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  border-radius: 7px;
  background: var(--bad);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}
.warn-badge[hidden] { display: none; }
/* Бейдж на иконке-триггере — в правом верхнем углу. */
.dropdown__trigger { position: relative; }
.dropdown__trigger > .warn-badge {
  position: absolute;
  top: -3px;
  right: -3px;
}
/* Инлайн-бейдж в пункте меню — слева от текста. */
.warn-badge--inline {
  position: static;
  margin-right: 6px;
  vertical-align: middle;
}

/* ===== Loading overlay ==================================== */

.loading {
  position: absolute;
  inset: 0;
  background: rgba(10, 13, 16, 0.78);
  backdrop-filter: blur(6px);
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
}
.loading__inner { text-align: center; }
.loading__spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.loading__status {
  font-family: var(--ff-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg);
  margin-bottom: 4px;
}
.loading__detail {
  font-family: var(--ff-mono);
  font-size: 11px;
  color: var(--muted);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Empty state ======================================== */

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  overflow: hidden;
}
.empty__grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: radial-gradient(ellipse at center, black 30%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at center, black 30%, transparent 75%);
}
.empty__content {
  position: relative;
  max-width: 540px;
  z-index: 1;
}
.empty__eyebrow {
  font-family: var(--ff-mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 18px;
}
.empty__title {
  margin: 0 0 18px;
  font-size: 36px;
  line-height: 1.12;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.empty__title em {
  font-style: normal;
  color: var(--accent);
  font-weight: 700;
}
.empty__lead {
  margin: 0 0 24px;
  font-size: 14px;
  color: var(--fg-2);
  max-width: 460px;
}
.empty__lead code {
  background: var(--surface);
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--accent-2);
}
.empty__bullets {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  font-family: var(--ff-mono);
  font-size: 12px;
  color: var(--fg-2);
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.empty__bullets li {
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.empty__bullets span {
  color: var(--muted);
  font-size: 10px;
}

/* ===== Status bar ========================================= */

.statusbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 12px;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  font-family: var(--ff-mono);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.statusbar__spacer { flex: 1; }
.statusbar__item--mono { color: var(--fg-2); }

/* ===== Индикатор занятости/синхронности БД («светофор») ===== */
.dbstatus {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.dbstatus__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--muted);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
.dbstatus__label { color: var(--muted); }

/* нет модели из БД — нейтрально-серый */
.dbstatus.is-idle    .dbstatus__dot { background: var(--muted); }
.dbstatus.is-idle    .dbstatus__label { color: var(--muted); }

/* синхронизировано — зелёный */
.dbstatus.is-synced  .dbstatus__dot { background: var(--good); box-shadow: 0 0 6px var(--good); }
.dbstatus.is-synced  .dbstatus__label { color: var(--good); }

/* есть несохранённые изменения (в очереди) — жёлтый */
.dbstatus.is-pending .dbstatus__dot { background: var(--warn); box-shadow: 0 0 6px var(--warn); }
.dbstatus.is-pending .dbstatus__label { color: var(--warn); }

/* БД занята записью — красный, пульсирует */
.dbstatus.is-busy    .dbstatus__dot { background: var(--bad); box-shadow: 0 0 8px var(--bad); animation: dbstatus-pulse 1s ease-in-out infinite; }
.dbstatus.is-busy    .dbstatus__label { color: var(--bad); }

/* ошибка записи — красный (без пульсации) */
.dbstatus.is-error   .dbstatus__dot { background: var(--bad); box-shadow: 0 0 8px var(--bad); }
.dbstatus.is-error   .dbstatus__label { color: var(--bad); }

@keyframes dbstatus-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

/* ===== Pick info ========================================== */

.pick-row {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 4px 10px;
  font-size: 11px;
  margin-bottom: 8px;
  font-family: var(--ff-mono);
}
.pick-row dt { color: var(--muted); text-transform: lowercase; }
.pick-row dd { margin: 0; color: var(--fg-2); word-break: break-word; }

/* Сворачиваемый список исходных id (комплексные/кластерные элементы). */
.pick-idlist__toggle {
  margin-left: 6px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent, #4ea1ff);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}
.pick-idlist__toggle:hover { opacity: 0.8; }

/* Кнопки действий в панели «Выбранный элемент». */
.pick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

/* ===== Model browser (DB) ================================= */

.browser {
  position: fixed;
  inset: 0;
  background: rgba(10, 13, 16, 0.78);
  backdrop-filter: blur(6px);
  z-index: var(--z-drop);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.browser__panel {
  width: min(820px, 100%);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-lg);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.browser__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.browser__title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  flex: 1;
}
.browser__head-actions { display: flex; align-items: center; gap: 8px; }
.browser__list {
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.browser__error { color: var(--bad); padding: 16px; font-size: 12px; }

.browser-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-2);
  transition: border-color 0.12s, background 0.12s;
}
.browser-row:hover { border-color: var(--border-2); background: var(--surface-2); }
.browser-row.is-current { border-color: var(--accent-dim); }
.browser-row.is-busy { opacity: 0.5; pointer-events: none; }

.browser-row__main { flex: 1; min-width: 0; cursor: default; }
.browser-row__name {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 8px;
}
.browser-row__badge {
  font-family: var(--ff-mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  border-radius: var(--r-sm);
  padding: 1px 5px;
}
.browser-row__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin-top: 4px;
  font-family: var(--ff-mono);
  font-size: 10px;
  color: var(--muted);
}
.browser-row__src { color: var(--fg-2); text-transform: uppercase; letter-spacing: 0.06em; }
.browser-row__owner { color: var(--fg-2); font-variant-numeric: tabular-nums; }
.browser-row__status.is-ready     { color: var(--good); }
.browser-row__status.is-importing { color: var(--warn); }
.browser-row__status.is-error     { color: var(--bad); }
.browser-row__id {
  margin-top: 4px;
  font-size: 9px;
  color: var(--muted-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.browser-row__actions { display: flex; gap: 6px; flex-shrink: 0; }
.browser-row__del:hover { border-color: var(--bad); color: var(--bad); }

/* ===== Админка пользователей (#admin-modal) ================= */
.admin__create {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.admin__create .input { flex: 1 1 140px; min-width: 120px; }
.admin__create .select { flex: 0 0 auto; }
.admin__active { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--fg-2); }

.admin-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-2);
}
.admin-row.is-current { border-color: var(--accent-dim); }
.admin-row.is-busy { opacity: 0.5; pointer-events: none; }
.admin-row__main { flex: 1; min-width: 0; }
.admin-row__name { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--fg); }
.admin-row__badge {
  font-family: var(--ff-mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  border-radius: var(--r-sm);
  padding: 1px 5px;
}
.admin-row__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin-top: 4px;
  font-family: var(--ff-mono);
  font-size: 10px;
  color: var(--muted);
}
.admin-row__role { color: var(--fg-2); text-transform: uppercase; letter-spacing: 0.06em; }
.admin-row__status.is-active   { color: var(--good); }
.admin-row__status.is-inactive { color: var(--muted-2); }
.admin-row__actions { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.admin-row__del:hover { border-color: var(--bad); color: var(--bad); }

/* Пользователь = строка + раскрываемый список его моделей под ней. */
.admin-user { display: flex; flex-direction: column; }
.admin-row__models {
  margin: 2px 0 6px 12px;
  padding: 6px 10px;
  border-left: 2px solid var(--border-2);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.admin-model {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 11px;
  color: var(--fg-2);
}
.admin-model__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-model__src { font-family: var(--ff-mono); font-size: 9px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.admin-model__date { font-family: var(--ff-mono); font-size: 9px; color: var(--muted-2); }

/* Владелец модели как выпадающий список (режим передачи модели, ALLOW_OWNER_REASSIGN). */
.browser-row__owner--edit { display: inline-flex; align-items: center; gap: 2px; cursor: pointer; }
.browser-row__owner-select {
  font-family: var(--ff-mono);
  font-size: 10px;
  color: var(--fg-2);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 1px 4px;
  cursor: pointer;
}
.browser-row__owner-select:hover { border-color: var(--accent-dim); }

.empty__actions { margin-top: 28px; }

/* ===== Toolbar dropdowns (группировка действий) ============= */

/* Тонкий разделитель перед кнопкой «Настройки» в тулбаре. */
.toolbar__spacer {
  width: 1px;
  align-self: stretch;
  margin: 6px 2px;
  background: var(--border);
}

.dropdown {
  position: relative;
  -webkit-app-region: no-drag;
}
.dropdown.is-open > .dropdown__trigger {
  border-color: var(--accent);
  color: var(--accent);
}
.dropdown__menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;                /* открываем влево от правого края — не уезжает за вьюпорт */
  left: auto;
  min-width: 220px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  z-index: var(--z-drop);
}
.dropdown__menu[hidden] { display: none; }
.dropdown__item {
  appearance: none;
  width: 100%;
  text-align: left;
  white-space: nowrap;
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg);
  font-family: var(--ff-mono);
  font-size: 11px;
  letter-spacing: 0.03em;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background 120ms, color 120ms;
}
.dropdown__item:hover:not(:disabled) { background: var(--surface-2); color: var(--accent); }
.dropdown__item:disabled { opacity: 0.4; cursor: not-allowed; }
/* Тоггл-пункты (изоляция, кластеризация поверхностей) во включённом состоянии. */
.dropdown__item.is-on,
.dropdown__item[aria-pressed="true"] {
  color: var(--accent);
  background: var(--accent-dim);
}
.dropdown__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px;
}
.dropdown__row-label {
  font-family: var(--ff-mono);
  font-size: 11px;
  letter-spacing: 0.03em;
  color: var(--muted);
}
/* Разделитель между группами действий в меню (напр. «Выгрузка в ЭМ» ↑ / прочее ↓). */
.dropdown__sep {
  height: 1px;
  margin: 4px 6px;
  background: var(--border);
}

/* ===== Степпер пайплайна в меню «Модель» ============================
   Пункт-шаг = маркер состояния + подпись. Состояния ставит main.js
   (updateModelPipeline): --done шаг выполнен (слой построен), --stale слой
   построен, но апстрим-шаг пересобран ПОСЛЕ него (данные не тронуты, только
   статус — рекомендация пересобрать), --next следующий доступный шаг (акцент),
   --busy идёт сборка (спиннер); без модификатора — шаг впереди (пустой кружок). */
.step-item {
  display: flex;
  align-items: center;
  gap: 8px;
}
.step-item__mark {
  flex: none;
  width: 12px;
  height: 12px;
  border: 1px solid var(--muted);
  border-radius: 50%;
  position: relative;
  opacity: 0.55;
}
.step-item--done .step-item__mark {
  border-color: var(--good);
  opacity: 1;
}
.step-item--done .step-item__mark::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 1px;
  width: 3px;
  height: 6px;
  border: solid var(--good);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}
.step-item--next .step-item__mark {
  border-color: var(--accent);
  opacity: 1;
  box-shadow: 0 0 6px var(--accent-dim);
}
.step-item--next .step-item__mark::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  background: var(--accent);
}
.step-item--stale .step-item__mark {
  border-color: var(--warn);
  opacity: 1;
}
.step-item--stale .step-item__mark::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  background: var(--warn);
}
.step-item--busy .step-item__mark {
  border-color: var(--border);
  border-top-color: var(--accent);
  opacity: 1;
  animation: spin 0.7s linear infinite;
}
/* Под-вариант шага («по якорным уровням»): сдвиг вправо; маркер зеркалит
   состояние основного шага упрощёнки (updateModelPipeline) — это альтернатива
   той же позиции пайплайна, без маркера выглядела невыполненным шагом. */
.step-item--sub { padding-left: 24px; }
/* disabled-пункт: маркер тоже приглушается общим opacity кнопки (0.4). */

/* Точка на триггере «Модель ▾»: есть доступный следующий шаг пайплайна.
   Во время сборки ЭМ превращается в мини-спиннер (--busy). */
.step-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 6px;
  vertical-align: 2px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}
.step-dot[hidden] { display: none; }
.step-dot--busy {
  background: transparent;
  box-shadow: none;
  width: 9px;
  height: 9px;
  border: 1.5px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
  vertical-align: 0;
}

/* Сегмент «Энергетическая модель» панели «Модель» во время сборки ЭМ:
   спиннер перед подписью, сам сегмент выключен (слоя ещё нет). */
.seg--busy::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  vertical-align: -1px;
  border: 1.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.seg--busy { opacity: 0.75; cursor: progress; }
/* Группа «подпись + сегментированный переключатель» внутри меню (напр. проекция).
   Столбцом, чтобы сегменты .seg легли под подписью в общем стиле панели «Модель». */
.dropdown__group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 10px;
}

/* ===== Settings modal ====================================== */

.browser__panel--narrow { width: min(440px, 100%); }

.settings__tabs {
  flex-direction: row;     /* перекрываем вертикальный .segmented */
  flex-wrap: wrap;
  gap: 4px;
  padding: 12px 16px 0;
}
.settings__body {
  padding: 14px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.settings__pane { display: flex; flex-direction: column; gap: 16px; }
.settings__pane[hidden] { display: none; }   /* перекрываем display:flex для скрытой вкладки */
.settings__field { display: flex; flex-direction: column; gap: 6px; }
.settings__field[hidden] { display: none; }
.settings__label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--ff-mono);
  font-size: 11px;
  letter-spacing: 0.03em;
  color: var(--fg-2);
}
.settings__val { color: var(--accent); }
.settings__hint { font-size: 10px; line-height: 1.4; color: var(--muted); }
.settings__hint--effect { margin-top: 4px; color: var(--fg-2); }
.settings__hint--effect strong { color: var(--accent); font-weight: 600; }

/* Список настроек в окне подтверждения выгрузки в ЭМ (dt = подпись, dd = значение). */
.em-export__list { margin: 10px 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; align-items: baseline; }
.em-export__list dt { color: var(--muted); font-size: 12px; }
.em-export__list dd { margin: 0; font-size: 12px; font-variant-numeric: tabular-nums; font-weight: 600; }
#settings-cl-mode { flex-direction: row; gap: 4px; }
.settings__range {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}
.settings__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

/* ===== Warnings modal ====================================== */

.warnings__summary {
  padding: 12px 16px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--fg-2);
  border-bottom: 1px solid var(--border);
}
.warnings__summary--empty { color: var(--muted); }
/* Заголовок группы предупреждений одного эмиттера: загрузчик модели (--warn)
   или построитель ЭМ (--info). Цвет полосы = цвет эмиттера. */
.warn-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 10px 6px 10px;
  border-left: 3px solid var(--warn);
  margin-top: 4px;
}
.warn-group--em { border-left-color: var(--info); }
.warn-group__title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--warn);
}
.warn-group--em .warn-group__title { color: var(--info); }
.warn-group__summary {
  font-size: 11px;
  line-height: 1.4;
  color: var(--fg-2);
}
/* Строка одного предупреждения в прокручиваемом списке (.browser__list). */
.warn-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--warn);
  border-radius: var(--r-md);
  background: var(--bg-2);
}
.warn-row--dropped  { border-left-color: var(--bad); }
.warn-row--recovered { border-left-color: var(--ok, #57c785); }
/* Записи построителя ЭМ — свой цвет полосы поверх статусного (после
   --dropped/--recovered, чтобы победить при равной специфичности). */
.warn-row--em { border-left-color: var(--info); }
/* Просмотренное предупреждение остаётся в списке, но приглушается — бейдж «!»
   гаснет уже когда непросмотренных не осталось, а не по удалению записи. */
.warn-row--seen { opacity: 0.55; }
.warn-row__head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.warn-row__name {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg);
}
.warn-row__status {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: var(--r-sm);
}
.warn-row__status--dropped   { background: var(--bad);  color: #fff; }
.warn-row__status--recovered { background: var(--ok, #57c785); color: #0b0e11; }
.warn-row__status--em        { background: var(--info); color: #0b0e11; }
.warn-row__seen-btn { margin-left: auto; padding: 2px 8px; font-size: 9px; }
.warn-row__meta {
  font-family: var(--ff-mono);
  font-size: 10px;
  color: var(--muted);
  word-break: break-all;
}
