/* Interface de la carte LiDAR — barre latérale à onglets type SIG. */

:root {
  --bg: #0b0e13;
  --panel: rgba(16, 20, 27, 0.93);
  --panel-border: rgba(255, 255, 255, 0.09);
  --text: #d9dee6;
  --muted: #8b94a3;
  --accent: #5aa9e6;
  --accent-dim: #2e7cc4;
  --danger: #e94560;
  --success: #4cc98a;
  --success-dim: #2f8f63;
  --radius: 10px;
  --sbw: 320px;  /* largeur de la barre latérale */
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body {
  height: 100%; overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 13px;
}
/* Décalage des contrôles ancrés à gauche (échelle Leaflet, puce zoom)
   selon la présence de la barre latérale. */
body { --left-ui: calc(var(--sbw) + 24px); }
body.sb-collapsed { --left-ui: 12px; }

#viewport { position: absolute; inset: 0; background: var(--bg); }
.leaflet-container { background: var(--bg); font: inherit; }
/* Fond OSM assombri pour faire ressortir les tuiles LiDAR : simple opacité
   sur le tile-pane (un filter CSS forcerait sa rastérisation complète à
   chaque frame de pan/zoom — coûteux) */
#viewport .leaflet-tile-pane { opacity: 0.45; }
#viewport.bright .leaflet-tile-pane { opacity: 1; }
#viewport .leaflet-bottom.leaflet-left { left: var(--left-ui); }

/* --- Panneaux : socle visuel commun (unité de l'interface) --- */
.panel {
  position: fixed; z-index: 900;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
  color: var(--text);
}

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-bottom: 1px solid var(--panel-border);
}
.panel-title {
  font-size: 12px; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--muted);
}

button {
  background: rgba(255, 255, 255, 0.06); color: var(--text);
  border: 1px solid var(--panel-border); border-radius: 6px;
  padding: 6px 12px; font-size: 13px; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: rgba(255, 255, 255, 0.12); border-color: var(--accent); }
button.primary { background: var(--accent-dim); border-color: var(--accent-dim); }
button.primary:hover { background: var(--accent); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.icon-btn { padding: 2px 8px; font-size: 14px; line-height: 1.2; }

select, input[type="checkbox"] { accent-color: var(--accent); }
.gen-select {
  background: rgba(255, 255, 255, 0.06); color: var(--text);
  border: 1px solid var(--panel-border); border-radius: 6px;
  padding: 3px 6px; font-size: 12px; cursor: pointer;
}

/* --- Barre latérale (gauche, pleine hauteur) --- */
#sidebar {
  top: 12px; bottom: 12px; left: 12px; width: var(--sbw);
  display: flex; flex-direction: column;
}
.sidebar-head { padding: 10px 12px 8px; border-bottom: 1px solid var(--panel-border); }
.head-row { display: flex; align-items: center; justify-content: space-between; }
#sidebar h1 { font-size: 14px; font-weight: 700; color: var(--accent); letter-spacing: 0.02em; }
#sidebar .stat { display: block; margin-top: 2px; font-size: 11px; color: var(--muted); }
#sidebarCollapse { color: var(--muted); border: none; background: none; }
#sidebarCollapse:hover { color: var(--text); }
#sidebar.collapsed { bottom: auto; }
#sidebar.collapsed .sidebar-body { display: none; }
#sidebar.collapsed #sidebarCollapse { transform: rotate(180deg); }

