:root {
  --bg: #1b1e24;
  --bg-alt: #23272f;
  --panel: #262b33;
  --border: #383e4a;
  --text: #e6e8eb;
  --text-dim: #9aa1ac;
  --accent: #4d8dff;
  --accent-hover: #6da0ff;
  --danger: #e5484d;
  --radius: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---------- Toolbar ---------- */
#toolbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 8px 14px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

button {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
button:hover { background: #30363f; border-color: var(--accent); }
button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.file-name {
  color: var(--text-dim);
  font-size: 12px;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Layout ---------- */
#main {
  flex: 1;
  display: flex;
  min-height: 0;
}

#sidebar {
  position: relative;
  width: 300px;
  min-width: 200px;
  max-width: 60vw;
  flex-shrink: 0;
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  overflow: hidden;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#sidebar.collapsed { display: none; }

/* Le panneau Informations est toujours affiché en entier, jamais de scroll. */
#panel-info { flex-shrink: 0; }

/* Panneaux d'outils (précision / coupe / mesure) : hauteur naturelle,
   avec leur propre scroll seulement s'ils dépassent. */
#sidebar-top {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* L'arbre occupe le reste de la hauteur ; seul son contenu scrolle. */
#panel-tree {
  flex: 1 1 auto;
  min-height: 120px;
  display: flex;
  flex-direction: column;
}
#tree-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* Poignée de redimensionnement sur le bord droit du ruban */
#sidebar-resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 6px;
  height: 100%;
  cursor: ew-resize;
  z-index: 3;
}
#sidebar-resizer:hover, #sidebar-resizer.dragging { background: rgba(77, 141, 255, 0.35); }

/* Mini bouton replier/déplier, accroché au bord gauche de la zone 3D
   (= bord droit du ruban quand il est ouvert) */
#sidebar-toggle {
  position: absolute;
  top: 8px;
  left: 0;
  z-index: 6;
  padding: 6px 4px;
  font-size: 11px;
  line-height: 1;
  border-radius: 0 var(--radius) var(--radius) 0;
  border-left: none;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.panel.hidden { display: none; }

.panel h2 {
  margin: 0 0 8px 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.empty-hint, .hint {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.4;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
}

select, input[type="range"], input[type="number"] {
  flex: 1;
}
input[type="number"] {
  background: var(--bg-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 6px;
  width: 100%;
  min-width: 0;
}

/* ---------- Precision panel ---------- */
#precision-custom.hidden { display: none; }
#btn-retry { width: 100%; margin: 4px 0 8px; }

/* ---------- Panneaux d'outils Coupe / Mesure, intégrés à la barre du haut ---------- */
.toolbar-tool-panel {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  max-width: 100%;
  min-width: 0;
  gap: 6px 10px;
  padding: 4px 10px;
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-size: 12px;
}
.toolbar-tool-panel.hidden { display: none; }

.tool-panel-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}
.tool-field {
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
/* neutralise le flex:1 générique (prévu pour les rangées du ruban gauche) */
.toolbar-tool-panel select,
.toolbar-tool-panel input[type="range"] {
  flex: 0 0 auto;
}

#section-slider { width: 150px; }

/* ---------- Measure mode selector ---------- */
.segmented {
  display: flex;
  gap: 4px;
}
.segmented button {
  font-size: 11px;
  padding: 5px 7px;
  white-space: nowrap;
  line-height: 1.2;
}

#measure-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

#measure-status {
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.legend-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--c);
  margin-right: 2px;
}
.legend-tri {
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 9px solid #ff9f43;
  margin-right: 2px;
}

/* ---------- Info panel ---------- */
#info-content dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  font-size: 12px;
}
#info-content dt { color: var(--text-dim); }
#info-content dd { margin: 0; text-align: right; }

/* ---------- Tree filter & selection bar ---------- */
.tree-filter-input {
  width: 100%;
  background: var(--bg-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 8px;
  font-size: 12.5px;
  margin-bottom: 6px;
}
.tree-filter-input:focus { outline: 1px solid var(--accent); }

/* ---------- Filtre et curseur par taille ---------- */
.tree-size-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 6px;
  font-size: 11.5px;
  color: var(--text-dim);
}
.tree-size-row input[type="number"] {
  flex: 1;
  min-width: 0;
  padding: 3px 5px;
  font-size: 11.5px;
}
.tree-size-row input[type="range"] { flex: 1; }
.tree-size-row button {
  padding: 2px 6px;
  font-size: 10px;
}
#size-readout { margin: 0 0 6px; }

