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

body {
  font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: #0f172a;
  color: #f1f5f9;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
#header {
  background: linear-gradient(90deg, #0f172a 0%, #1e293b 100%);
  border-bottom: 1px solid #334155;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 1000;
  flex-shrink: 0;
}

#header h1 {
  font-size: 16px;
  font-weight: 600;
  color: #f1f5f9;
  letter-spacing: .3px;
}

/* ── Compteurs centrés ──────────────────────────────────────────────────── */
#stats {
  display: flex;
  align-items: center;
  flex: 1;
  justify-content: center;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px;
}
.stat-value {
  font-size: 18px;
  font-weight: 700;
  color: #f1f5f9;
  line-height: 1.1;
}
.stat-label {
  font-size: 10px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-top: 1px;
}
.stat-item.green .stat-value { color: #4ade80; }
.stat-item.red   .stat-value { color: #f87171; }
.stat-item.green .stat-label { color: #4ade80; opacity: .7; }
.stat-item.red   .stat-label { color: #f87171; opacity: .7; }
.stat-sep { width: 1px; height: 28px; background: #334155; }

/* ── Roue de configuration ──────────────────────────────────────────────── */
#settings-wrap { position: relative; flex-shrink: 0; }

#settings-btn {
  background: none;
  border: 1px solid #334155;
  color: #94a3b8;
  width: 34px; height: 34px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s;
}
#settings-btn:hover { background: #1e293b; border-color: #475569; color: #f1f5f9; }

#settings-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 180px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 2000;
  flex-direction: column;
  gap: 4px;
}
#settings-menu.open { display: flex; }

.settings-section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: #475569;
  margin-bottom: 2px;
}
.settings-divider { height: 1px; background: #334155; margin: 4px 0; }

/* ── Filtres ────────────────────────────────────────────────────────────── */
.filter-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  font-size: 12px;
  padding: 5px 8px;
  border-radius: 6px;
  transition: background .15s;
  user-select: none;
  color: #cbd5e1;
}
.filter-label:hover { background: #273549; }
.filter-label .green { color: #4ade80; }
.filter-label .red   { color: #f87171; }
.filter-label input[type=checkbox] {
  width: 13px; height: 13px;
  cursor: pointer;
  accent-color: #3b82f6;
}

.settings-action {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: #cbd5e1;
  font-size: 12px;
  padding: 5px 8px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s;
  font-family: inherit;
}
.settings-action:hover { background: #273549; color: #f1f5f9; }

/* ── Layout carte + panneau ─────────────────────────────────────────────── */
#loading {
  display: none;
  text-align: center;
  padding: 7px;
  background: #854d0e;
  color: #fef3c7;
  font-size: 13px;
}

#main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;  /* essentiel pour que flex-children respectent la hauteur */
}

#map { flex: 1; }

/* ── Panneau latéral ────────────────────────────────────────────────────── */
#side-panel {
  width: 280px;
  flex-shrink: 0;
  background: #1e293b;
  border-left: 1px solid #334155;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 10px;
  font-size: 12px;
  /* height contraint par #main-layout flex, scrollable automatiquement */
  min-height: 0;
}

/* Scrollbar panneau */
#side-panel::-webkit-scrollbar       { width: 4px; }
#side-panel::-webkit-scrollbar-track { background: transparent; }
#side-panel::-webkit-scrollbar-thumb { background: #334155; border-radius: 2px; }

.side-empty {
  color: #64748b;
  text-align: center;
  padding: 24px 8px;
  font-size: 13px;
}

.side-title {
  font-weight: 700;
  font-size: 12px;
  color: #f87171;
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid #334155;
}

/* Bloc workspace : séparateur discret entre workspaces */
.side-workspace {
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid #273549;
}
.side-workspace:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.side-room {
  font-weight: 600;
  font-size: 12px;
  color: #e2e8f0;
  margin: 0 0 6px 0;
  padding-left: 0;
  display: flex;
  align-items: center;
  gap: 5px;
}
.side-room::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #f87171;
  flex-shrink: 0;
}

.side-device {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #94a3b8;
  font-size: 11px;
  margin: 3px 0 2px 10px;
  font-weight: 500;
}

.side-issue {
  color: #fca5a5;
  font-size: 11px;
  margin: 3px 0 3px 22px;
  line-height: 1.5;
  padding: 1px 0;
}

/* ── Popup Leaflet ──────────────────────────────────────────────────────── */
.webex-popup .leaflet-popup-content-wrapper {
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.28);
  border: 1px solid #e2e8f0;
  background: #fff;
}
.webex-popup .leaflet-popup-content {
  margin: 0;
  overflow: visible;
}
.webex-popup .leaflet-popup-tip-container { display: none; }

/* Scrollbar popup */
.webex-popup ::-webkit-scrollbar       { width: 4px; }
.webex-popup ::-webkit-scrollbar-track { background: #f8fafc; border-radius: 2px; }
.webex-popup ::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* ── Popup intérieur ────────────────────────────────────────────────────── */
.popup-root { font-family: 'Inter','Segoe UI',Arial,sans-serif; }

.popup-header {
  padding: 12px 14px 10px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}

.popup-room-name {
  font-weight: 700;
  font-size: 14px;
  color: #0f172a;
  margin-bottom: 4px;
}

.popup-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.popup-loc {
  font-size: 11px;
  color: #64748b;
}

.status-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
}
.status-badge.ok  { background: #dcfce7; color: #166534; }
.status-badge.err { background: #fee2e2; color: #991b1b; }

.popup-body {
  padding: 10px 12px;
  max-height: 400px;
  overflow-y: auto;
}

/* ── Section labels ─────────────────────────────────────────────────────── */
.section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  margin: 8px 0 4px;
}
.section-label.err { color: #dc2626; }
.section-label.ok  { color: #16a34a; }

/* ── Room card (cluster) ────────────────────────────────────────────────── */
.room-card {
  border: 1px solid #e2e8f0;
  border-left-width: 3px;
  border-radius: 8px;
  margin-top: 8px;
  margin-bottom: 8px;
  overflow: hidden;
}

.room-card-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  background: #f8fafc;
  cursor: pointer;
}

.room-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.room-card-name {
  font-weight: 600;
  font-size: 12px;
  color: #0f172a;
  flex: 1;
}

.room-devcount {
  font-size: 11px;
  color: #94a3b8;
  margin-right: 4px;
}

/* ── Device card ────────────────────────────────────────────────────────── */
.dev-card {
  border: 1px solid;
  border-radius: 8px;
  margin-top: 6px;
  overflow: hidden;
}

.dev-header {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 10px;
  background: #f8fafc;
  cursor: pointer;
}

.dev-title-wrap { flex: 1; min-width: 0; }

.dev-title {
  font-weight: 600;
  font-size: 12px;
  color: #0f172a;
}

.dev-short-err {
  display: block;
  color: #dc2626;
  font-size: 10px;
  font-weight: 400;
  margin-top: 1px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 230px;
}

.dev-arrow {
  color: #94a3b8;
  font-size: 9px;
  flex-shrink: 0;
  padding-top: 2px;
}

.dev-detail {
  display: none;
  padding: 8px 10px;
  background: #fff;
  border-top: 1px solid #f1f5f9;
  max-height: 240px;
  overflow-y: auto;
}

/* ── Lignes de diagnostic ───────────────────────────────────────────────── */
.diag-line {
  font-size: 11px;
  padding: 2px 0;
  line-height: 1.6;
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 4px;
}
.diag-err  { color: #dc2626; }
.diag-warn { color: #d97706; }
.diag-info { color: #475569; }

.btn-llm {
  cursor: pointer;
  font-size: 11px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 4px;
  padding: 0 5px;
  flex-shrink: 0;
  line-height: 1.6;
}
.btn-llm:hover { background: #dbeafe; }

.llm-result {
  background: #fffbeb;
  border-left: 3px solid #f59e0b;
  padding: 6px 8px;
  border-radius: 4px;
  margin-top: 4px;
  font-size: 11px;
  width: 100%;
}
.llm-label {
  font-weight: 600;
  color: #92400e;
  margin-bottom: 2px;
}
.llm-text { color: #374151; }
/* ── Barre de progression LLM ───────────────────────────────────────────── */
.llm-loading {
  width: 100%;
  margin-top: 4px;
}
.llm-loading-text {
  font-size: 10px;
  color: #94a3b8;
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
}
.llm-progress-track {
  height: 4px;
  background: #e2e8f0;
  border-radius: 2px;
  overflow: hidden;
}
.llm-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
  border-radius: 2px;
  transition: width 0.3s ease;
  width: 0%;
}
/* ══════════════════════════════════════════════════════════════════════════
   Notifications nouveaux problèmes (stackable, bas-centre)
   ══════════════════════════════════════════════════════════════════════════ */
#notifications-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column-reverse; /* nouvelles en bas */
  align-items: center;
  gap: 8px;
  z-index: 5000;
  pointer-events: none;
  max-width: 420px;
  width: 90vw;
}

.issue-notif {
  pointer-events: all;
  background: #1e293b;
  border: 1px solid #ef4444;
  border-left: 4px solid #ef4444;
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
  width: 100%;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity .3s ease, transform .3s ease;
  font-family: 'Inter','Segoe UI',Arial,sans-serif;
}
.issue-notif.visible {
  opacity: 1;
  transform: translateY(0);
}
.issue-notif.hiding {
  opacity: 0;
  transform: translateY(20px);
}

.notif-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.notif-icon  { font-size: 14px; color: #f87171; }
.notif-title { font-size: 12px; font-weight: 700; color: #f87171; flex: 1; }
.notif-close {
  background: none; border: none;
  color: #64748b; cursor: pointer;
  font-size: 11px; padding: 0 2px;
  line-height: 1;
}
.notif-close:hover { color: #f1f5f9; }

.notif-room   { font-size: 11px; color: #e2e8f0; margin-bottom: 2px; }
.notif-device { font-size: 11px; color: #94a3b8; margin-bottom: 2px; }
.notif-issue  { font-size: 11px; color: #fca5a5; }

/* ══════════════════════════════════════════════════════════════════════════
   Overlays graphiques sur la carte (bas-droite, DANS #map)
   ══════════════════════════════════════════════════════════════════════════ */

/* #map est position:relative — les overlays s'ancrent dedans */
#map { position: relative; }

#map-overlays {
  position: absolute;
  bottom: 16px;
  right: 16px;           /* dans #map : ne déborde PAS sur le panneau latéral */
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 800;          /* sous popups Leaflet (z:1000+) mais au-dessus des tuiles */
  pointer-events: none;
  width: 250px;
  /* Pas de max-height ici — les cards ont leur propre hauteur fixe */
}

.map-overlay-card {
  pointer-events: all;
  background: rgba(8, 15, 30, 0.80);   /* semi-transparent foncé */
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(51, 65, 85, 0.65);
  border-radius: 10px;
  padding: 8px 10px;
  width: 250px;
  /* HAUTEUR FIXE : empêche la croissance infinie du canvas responsive */
  height: 155px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  flex-shrink: 0;        /* empêche la compression dans le flex parent */
}

.overlay-title {
  font-size: 10px;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 5px;
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  line-height: 1;
}

.overlay-canvas-wrap {
  flex: 1;
  min-height: 0;      /* CRITIQUE : sans ça, le canvas ignore la hauteur du parent */
  position: relative;
  overflow: hidden;
}

/* Liste de conseils LLM */
.llm-advice {
  margin: 2px 0 0 0;
  padding-left: 18px;
  color: #374151;
}
.llm-advice li {
  font-size: 11px;
  line-height: 1.5;
  margin-bottom: 3px;
}