.sidebar-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Onglets : contrôle segmenté */
.tabbar {
  display: flex; gap: 4px; margin: 8px; padding: 3px;
  background: rgba(255, 255, 255, 0.05); border-radius: 8px;
}
.tab {
  flex: 1; border: none; background: transparent; border-radius: 6px;
  padding: 6px 8px; font-size: 12px; font-weight: 600; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.tab:hover { background: rgba(255, 255, 255, 0.07); color: var(--text); border-color: transparent; }
.tab.active { background: var(--accent-dim); color: #fff; }
.tab-badge {
  min-width: 16px; padding: 0 4px; border-radius: 999px;
  background: var(--accent); color: #06263f;
  font-size: 10px; font-weight: 700; line-height: 15px;
}

.tab-page { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 8px 10px; }

/* --- Lignes de couches --- */
.layer-row {
  display: grid; grid-template-columns: 16px 24px minmax(0, 1fr) 80px 30px;
  align-items: center; gap: 6px;
  padding: 5px 6px; border-radius: 6px;
  user-select: none;
}
#osmRow { grid-template-columns: 24px minmax(0, 1fr) 80px 30px; }
.layer-row:hover { background: rgba(255, 255, 255, 0.05); }
.layer-row.dragging { opacity: 0.45; }

.layer-grip {
  color: var(--muted); cursor: grab; font-size: 13px;
  text-align: center; line-height: 1;
}
.layer-grip:hover, .layer-row.dragging .layer-grip { color: var(--accent); }

.eye {
  width: 24px; height: 24px; padding: 0; border: none; background: none;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
}
.eye.on { color: var(--accent); }
.eye svg { width: 16px; height: 16px; }

.layer-name {
  font-size: 12.5px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; color: var(--muted);
}
.layer-row.on .layer-name { color: var(--text); }
.layer-pct { font-size: 10.5px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

.layer-sub {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 10.5px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.05em; padding: 8px 6px 4px;
  border-top: 1px solid var(--panel-border); margin-top: 6px;
}

/* Sliders d'opacité : piste fine dans une zone cliquable haute de 18 px —
   le pouce reste saisissable au drag (l'élément lui-même fait toute la
   hauteur, pas seulement la piste de 4 px). */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 18px; background: transparent;
  outline: none; cursor: pointer; margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.18);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--accent); margin-top: -4.5px;
  border: 2px solid #0b0e13;
  box-shadow: 0 0 0 1px rgba(90, 169, 230, 0.4);
}
input[type="range"]:hover::-webkit-slider-thumb { background: #7ec4f5; }
input[type="range"]::-moz-range-track {
  height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.18);
}
input[type="range"]::-moz-range-thumb {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); border: 2px solid #0b0e13;
}

/* --- Tuiles LiDAR sur la carte --- */
.ltile-anchor { width: 0; height: 0; }
.ltile {
  position: absolute; left: 0; top: 0; overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.10);
  /* Fond transparent obligatoire : l'opacité des couches doit laisser voir
     les couches du dessous et le fond de carte, pas un rectangle noir. */
  background: transparent;
  /* Layout et peinture des tuiles hors écran skippés par le navigateur */
  content-visibility: auto;
}
/* Uniquement pendant l'animation de zoom (classe posée par app.js) :
   scaling sur le GPU, puis libération pour ne pas immobiliser de mémoire. */
body.zooming .ltile { will-change: transform; }
.ltile img {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: fill; display: block;
  /* Évite le drag natif des images qui avale le mouseup (dessin de zones) */
  pointer-events: none; -webkit-user-drag: none; user-select: none;
}
.ltile:hover { border-color: var(--accent); box-shadow: 0 0 8px rgba(90, 169, 230, 0.35); }
.ltile.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 12px rgba(90, 169, 230, 0.5); }

