:root {
  --bg-color: #f8fafc;
  --panel-bg: rgba(255, 255, 255, 0.8);
  --panel-border: rgba(0, 0, 0, 0.1);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
  background-color: var(--bg-color);
  font-family: 'Inter', sans-serif;
  color: var(--text-primary);
}

#viewer-canvas {
  width: 100vw;
  height: 100vh;
  display: block;
}

/* Loader */
.loader-container {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background-color: var(--bg-color);
  z-index: 100;
  transition: opacity 0.5s ease;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 3px solid rgba(0,0,0,0.1);
  border-radius: 50%;
  border-top-color: var(--accent);
  animation: spin 1s ease-in-out infinite;
  margin-bottom: 20px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loader-text {
  font-size: 1rem;
  color: var(--text-secondary);
  letter-spacing: 1px;
}

/* UI Elements */
.ui-container {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 24px;
}

.glass-panel {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 16px 24px;
  pointer-events: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* Hamburger Menu Button */
.menu-btn {
  position: absolute;
  top: 24px;
  left: 24px;
  background: white;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  z-index: 2000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  pointer-events: auto;
}
.menu-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(0,0,0,0.15);
}

/* Side Menu */
.side-menu {
  position: absolute;
  top: 0;
  left: -320px;
  width: 320px;
  height: 100%;
  background: white;
  z-index: 3000;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 4px 0 24px rgba(0,0,0,0.15);
  padding: 30px;
  display: flex;
  flex-direction: column;
  pointer-events: auto;
}
.side-menu.open {
  transform: translateX(320px);
}
.menu-overlay {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.3);
  backdrop-filter: blur(2px);
  z-index: 2500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.menu-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.menu-header {
  margin-bottom: 24px;
}
.menu-header h2 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
}
.project-info {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-family: monospace;
  margin-top: 5px;
}

.positions-list {
  flex: 1;
  overflow-y: auto;
  margin: 0 -10px;
  padding: 0 10px;
}
.position-item {
  padding: 14px;
  margin-bottom: 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
}
.position-item:hover {
  background: #f1f5f9;
}
.position-item.active {
  background: var(--accent);
  color: white;
}
.position-item.active .pos-meta {
  color: rgba(255, 255, 255, 0.8);
}

.pos-name {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 3px;
}
.pos-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Title and UI */
.header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.project-title-container {
  position: absolute;
  top: 24px;
  left: 96px; /* Увеличен отступ от гамбургера */
  text-align: left;
  pointer-events: none;
  z-index: 5;
  height: 50px;
  display: flex;
  align-items: center;
}

.project-title-container h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: #5c463a;
  margin-bottom: 0;
  text-shadow: 0 0 10px white, 0 0 20px white;
}

/* Desktop Adaptive: Sidebar always open */
@media (min-width: 1024px) {
  .side-menu {
    left: 0;
    transform: none !important;
    box-shadow: 1px 0 10px rgba(0,0,0,0.05);
    border-right: 1px solid var(--panel-border);
  }
  .menu-btn {
    display: none !important;
  }
  .menu-overlay {
    display: none !important;
  }
  .project-title-container {
    display: none !important; /* На десктопе заголовок не нужен, он есть в списке */
  }
}

/* ===== Правая панель инструментов (виды / проекция / стили) ===== */
.side-tools {
  position: absolute;
  top: 90px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
  z-index: 20;
  max-height: calc(100vh - 180px);
  overflow-y: auto;
}

.tool-group {
  padding: 12px !important;
  border-radius: 12px !important;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 150px;
}

.tool-group-title {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 2px;
}

.view-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

/* Фасады скрыты — состояние должно быть заметно с одного взгляда */
.tool-btn.danger-active {
  background: rgba(239, 68, 68, 0.15);
  color: #991b1b;
  border-color: rgba(239, 68, 68, 0.4);
}

@media (hover: hover) {
  .tool-btn.danger-active:hover {
    background: rgba(239, 68, 68, 0.22);
  }
}

.tool-btn {
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 6px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
}

.tool-btn.wide {
  text-align: left;
  padding: 8px 10px;
}

@media (hover: hover) {
  .tool-btn:hover {
    background: rgba(0, 0, 0, 0.09);
  }
}

.tool-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.tool-sep {
  height: 1px;
  background: rgba(0, 0, 0, 0.08);
  margin: 4px 0;
}

.tool-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-primary);
  cursor: pointer;
  padding: 3px 2px;
  user-select: none;
}

.tool-check input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

/* Кнопка сворачивания панели — нужна на узких экранах */
.tools-toggle-btn {
  position: absolute;
  top: 84px;
  right: 24px;
  background: white;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
  z-index: 25;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  pointer-events: auto;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
}

/* На узких экранах панель прячется за кнопку */
@media (max-width: 900px) {
  .tools-toggle-btn {
    display: flex;
  }
  .side-tools {
    top: 140px;
    display: none;
  }
  .side-tools.open {
    display: flex;
  }
}

.top-right-logo {
  position: absolute;
  top: 24px;
  right: 24px;
  max-width: 150px;
  max-height: 50px;
  z-index: 1000;
  filter: drop-shadow(0px 0px 2px rgba(0,0,0,0.5));
  opacity: 0;
  transition: opacity 0.3s ease;
}

