:root {
  --navy: #1a237e;
  --navy-deep: #0d1550;
  --red: #c62828;
  --red-soft: #e57373;
  --blue: #2962ff;
  --blue-soft: #90caf9;
  --paper: #f4f5f9;
  --ink: #1c1f2b;
  --ink-soft: #5a5f75;
  --line: #dde0ec;
  --white: #ffffff;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(13, 21, 80, 0.16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  overscroll-behavior: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- En-tête ---------- */

header {
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-deep) 100%);
  color: var(--white);
  padding: 12px 18px;
  z-index: 1000;
  box-shadow: var(--shadow);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-apart {
  width: 34px;
  height: 34px;
  object-fit: contain;
  flex-shrink: 0;
}

.brand-texte {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.brand-ligne1 {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.brand .mark {
  font-weight: 800;
  letter-spacing: 0.04em;
  font-size: 0.95rem;
  color: var(--blue-soft);
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.brand-sous {
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.55);
  letter-spacing: 0.01em;
}

.total-pill {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.78rem;
  white-space: nowrap;
}

.total-pill strong {
  color: var(--blue-soft);
}

/* Fil d'Ariane */

.breadcrumb {
  margin-top: 10px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.85rem;
}

.breadcrumb button {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.75);
  cursor: pointer;
  font: inherit;
  padding: 3px 2px;
  border-radius: 4px;
}

.breadcrumb button.actif {
  color: var(--white);
  font-weight: 600;
  cursor: default;
}

.breadcrumb button:not(.actif):hover {
  color: var(--white);
  text-decoration: underline;
}

.breadcrumb .sep {
  color: rgba(255, 255, 255, 0.4);
}

/* ---------- Carte ---------- */

#map-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}

#map {
  position: absolute;
  inset: 0;
  background: #eef1fb;
}

.leaflet-container {
  font-family: inherit;
}

/* Badges de comptage (façon Info-Pannes) */

.badge-compte {
  background: var(--red);
  color: var(--white);
  border: 2px solid var(--white);
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.78rem;
  min-width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, -50%);
  white-space: nowrap;
}

.badge-compte.muni {
  background: var(--blue);
}

.etiquette-carte {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--navy-deep);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
  white-space: nowrap;
}

/* Bouton retour flottant */

.btn-retour {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 900;
  background: var(--white);
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 9px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--navy);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-retour:hover { background: #eef1ff; }

/* Bandeau de chargement */

#chargement {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy-deep);
  color: var(--white);
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 0.8rem;
  box-shadow: var(--shadow);
  z-index: 950;
  display: none;
  align-items: center;
  gap: 8px;
}

#chargement.visible { display: flex; }

.spinner {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: var(--white);
  animation: tourner 0.7s linear infinite;
}

@keyframes tourner { to { transform: rotate(360deg); } }

/* Message d'état vide / erreur */

#message-etat {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 22px;
  font-size: 0.88rem;
  color: var(--ink-soft);
  text-align: center;
  max-width: 280px;
  display: none;
  z-index: 900;
}

#message-etat.visible { display: block; }

/* ---------- Modale : fiche du bail ---------- */

.modale-fond {
  position: fixed;
  inset: 0;
  background: rgba(13, 21, 80, 0.55);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 2000;
}

.modale-fond.visible { display: flex; }

.modale {
  background: var(--white);
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.3);
  animation: monter 0.22s ease-out;
}

@media (min-width: 620px) {
  .modale-fond { align-items: center; }
  .modale { border-radius: var(--radius); max-height: 84vh; }
}

@keyframes monter {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modale-tete {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-deep) 100%);
  color: var(--white);
  padding: 18px 20px;
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.modale-tete h2 {
  margin: 0 0 4px;
  font-size: 1.02rem;
  font-weight: 700;
}

.modale-tete .sous-titre {
  font-size: 0.78rem;
  color: var(--blue-soft);
}

.modale-fermer {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: var(--white);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
}

.modale-corps { padding: 18px 20px 26px; }

.fiche-grille {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.fiche-item {
  background: var(--paper);
  border-radius: 8px;
  padding: 10px 12px;
}

.fiche-item .label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  display: block;
  margin-bottom: 3px;
}

.fiche-item .valeur {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--navy-deep);
}

.section-titre {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  margin: 18px 0 8px;
  font-weight: 700;
}

.historique-ligne {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.86rem;
}

.historique-ligne:last-child { border-bottom: none; }

.historique-annee { color: var(--ink-soft); }
.historique-cout { font-weight: 700; }

.historique-hausse {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 700;
}

.hausse-ok { background: #e3f2ec; color: #1e7e4f; }
.hausse-abusive { background: #fdeaea; color: var(--red); }

.alerte-abus {
  margin-top: 14px;
  background: #fdeaea;
  border: 1px solid #f5c6c6;
  color: #8a1f1f;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.8rem;
  line-height: 1.4;
}

.info-conforme {
  margin-top: 14px;
  background: #e3f2ec;
  border: 1px solid #bfe3cf;
  color: #1e5f3c;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.8rem;
  line-height: 1.4;
}

/* Bâtiment sélectionné (contour OSM) */

.contour-batiment {
  filter: drop-shadow(0 0 4px rgba(198, 40, 40, 0.5));
}

/* Petits écrans */

@media (max-width: 480px) {
  .fiche-grille { grid-template-columns: 1fr 1fr; }
  header { padding: 10px 14px; }
  .brand h1 { font-size: 0.92rem; }
  .logo-apart { width: 28px; height: 28px; }
  .brand-sous { display: none; }
}