/* --- Fiche tuile (onglet Tuile) --- */
.tile-info { padding: 6px 6px 10px; }
.tile-info-head { display: flex; align-items: center; gap: 8px; }
.tile-info-title { font-size: 13px; font-weight: 700; }
.tile-info-badge {
  font-size: 10.5px; color: var(--accent); background: rgba(90, 169, 230, 0.12);
  border-radius: 999px; padding: 1px 8px; font-variant-numeric: tabular-nums;
}
.tile-info-close { margin-left: auto; color: var(--muted); border: none; background: none; font-size: 16px; }
.tile-info-close:hover { color: var(--danger); }
.tile-empty {
  padding: 20px 12px; color: var(--muted); font-size: 12px;
  line-height: 1.5; text-align: center;
}
.tile-info-dalle {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 10.5px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 3px;
}
.tile-info-meta { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.tile-info-sub {
  font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em;
  margin: 8px 0 6px; border-top: 1px solid var(--panel-border); padding-top: 8px;
}

/* Puces de couches : œil + nom + téléchargement, repliées sur 2 colonnes */
.vpills { display: flex; flex-wrap: wrap; gap: 5px; }
.vpill {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 4px 2px 7px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
}
.vpill.on { background: rgba(90, 169, 230, 0.14); }
.vpill-eye, .vpill-name {
  border: none; background: none; padding: 0; cursor: pointer; color: var(--muted);
}
.vpill-eye {
  display: inline-flex; width: 16px; height: 16px;
  align-items: center; justify-content: center;
}
.vpill-eye svg { width: 13px; height: 13px; }
.vpill.on .vpill-eye { color: var(--accent); }
.vpill-name { font-size: 11.5px; color: var(--text); white-space: nowrap; }
.vpill-name:hover { color: var(--accent); }
.vpill-dl {
  color: var(--muted); text-decoration: none; font-size: 12px;
  padding: 0 4px; border-radius: 4px;
}
.vpill-dl:hover { color: var(--accent); }

.tile-info-actions { margin-top: 10px; }
.tile-info-actions button { width: 100%; font-size: 12px; padding: 6px 10px; }

/* --- Outils carte (haut droite) --- */
#mapTools { top: 12px; right: 12px; display: flex; gap: 6px; padding: 6px; }
#mapTools button { width: 32px; height: 32px; padding: 0; font-size: 16px; }
#btnMenu { display: none; }

/* --- Puces d'état (bas d'écran) --- */
.chip {
  position: fixed; z-index: 900;
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 6px; padding: 5px 10px;
  font-size: 11px; color: var(--muted);
}
#zoomIndicator { bottom: 12px; left: var(--left-ui); font-variant-numeric: tabular-nums; }
#hint { bottom: 12px; right: 12px; text-align: right; line-height: 1.5; }

/* --- Onglet Génération --- */
/* Actions Zone / Compléter : propres à l'onglet, pleine largeur */
.gen-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.gen-actions button { width: 100%; font-size: 12.5px; }
#btnGenZone, #btnGenSel { background: var(--accent-dim); border-color: var(--accent-dim); }
#btnGenZone:hover, #btnGenSel:hover { background: var(--accent); border-color: var(--accent); }
#btnComplete {
  font-weight: 600; letter-spacing: 0.02em;
  background: var(--success-dim); border-color: var(--success-dim); color: #eafff4;
}
#btnComplete:hover { background: var(--success); border-color: var(--success); }
#btnComplete .ok-ic { margin-right: 6px; font-weight: 700; }
#genBar {
  display: none; flex-direction: column; gap: 8px;
  margin-top: 8px; padding: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-border); border-radius: 8px;
}
#genBar.show { display: flex; }
#genMsg { font-size: 12.5px; line-height: 1.45; }
.gen-opt {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  font-size: 12px; color: var(--text); cursor: pointer;
}
.gen-opt.col { flex-direction: column; align-items: stretch; gap: 4px; }
.gen-opt.col > span { color: var(--muted); font-size: 11px; }
.gen-opt select { flex: 1; min-width: 0; }
.gen-run { display: flex; gap: 8px; margin-top: 2px; }
.gen-run #genGo { flex: 1; }

