/* ============================================================
   FM3A - Styles principaux
   ============================================================ */

:root {
  --primary: #1D9E75;
  --primary-dark: #0F6E56;
  --primary-light: #E1F5EE;
  --secondary: #185FA5;
  --accent: #BA7517;
  --danger: #C04828;
  --warning: #EF9F27;
  --success: #3B6D11;

  --bg: #f8f9fa;
  --bg-card: #ffffff;
  --border: #dee2e6;
  --text: #212529;
  --text-muted: #6c757d;
  --text-light: #adb5bd;

  --sidebar-w: 340px;
  --header-h: 56px;
  --shadow: 0 2px 8px rgba(0,0,0,.1);
  --shadow-lg: 0 4px 20px rgba(0,0,0,.15);
  --radius: 10px;
  --radius-sm: 6px;

  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  height: 100vh;
}

/* ============================================================
   LAYOUT PRINCIPAL
   ============================================================ */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#header {
  height: var(--header-h);
  background: var(--primary-dark);
  color: white;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 1000;
  flex-shrink: 0;
  box-shadow: var(--shadow);
}

#header .logo {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

#header .logo img {
  height: 32px;
  border-radius: 50%;
}

#header nav {
  display: flex;
  gap: 4px;
  margin-left: 16px;
}

#header nav button {
  background: transparent;
  border: none;
  color: rgba(255,255,255,.75);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all .2s;
}

#header nav button:hover,
#header nav button.active {
  background: rgba(255,255,255,.15);
  color: white;
}

#header .spacer { flex: 1; }

#header .user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  opacity: .9;
}

#header .user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255,255,255,.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
}

#main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ============================================================
   CARTE (gauche)
   ============================================================ */
#map-container {
  flex: 1;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
}

.map-controls {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.map-controls .ctrl-btn {
  background: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  cursor: pointer;
  box-shadow: var(--shadow);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  transition: all .2s;
  white-space: nowrap;
}

.map-controls .ctrl-btn:hover {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.map-controls .ctrl-btn.active {
  background: var(--primary);
  color: white;
}

.layer-switcher {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 500;
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px;
  min-width: 140px;
}

.layer-switcher h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.layer-switcher label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  cursor: pointer;
  font-size: 12px;
}

/* ============================================================
   SIDEBAR DROITE
   ============================================================ */
#sidebar {
  width: var(--sidebar-w);
  height: 100%;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.sidebar-tab {
  flex: 1;
  padding: 10px 4px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: all .2s;
  border-bottom: 2px solid transparent;
}

.sidebar-tab i { font-size: 18px; }

.sidebar-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: var(--bg-card);
}

.sidebar-panel {
  flex: 1;
  overflow-y: auto;
  display: none;
}

.sidebar-panel.active { display: block; }

/* ============================================================
   STATISTIQUES
   ============================================================ */
.stats-header {
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: white;
}

.stats-header h3 {
  font-size: 15px;
  margin-bottom: 2px;
}

.stats-header p {
  font-size: 12px;
  opacity: .8;
}

.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
}

.kpi-box {
  background: var(--bg-card);
  padding: 14px;
  text-align: center;
  cursor: pointer;
  transition: background .2s;
}

.kpi-box:hover { background: var(--primary-light); }

.kpi-val {
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  color: var(--primary);
}

.kpi-val.danger  { color: var(--danger); }
.kpi-val.warning { color: var(--warning); }
.kpi-val.success { color: var(--success); }

.kpi-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.3;
}

.section-title {
  padding: 10px 16px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
  font-weight: 600;
}

/* Barres par type */
.type-bar-item {
  display: flex;
  align-items: center;
  padding: 6px 16px;
  gap: 8px;
  cursor: pointer;
  transition: background .2s;
}

.type-bar-item:hover { background: var(--bg); }

.type-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: white;
  flex-shrink: 0;
}

.type-bar-wrap {
  flex: 1;
}

.type-bar-label {
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  margin-bottom: 2px;
}

.type-bar {
  height: 5px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
}

.type-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width .4s ease;
}

/* ============================================================
   LISTE DES POINTS
   ============================================================ */
.search-bar {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 6px;
}

.search-bar input {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
}

.search-bar input:focus { border-color: var(--primary); }

.filter-row {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-chip {
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 11px;
  cursor: pointer;
  background: white;
  transition: all .2s;
  white-space: nowrap;
}

.filter-chip:hover, .filter-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.points-list { }

.point-item {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .15s;
}

.point-item:hover { background: var(--bg); }
.point-item.active { background: var(--primary-light); }

.point-thumb {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.point-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius-sm);
}

.point-info { flex: 1; min-width: 0; }

