:root { color-scheme: light; font-family: Inter, system-ui, -apple-system, Segoe UI, sans-serif; }
* { box-sizing: border-box; }
body { margin: 0; background: #eef2f6; color: #111827; }
.panel { position: fixed; top: 18px; left: 18px; z-index: 10; width: 360px; max-width: calc(100vw - 36px); max-height: calc(100vh - 36px); overflow-y: auto; background: rgba(255,255,255,.94); border-radius: 14px; padding: 16px; box-shadow: 0 16px 45px rgba(15,23,42,.16); backdrop-filter: blur(10px); }
.panel.wide { position: static; margin: 24px auto; width: min(900px, calc(100vw - 32px)); max-width: none; }
h1 { font-size: 20px; margin: 0 0 10px; }
h2 { font-size: 16px; margin: 18px 0 8px; }
label { display: block; font-size: 13px; margin: 10px 0; }
input, select { width: 100%; border: 1px solid #cbd5e1; border-radius: 8px; padding: 9px; background: white; }
input[type="range"] { padding: 0; }
button, .button { display: inline-block; border: 0; border-radius: 8px; padding: 10px 13px; margin: 5px 5px 5px 0; background: #0f172a; color: white; font-weight: 650; text-decoration: none; cursor: pointer; }
button.secondary { background: #475569; }
.status { margin-top: 10px; padding: 10px; border-radius: 8px; background: #f8fafc; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.muted { color: #64748b; font-size: 13px; }
.job { border-top: 1px solid #e2e8f0; padding: 12px 0; }
canvas.viewer { width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; }
.toolbar-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.metric { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: #0f172a; color: white; border-radius: 8px; padding: 9px; margin-top: 8px; max-height: 120px; overflow: auto; }
@media (max-width: 760px) { .panel { width: calc(100vw - 24px); top: 12px; left: 12px; padding: 12px; } }

.model-list { max-height: 240px; overflow: auto; border: 1px solid #e2e8f0; border-radius: 10px; background: rgba(248,250,252,.75); padding: 6px; }
.model-row { display: flex; flex-direction: column; gap: 4px; padding: 7px; border-bottom: 1px solid #e2e8f0; }
.model-row:last-child { border-bottom: 0; }
.model-row input[type="checkbox"] { width: auto; margin-top: 2px; }
.model-row-title { font-weight: 650; overflow-wrap: anywhere; }
.model-row-meta { color: #64748b; font-size: 12px; overflow-wrap: anywhere; }
.federated-panel { width: 462px; max-height: calc(100vh - 36px); overflow: auto; }
@media (max-width: 760px) { .federated-panel { max-height: 65vh; } }

/* First-person walk mode crosshair */
.fp-crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  pointer-events: none;
  z-index: 50;
  display: none;
}
.fp-crosshair::before,
.fp-crosshair::after {
  content: "";
  position: absolute;
  background: rgba(15, 23, 42, 0.85);
}
.fp-crosshair::before { left: 8px; top: 0; width: 2px; height: 18px; }
.fp-crosshair::after { top: 8px; left: 0; height: 2px; width: 18px; }
.fp-crosshair.active { display: block; }

/* ===== Priority 1 tools UI ===== */
.tool-section {
  margin: 8px 0;
  padding: 8px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
}
.tool-section-title {
  font-weight: 650;
  font-size: 13px;
  color: #475569;
  margin-bottom: 6px;
}
.toolbar-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}
.toolbar-row button {
  flex: 1;
  margin: 0;
}
.tool-hint {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 4px;
  line-height: 1.4;
}
button.active-tool {
  background: #2f7fff !important;
  color: #fff;
}
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ViewCube */
.view-cube {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  background: rgba(255, 255, 255, 0.92);
  padding: 8px;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.12);
}
.view-cube-btn {
  font-size: 11px;
  padding: 5px 8px;
  margin: 0;
  background: #334155;
  border-radius: 6px;
}
.view-cube-btn:hover { background: #475569; }

/* Per-model tint */
.tint-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: middle;
}
.tint-btn {
  font-size: 11px;
  padding: 4px 8px;
  margin: 0;
  align-self: flex-start;
}
/* ===== 3D ViewCube gizmo ===== */
.view-cube-3d {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 40;
  background: rgba(255,255,255,0.6);
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(15,23,42,0.12);
}

/* ===== Sections UI ===== */
.section-list { margin-top: 6px; display: flex; flex-direction: column; gap: 5px; }
.sec-row {
  display: flex; align-items: center; gap: 5px;
  background: #f1f5f9; border-radius: 6px; padding: 4px 6px;
}
.sec-row .sec-axis { flex: 1; font-size: 12px; padding: 3px 4px; border-radius: 5px; border: 1px solid #cbd5e1; }
.sec-row .sec-custom { flex: 1; font-size: 12px; color: #64748b; }
.sec-flip, .sec-del {
  font-size: 12px; padding: 3px 8px; margin: 0; min-width: 28px;
}
.sec-del { background: #b91c1c; }

/* ===== Tint swatches (federated) ===== */
.tint-swatch-btn {
  width: 17px; height: 17px; border-radius: 4px; padding: 0; margin: 0;
  border: 2px solid transparent; cursor: pointer; position: relative;
}
.tint-swatch-btn.used::after {
  content: "✕"; position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 11px; font-weight: bold;
  text-shadow: 0 0 2px rgba(0,0,0,0.8);
}
.tint-swatch-btn.active { border-color: #0f172a; }
.tint-clear-btn { font-size: 11px; padding: 3px 6px; margin: 4px 0 0; }

/* ===== Projects page ===== */
.projects-page { max-width: 900px; margin: 0 auto; padding: 24px 20px 60px; }
.projects-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.projects-header h1 { margin: 0; }
.token-field { font-size: 13px; color: #475569; display: flex; align-items: center; gap: 6px; }
.token-field input { width: 160px; }
.project-create { margin-top: 20px; padding: 16px; border: 1px solid #e2e8f0; border-radius: 12px; background: #f8fafc; }
.project-create h2, .project-list-section h2 { margin: 0 0 12px; font-size: 16px; }
.project-create .field { margin-bottom: 10px; }
.project-create .field label { display: block; font-size: 12px; color: #64748b; margin-bottom: 3px; }
.project-create .field input { width: 100%; }
.msg { margin-top: 8px; font-size: 13px; }
.msg.ok { color: #15803d; }
.msg.err, .err { color: #b91c1c; }
.project-list-section { margin-top: 28px; }
.project-list { display: flex; flex-direction: column; gap: 12px; }
.project-card {
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px 16px; border: 1px solid #e2e8f0; border-radius: 12px; background: #fff;
}
.project-card-main { flex: 1; min-width: 260px; display: flex; flex-direction: column; gap: 6px; }
.proj-name { font-weight: 650; font-size: 15px; }
.proj-folder { font-family: monospace; font-size: 12px; color: #475569; }
.proj-models { font-size: 12px; margin-top: 2px; }
.project-card-actions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; min-width: 150px; }
.project-card-actions button { margin: 0; }
button.danger { background: #b91c1c; }

/* Per-model opacity slider (Stage 2) */
.opacity-row { display: flex; flex-direction: column; gap: 2px; min-width: 110px; margin-top: 4px; }
.opacity-label { font-size: 10px; color: #94a3b8; }
.opacity-slider { width: 100%; margin: 0; }

/* Saved views list (Stage 3) */
.view-list { display: flex; flex-direction: column; gap: 4px; margin: 6px 0; }
.view-row { display: flex; gap: 5px; }
.view-open { flex: 1; text-align: left; font-size: 12px; padding: 5px 8px; margin: 0; }
.view-del { padding: 5px 9px; margin: 0; background: #b91c1c; }

/* Model row: name fits, colors collapsed in spoiler (problem 1) */
.model-row-head { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; }
.model-row-namebox { flex: 1; min-width: 0; }
.model-row-namebox .model-row-title { display: block; word-break: break-word; font-weight: 600; font-size: 13px; }
.tint-spoiler { margin-top: 6px; }
.tint-spoiler > summary { cursor: pointer; font-size: 12px; color: #475569; padding: 2px 0; user-select: none; }
.tint-spoiler[open] > summary { margin-bottom: 6px; }
.tint-colors { display: flex; flex-wrap: wrap; gap: 3px; width: 100%; box-sizing: border-box; }

/* ===== Two-block UI organization ===== */
.ui-block { margin-top: 14px; padding: 10px; border: 1px solid #e2e8f0; border-radius: 12px; background: rgba(248,250,252,.55); }
.ui-block-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: #0f172a; margin-bottom: 8px; }
.ui-group { margin-top: 8px; border-top: 1px solid #eef2f6; padding-top: 8px; }
.ui-group:first-of-type { border-top: 0; padding-top: 0; }
.ui-group > summary { cursor: pointer; font-size: 13px; font-weight: 600; color: #334155; padding: 4px 0; user-select: none; list-style: none; }
.ui-group > summary::before { content: "▸ "; color: #94a3b8; }
.ui-group[open] > summary::before { content: "▾ "; }
.ui-group[open] > summary { margin-bottom: 6px; }

/* First-person walk-mode hotkey hint (bottom) */
.fp-hint {
  display: none;
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  z-index: 50; max-width: 92vw;
  background: rgba(15,23,42,.82); color: #e2e8f0;
  padding: 10px 16px; border-radius: 10px;
  font-size: 12.5px; line-height: 1.7; text-align: center;
  backdrop-filter: blur(6px); box-shadow: 0 6px 24px rgba(0,0,0,.3);
  pointer-events: none;
}
.fp-hint.active { display: block; }
.fp-hint-row { white-space: normal; }
.fp-hint b { color: #fff; }
.fp-hint .hk {
  display: inline-block; background: #334155; color: #fff;
  border-radius: 4px; padding: 1px 6px; margin: 0 1px; font-weight: 600;
  font-family: ui-monospace, monospace; font-size: 11.5px;
}
.fp-hint .hk.on { background: #2563eb; }

/* ===== Per-item delete badges (✕) for measurements & annotations ===== */
.delete-badge-layer { position: fixed; inset: 0; pointer-events: none; z-index: 40; }
.delete-badge {
  position: fixed; transform: translate(-50%, -50%);
  width: 20px; height: 20px; border-radius: 50%;
  border: none; cursor: pointer; pointer-events: auto;
  font-size: 12px; line-height: 1; font-weight: 700;
  color: #fff; opacity: 0.35; transition: opacity .12s, transform .12s;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.delete-badge:hover { opacity: 1; transform: translate(-50%, -50%) scale(1.25); }
.badge-measure { background: #ff6633; }
.badge-annot { background: #2563eb; }
.badge-elev { background: #0f766e; }
/* Список «Модели на сцене» — раскрывать до ~5 моделей */
#loadedModels { max-height: 420px; }
/* #1/#2 — иерархия по разделам */
.section-group { border-bottom: 1px solid #e2e8f0; }
.section-group > summary {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 7px; cursor: pointer; font-weight: 700; list-style: none;
}
.section-group > summary::-webkit-details-marker { display: none; }
.section-group > summary::before { content: '▸'; margin-right: 4px; color: #64748b; transition: transform .12s; }
.section-group[open] > summary::before { transform: rotate(90deg); }
.section-group .sgn { overflow-wrap: anywhere; }
.section-group .sgc { color: #64748b; font-size: 12px; font-weight: 600; white-space: nowrap; }
.sec-group-controls { display: flex; flex-direction: column; gap: 6px; padding: 4px 7px 10px; background: #f8fafc; }
.sec-group-controls .sec-load-row { display: flex; gap: 6px; }
.sec-group-controls .sec-load-row button { flex: 1; }
.sec-group-controls .sec-vis { display: flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; }
.sec-tint-row { display: flex; flex-direction: column; gap: 3px; }
.model-row-unloaded { flex-direction: row; align-items: center; justify-content: space-between; opacity: .85; }
.model-row-unloaded .model-load-btn { white-space: nowrap; }
.model-row-actions { display: flex; gap: 6px; margin-top: 4px; }
.model-row-actions button { flex: 1; }
.section-group .model-row { padding-left: 14px; }

/* === Уплотнение и единообразие боковой панели (фидбек по тесту) === */
.federated-panel button { font-size: 12.5px; padding: 8px 11px; min-height: 34px; box-sizing: border-box; }
.federated-panel button.compact { padding: 4px 9px; font-size: 12px; line-height: 1.15; min-height: 34px; }
.federated-panel .toolbar-row { margin-bottom: 6px; }
.federated-panel .toolbar-row button { min-height: 34px; }
.federated-panel .sec-grp-eye { min-height: 0; }

/* Блоки без спойлера (Граница 3D-вида, Камера и навигация) */
.ui-block { margin-top: 8px; border-top: 1px solid #eef2f6; padding-top: 8px; }
.ui-block-title { font-size: 13px; font-weight: 600; color: #334155; padding: 2px 0 4px; }

/* Вложенные спойлеры (цвет/прозрачность раздела, сохранённые виды) */
.ui-group.sub { margin-top: 6px; border-top: 0; padding-top: 0; }
.ui-group.sub > summary { font-size: 12px; font-weight: 600; color: #475569; padding: 3px 0; }

/* Сечения: ряд создания X/Y/Z + «По грани» */
.sec-create-row { align-items: center; gap: 5px; }
.sec-create-row .row-label { font-size: 12px; color: #64748b; flex: 0 0 auto; }
.sec-create-row button { flex: 0 0 auto; min-width: 30px; }
.sec-create-row #alignSectionBtn { flex: 1 1 auto; min-width: 0; }

/* Список разделов: имя слева, счётчик+глазик справа в строке спойлера */
.section-group > summary { padding: 7px 4px; }
.section-group .sgn { flex: 1 1 auto; text-align: left; }
.section-group .sg-right { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.sec-grp-eye { border: 0; background: transparent; padding: 2px; margin: 0; min-width: 0; width: auto; cursor: pointer; color: #334155; display: inline-flex; align-items: center; line-height: 0; border-radius: 6px; }
.sec-grp-eye:hover { background: #e2e8f0; }
.sec-grp-eye:disabled { opacity: .4; cursor: default; background: transparent; }

/* ===== Панель свойств элемента (Этап C) ===== */
.props-panel {
  position: fixed; right: 16px; top: 132px; z-index: 41;
  width: 300px; max-width: calc(100vw - 32px); max-height: calc(100vh - 160px);
  display: flex; flex-direction: column;
  background: rgba(255,255,255,0.97); border-radius: 12px;
  box-shadow: 0 8px 28px rgba(15,23,42,0.18); overflow: hidden;
  font-size: 12.5px;
}
.props-head { display: flex; align-items: center; justify-content: space-between; padding: 9px 12px; border-bottom: 1px solid #eef2f6; }
.props-title { font-weight: 700; color: #0f172a; }
.props-close { border: none; background: transparent; cursor: pointer; font-size: 15px; color: #64748b; width: 26px; height: 26px; border-radius: 6px; padding: 0; }
.props-close:hover { background: #e2e8f0; }
.props-sub { padding: 7px 12px; color: #475569; border-bottom: 1px solid #f1f5f9; overflow-wrap: anywhere; }
.props-sub .props-cat { color: #64748b; font-size: 11.5px; }
.props-body { overflow-y: auto; padding: 4px 0; }
.props-group { border-bottom: 1px solid #f4f6f9; }
.props-group > summary { padding: 7px 12px; cursor: pointer; font-weight: 600; color: #334155; list-style: none; display: flex; justify-content: space-between; align-items: center; }
.props-group > summary::-webkit-details-marker { display: none; }
.props-group > summary::before { content: '▸'; color: #94a3b8; margin-right: 6px; transition: transform .12s; }
.props-group[open] > summary::before { transform: rotate(90deg); }
.props-group .pg-count { color: #94a3b8; font-size: 11px; font-weight: 500; }
.props-row { display: flex; gap: 8px; padding: 4px 12px 4px 24px; }
.props-row .pr-name { flex: 0 0 44%; color: #64748b; overflow-wrap: anywhere; }
.props-row .pr-val { flex: 1 1 auto; color: #0f172a; overflow-wrap: anywhere; }
.props-row .pr-type { font-size: 9px; color: #92a3b8; border: 1px solid #cbd5e1; border-radius: 4px; padding: 0 3px; margin-left: 4px; vertical-align: middle; }
.props-empty { padding: 14px 12px; color: #64748b; }
@media (max-width: 760px) {
  .props-panel { top: auto; bottom: 92px; right: 8px; left: 8px; width: auto; max-height: 46vh; }
}

/* ===== Секция «Параметры» (Этап D) ===== */
.param-input { width: 100%; box-sizing: border-box; margin: 4px 0; padding: 6px 8px; border: 1px solid #cbd5e1; border-radius: 7px; font-size: 12.5px; }
.param-select { flex: 1 1 auto; padding: 5px 6px; border: 1px solid #cbd5e1; border-radius: 7px; font-size: 12px; background: #fff; }
.param-sep { margin: 9px 0 2px; font-size: 11px; font-weight: 600; color: #94a3b8; text-transform: uppercase; letter-spacing: .03em; }
.param-info { margin-top: 6px; font-size: 11.5px; color: #475569; }
.param-legend { margin: 6px 0 2px; max-height: 200px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.param-legend:empty { display: none; }
.legend-row { display: flex; align-items: center; gap: 7px; padding: 3px 4px; border-radius: 5px; cursor: pointer; font-size: 12px; }
.legend-row:hover { background: #f1f5f9; }
.legend-sw { width: 13px; height: 13px; border-radius: 3px; flex: 0 0 auto; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12); }
.legend-val { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #0f172a; }
.legend-cnt { color: #94a3b8; font-size: 11px; flex: 0 0 auto; }