/* File de génération : section de l'onglet, largeur de la barre latérale */
#genQueue { margin-top: 10px; border-top: 1px solid var(--panel-border); padding-top: 8px; }
.queue-head { display: flex; align-items: center; gap: 8px; padding: 0 2px 6px; }
#genQueueCount { margin-left: auto; font-size: 11px; color: var(--muted); }
#genQueueBody {
  display: flex; flex-direction: column; gap: 8px;
}
.gen-task { border: 1px solid var(--panel-border); border-radius: 6px; }
.gen-task-head { display: flex; align-items: center; gap: 8px; padding: 6px 8px; flex-wrap: wrap; }
.gen-task-dot {
  width: 9px; height: 9px; border-radius: 50%; flex: none;
  background: var(--muted);
}
.gen-task.running .gen-task-dot {
  background: var(--accent); animation: gen-pulse 1.1s ease-in-out infinite;
}
.gen-task.done .gen-task-dot { background: #39d98a; }
.gen-task.failed .gen-task-dot { background: var(--danger); }
@keyframes gen-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
.gen-task-label {
  font-size: 12px; flex: 1; min-width: 120px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.gen-task-state { font-size: 11px; white-space: nowrap; }
.gen-task.running .gen-task-state { color: var(--accent); }
.gen-task.done .gen-task-state { color: #39d98a; }
.gen-task.failed .gen-task-state { color: var(--danger); }
.gen-task-time {
  font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.gen-task-toggle { padding: 1px 6px; font-size: 11px; }
.gen-task-log {
  margin: 0 8px 8px; max-height: 140px; overflow: auto;
  background: #0d1017; border: 1px solid var(--panel-border); border-radius: 6px;
  padding: 8px 10px; font: 10.5px/1.45 ui-monospace, Menlo, monospace;
  color: #9fb3d9; white-space: pre-wrap;
}

/* Tuiles une par une : nom court + puces d'étapes (types de visualisation) */
.gen-task-tiles {
  margin: 0 8px 8px;
  display: flex; flex-direction: column; gap: 4px;
}
.gen-tile {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  border: 1px solid var(--panel-border); border-radius: 6px;
  padding: 4px 8px; font-size: 11.5px;
}
.gen-tile-name {
  min-width: 78px; flex: none; font-variant-numeric: tabular-nums;
  color: var(--text); cursor: default;
}
.gen-tile-steps { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; min-width: 0; }
.gen-step {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 7px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.05); color: var(--muted);
  font-size: 10.5px; white-space: nowrap;
}
.gen-step::before { content: '·'; font-weight: bold; }
.gen-step.running { color: var(--accent); background: rgba(90, 169, 230, 0.12); }
.gen-step.running::before { content: '⟳'; animation: gen-pulse 1.1s ease-in-out infinite; }
.gen-step.ok { color: #39d98a; background: rgba(57, 217, 138, 0.10); }
.gen-step.ok::before { content: '✓'; }
.gen-step.fail { color: var(--danger); background: rgba(233, 69, 96, 0.12); }
.gen-step.fail::before { content: '✗'; }
.gen-step.skip::before { content: '–'; }
.gen-tile-state { flex: none; font-size: 11px; }
.gen-tile.done .gen-tile-state { color: #39d98a; }
.gen-tile.failed .gen-tile-state { color: var(--danger); }

/* --- Onglet Export : mosaïque de dalles adjacentes (téléphone) --- */
.export-intro {
  font-size: 12px; color: var(--muted); line-height: 1.5; padding: 4px 2px 0;
}
#btnExportSel { background: var(--accent-dim); border-color: var(--accent-dim); }
#btnExportSel:hover { background: var(--accent); border-color: var(--accent); }
.export-count { font-size: 12.5px; font-weight: 600; }
.export-count .sub { font-weight: 400; color: var(--muted); font-size: 11px; }
#exportBar {
  display: none; flex-direction: column; gap: 8px;
  margin-top: 8px; padding: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-border); border-radius: 8px;
}
#exportBar.show { display: flex; }
#exportMsg { font-size: 12.5px; line-height: 1.45; }
#exportDone { margin-top: 10px; border-top: 1px solid var(--panel-border); padding-top: 8px; }
#exportDoneList { display: flex; flex-direction: column; gap: 6px; }
#exportDoneList a {
  font-size: 11.5px; color: var(--accent); text-decoration: none;
  word-break: break-all;
}
#exportDoneList a:hover { text-decoration: underline; }
#exportDoneList .dl-ic { margin-right: 4px; }
/* Surlignage vert des dalles retenues pour l'export (surcouche écran
   uniquement — l'image exportée colle les dalles sans aucun trait). */
.ltile.exportSel {
  border-color: #39d98a;
  box-shadow: 0 0 0 1px #39d98a, 0 0 12px rgba(57, 217, 138, 0.5);
}
body.exporting, body.exporting #viewport { cursor: pointer; }

/* Surlignage bleu des dalles retenues pour la régénération (mode
   « Sélectionner des tuiles » de l'onglet Génération). */
.ltile.genSel {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 12px rgba(90, 169, 230, 0.5);
}
body.genSel, body.genSel #viewport { cursor: pointer; }

/* Barres de défilement fines et discrètes */
.tab-page::-webkit-scrollbar,
.gen-task-log::-webkit-scrollbar { width: 8px; }
.tab-page::-webkit-scrollbar-thumb,
.gen-task-log::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14); border-radius: 4px;
}
.tab-page::-webkit-scrollbar-track,
.gen-task-log::-webkit-scrollbar-track { background: transparent; }

body.drawing, body.drawing #viewport { cursor: crosshair !important; }

/* --- Responsive : la barre latérale devient un tiroir --- */
@media (max-width: 720px) {
  body { --left-ui: 12px; }
  #sidebar {
    width: min(320px, 88vw); z-index: 1200;
    transform: translateX(calc(-100% - 20px));
    transition: transform 0.25s ease;
  }
  body.menu-open #sidebar { transform: none; }
  #btnMenu { display: inline-block; }
  #hint { display: none; }
}