.tree-selection-bar {
  display: none;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.tree-selection-bar.visible { display: flex; }
#tree-selection-count {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-right: auto;
}
.tree-selection-bar button {
  font-size: 11px;
  padding: 3px 7px;
}

/* ---------- Tree ---------- */
#tree-content ul {
  list-style: none;
  margin: 0;
  padding-left: 16px;
}
#tree-content > ul { padding-left: 0; }
#tree-content li { margin: 2px 0; }
.tree-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  border-radius: 4px;
  padding: 1px 3px;
  cursor: pointer;
}
.tree-row.selected {
  background: rgba(77, 141, 255, 0.22);
  outline: 1px solid rgba(77, 141, 255, 0.5);
}
.tree-row label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.tree-toggle {
  cursor: pointer;
  width: 14px;
  color: var(--text-dim);
  user-select: none;
  text-align: center;
  flex-shrink: 0;
}

/* ---------- Measure list (compacte, dans la barre du haut) ---------- */
#measure-list {
  max-height: 52px;
  overflow-y: auto;
  min-width: 200px;
}
#measure-list:empty { display: none; }
#measure-list .measure-item {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11.5px;
  padding: 1px 0;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
#measure-list .measure-item span:last-of-type { margin-left: auto; }

/* croix de suppression d'une mesure */
.measure-delete {
  padding: 0 4px;
  font-size: 10px;
  line-height: 1.5;
  border: none;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
}
.measure-delete:hover {
  color: #fff;
  background: var(--danger);
  border: none;
}

/* ---------- Viewport ---------- */
#viewport-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

#viewport {
  position: absolute;
  inset: 0;
}

#viewport canvas { display: block; }

/* origin gizmo (AutoCAD-style UCS icon) axis labels */
.axis-gizmo-label {
  font-size: 13px;
  font-weight: 700;
  pointer-events: none;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.9), 0 0 3px rgba(0, 0, 0, 0.9);
}

/* label overlay for measurements */
.measure-label {
  background: rgba(20, 22, 27, 0.85);
  border: 1px solid var(--accent);
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
}

/* petites étiquettes ΔX / ΔY / ΔZ du triangle trigonométrique */
.measure-sublabel {
  background: rgba(20, 22, 27, 0.75);
  color: #fff;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 10px;
  white-space: nowrap;
  pointer-events: none;
}

/* ---------- Dropzone ---------- */
#dropzone {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(27, 30, 36, 0.9);
  transition: background 0.15s ease;
  z-index: 5;
}
#dropzone.drag-over { background: rgba(77, 141, 255, 0.15); }
#dropzone.hidden { display: none; }

.dropzone-inner {
  text-align: center;
  color: var(--text-dim);
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 40px 60px;
}
.dropzone-icon { font-size: 40px; margin-bottom: 10px; }
.dropzone-inner button {
  margin-top: 14px;
}

/* ---------- Loading overlay ---------- */
#loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(20, 22, 27, 0.75);
  z-index: 10;
}
#loading-overlay.hidden { display: none; }
#btn-cancel-load { margin-top: 4px; }
#btn-cancel-load.hidden { display: none; }

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Menu contextuel (clic droit) ---------- */
.context-menu {
  position: fixed;
  z-index: 100;
  display: flex;
  flex-direction: column;
  min-width: 190px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
}
.context-menu.hidden { display: none; }
.context-menu button {
  border: none;
  background: none;
  text-align: left;
  padding: 6px 10px;
  font-size: 12.5px;
  border-radius: 4px;
}
.context-menu button:hover:not(:disabled) {
  background: var(--accent);
  border: none;
  color: #fff;
}
.context-sep {
  height: 1px;
  margin: 4px 2px;
  background: var(--border);
}

/* ---------- Boîte de dialogue modale (export IFC) ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 14, 18, 0.65);
}
.modal.hidden { display: none; }

.modal-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(560px, 92vw);
  max-height: 86vh;
  padding: 16px 18px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}
.modal-box h2 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}
.modal-box .hint { margin: 0; }
.modal-bulk { font-size: 12px; color: var(--text-dim); }
.modal-bulk select { margin-left: 6px; }

#ifc-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
}
.ifc-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 2px;
  font-size: 12px;
}
.ifc-row span {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ifc-row select { flex: 0 0 200px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.modal-actions .primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.modal-actions .primary:hover { background: var(--accent-hover); }

/* ---------- Error banner ---------- */
#error-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--danger);
  color: #fff;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 20;
  max-width: 80%;
}
#error-banner.hidden { display: none; }
