* { margin: 0; padding: 0; }

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  font-family: 'Segoe UI', system-ui, sans-serif;
  overflow: hidden;
}

[data-bs-theme="dark"] body {
  background: #111827;
  color: #e5e7eb;
}

/* ── LOADING ── */
#app-loading {
  position: fixed; inset: 0; z-index: 9999;
  background: #111827;
  display: flex; align-items: center; justify-content: center;
}

/* ── LOADING OVERLAYS ── */
#canvas-loading {
  position: absolute; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  z-index: 20;
  background: rgba(13,17,23,0.55);
  pointer-events: none;
}
#canvas-loading.visible { display: flex; }

#proj-picker-loading {
  display: none;
  position: absolute; inset: 0;
  align-items: center; justify-content: center;
  background: rgba(31,41,55,0.7);
  border-radius: 10px;
  z-index: 10;
}
#proj-picker-loading.visible { display: flex; }

#dz-loading {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: #6b7280;
  font-size: 0.82rem;
}
#dz-loading.visible { display: flex; }

/* ── APP SHELL ── */
#topbar.no-plan {
  /* Above Bootstrap Offcanvas (1045) so the navbar stays accessible when the
     drawer covers the full viewport in no-plan mode. Below modal backdrop (1050). */
  position: relative;
  z-index: 1046;
}
#app-shell {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── SIDEBAR ── */
#sidebar {
  width: 220px;
  min-width: 120px;
  background: #1f2937;
  border-right: 1px solid #374151;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  transition: width 0.15s ease, min-width 0.15s ease;
}
#sidebar.sidebar-hidden {
  width: 40px !important;
  min-width: 40px !important;
}
#sidebar.sidebar-hidden #sidebar-scroll,
#sidebar.sidebar-hidden #sidebar-footer,
#sidebar.sidebar-hidden #sidebar-resize { display: none !important; }
#sidebar.sidebar-hidden .sidebar-title,
#sidebar.sidebar-hidden #sidebar-maximize-btn { display: none; }
#sidebar.sidebar-hidden #sidebar-header {
  padding-left: 4px;
  padding-right: 4px;
  justify-content: center;
  border-bottom: 0;
}
#app-shell.sidebar-maximized #sidebar {
  flex: 1;
  width: auto !important;
  min-width: 0 !important;
  max-width: none !important;
}
#app-shell.sidebar-maximized #main { display: none; }
#app-shell.sidebar-maximized #sidebar-resize { display: none; }

#sidebar-header,
#drawer-header { background: #111827; }

#drawer-tab {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 40px;
  background: #1f2937;
  border-left: 1px solid #374151;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}
#drawer-tab:hover { background: #374151; }
#drawer-tab.d-none { display: none !important; }

#sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}
#sidebar-scroll::-webkit-scrollbar { width: 5px; }
#sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
#sidebar-scroll::-webkit-scrollbar-thumb { background: #374151; border-radius: 3px; }



/* ── MAIN / CANVAS ── */
#main {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #0d1117;
  background-image: radial-gradient(circle, #1f2937 1px, transparent 1px);
  background-size: 20px 20px;
  min-width: 0;
}
#canvas {
  position: absolute; top: 0; left: 0;
  cursor: crosshair; display: none;
}
#drop-zone {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 48px 40px;
  border: 2px dashed #374151;
  border-radius: 14px;
  color: #4b5563;
  text-align: center;
  z-index: 10;
  pointer-events: none;
}
#drop-zone p { font-size: 0.88rem; line-height: 1.6; }
#drop-zone.upload-mode {
  pointer-events: auto;
  cursor: pointer;
}
#drop-zone.upload-mode:hover,
#drop-zone.upload-mode.dragover {
  border-color: #3b82f6;
  background: rgba(59,130,246,0.07);
  color: #9ca3af;
}
.dz-hint {
  font-size: 0.72rem;
  color: #4b5563;
  letter-spacing: 0.04em;
  margin-top: 2px;
}
#status {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.78);
  color: #e5e7eb; padding: 5px 16px; border-radius: 20px;
  font-size: 0.8rem; pointer-events: none; white-space: nowrap;
  z-index: 100;
}
#status.hidden { opacity: 0; }
#zoom-bar {
  position: absolute; bottom: 14px; right: 14px;
  display: none; align-items: center; gap: 6px;
  background: rgba(0,0,0,0.6);
  border-radius: 20px; padding: 4px 10px; z-index: 100;
}
#zoom-bar.visible { display: flex; }
#zoom-level { font-size: 0.78rem; color: #9ca3af; min-width: 38px; text-align: center; }
#btn-measure.measure-active { color: #f59e0b !important; }



/* ── TIROIR CHIFFRAGE (Bootstrap Offcanvas) ── */
#drawer {
  --bs-offcanvas-width: 360px;
  box-shadow: -6px 0 24px rgba(0,0,0,0.55);
}
#app-shell.drawer-maximized #drawer {
  --bs-offcanvas-width: 100vw;
}
#app-shell.drawer-maximized #drawer-resize { display: none; }
/* Centrer et limiter le contenu à ~1200px quand le drawer est plein écran */
#app-shell.drawer-maximized #drawer-content {
  padding-inline: clamp(20px, calc(50% - 600px), 20%);
}
/* Table en layout fixe pour permettre le redimensionnement des colonnes */
#app-shell.drawer-maximized .chif-table { table-layout: fixed; }
#app-shell.drawer-maximized .chif-th-nom { min-width: 100px; }