.point-nom {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.point-meta {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.etat-badge {
  padding: 2px 7px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 600;
  flex-shrink: 0;
}

.etat-bon           { background: #d4edda; color: #155724; }
.etat-a_reparer     { background: #fff3cd; color: #856404; }
.etat-non_fonctionnel { background: #f8d7da; color: #721c24; }
.etat-en_construction { background: #cce5ff; color: #004085; }
.etat-ferme         { background: #e2e3e5; color: #383d41; }
.etat-inconnu       { background: #f8f9fa; color: #6c757d; }

/* ============================================================
   POPUP / DÉTAIL D'UN POINT
   ============================================================ */
.point-detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}

.point-detail-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.point-detail-modal {
  background: white;
  border-radius: var(--radius);
  width: 100%;
  max-width: 760px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform .25s;
}

.point-detail-overlay.open .point-detail-modal {
  transform: translateY(0);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  background: white;
  z-index: 10;
}

.modal-header h2 {
  flex: 1;
  font-size: 17px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 4px;
}

.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
}

.modal-tab {
  padding: 10px 14px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: all .2s;
}

.modal-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.modal-body {
  padding: 16px 20px;
}

.modal-panel { display: none; }
.modal-panel.active { display: block; }

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.info-field label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.info-field p {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.info-field.full { grid-column: 1 / -1; }

/* Galerie photos */
.photo-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.photo-item {
  aspect-ratio: 4/3;
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
  cursor: pointer;
  background: var(--bg);
}

.photo-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .3s;
}

.photo-item:hover img { transform: scale(1.05); }

.photo-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  color: white;
  background: rgba(0,0,0,.6);
}

/* Slider avant/après */
.before-after-container {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  margin: 12px 0;
  user-select: none;
}

.before-after-container img {
  width: 100%;
  display: block;
}

.before-after-container .after-img {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.before-after-container .after-img img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
}

.ba-slider {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  background: white;
  cursor: ew-resize;
  z-index: 10;
}

.ba-handle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 36px;
  height: 36px;
  background: white;
  border-radius: 50%;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-size: 16px;
}

/* Tableau finances */
.finance-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.finance-table th {
  padding: 8px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.finance-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.finance-table tr:hover td { background: var(--bg); }

.montant-recette { color: var(--success); font-weight: 600; }
.montant-depense { color: var(--danger); font-weight: 600; }

.finance-totaux {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px 0;
}

.finance-total-box {
  text-align: center;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.finance-total-box .val {
  font-size: 16px;
  font-weight: 700;
  display: block;
}

.finance-total-box .lbl {
  font-size: 11px;
  color: var(--text-muted);
}

/* Formulaire */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  transition: border .2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29,158,117,.12);
}

.form-group textarea { resize: vertical; min-height: 80px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all .2s;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #9e3a1f; }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideIn .3s ease;
  max-width: 300px;
}

.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.info    { background: var(--secondary); }
.toast.warning { background: var(--accent); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ============================================================
   LOADER
   ============================================================ */
.loader-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,.8);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

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

/* ============================================================
   RESPONSIVE / MOBILE (terrain)
   ============================================================ */
@media (max-width: 768px) {
  :root { --sidebar-w: 100%; }
  #main-content { flex-direction: column; }
  #map-container { height: 45vh; }
  #sidebar { height: 55vh; border-left: none; border-top: 2px solid var(--border); }
}

/* ============================================================
   MARQUEURS CARTE CUSTOM
   ============================================================ */
.custom-marker {
  width: 36px;
  height: 36px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid white;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
  display: flex;
  align-items: center;
  justify-content: center;
}

.custom-marker i {
  transform: rotate(45deg);
  font-size: 15px;
  color: white;
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 0;
  overflow: hidden;
}

.leaflet-popup-content {
  margin: 0;
  width: 260px !important;
}

.map-popup {
  font-family: var(--font);
}

.map-popup-header {
  padding: 10px 12px;
  color: white;
  font-size: 13px;
  font-weight: 600;
}

.map-popup-body {
  padding: 10px 12px;
  font-size: 12px;
}

.map-popup-body .row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 1px solid #f0f0f0;
}

.map-popup-footer {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 6px;
}

/* ============================================================
   PAGE LOGIN
   ============================================================ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--secondary) 100%);
  overflow: auto;
}

.login-card {
  background: white;
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo h1 {
  font-size: 26px;
  color: var(--primary-dark);
  font-weight: 800;
}

.login-logo p {
  color: var(--text-muted);
  font-size: 14px;
}

/* QR code styles */
.qr-container {
  text-align: center;
  padding: 20px;
}

.qr-container canvas {
  border: 4px solid white;
  box-shadow: var(--shadow);
  border-radius: 4px;
}

/* Chart canvas */
.chart-wrap {
  padding: 12px 16px;
  position: relative;
  height: 180px;
}

/* Barre d'état offline */
.offline-banner {
  position: fixed;
  top: var(--header-h);
  left: 0; right: 0;
  background: var(--warning);
  color: white;
  text-align: center;
  padding: 6px;
  font-size: 13px;
  font-weight: 600;
  z-index: 999;
  display: none;
}

.offline-banner.visible { display: block; }
