/* ============================================================
   RESET & BASE
   ============================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: #f1f5f9;
  color: #1e293b;
  font-size: 13px;
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: #94a3b8; font-size: 12px; }
.count { font-weight: 400; color: #94a3b8; }

/* ============================================================
   LAYOUT PRINCIPAL
   ============================================================ */
/* Colonnes : arbre | poignée | fiche (| poignée | visionneuse), largeurs réglées par les poignées (app.js) */
.app {
  --largeur-arbre: 320px;
  --largeur-visionneuse: 560px;
  display: grid;
  grid-template-columns: var(--largeur-arbre) 5px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}
.app.avec-visionneuse { grid-template-columns: var(--largeur-arbre) 5px minmax(0, 1fr) 5px var(--largeur-visionneuse); }

.poignee { cursor: col-resize; background: #e2e8f0; transition: background 0.15s; touch-action: none; }
.poignee:hover, .redimension .poignee { background: #a5b4fc; }
.redimension { cursor: col-resize; user-select: none; }
.redimension iframe { pointer-events: none; }

/* ============================================================
   CHAMPS DE SAISIE
   ============================================================ */
input[type="text"], input[type="search"], input[type="number"], input[type="date"], select, textarea {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  background: white;
  color: inherit;
}

textarea { resize: vertical; line-height: 1.5; min-height: 70px; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px 14px;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
  font-weight: 500;
  color: #475569;
}

.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-full { grid-column: 1 / -1; }
.form-grid .requis::after { content: ' *'; color: #dc2626; }

.field-checkbox {
  flex-direction: row !important;
  align-items: center;
  align-self: end;
  gap: 8px !important;
  padding-bottom: 7px;
  cursor: pointer;
}

.field-checkbox input { width: 16px; height: 16px; accent-color: #6366f1; cursor: pointer; }

.section-titre {
  grid-column: 1 / -1;
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid #f1f5f9;
}

@media (max-width: 1000px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  background: white;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 12px 16px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: white;
}

.sidebar-header h1 { font-size: 16px; font-weight: 600; }

.sidebar-section {
  padding: 10px 12px;
  border-bottom: 1px solid #e2e8f0;
}

.sidebar-section h3 {
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.toolbar { display: flex; gap: 4px; margin-bottom: 8px; }
.toolbar-spacer { flex: 1; }

.tool-btn {
  min-width: 34px;
  height: 30px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: white;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  transition: all 0.15s;
}

.tool-btn-label { padding: 0 10px; font-size: 13px; }
.tool-btn:hover:not(:disabled) { background: #eef2ff; border-color: #6366f1; }
.tool-btn:disabled { opacity: 0.35; cursor: default; }

/* ============================================================
   ARBRE
   ============================================================ */
.tree-section { flex: 1; overflow-y: auto; border-bottom: none; }

.tree, .tree ul { list-style: none; }
.tree ul { margin-left: 15px; border-left: 1px solid #e2e8f0; padding-left: 4px; }
.tree .empty { color: #94a3b8; padding: 6px 8px; }

.tree-row {
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  user-select: none;
}

.tree-row:hover { background: #f1f5f9; }
.tree-row.active { background: #eef2ff; color: #4338ca; font-weight: 500; }
.tree-row .icone { flex-shrink: 0; width: 18px; text-align: center; }
.tree-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row .name small { color: #94a3b8; margin-left: 6px; font-weight: 400; }
.tree-row .name mark { background: #fef08a; color: inherit; border-radius: 2px; }

.caret {
  width: 16px;
  flex-shrink: 0;
  text-align: center;
  color: #64748b;
  border-radius: 3px;
  font-size: 10px;
}

.caret:hover { background: #e2e8f0; }
.caret-empty { visibility: hidden; }

/* Racine de l'arbre (nom paramétrable) et ses boutons d'ajout, en icônes seules */
.tree-racine { font-weight: 600; }
.tree-racine .icone { width: auto; }
.tree > li > ul { margin-left: 9px; }
.tree-add-group { display: flex; gap: 2px; flex-shrink: 0; }
.tree-add {
  width: 26px;
  height: 24px;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  background: white;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}
.tree-add:hover { background: #eef2ff; border-color: #6366f1; }

.param-champ { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.param-champ input { padding: 7px 10px; border: 1px solid #cbd5e1; border-radius: 6px; font: inherit; }

/* ============================================================
   BOUTONS
   ============================================================ */
.btn, .btn-primary {
  padding: 6px 12px;
  border: 1px solid #cbd5e1;
  background: white;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  white-space: nowrap;
  transition: all 0.15s;
}

.btn:hover { background: #f8fafc; border-color: #94a3b8; }

.btn-primary { background: #6366f1; color: white; border-color: #6366f1; }
.btn-primary:hover { background: #4f46e5; }
.btn-primary:disabled { background: #c7d2fe; border-color: #c7d2fe; cursor: default; }

.btn-danger { color: #dc2626; border-color: #fca5a5; }
.btn-danger:hover { background: #fef2f2; border-color: #dc2626; }

.btn-small { padding: 3px 8px; font-size: 12px; }

/* ============================================================
   ZONE PRINCIPALE : FICHE
   ============================================================ */
.main { display: flex; overflow: hidden; min-width: 0; }
.detail-zone { flex: 1; min-width: 0; overflow-y: auto; padding: 20px 24px; }

.empty-state { color: #94a3b8; text-align: center; margin-top: 80px; font-size: 14px; }

.detail { max-width: 1400px; }

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.detail-title { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; }
.detail-title h2 { font-size: 20px; font-weight: 600; }
.breadcrumb { flex-basis: 100%; font-size: 12px; color: #64748b; min-height: 18px; }
.breadcrumb a { color: #4338ca; text-decoration: none; cursor: pointer; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .sep { margin: 0 6px; color: #cbd5e1; }

.detail-meta { flex-basis: 100%; color: #64748b; font-size: 12px; }
.detail-actions { display: flex; gap: 8px; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 1px 8px;
  border-radius: 10px;
  background: #e2e8f0;
  color: #475569;
}

.badge-site     { background: #dbeafe; color: #1d4ed8; }
.badge-batiment { background: #fef3c7; color: #b45309; }
.badge-niveau   { background: #dcfce7; color: #15803d; }
.badge-local    { background: #f3e8ff; color: #7e22ce; }
.badge-terrain  { background: #ecfccb; color: #4d7c0f; }

/* ============================================================
   CARTES
   ============================================================ */
.card {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 14px;
}

.card h3 { font-size: 13px; font-weight: 600; color: #334155; margin-bottom: 12px; }

.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.card-title h3 { margin-bottom: 0; }
.card-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 14px; }
.dirty-hint { color: #b45309; font-size: 12px; }

/* Tableau des sous-éléments */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 6px 8px;
  border-bottom: 1px solid #e2e8f0;
}

.table td { padding: 7px 8px; border-bottom: 1px solid #f1f5f9; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: #f8fafc; }
.table .num { text-align: right; white-space: nowrap; }

/* ============================================================
   MODALE & TOAST
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-box {
  background: white;
  border-radius: 8px;
  padding: 20px;
  width: 420px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.modal-box p { white-space: pre-line; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #1e293b;
  color: white;
  padding: 10px 16px;
  border-radius: 6px;
  z-index: 200;
}

.toast.error { background: #dc2626; }

/* ============================================================
   MENU CONTEXTUEL (clic droit sur l'arbre)
   ============================================================ */
.menu {
  position: fixed;
  z-index: 50;
  min-width: 230px;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  padding: 4px;
}

.menu-titre {
  font-size: 11px;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 6px 8px 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 10px;
  border: none;
  background: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  color: inherit;
}

.menu-item:hover { background: #eef2ff; color: #4338ca; }
.menu .empty { padding: 6px 10px; color: #94a3b8; }

/* ============================================================
   PARAMÉTRAGE
   ============================================================ */
.param-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
  cursor: pointer;
}

.param-option input { width: 16px; height: 16px; margin-top: 2px; accent-color: #6366f1; flex-shrink: 0; cursor: pointer; }
.param-option .muted { display: inline-block; margin-top: 4px; line-height: 1.5; }

.menu-sep { height: 1px; background: #e2e8f0; margin: 4px 2px; }
.menu-item.menu-danger { color: #dc2626; }
.menu-item.menu-danger:hover { background: #fef2f2; color: #b91c1c; }
.tree-row.ctx { outline: 1px dashed #6366f1; outline-offset: -1px; }

/* ============================================================
   ONGLETS DE LA FICHE
   ============================================================ */
.onglets { display: flex; gap: 2px; border-bottom: 1px solid #e2e8f0; margin-bottom: 14px; }
.onglet {
  padding: 8px 16px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  font: inherit;
  font-size: 13px;
  color: #64748b;
  cursor: pointer;
  margin-bottom: -1px;
}
.onglet:hover { color: #334155; }
.onglet.actif { color: #4338ca; border-bottom-color: #6366f1; font-weight: 600; }

/* Champs conditionnels (ex. types d'ERP si la case ERP est cochée) */
.desactive { opacity: 0.45; }

/* ============================================================
   LISTE DÉROULANTE À CASES À COCHER (types d'ERP)
   ============================================================ */
.field-multi { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: #64748b; }
.multi { position: relative; }
.multi-btn {
  width: 100%;
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: white;
  font: inherit;
  font-size: 13px;
  color: #334155;
  text-align: left;
  cursor: pointer;
}
.multi-btn:disabled { cursor: default; background: #f8fafc; }
.multi-resume { flex: 1; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; overflow: hidden; }
.multi-resume b { color: #4338ca; }
.multi-fleche { color: #64748b; font-size: 11px; }
.puce { background: #eef2ff; color: #4338ca; font-weight: 600; font-size: 12px; padding: 1px 7px; border-radius: 10px; }
.multi-panel {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  min-width: 360px;
  max-height: 320px;
  overflow-y: auto;
  z-index: 40;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  padding: 4px;
}
.multi-panel label {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  color: #334155;
  font-size: 13px;
}
.multi-panel label:hover { background: #f1f5f9; }
.multi-panel input { width: 15px; height: 15px; accent-color: #6366f1; flex-shrink: 0; }
.multi-panel b { min-width: 32px; color: #4338ca; }

/* ============================================================
   ADRESSE (BAN)
   ============================================================ */
.adresse { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr; gap: 10px; }
.adresse-ligne { display: flex; align-items: center; gap: 14px; }
.adresse-recherche { flex: 1; min-width: 0; position: relative; }
.adresse-action { color: #4338ca; font-size: 13px; white-space: nowrap; text-decoration: none; cursor: pointer; }
.adresse-action:hover { text-decoration: underline; }
.adresse-q { width: 100%; padding: 7px 10px; border: 1px solid #a5b4fc; border-radius: 6px; font: inherit; background: #f8faff; }
.adresse-suggestions {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  z-index: 40;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  padding: 4px;
}
.adresse-sugg {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 10px;
  border: none;
  background: none;
  border-radius: 5px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.adresse-sugg small { color: #94a3b8; margin-left: 6px; }
.adresse-sugg.actif, .adresse-sugg:hover { background: #eef2ff; color: #4338ca; }
.adresse-vide { padding: 6px 10px; }
.adresse-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px 14px; align-content: start; }
.adresse-grid .c1 { grid-column: span 1; }
.adresse-grid .c2 { grid-column: span 2; }
.adresse-grid .c3 { grid-column: span 3; }
.adresse-grid .c4 { grid-column: span 4; }

/* ============================================================
   DOCUMENTS (plans)
   ============================================================ */
.depot {
  border: 2px dashed #cbd5e1;
  border-radius: 8px;
  padding: 18px;
  text-align: center;
  color: #94a3b8;
  font-size: 13px;
  margin-bottom: 12px;
}
.depot.survol { border-color: #6366f1; background: #eef2ff; color: #4338ca; }
.docs tbody tr.actif { background: #eef2ff; }
.docs tbody tr.actif .doc-nom { color: #4338ca; font-weight: 600; }
.doc-icone { width: 28px; font-size: 16px; }
.doc-nom { word-break: break-word; }
.doc-actions { width: 80px; }
.doc-actions .tool-btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; height: 26px; min-width: 30px; }

/* ============================================================
   VISIONNEUSE DE DOCUMENT (colonne de droite)
   ============================================================ */
.visionneuse { background: white; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.visionneuse-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid #e2e8f0;
}
.visionneuse-header .tool-btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; color: inherit; }
.visionneuse-nom { flex: 1; font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.visionneuse-corps { flex: 1; min-height: 0; display: flex; background: #f1f5f9; }
.visionneuse-corps iframe { flex: 1; border: none; background: white; }
.visionneuse-image { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; padding: 10px; }
.visionneuse-image img { max-width: 100%; max-height: 100%; object-fit: contain; box-shadow: 0 2px 8px rgba(15, 23, 42, 0.15); background: white; }
.visionneuse-vide { margin: auto; text-align: center; color: #64748b; padding: 20px; }
.visionneuse-vide .grande-icone { font-size: 56px; margin-bottom: 10px; }
.visionneuse-vide p { margin-bottom: 14px; }
.visionneuse-vide .btn-primary { text-decoration: none; display: inline-block; }
.table tfoot td { font-weight: 600; border-top: 1px solid #e2e8f0; padding: 7px 8px; }

/* Rattachements (locaux et terrains d'un logement) : liste à cocher pour en ajouter plusieurs d'un coup */
.ajout-ratt { border: 1px solid #c7d2fe; background: #f8faff; border-radius: 8px; padding: 8px 10px; margin-bottom: 14px; }
.ajout-ratt .table { background: white; }
.ajout-ratt input[type="checkbox"] { width: 15px; height: 15px; accent-color: #6366f1; cursor: pointer; }
.ajout-ratt th:first-child, .ajout-ratt td:first-child { width: 28px; }
.ajout-ratt .ajout-groupe td { background: #eef2ff; font-weight: 600; color: #4338ca; font-size: 12px; }
.ajout-ratt tr.pris td { color: #94a3b8; cursor: default; }
.ajout-ratt tr.pris input { cursor: default; }
.ajout-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.ajout-resume { flex: 1; }
.card-title .btn:disabled { opacity: 0.45; cursor: default; }
.badge-logement { background: #fef3c7; color: #92400e; }

/* Documents : zone de dépôt avec type et date, type et date modifiables dans la liste */
.depot .lien { color: #4338ca; text-decoration: underline; cursor: pointer; }
.depot-options { display: flex; justify-content: center; gap: 16px; margin-top: 10px; flex-wrap: wrap; }
.depot-options label { display: flex; align-items: center; gap: 6px; color: #64748b; font-size: 12px; }
.depot-options select, .depot-options input { width: auto; }
.docs select, .docs input[type="date"] { padding: 3px 6px; font-size: 12px; width: auto; max-width: 220px; }

/* Carte (onglet Carte) */
.carte-bloc { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 8px; }
.carte-outils { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.carte-outils .btn:disabled { opacity: 0.4; cursor: default; }
.carte-mesure { font-size: 13px; color: #334155; display: flex; align-items: center; gap: 8px; }
.carte-google { color: #4338ca; font-size: 12px; }
.carte-aide { min-height: 16px; }
.carte-map { height: 520px; border: 1px solid #cbd5e1; border-radius: 8px; z-index: 0; }
.carte-map.en-selection, .carte-map.en-selection .leaflet-interactive { cursor: pointer; }
.carte-map.en-attente, .carte-map.en-attente .leaflet-interactive { cursor: progress; }
.carte-parcelles { display: flex; flex-wrap: wrap; gap: 6px; }
.carte-parcelles:empty { display: none; }
.parcelle-puce { display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px 2px 10px; border: 1px solid #cbd5e1; border-radius: 999px; background: #f8fafc; font-size: 12px; }
.parcelle-puce.introuvable { border-color: #fca5a5; background: #fef2f2; }
.parcelle-puce button { border: none; background: none; cursor: pointer; color: #64748b; padding: 0 4px; border-radius: 50%; }
.parcelle-puce button:hover { background: #e2e8f0; color: #0f172a; }
.param-couleur input[type=color] { width: 48px; height: 30px; padding: 2px; vertical-align: middle; cursor: pointer; }

/* Parcelles cadastrales (type parcelle, onglet Parcelles, vue Parcellaire, import) */
.badge-parcelle { background: #ffedd5; color: #c2410c; }
.tree-parcellaire .name small { margin-left: 6px; }
input.lecture { background: #f1f5f9; color: #475569; }
.carte-ref { flex: 1; min-width: 220px; max-width: 360px; padding: 5px 8px; border: 1px solid #cbd5e1; border-radius: 6px; font: inherit; font-size: 13px; }
.carte-mesure:empty { display: none; }
.parcelle-puce a { cursor: pointer; color: #4338ca; font-weight: 600; }
.parcelle-puce a:hover { text-decoration: underline; }
#parcellaire .carte-map { height: 560px; }
.legende { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: #475569; }
.legende i { display: inline-block; width: 14px; height: 10px; border-radius: 2px; margin-left: 6px; }
.legende-commune { background: var(--couleur-commune, #f59e0b); opacity: 0.7; }
.legende-autre { background: #6366f1; opacity: 0.7; }
.parcellaire-filtres { display: flex; gap: 6px; }
.parcellaire-filtres input, .parcellaire-filtres select { padding: 4px 8px; border: 1px solid #cbd5e1; border-radius: 6px; font: inherit; font-size: 13px; }
.parcellaire-filtres input { width: 280px; }
.champ-court { width: 120px; }
.modal-box.modal-import { width: min(900px, 94vw); }
.import-options { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.import-options input[type=text] { padding: 5px 8px; border: 1px solid #cbd5e1; border-radius: 6px; font: inherit; margin-left: 6px; }
.import-table { max-height: 45vh; overflow: auto; border: 1px solid #e2e8f0; border-radius: 6px; }
.import-table .table tbody tr { cursor: default; }
.erreur { color: #b91c1c; }
.ok { color: #15803d; }
/* Paramétrage : commune (code postal, ville, code INSEE) */
.param-commune { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.param-commune label { display: flex; flex-direction: column; gap: 2px; font-size: 0.9em; }

/* Paramétrage : types de document */
.param-types-docs { list-style: none; display: flex; flex-direction: column; gap: 4px; max-height: 240px; overflow-y: auto; padding: 0; margin: 0; }
.param-types-docs li { display: flex; align-items: center; gap: 4px; }
.param-types-docs input { flex: 1; padding: 5px 8px; }
.param-types-docs li:first-child [data-type-doc-haut] { visibility: hidden; }
.param-ajout { align-self: flex-start; }

/* Documents : tuiles de filtre par type, fichiers en attente de typage */
.tuiles-docs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.tuile-doc {
  display: flex; flex-direction: column; align-items: flex-start; min-width: 92px; padding: 6px 12px;
  border: 1px solid #e2e8f0; border-radius: 8px; background: #f8fafc; font: inherit; cursor: pointer; text-align: left;
}
.tuile-doc b { font-size: 18px; color: #1e293b; line-height: 1.2; }
.tuile-doc span { font-size: 12px; color: #64748b; }
.tuile-doc:hover:not(:disabled) { border-color: #a5b4fc; background: #eef2ff; }
.tuile-doc.actif { border-color: #6366f1; background: #eef2ff; box-shadow: inset 0 0 0 1px #6366f1; }
.tuile-doc.actif b, .tuile-doc.actif span { color: #4338ca; }
.tuile-doc.vide { opacity: 0.45; cursor: default; }
.depot-attente { border: 1px solid #c7d2fe; background: #f8faff; border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; }
.depot-attente-titre { display: flex; gap: 10px; align-items: baseline; margin-bottom: 6px; }
.depot-attente-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; color: #64748b; }
.depot-attente-actions label { display: flex; align-items: center; gap: 6px; }
.docs select.a-typer { border-color: #f59e0b; background: #fffbeb; }

/* ============================================================
   PARAMÉTRAGE EN ONGLETS : la fenêtre prend la place disponible (plein écran sur petit écran)
   ============================================================ */
.modal-box.modal-param {
  width: min(980px, 96vw);
  height: min(760px, 94vh);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}
.param-entete { padding: 16px 20px 0; border-bottom: 1px solid #e2e8f0; }
.param-entete h3 { margin-bottom: 10px; }
.param-onglets { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: thin; }
.param-onglet {
  border: none; background: none; font: inherit; font-size: 13px; padding: 8px 14px; cursor: pointer; color: #64748b;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.param-onglet:hover { color: #4338ca; }
.param-onglet.actif { color: #4338ca; border-bottom-color: #6366f1; font-weight: 600; }
.param-corps { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 20px; }
.param-panneau.hidden { display: none; }
.modal-param .modal-actions { margin: 0; padding: 12px 20px; border-top: 1px solid #e2e8f0; background: #f8fafc; }
.param-types-docs { max-height: none; }

/* Éditeur des types d'équipement : liste des types | type sélectionné */
.param-equip { display: grid; grid-template-columns: minmax(180px, 240px) 1fr; gap: 16px; margin-top: 10px; align-items: start; }
.param-equip-liste { display: flex; flex-direction: column; gap: 6px; }
#paramEquipTypes { display: flex; flex-direction: column; gap: 4px; }
.equip-type {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; text-align: left; font: inherit; font-size: 13px;
  padding: 7px 10px; border: 1px solid #e2e8f0; border-radius: 6px; background: white; cursor: pointer;
}
.equip-type small { color: #94a3b8; white-space: nowrap; }
.equip-type:hover { border-color: #a5b4fc; }
.equip-type.actif { border-color: #6366f1; background: #eef2ff; color: #4338ca; }
.param-equip-editeur { border: 1px solid #e2e8f0; border-radius: 8px; padding: 12px; min-width: 0; }
.param-equip-editeur input, .param-equip-editeur select { padding: 6px 8px; border: 1px solid #cbd5e1; border-radius: 6px; font: inherit; font-size: 13px; min-width: 0; }
.equip-entete { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.equip-entete label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: #64748b; }
.equip-icone input { width: 64px; text-align: center; font-size: 18px; }
.equip-nom { flex: 1; }
.equip-champs-titre { margin-bottom: 6px; font-size: 13px; }
.equip-champs { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.equip-champ { display: grid; grid-template-columns: minmax(140px, 1.3fr) 130px minmax(140px, 1.5fr) auto; gap: 6px; align-items: center; }
.equip-champ-actions { display: flex; gap: 2px; }
.equip-champ:first-child [data-champ-haut] { visibility: hidden; }

@media (max-width: 760px) {
  .modal-box.modal-param { width: 100vw; height: 100vh; height: 100dvh; max-width: none; border-radius: 0; }
  .param-equip { grid-template-columns: 1fr; }
  .equip-champ { grid-template-columns: 1fr 1fr auto; }
  .equip-champ .equip-options { grid-column: 1 / 3; grid-row: 2; }
  .equip-champ .equip-options:empty { display: none; }
  .param-commune { flex-direction: column; }
}
@media (max-height: 560px) {
  .modal-box.modal-param { height: 100vh; height: 100dvh; }
  .param-entete h3 { display: none; }
}

/* Équipements et carte du patrimoine */
.badge-equipement { background: #e0f2fe; color: #0369a1; }
.tree-virtuel .name small { margin-left: 6px; }
.tool-btn.actif { background: #eef2ff; border-color: #6366f1; }
.marqueur-emoji { background: none; border: none; }
.marqueur-emoji span {
  display: flex; align-items: center; justify-content: center; width: 30px; height: 30px; font-size: 17px;
  background: white; border: 2px solid #6366f1; border-radius: 50%; box-shadow: 0 2px 6px rgba(15, 23, 42, 0.35);
}
.marqueur-site span { border-color: #059669; }
.marqueur-batiment span { border-color: #2563eb; }
.marqueur-equipement span { border-color: #dc2626; }
.marqueur-actif span { border-color: #dc2626; width: 34px; height: 34px; font-size: 19px; }
.position-coord { font-size: 12px; }
.popup-element { display: flex; flex-direction: column; gap: 3px; font-size: 13px; min-width: 190px; }
.popup-actions { margin-top: 6px; }
.carte-patrimoine-card { padding: 10px; }
.carte-map.carte-patrimoine { height: calc(100vh - 200px); min-height: 380px; }
.dupliquer-apercu { font-size: 13px; margin-top: 8px; color: #475569; }
.marqueur-autre span { opacity: 0.55; width: 24px; height: 24px; margin: 3px; font-size: 13px; border-color: #94a3b8; }

.historique td { vertical-align: top; font-size: 13px; }
.historique td div + div { margin-top: 2px; }
.nowrap { white-space: nowrap; }

/* Comptes : écran de connexion, mon compte, gestion des comptes */
.ecran-connexion {
  position: fixed; inset: 0; z-index: 3000; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%); overflow: auto;
}
.connexion-box { background: white; border-radius: 12px; padding: 24px 28px; width: min(420px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.connexion-box h2 { font-size: 18px; margin-bottom: 4px; }
.connexion-box h3 { font-size: 15px; margin-bottom: 8px; color: #4338ca; }
.connexion-box > p.muted { margin-bottom: 12px; font-size: 13px; }
.connexion-box .btn-primary { width: 100%; padding: 9px; }
.connexion-erreur { color: #dc2626; font-size: 13px; min-height: 1.2em; margin-bottom: 8px; }
.compte-btn {
  margin-top: 6px; border: 1px solid transparent; background: none; color: inherit; opacity: .9; font: inherit; font-size: 12px;
  padding: 2px 6px; border-radius: 6px; cursor: pointer; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.compte-btn:hover { opacity: 1; border-color: currentColor; }
.compte-mdp { border-top: 1px solid #e2e8f0; margin-top: 12px; padding-top: 12px; }
.compte-mdp h4, .compte-edit h4 { font-size: 14px; margin-bottom: 8px; }
.modal-box.modal-comptes { width: min(860px, 96vw); max-height: 94vh; overflow: auto; }
.comptes-table { max-height: 260px; overflow: auto; margin: 8px 0 12px; }
#comptesListe tr { cursor: pointer; }
#comptesListe tr:hover { background: #f1f5f9; }
#comptesListe tr.actif { background: #eef2ff; }
#comptesListe tr.compte-inactif td { color: #94a3b8; }
.compte-edit { border-top: 1px solid #e2e8f0; padding-top: 12px; }
.compte-edit-grille { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.compte-edit select { padding: 7px 10px; border: 1px solid #cbd5e1; border-radius: 6px; font: inherit; }
.compte-mdp-ligne { display: flex; gap: 6px; }
.compte-mdp-ligne input { flex: 1; min-width: 0; font-family: ui-monospace, monospace; }
.compte-actif { display: flex; gap: 6px; align-items: center; font-size: 13px; }

/* ============================================================
   MODULES ET PAGE D'ACCUEIL (body.module-accueil | module-patrimoine | module-controles, voir controles.js)
   ============================================================ */
body:not(.module-accueil) .accueil { display: none; }
body:not(.module-patrimoine):not(.module-controles) .app { display: none; }
body:not(.module-patrimoine) [data-module="patrimoine"],
body:not(.module-controles) [data-module="controles"] { display: none !important; }

.accueil {
  min-height: 100vh; padding: 48px 24px; display: flex; flex-direction: column; align-items: center; gap: 36px;
  background: linear-gradient(160deg, #eef2ff 0%, #f1f5f9 55%);
}
.accueil-entete { width: min(900px, 100%); display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.accueil-entete h1 { font-size: 26px; font-weight: 600; color: #1e293b; }
.accueil-entete p { color: #64748b; font-size: 14px; }
.accueil-entete .compte-btn { color: #4338ca; margin: 0; }
.accueil-tuiles { width: min(900px, 100%); display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 24px; }
.accueil-tuile {
  display: flex; flex-direction: column; gap: 8px; padding: 28px; border-radius: 14px; background: white;
  border: 1px solid #e2e8f0; color: inherit; text-decoration: none; box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.accueil-tuile:hover { transform: translateY(-3px); border-color: #a5b4fc; box-shadow: 0 12px 28px rgba(99, 102, 241, 0.18); }
.accueil-icone { font-size: 44px; line-height: 1; }
.accueil-tuile h2 { font-size: 20px; font-weight: 600; color: #4338ca; }
.accueil-tuile p { color: #64748b; font-size: 13px; }
.accueil-chiffres { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.accueil-chiffres span { background: #f1f5f9; border-radius: 999px; padding: 3px 10px; font-size: 12px; color: #475569; }
.accueil-chiffres b { color: #1e293b; }
.accueil-chiffres .alerte { background: #fef2f2; color: #b91c1c; }
.accueil-chiffres .attention { background: #fffbeb; color: #b45309; }

.sidebar-titre { display: flex; align-items: center; gap: 8px; }
.accueil-lien { color: white; text-decoration: none; font-size: 16px; opacity: 0.85; border-radius: 6px; padding: 0 3px; }
.accueil-lien:hover { opacity: 1; background: rgba(255, 255, 255, 0.18); }

/* ============================================================
   SUIVI DES CONTRÔLES
   ============================================================ */
.controles-filtres { display: flex; gap: 6px; margin-top: 6px; }
.controles-filtres select { padding: 4px 6px; font-size: 12px; min-width: 0; }
.controles-liste { list-style: none; }
.controles-liste .empty { color: #94a3b8; padding: 6px 8px; }
.controles-annee { font-size: 11px; font-weight: 600; color: #94a3b8; letter-spacing: 0.5px; padding: 10px 8px 4px; }
.controle-item { padding: 7px 8px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; }
.controle-item + .controle-item { margin-top: 2px; }
.controle-item:hover { background: #f1f5f9; }
.controle-item.actif { background: #eef2ff; border-color: #c7d2fe; }
.ci-haut { display: flex; justify-content: space-between; gap: 8px; }
.ci-intitule { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.controle-item.actif .ci-intitule { color: #4338ca; }
.ci-date { color: #64748b; font-size: 12px; white-space: nowrap; }
.ci-bas { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-top: 3px; }
.ci-type { margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.res-ok { background: #dcfce7; color: #15803d; }
.res-obs { background: #ffedd5; color: #c2410c; }
.res-nc { background: #fee2e2; color: #b91c1c; }
.ech-retard { background: #fee2e2; color: #b91c1c; }
.ech-bientot { background: #fef3c7; color: #b45309; }
.ech-ok { background: #f1f5f9; color: #475569; }
.ech-remplacee { background: #f8fafc; color: #94a3b8; }

.ctrl-echeance { display: flex; flex-direction: column; gap: 3px; }
.ctrl-periodes { display: flex; gap: 8px; font-size: 12px; }
.lien-btn { background: none; border: none; padding: 0; color: #4338ca; cursor: pointer; font: inherit; font-size: 12px; }
.lien-btn:hover { text-decoration: underline; }
.lien, .doc-controle-lien, a[data-ouvrir-controle] { color: #4338ca; cursor: pointer; }
.lien:hover, .doc-controle-lien:hover { text-decoration: underline; }
.doc-controle-lien { display: inline-block; margin-left: 6px; font-size: 11px; background: #eef2ff; border-radius: 10px; padding: 0 7px; }
.aide-controles { margin-top: 10px; }

.ctrl-groupe + .ctrl-groupe { margin-top: 10px; }
.ctrl-groupe-titre { font-size: 12px; font-weight: 600; color: #475569; margin-bottom: 5px; }
.ctrl-puces { display: flex; flex-wrap: wrap; gap: 6px; }
.puce {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 10px; border: 1px solid #e2e8f0;
  border-radius: 999px; background: #f8fafc; font-size: 12px;
}
.puce a { color: #1e293b; cursor: pointer; text-decoration: none; }
.puce a:hover { color: #4338ca; text-decoration: underline; }
.puce small { color: #94a3b8; }
.puce button { border: none; background: none; color: #94a3b8; cursor: pointer; border-radius: 50%; width: 18px; height: 18px; line-height: 1; }
.puce button:hover { background: #fee2e2; color: #b91c1c; }

.modal-box.modal-choix { width: min(760px, 96vw); height: min(780px, 94vh); display: flex; flex-direction: column; gap: 10px; }
.modal-choix h3 { margin: 0; }
.choix-raccourcis { display: flex; flex-wrap: wrap; gap: 8px; }
.choix-raccourcis:empty { display: none; }
.choix-arbre { flex: 1; overflow-y: auto; border: 1px solid #e2e8f0; border-radius: 8px; padding: 6px; }
.choix-arbre > ul { margin-left: 0; border-left: none; padding-left: 0; }
.choix-row label { display: flex; align-items: center; gap: 5px; flex: 1; min-width: 0; cursor: pointer; }
.choix-row input[type="checkbox"] { width: 15px; height: 15px; accent-color: #6366f1; flex-shrink: 0; }
.choix-branche { width: 24px; height: 22px; font-size: 12px; opacity: 0; }
.choix-row:hover .choix-branche { opacity: 1; }
.choix-resume { font-size: 13px; color: #475569; align-self: center; }
.modal-choix .modal-actions { margin-top: 0; }