/* Handles de redimensionnement des colonnes */
.chif-table thead th { position: relative; }
.chif-col-hdl {
  display: none;
  position: absolute;
  top: 0; right: -3px;
  width: 7px; height: 100%;
  cursor: col-resize;
  z-index: 2;
}
.chif-col-hdl::after {
  content: '';
  position: absolute;
  left: 3px; top: 15%; bottom: 15%;
  width: 1px;
  background: #374151;
  transition: background .15s;
}
.chif-col-hdl:hover::after { background: #3b82f6; }
#app-shell.drawer-maximized .chif-col-hdl { display: block; }

.resize-handle {
  width: 4px;
  cursor: col-resize;
  z-index: 20;
  background: transparent;
}
.resize-handle:hover,
.resize-handle.dragging { background: #3b82f6; opacity: 0.5; }
#sidebar-resize { right: 0; }
#drawer-resize  { left: 0; }

#drawer-header { background: #111827; }
#drawer-content {
  container-type: inline-size;
  padding: 0 20px 20px;
}
#drawer-content::-webkit-scrollbar { width: 5px; }
#drawer-content::-webkit-scrollbar-thumb { background: #374151; border-radius: 3px; }

/* ── CALIBRATION ── */
#scale-badge, #geo-badge {
  display: none;
  font-size: 0.75rem;
  color: #d1d5db;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 5px;
  padding: 5px 8px;
  line-height: 1.5;
}
#scale-badge.visible, #geo-badge.visible { display: block; }
#geo-badge { display: none; align-items: center; gap: 6px; }
#geo-badge.visible { display: flex; }

#calib-form {
  display: none;
  flex-direction: column;
  gap: 6px;
  font-size: 0.78rem;
  color: #9ca3af;
}
#calib-form.visible { display: flex; }
#calib-form label { color: #9ca3af; }

#geo-calib-form {
  display: none;
  position: absolute;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  flex-direction: column;
  gap: 8px;
  font-size: 0.78rem;
  color: #9ca3af;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 12px 16px;
  z-index: 50;
  min-width: 240px;
}
#geo-calib-form.visible { display: flex; }
#geo-calib-form label { color: #9ca3af; }

