:root {
  --bg: #0d0e11;
  --bg-canvas: #14161a;
  --panel: #16181d;
  --panel-2: #1c1f25;
  --line: #262a32;
  --text: #e6e8ec;
  --muted: #8b929e;
  --accent: #e8a33d;
  --accent-soft: rgba(232, 163, 61, 0.16);
  --blue: #4aa3ff;
  --danger: #e2685f;
  --radius: 8px;
  --topbar: 52px;
  --status: 26px;
  --left: 290px;
  --right: 288px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, select { font: inherit; color: inherit; }

.app {
  display: grid;
  grid-template-columns: var(--left) minmax(0, 1fr) var(--right);
  grid-template-rows: var(--topbar) minmax(0, 1fr) var(--status);
  grid-template-areas:
    "top top top"
    "left view right"
    "status status status";
  height: 100%;
}

/* Свёрнутые панели оставляют узкую «рельсу» с кнопкой возврата */
.app.collapsed-left { --left: 44px; }
.app.collapsed-right { --right: 44px; }

/* ---------- top bar ---------- */

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.brand { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  padding: 0 6px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.brand-title { font-size: 13px; font-weight: 600; color: var(--text); }

.tools { display: flex; align-items: center; gap: 8px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tools::-webkit-scrollbar { display: none; }

.divider { width: 1px; height: 22px; background: var(--line); flex-shrink: 0; }

.tool-group { display: flex; gap: 2px; padding: 2px; background: var(--panel-2); border-radius: var(--radius); flex-shrink: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.btn:hover { background: rgba(255, 255, 255, 0.06); }
.btn:active { background: rgba(255, 255, 255, 0.1); }
.btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }

.btn-primary { background: var(--accent); color: #1a1408; font-weight: 600; }
.btn-primary:hover { background: #f0b055; }
.btn-primary:active { background: #d8952f; }

.btn-ghost { border-color: var(--line); color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: #353a44; }

.btn.tool.active { background: var(--accent-soft); color: var(--accent); }
.btn.active { background: rgba(255, 255, 255, 0.08); color: var(--text); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:disabled:hover { background: transparent; }

.field { display: flex; align-items: center; gap: 6px; color: var(--muted); flex-shrink: 0; }

.field select {
  height: 30px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}

/* ---------- panels ---------- */

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  overflow: hidden;
}

.panel-left { grid-area: left; border-right: 1px solid var(--line); }
.panel-right { grid-area: right; border-left: 1px solid var(--line); }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px 8px;
  flex-shrink: 0;
}

.panel-head h2 { margin: 0; font-size: 11px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
.panel-head-sub { border-top: 1px solid var(--line); padding-top: 12px; }

.badge {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.panel-body { flex: 1; min-height: 0; overflow: auto; padding: 0 10px 10px; }

.panel.collapsed .panel-head,
.panel.collapsed .panel-body,
.panel.collapsed .panel-foot { display: none; }

.rail-restore {
  display: none;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  padding: 12px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.rail-restore:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.rail-restore:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
.panel.collapsed .rail-restore { display: flex; }

.rail-label {
  writing-mode: vertical-rl;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.rail-restore-right .rail-label { transform: rotate(180deg); }

.rail-badge { font-size: 10px; }
.panel-body-layers { flex: 0 1 auto; max-height: 42%; }
.panel-body-props { flex: 1 1 auto; }

.panel-foot {
  display: flex;
  gap: 6px;
  padding: 10px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.panel-foot .btn { flex: 1; justify-content: center; }

.note { margin: 4px 4px 10px; color: var(--muted); font-size: 12px; line-height: 1.5; }

/* ---------- measurements ---------- */

.measure-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }

.measure-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  cursor: pointer;
}

.measure-item:hover { border-color: #363b46; }
.measure-item.selected { border-color: var(--accent); background: var(--accent-soft); }

.measure-value { font-variant-numeric: tabular-nums; font-size: 14px; font-weight: 600; }
.measure-meta { color: var(--muted); font-size: 11px; grid-column: 1 / 2; }
.measure-actions { grid-row: 1 / 3; display: flex; align-items: center; gap: 2px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }

/* ---------- layers ---------- */

.layer-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }

.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
}
.layer-item:hover { background: rgba(255, 255, 255, 0.04); }

.layer-pill { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35); }
.layer-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-item.off .layer-name { color: var(--muted); text-decoration: line-through; text-decoration-color: #4a4f5a; }

.check {
  width: 15px;
  height: 15px;
  border: 1px solid #3b414d;
  border-radius: 4px;
  background: var(--bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: transparent;
  font-size: 10px;
}
.layer-item:not(.off) .check { background: var(--accent); border-color: var(--accent); color: #1a1408; }

/* ---------- properties ---------- */

.props { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 0 4px 10px; }
.props dt { color: var(--muted); font-size: 12px; }
.props dd { margin: 0; font-size: 12px; word-break: break-word; }

.props-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.props-table td { padding: 4px 6px; border-top: 1px solid var(--line); vertical-align: top; }
.props-table td:first-child { color: var(--muted); width: 45%; }

/* ---------- viewport ---------- */

.viewport {
  grid-area: view;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--bg-canvas);
  cursor: default;
}

.viewport canvas { display: block; }
.viewport.measuring { cursor: crosshair; }

.labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

.measure-label {
  position: absolute;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(20, 22, 26, 0.92);
  border: 1px solid rgba(232, 163, 61, 0.55);
  color: #ffd699;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  will-change: transform;
}

.measure-label.selected { border-color: var(--blue); color: #cfe4ff; }

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  pointer-events: none;
}

.empty-card {
  max-width: 420px;
  text-align: center;
  padding: 34px 30px;
  border: 1px dashed #333844;
  border-radius: 14px;
  color: var(--muted);
  background: rgba(22, 24, 29, 0.6);
}

.empty-card svg { color: var(--accent); opacity: 0.85; }
.empty-card h1 { margin: 14px 0 6px; font-size: 15px; font-weight: 600; color: var(--text); }
.empty-card p { margin: 0; font-size: 12px; line-height: 1.6; }

.model-list { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); text-align: left; }
.model-list h2 {
  margin: 0 0 8px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}
.model-list ul { list-style: none; margin: 0; padding: 0; max-height: 190px; overflow: auto; display: flex; flex-direction: column; gap: 2px; }

.model-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 12.5px;
}
.model-item:hover { background: rgba(255, 255, 255, 0.06); }
.model-item .model-size { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; flex-shrink: 0; }

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(13, 14, 17, 0.72);
  backdrop-filter: blur(2px);
  color: var(--text);
  z-index: 5;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.drop-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(232, 163, 61, 0.1);
  border: 2px dashed var(--accent);
  border-radius: 10px;
  margin: 10px;
  color: var(--accent);
  font-weight: 600;
  z-index: 6;
  pointer-events: none;
}
.drop-overlay.active { display: flex; }

.mobile-measures { display: none; }
.close-drawer { display: none; }

.hint-pill {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 24px);
  padding: 8px 12px;
  border: 1px solid rgba(232, 163, 61, 0.45);
  border-radius: 999px;
  background: rgba(20, 22, 26, 0.94);
  color: var(--text);
  font-size: 12.5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  z-index: 9;
  pointer-events: none;
}

.hint-pill .btn { pointer-events: auto; height: 26px; font-size: 12px; }

@media (pointer: coarse) {
  .hint-pill:not(.hidden) { display: inline-flex; }
}

.cursor-tag {
  position: absolute;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(232, 163, 61, 0.95);
  color: #1a1408;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  pointer-events: none;
  transform: translate(12px, 14px);
  z-index: 4;
}

/* ---------- status bar ---------- */

.statusbar {
  grid-area: status;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 14px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
  overflow: hidden;
}

.status-file, .status-hint { overflow: hidden; text-overflow: ellipsis; }
.status-hint { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 6, 8, 0.66);
  z-index: 20;
  padding: 20px;
}

.modal-card {
  width: min(460px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.modal-card h2 { margin: 0 0 8px; font-size: 15px; }
.modal-card p { margin: 0 0 18px; color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

.hidden { display: none !important; }

@media (max-width: 1440px) {
  /* Кнопки вида переходим на иконки: подписи остаются у инструментов измерения */
  .view-tools .btn-label { display: none; }
}

@media (max-width: 1180px) {
  .app { grid-template-columns: var(--left) minmax(0, 1fr); grid-template-areas: "top top" "left view" "status status"; }
  .panel-right { display: none; }
}

@media (max-width: 820px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) var(--status);
    grid-template-areas: "top" "view" "status";
  }
  .topbar { flex-wrap: wrap; height: auto; padding: 6px 10px; row-gap: 6px; }
  .brand-title { display: none; }
  .tools { width: 100%; gap: 5px; }
  .topbar > .btn-primary { margin-left: auto; }
  .field > span { display: none; }
  .field[for="snap-mode"] { display: none; }
  .btn-label { display: none; }
  .btn { padding: 0 6px; }

  /* Инструменты измерения подписаны, кнопки вида уходят в плавающий блок */
  .tool-tools .btn:not([data-tool="select"]) .btn-label { display: inline; }
  .view-tools {
    position: fixed;
    right: 10px;
    bottom: 10px;
    z-index: 11;
    background: rgba(22, 24, 29, 0.92);
    border: 1px solid var(--line);
  }

  .status-hint { display: none; }

  .panel-left {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    max-height: 64%;
    z-index: 12;
    border-top: 1px solid var(--line);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -18px 40px rgba(0, 0, 0, 0.45);
    transform: translateY(101%);
    transition: transform 0.18s ease;
  }
  .panel-left.open { transform: translateY(0); }

  .close-drawer { display: inline-flex; }
  .panel-toggle, .rail-restore { display: none !important; }

  .mobile-measures {
    display: inline-flex;
    position: absolute;
    left: 10px;
    bottom: 10px;
    z-index: 11;
    background: rgba(22, 24, 29, 0.92);
    gap: 8px;
  }
}