#geo-pts-progress { display: flex; gap: 8px; margin: 2px 0; }
.geo-pt-step { display: flex; align-items: center; }
.geo-pt-dot {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #374151;
  border: 1px solid #4b5563;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 700; color: #6b7280;
}
.geo-pt-step.done   .geo-pt-dot { background: #14532d; border-color: #22c55e; color: #4ade80; }
.geo-pt-step.active .geo-pt-dot { background: #1e3a5f; border-color: #3b82f6; color: #93c5fd; }





.input-row input, .input-row select {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 5px;
  color: #e5e7eb;
  font-size: 0.82rem;
  padding: 5px 7px;
}
.input-row input { flex: 1; min-width: 0; }
.input-row input:focus, .input-row select:focus { outline: none; border-color: #3b82f6; }
.input-row select { background: #111827; }



/* ── SHAPE CARDS ── */
#measurements { display: flex; flex-direction: column; gap: 6px; }

.shape-card {
  background: #111827;
  border: 1px solid #374151;
  border-left: 3px solid #3b82f6;
  border-radius: 7px;
  padding: 8px 9px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.shape-card:hover { border-color: #4b5563; }
.shape-card.selected { border-color: #3b82f6; background: #0f172a; }
.shape-card.canvas-hovered { background: #1a2535; border-color: #6b7280; }
.shape-card.shape-hidden { opacity: 0.45; }
.shape-card.grouped { margin-left: 14px; border-left-width: 2px; }
.shape-card .name-input { font-size: 0.78rem; }
.shape-tex-thumb {
  width: 18px; height: 18px; flex-shrink: 0;
  border-radius: 3px; border: 1px solid #374151;
  object-fit: cover; image-rendering: pixelated;
  cursor: pointer; opacity: 0.85;
}
.shape-tex-thumb:hover { opacity: 1; border-color: #6b7280; }

/* ── GROUPE HEADERS ── */
.groupe-header {
  background: #1a2535;
  border: 1px solid #374151;
  border-left: 3px solid #6b7280;
  border-radius: 7px;
  padding: 6px 9px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}
.groupe-header.groupe-hidden { opacity: 0.45; }
.groupe-header.drag-over { border-color: #3b82f6; background: #0a1929; }
.groupe-header.dragging { opacity: .4; }
.groupe-name-input {
  flex: 1;
  min-width: 0;
  background: transparent !important;
  border-color: transparent !important;
  font-size: 0.78rem;
  font-weight: 600;
  color: #9ca3af;
}
.groupe-name-input:focus { border-color: #374151 !important; background: #111827 !important; }
.groupe-add-btn { font-size: 0.73rem; padding: 3px 8px; }
.groupe-collapse-btn { width: 16px; flex-shrink: 0; }
.groupe-collapse-btn svg { transition: transform 0.15s; }
.groupe-header.collapsed .groupe-collapse-btn svg { transform: rotate(-90deg); }
.groupe-count { font-size: 0.65rem; color: #6b7280; background: #1f2937; border-radius: 8px; padding: 1px 5px; flex-shrink: 0; }
.groupe-row { margin-top: 1px; }
.groupe-sel { font-size: 0.7rem; padding: 1px 4px; height: auto; }


.esq-drag-hdl {
  color: #4b5563; font-size: 0.75rem; line-height: 1;
  cursor: grab; user-select: none; flex-shrink: 0; padding: 2px 1px;
  letter-spacing: -1px;
}
.esq-drag-hdl:active { cursor: grabbing; }
.shape-card.dragging { opacity: .4; }
.esq-drop-ind {
  height: 2px; background: #3b82f6; border-radius: 1px; margin: 1px 0; pointer-events: none;
}

/* color-pick is now only used inside the shape-config modal */
#scm-color {
  height: 34px;
  cursor: pointer;
}


.rect-dim-input { width: 52px; flex-shrink: 0; }

/* ── SHAPE INFO POPOVER ── */
.shape-info-pop {
  --bs-popover-bg: #1f2937;
  --bs-popover-border-color: #374151;
  --bs-popover-body-color: #d1d5db;
  --bs-popover-body-padding-x: 10px;
  --bs-popover-body-padding-y: 8px;
  --bs-popover-max-width: 230px;
  font-size: 0.78rem;
}
.shape-info-pop .popover-arrow::before { border-right-color: #374151; }
.shape-info-pop .popover-arrow::after  { border-right-color: #1f2937; }
.shape-info-pop .shape-pop-desc {
  margin-bottom: 6px;
  color: #9ca3af;
  white-space: pre-wrap;
  word-break: break-word;
}
.shape-info-pop .shape-pop-metric {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.73rem;
  line-height: 1.5;
}
.shape-info-pop .shape-pop-metric span:first-child { color: #6b7280; }
.shape-info-pop .shape-pop-metric span:last-child  { color: #d1d5db; font-variant-numeric: tabular-nums; }


/* ── LIEN AUTOCOMPLETE ── */
.chif-lien-ac {
  position: absolute;
  top: calc(100% + 3px);
  left: 0; right: 0;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 7px;
  z-index: 6000;
  overflow: hidden;
}

.chif-lien-ac-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 10px; gap: 8px; cursor: pointer;
  border-bottom: 1px solid #374151;
}
.chif-lien-ac-item:last-child { border-bottom: none; }
.chif-lien-ac-item:hover { background: #374151; }
.chif-lien-ac-name { font-size: 0.82rem; color: #e5e7eb; flex: 1; min-width: 0; }
.chif-lien-ac-meta { font-size: 0.75rem; color: #6b7280; flex-shrink: 0; white-space: nowrap; }
.lien-cat-row:hover { background: #1f2937; }


/* ── GEO MODAL ── */
#geo-modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 3000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
#geo-modal-overlay.visible { display: flex; }

#geo-modal {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 14px;
  width: min(680px, 100%);
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#geo-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 18px 12px;
  border-bottom: 1px solid #374151;
  flex-shrink: 0;
}
#geo-modal-header h2 { font-size: 0.92rem; font-weight: 700; color: #f9fafb; margin-bottom: 3px; }
#geo-modal-header p  { font-size: 0.78rem; color: #6b7280; line-height: 1.4; }
#geo-modal-close {
  background: none; border: none; color: #6b7280;
  font-size: 1.2rem; cursor: pointer; padding: 2px 6px;
  border-radius: 4px; line-height: 1; flex-shrink: 0;
}
#geo-modal-close:hover { color: #e5e7eb; background: #374151; }

#geo-point-indicators {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-bottom: 1px solid #374151;
  flex-shrink: 0;
}
.geo-pt-ind {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 6px 9px;
}
.pt-num {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #374151;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 700; color: #9ca3af;
  flex-shrink: 0;
}
.geo-pt-ind.set .pt-num { background: #14532d; color: #4ade80; }
.geo-ind-text { font-size: 0.74rem; color: #6b7280; }
.geo-pt-ind.set .geo-ind-text { color: #4ade80; }

#geo-search-wrap {
  position: relative;
  padding: 8px 18px;
  border-bottom: 1px solid #374151;
  flex-shrink: 0;
  display: flex;
  gap: 6px;
}
#geo-search-input { flex: 1; }
#geo-search-results {
  position: fixed;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 6px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 10000;
  display: none;
}
#geo-search-results.visible { display: block; }
.geo-search-item {
  padding: 8px 12px;
  font-size: 0.82rem;
  color: #d1d5db;
  cursor: pointer;
  border-bottom: 1px solid #374151;
}
.geo-search-item:last-child { border-bottom: none; }
.geo-search-item:hover { background: #374151; }

#leaflet-map { flex: 1; min-height: 260px; }

#geo-modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 10px 18px;
  border-top: 1px solid #374151;
  flex-shrink: 0;
}

/* ── LINK POPOVER ── */
#link-popover {
  position: fixed;
  width: 280px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 10px;
  z-index: 4000;
  overflow: hidden;
  font-size: 0.82rem;
}


#link-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-bottom: 1px solid #374151;
  background: #111827;
}
#link-popover-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: #e5e7eb;
  max-width: 200px;
}

#link-popover-body {
  padding: 8px;
  max-height: 180px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.link-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 8px;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 5px;
}
.link-item.active { border-color: #15803d; }

.link-item-name {
  flex: 1; min-width: 0;
  color: #d1d5db; font-size: 0.78rem;
  background: none; border: none; padding: 0; text-align: left; cursor: pointer;
}
.link-item-name:hover { color: #93c5fd; text-decoration: underline; }
.link-item.inactive .link-item-name { color: #6b7280; }
.link-item.inactive .link-item-name:hover { color: #9ca3af; }
.link-toggle-btn {
  flex-shrink: 0;
  background: #374151; border: 1px solid #4b5563; border-radius: 4px;
  color: #d1d5db; font-size: 0.7rem; padding: 2px 7px; cursor: pointer;
}
.link-toggle-btn:hover { background: #4b5563; }
.link-item.active .link-toggle-btn { background: #14532d; border-color: #22c55e; color: #4ade80; }
.link-item.active .link-toggle-btn:hover { background: #166534; }
.link-del-btn {
  flex-shrink: 0; background: none; border: none;
  color: #4b5563; font-size: 1rem; line-height: 1; padding: 0 2px; cursor: pointer;
}
.link-del-btn:hover { color: #f87171; }
.link-extract-btn {
  flex-shrink: 0; background: none; border: none;
  color: #4b5563; font-size: 0.8rem; line-height: 1; padding: 0 2px; cursor: pointer;
}
.link-extract-btn:hover { color: #60a5fa; }
.link-item-density {
  font-size: 0.71rem; color: #6b7280;
}
.link-item-density label { display: flex; align-items: center; gap: 4px; }
.link-item-density input {
  width: 58px; background: #1f2937; border: 1px solid #374151; border-radius: 3px;
  color: #d1d5db; font-size: 0.71rem; padding: 1px 4px; text-align: right;
}
.link-item-qte { font-size: 0.72rem; color: #4ade80; padding-left: 1px; }
.link-item.inactive .link-item-qte { display: none; }

#link-popover-footer {
  padding: 8px;
  border-top: 1px solid #374151;
}

/* ── TOOLTIP ── */
#tooltip {
  position: fixed;
  background: #0f172a;
  border: 1px solid #4b5563;
  color: #e5e7eb;
  font-size: 0.78rem;
  white-space: pre-line;
  max-width: 280px;
  padding: 5px 11px;
  border-radius: 6px;
  pointer-events: none;
  opacity: 0;
  z-index: 9999;
  transform: translateY(-50%);
}

/* ── TOPBAR : outil actif ── */
.topbar-btn.active {
  background-color: #1e40af !important;
  border-color: #3b82f6 !important;
  color: #93c5fd !important;
}


/* ══════════════════════════════════════
   MODULE CHIFFRAGE (Phase 4)
══════════════════════════════════════ */

/* Panel structure */
.chif-panel {
  border-bottom: 1px solid #374151;
  padding-bottom: 8px;
  margin-bottom: 12px;
}
.chif-panel-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 2px;
}
.chif-panel-toggle {
  background: none;
  border: none;
  color: #9ca3af;
  font-size: 0.72rem;
  letter-spacing: .08em;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 0;
}
.chif-panel-toggle:hover { color: #e5e7eb; }
.chif-panel.collapsed .chif-toggle-icon { transform: rotate(-90deg); }
.chif-panel.collapsed .chif-panel-body { display: none; }
.chif-panel-body { padding-top: 4px; }

/* Catalogue */
.chif-search { flex: 1; min-width: 0; }
.chif-cat-group { margin-bottom: 2px; }
.chif-cat-group-hdr {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #6b7280;
  padding: 4px 4px 3px;
  cursor: pointer;
  border-radius: 3px;
}
.chif-cat-group-hdr:hover { background: #1f2937; color: #9ca3af; }
.chif-cat-group.collapsed .chif-cat-items { display: none; }
.chif-cat-items { padding: 0 0 4px 2px; }
.chif-cat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 4px;
  cursor: grab;
  font-size: 0.76rem;
  margin-bottom: 2px;
  border: 1px solid transparent;
}
.chif-cat-item:hover { background: #1f2937; border-color: #374151; }
.chif-cat-item:active { cursor: grabbing; }
.chif-cat-item-name { color: #d1d5db; flex: 1; min-width: 0; }
.chif-cat-item-meta { color: #6b7280; font-size: 0.72rem; flex-shrink: 0; }

/* Toolbar */
#chif-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0 12px;
  gap: 6px;
  border-bottom: 1px solid #374151;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.chif-marge-label input {
  width: 50px;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 3px;
  color: #d1d5db;
  font-size: 0.72rem;
  padding: 2px 4px;
  text-align: right;
}
.chif-expert-label { cursor: pointer; }
/* Lot rows (flat table section headers) */
.chif-lot-row:first-child { border-top: none; }
.chif-non-classe-row { background: #141d2b; }
.chif-non-classe-row .chif-lot-titre { border-top-style: dashed; }
.chif-lot-row.drag-over { background: #0a1929; outline: 1px solid #3b82f6; }
.chif-lot-row.dragging-section { opacity: .4; }
.chif-lot-toggle {
  background: none;
  border: none;
  color: #6b7280;
  font-size: 0.72rem;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}
.chif-lot-toggle:hover { color: #d1d5db; }
.chif-lot-titre { vertical-align: middle !important; padding-top: 3px !important; padding-bottom: 3px !important; }
.chif-lot-total, .chif-lot-marge {
  font-size: 0.74rem;
  font-weight: 600;
  color: #e5e7eb;
  white-space: nowrap;
}
.chif-lot-marge { color: #60a5fa; }
.chif-lot-comment-inline {
  font-size: 0.72rem;
  color: #9ca3af;
  font-style: italic;
  display: block;
  padding-top: 2px;
}
.chif-lot-drop-ind td div { height: 2px; background: #3b82f6; border-radius: 1px; }

/* Entity row indentation */
.chif-entity-row .chif-th-drag { padding-left: 20px !important; }

/* Add-entity row */
.chif-add-entity-row td {
  padding: 2px 6px 4px 28px !important;
  border-bottom: none;
}
.chif-add-entity-row:hover { background: transparent !important; }
.chif-sec-add-btn {
  font-size: 0.75rem;
  color: #4b5563;
  padding: 0;
  text-decoration: none;
}
.chif-sec-add-btn:hover { color: #9ca3af; }

/* Kept for section title input (reused in lot-row) */
.chif-sec-title {
  flex: 1;
  background: transparent;
  border: none;
  color: #e5e7eb;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 2px 4px;
  border-radius: 3px;
  min-width: 0;
}
.chif-sec-title:focus { outline: none; background: #111827; }
.chif-non-classe-label {
  font-size: 0.68rem;
  letter-spacing: 0.07em;
  color: #6b7280;
}

/* Table */

.chif-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.chif-table thead th {
  background: #1f2937;
  color: #6b7280;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 4px 6px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid #374151;
}
@keyframes chif-row-flash {
  0%   { background: #1e3a5f; }
  60%  { background: #1e3a5f; }
  100% { background: transparent; }
}
.chif-table tbody tr { border-bottom: 1px solid #1f2937; }
.chif-table tbody tr:hover { background: #1a2435; }
.chif-table tbody tr.chif-flash { animation: chif-row-flash 1.4s ease-out forwards; }
.chif-table tbody tr.chif-validated { opacity: .55; }
.chif-table tbody tr.chif-validated .chif-nom-in { text-decoration: line-through; }
.chif-table tbody tr.dragging { opacity: .45; }
.chif-table tbody tr.drag-over-row { background: #1e3a5f; }
.chif-drop-ind td div { height: 2px; background: #3b82f6; margin: 0; border-radius: 1px; }

.chif-th-drag { width: 16px; padding: 0 4px !important; }
.chif-th-val  { width: 22px; padding: 0 2px !important; }
.chif-th-info { width: 22px; padding: 0 2px !important; }
.chif-th-code { width: 58px; }
.chif-td-code {
  width: 58px; font-size: 0.72rem;
  color: #6b7280; letter-spacing: 0.04em; white-space: nowrap;
  cursor: pointer; user-select: none;
}
.chif-td-code:hover { color: #9ca3af; }
.chif-drag-hdl {
  color: #4b5563;
  cursor: grab;
  font-size: 0.8rem;
}
.chif-drag-hdl:hover { color: #9ca3af; }
.chif-th-nom { width: 9999px; min-width: 160px; }
.chif-th-drag, .chif-th-val, .chif-th-info, .chif-th-code,
.chif-th-prix, .chif-th-qte, .chif-th-unite, .chif-th-total,
.chif-th-marge, .chif-th-actions { white-space: nowrap; }
.chif-th-prix, .chif-th-qte, .chif-th-unite, .chif-th-total, .chif-th-marge { width: 72px; text-align: right !important; }
.chif-th-actions { width: 36px; }

.chif-table td { padding: 3px 5px; vertical-align: middle; }
.chif-td-nom { min-width: 160px; vertical-align: top; padding-top: 5px !important; overflow: hidden; }

.chif-lot-badge {
  font-size: 0.62rem;
  color: #a78bfa;
  background: rgba(167,139,250,.12);
  border: 1px solid rgba(167,139,250,.3);
  border-radius: 3px;
  padding: 0 3px;
  line-height: 1.5;
  margin-right: 4px;
  vertical-align: middle;
}
.chif-shapes-badge[hidden] { display: none; }
.chif-shapes-badge {
  font-size: 0.62rem;
  color: #4ade80; background: rgba(74,222,128,.1);
  border: 1px solid rgba(74,222,128,.3);
  border-radius: 3px; padding: 0 4px; line-height: 1.5;
  flex-shrink: 0; cursor: pointer;
}
.chif-shapes-badge:hover { background: rgba(74,222,128,.2); }
.chif-shapes-badge.partial { color: #fbbf24; background: rgba(251,191,36,.1); border-color: rgba(251,191,36,.35); }
.chif-shapes-badge.partial:hover { background: rgba(251,191,36,.2); }
.chif-td-num { width: 68px; }
.chif-td-total, .chif-td-marge { width: 72px; color: #9ca3af; white-space: nowrap; padding-right: 8px !important; }
.chif-td-marge { color: #60a5fa; }
.chif-td-act { width: 50px; text-align: right; white-space: nowrap; }

.chif-nom-in {
  display: block;
  width: 100%;
  box-sizing: border-box;
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  color: #d1d5db;
  font-size: 0.85rem;
  font-family: inherit;
  line-height: 1.4;
  padding: 2px 3px;
  resize: none;
  overflow: hidden;
  min-height: 0;
}
.chif-nom-in:focus { outline: none; border-bottom-color: #4b5563; background: #111827; }
.chif-nom-in[readonly] { color: #9ca3af; cursor: default; }

.chif-num-in {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  color: #d1d5db;
  font-size: 0.85rem;
  padding: 2px 3px;
  text-align: right;
}
.chif-num-in:focus { outline: none; border-bottom-color: #4b5563; background: #111827; }
.chif-prix-locked { cursor: default; }
.chif-qte-ro { color: var(--bs-secondary-color); font-style: italic; }
.chif-unite-in {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  color: #9ca3af;
  font-size: 0.85rem;
  padding: 2px 3px;
  text-align: right;
}
.chif-unite-in:focus { outline: none; border-bottom-color: #4b5563; }

.chif-act-btn.chif-act-ok { color: #22c55e; }
.chif-act-btn.chif-act-del:hover { color: #f87171; }
.chif-act-btn.chif-act-info { font-size: 0.75rem; color: #6b7280; }
.chif-act-btn.chif-act-info:hover { color: #93c5fd; }

/* Entity info modal */
.chif-info-desc {
  font-size: 0.82rem;
  color: #9ca3af;
  white-space: pre-wrap;
  margin-bottom: 14px;
  line-height: 1.5;
}
.chif-info-grid { margin-bottom: 16px; }
.chif-info-row { font-size: 0.83rem; }
.chif-info-label { color: #6b7280; min-width: 80px; flex-shrink: 0; }
.chif-info-value { color: #d1d5db; }

/* Section total and marge are now inline in .chif-lot-total / .chif-lot-marge (see lot-row section above) */
.chif-total-marge { color: #60a5fa; }

/* Footer totals (unchanged) */

/* Footer totals */
#chif-footer {
  font-size: 0.78rem;
  color: #9ca3af;
  text-align: right;
  padding: 12px 2px 6px;
  border-top: 1px solid #374151;
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
#chif-footer strong { color: #e5e7eb; }


/* ══════════════════════════════════════════════════
   ADMIN PAGE
══════════════════════════════════════════════════ */
.admin-nav-item { border-bottom: 3px solid transparent !important; border-radius: 0 !important; }
.admin-nav-item.active { color: #3b82f6 !important; border-bottom-color: #3b82f6 !important; font-weight: 600; }
.admin-toggle-archived.active { color: #fbbf24; border-color: #d97706; }
.admin-toggle-archived.only  { color: #f97316; border-color: #ea580c; }
.admin-lot-row {
  border: 1px solid #374151;
  border-radius: 6px;
  margin-bottom: 8px;
}
.admin-lot-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  background: #1f2937;
  border-radius: 6px;
}
.admin-lot-row.open .admin-lot-header {
  border-radius: 6px 6px 0 0;
}
.admin-lot-header:hover { background: #243447; }
.admin-lot-chevron {
  color: #6b7280;
  font-size: 0.7rem;
  flex-shrink: 0;
}
.admin-lot-chevron.open { transform: rotate(90deg); }
.admin-lot-title { flex: 1; color: #d1d5db; font-size: 0.84rem; }
.admin-lot-body {
  background: #111827;
  padding: 10px 12px;
  border-top: 1px solid #374151;
  border-radius: 0 0 6px 6px;
}
.admin-lot-item-row {
  padding: 5px 0;
  border-bottom: 1px solid #1f2937;
  font-size: 0.8rem;
  color: #d1d5db;
}
.admin-lot-item-row:last-child { border-bottom: none; }
.admin-lot-item-name { flex: 1; }
.admin-lot-item-qty { color: #9ca3af; white-space: nowrap; }
.admin-lot-add-form {
  margin-top: 12px;
  border-top: 1px solid #1f2937;
  padding-top: 10px;
}

.admin-lot-form-label {
  width: 76px;
  flex-shrink: 0;
  color: #6b7280;
  font-size: 0.76rem;
  padding-top: 7px;
}
.admin-lot-form-label small {
  display: block;
  font-size: 0.68rem;
  color: #4b5563;
  line-height: 1.2;
  margin-top: 2px;
}

.admin-lot-prix-option {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: #d1d5db;
  cursor: pointer;
  user-select: none;
}
.admin-lot-prix-option input[type="number"] {
  width: 84px;
  flex-shrink: 0;
}
.admin-lot-item-prix {
  color: #6b7280;
  font-size: 0.78rem;
  white-space: nowrap;
}
.admin-lot-item-prix.overridden { color: #f59e0b; }
.admin-lot-thumb {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid #374151;
  flex-shrink: 0;
}
.admin-lot-image-preview {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid #374151;
  flex-shrink: 0;
}


/* ══════════════════════════════════════════════════
   NO-PLAN LAYOUT
══════════════════════════════════════════════════ */
#app-shell.no-plan #sidebar,
#app-shell.no-plan #main { display: none; }
#app-shell.no-plan #drawer {
  --bs-offcanvas-width: 100vw;
  top: 48px; /* navbar height — offcanvas starts below the topbar */
  height: calc(100vh - 48px);
}
#app-shell.no-plan #drawer-resize { display: none; }


/* ── Import catalogue ─────────────────────────────── */
.admin-import-zone {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  background: #111827;
  border: 1px dashed #374151;
  border-radius: 6px;
  margin-bottom: 12px;
}
.admin-import-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #1f2937;
  border: 1px solid #3b82f6;
  border-radius: 6px;
  margin-bottom: 12px;
  font-size: 0.84rem;
  color: #d1d5db;
}
.admin-import-mapping {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 12px;
  font-size: 0.84rem;
}
.admin-import-conflict {
  margin-top: 12px;
  font-size: 0.82rem;
  color: #9ca3af;
}
.imp-badge {
  padding: 1px 7px;
  font-size: 0.73rem;
  line-height: 1.6;
}
.imp-badge-new    { background: #064e3b; color: #34d399; }
.imp-badge-update { background: #1e3a5f; color: #93c5fd; }
.imp-badge-ignore { background: #1f2937; color: #6b7280; border: 1px solid #374151; }
.imp-summary { margin: 8px 0 0; }

/* ── Historique dans le fmodal ───────────────────── */
.fm-hist-section { margin-top: 18px; }
.fm-hist-header {
  font-size: 0.75rem;
  font-weight: 600;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-bottom: 6px;
  border-bottom: 1px solid #374151;
  margin-bottom: 6px;
}
.fm-hist-row {
  padding: 5px 0;
  border-bottom: 1px solid #1f2937;
  font-size: 0.78rem;
}
.fm-hist-date  { white-space: nowrap; min-width: 115px; color: #6b7280; }
.fm-hist-label { flex: 1; color: #d1d5db; }

.bulk-ent-list {
  max-height: 340px;
  overflow-y: auto;
  border: 1px solid #374151;
  border-radius: 6px;
}
.bulk-ent-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid #374151;
  font-size: 0.8rem;
}
.bulk-ent-row:last-child { border-bottom: none; }

.bulk-ent-name { font-weight: 500; color: #d1d5db; line-height: 1.35; }
.bulk-ent-desc { font-size: 0.75rem; color: #6b7280; line-height: 1.35; }

.bulk-ent-bottom-label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.72rem;
  color: #9ca3af;
}
.bulk-ent-row .bulk-coeff { width: 80px; }
.bulk-ent-row .bulk-src   { width: 190px; }

/* ── Entités toolbar + bulk + pagination ─────────── */
.ent-toolbar {
  margin-bottom: 12px;
}
.ent-search { min-width: 150px; max-width: 240px; }
.ent-bulk-bar {
  padding: 7px 12px; margin-bottom: 10px;
  background: #1e3a5f; border: 1px solid #2563eb; border-radius: 6px;
  font-size: 0.81rem; color: #93c5fd;
}
.ent-pagination {
  padding: 10px 0 4px;
}
.ent-page-btn { min-width: 30px; height: 28px; }
.ent-page-btn.active { background: #2563eb; border-color: #2563eb; color: #fff; font-weight: 600; }
.ent-page-ellipsis { color: #6b7280; font-size: 0.78rem; padding: 0 4px; user-select: none; }
tr.archived td { opacity: 0.45; }
tr.ent-selected td { background: #1e2d45; }
tr.ent-selected:hover td { background: #243554; }
.ent-code-badge {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a78bfa;
  background: #1e1b4b;
  border: 1px solid #4c1d95;
  border-radius: 4px;
  padding: 2px 6px;
  cursor: pointer;
  user-select: none;
}
.ent-code-badge:hover { background: #2e1065; color: #c4b5fd; }
.ent-code-badge.copied { background: #14532d; border-color: #166534; color: #86efac; }

.ent-ident-tag {
  font-size: 0.72rem;
  color: #6b7280;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 3px;
  padding: 1px 5px;
  margin-left: 4px;
  vertical-align: middle;
}

/* ══════════════════════════════════════════════════
   ADMIN PROJETS
══════════════════════════════════════════════════ */
.proj-list-row { cursor: pointer; }
.proj-list-row:hover td { background: #1f2937; }




.admin-panels-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) {
  .admin-panels-grid { grid-template-columns: 1fr; }
}

.admin-panel {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}
.admin-panel:last-child { margin-bottom: 0; }

.admin-panel-title {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: #6b7280;
  margin-bottom: 12px;
}

.admin-chiffrage-section { margin-bottom: 16px; }
.admin-chiffrage-section:last-child { margin-bottom: 0; }

.admin-chiffrage-sec-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: #d1d5db;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid #374151;
}


/* ── Validated entity picker ──────────────────────────────────────── */
.chif-val-list {
  height: 320px;
  overflow-y: auto;
  margin-bottom: 12px;
}
.chif-val-card {
  padding: 8px 10px;
  border: 1px solid #374151;
  border-radius: 6px;
  cursor: pointer;
  background: #1f2937;
}
.chif-val-card:hover { border-color: #4b5563; background: #243447; }
.chif-val-card.selected { border-color: #3b82f6; background: #172554; }
.chif-val-card-title {
  font-weight: 600;
  font-size: .9rem;
  color: #e5e7eb;
}
.chif-val-card-desc {
  font-size: .8rem;
  color: #9ca3af;
  margin-top: 2px;
  white-space: pre-wrap;
}
.chif-val-card-prix {
  font-size: .8rem;
  color: #6ee7b7;
  margin-top: 4px;
}

/* ── Responsive chiffrage table (container queries sur #drawer) ───── */
/* < 620px : drag + margé (expert) */
@container (max-width: 619px) {
  .chif-th-drag { display: none; }
  .chif-th-marge, .chif-td-marge { display: none; }
}
/* < 540px : aussi unité */
@container (max-width: 539px) {
  .chif-th-unite, .chif-col-unite { display: none; }
}
/* < 440px : aussi code */
@container (max-width: 439px) {
  .chif-th-code, .chif-td-code { display: none; }
}
/* ≥ 950px : colonnes numériques élargies */
@container (min-width: 950px) {
  .chif-table { font-size: 0.9rem; }
  .chif-table thead th, .chif-table td { padding: 5px 8px; }
  .chif-th-code, .chif-td-code { width: 80px; }
  .chif-th-prix, .chif-th-qte, .chif-th-unite,
  .chif-th-total, .chif-th-marge { width: 100px; }
  .chif-td-num { width: 94px; }
  .chif-td-total, .chif-td-marge { width: 100px; }
  .chif-th-actions { width: 50px; }
  .chif-td-act { width: 50px; }
}

/* ── Mode non-expert ── */
.non-expert .expert-only        { display: none !important; }
.non-expert #btn-dessin-mode    { display: none !important; }
.non-expert .shape-tex-thumb    { display: none !important; }
.non-expert #sidebar-resize     { display: none !important; }
.non-expert #sidebar            { width: 220px !important; min-width: 220px !important; resize: none; }

/* ── Catalogue : layout deux panneaux ────────────────────────────── */
.cat-two-panel {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 768px) {
  .cat-two-panel { grid-template-columns: 1fr; }
}

.cat-sidebar {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 12px;
  position: sticky;
  top: 0;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
}

.cat-sidebar-list {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.cat-sidebar-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.83rem;
  color: #d1d5db;
  user-select: none;
}
.cat-sidebar-item:hover { background: #243447; }
.cat-sidebar-item.active { background: #1e3a5f; color: #93c5fd; }

.cat-sidebar-count {
  font-size: 0.72rem;
  color: #6b7280;
  margin-left: 2px;
  flex-shrink: 0;
}
.cat-sidebar-edit,
.cat-sidebar-del {
  display: none;
  font-size: 0.75rem;
  line-height: 1;
  padding: 0 2px;
  color: #6b7280;
  flex-shrink: 0;
}
.cat-sidebar-item:hover .cat-sidebar-edit,
.cat-sidebar-item:hover .cat-sidebar-del { display: inline; }
.cat-sidebar-del:hover { color: #f87171; }
.cat-sidebar-edit:hover { color: #93c5fd; }

.cat-sidebar-add { border-top: 1px solid #374151; padding-top: 10px; }

/* ── Atelier : boîte d'aide ──────────────────────────────────────── */
.atelier-help-box {
  background: #1a2535;
  border: 1px solid #2d3f55;
  border-left: 3px solid #3b82f6;
  border-radius: 6px;
  padding: 14px 18px;
  font-size: 0.83rem;
  color: #c9d1db;
  line-height: 1.65;
  max-width: 720px;
}
.atelier-help-box p  { margin-bottom: 8px; }
.atelier-help-box p:last-child { margin-bottom: 0; }
.atelier-help-box ol { margin: 6px 0 10px 0; padding-left: 18px; }
.atelier-help-box li { margin-bottom: 4px; }

/* ── Sync catalogue ──────────────────────────────────────────────── */
.sync-table th, .sync-table td { vertical-align: middle; font-size: 0.82rem; }
.sync-new { color: #34d399; font-weight: 500; }

/* ── Wizard de validation ─────────────────────────────────────────── */
.wiz-container { max-width: 900px; }

.wiz-steps { display: flex; align-items: center; }

.wiz-step {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #374151;
  color: #9ca3af;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 600;
  flex-shrink: 0;
}
.wiz-step.active  { background: #3b82f6; color: #fff; }
.wiz-step.done    { background: #10b981; color: #fff; }
.wiz-step-sep     { flex: 1; max-width: 32px; height: 2px; background: #374151; margin: 0 4px; }

.wiz-table th, .wiz-table td { vertical-align: middle; padding: 4px 6px; }
.wiz-table input[type="text"],
.wiz-table input[type="number"],
.wiz-table select { font-size: 0.82rem; }

/* ── Admin texture cards ─────────────────────────────────────────── */
.tex-admin-card { width: 130px; flex-shrink: 0; transition: width .15s; }
.tex-admin-card.tex-editing { width: 210px; }
.tex-admin-preview {
  height: 72px; display: flex; align-items: center; justify-content: center;
  background: repeating-conic-gradient(#e2e8f0 0% 25%, #f8fafc 0% 50%) 0 0 / 16px 16px;
  border-bottom: 1px solid var(--bs-border-color);
  overflow: hidden;
}
.tex-admin-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* ── Texture picker ───────────────────────────────────────────────── */
.tex-thumb {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 4px; border: 2px solid #374151; border-radius: 6px;
  background: #1e293b; cursor: pointer; width: 52px;
  transition: border-color .15s;
}
.tex-thumb:hover { border-color: #6b7280; }
.tex-thumb.tex-sel { border-color: #3b82f6; background: #1e3a5f; }
.tex-lbl { font-size: 0.62rem; color: #9ca3af; text-align: center; line-height: 1.1; }
.tex-none {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; color: #6b7280; background: #111827; border-radius: 3px;
}

/* ── Texture tags ─────────────────────────────────────────────────── */
.tex-tag {
  font-size: 0.62rem; font-weight: 400; background: #e2e8f0;
  color: #475569; border-radius: 100px; padding: 0.1rem 0.4rem;
}
.tex-tag-filter {
  font-size: 0.7rem; padding: 0.15rem 0.6rem; border-radius: 100px;
  border: 1px solid #cbd5e1; background: transparent; color: #64748b;
  cursor: pointer; transition: background .12s, color .12s, border-color .12s;
}
.tex-tag-filter:hover { border-color: #94a3b8; background: #f1f5f9; }
.tex-tag-filter.active { background: #3b82f6; color: white; border-color: #3b82f6; }
