:root {
  --bg: #070d1a;
  --bg2: #0c1426;
  --panel: rgba(17, 27, 48, .82);
  --border: #1c2944;
  --text: #e6edf9;
  --muted: #8494b4;
  --online: #22c55e;
  --warning: #f59e0b;
  --offline: #ef4444;
  --unknown: #64748b;
  --accent: #38bdf8;
  --critical: #ff2d55;
  /* Couleurs d'accent par type d'équipement (distinctes des couleurs d'état) */
  --t-gateway: #38bdf8;
  --t-switch: #a78bfa;
  --t-ap: #f472b6;
  --radius: 14px;
  font-size: clamp(12px, 0.78vw, 20px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 15% -10%, #12224a 0%, transparent 60%),
              radial-gradient(900px 500px at 110% 110%, #1a1440 0%, transparent 60%), var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.muted { color: var(--muted); }
.small { font-size: .8rem; font-weight: 400; }
[hidden] { display: none !important; }

.screen { height: 100vh; display: flex; flex-direction: column; padding: 1rem 1.2rem; gap: .9rem; }

/* ------------------------------------------------------------ En-tête */
.top { display: flex; align-items: center; gap: 1.5rem; }
.brand { display: flex; align-items: center; gap: 1.1rem; min-width: 0; flex: 1; }
.brand img { max-height: 4.2rem; max-width: 14rem; object-fit: contain; }
.brand-text { min-width: 0; }
.brand h1 { margin: 0; font-size: 1.75rem; font-weight: 700; letter-spacing: -.01em; line-height: 1.15; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.brand .muted { font-size: 1rem; margin-top: .15rem; }

.kpis { display: flex; gap: .7rem; }
.kpi {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .55rem 1.2rem; min-width: 7.6rem; display: flex; flex-direction: column; align-items: center;
  position: relative; overflow: hidden;
}
.kpi::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--accent); opacity: .8; }
.kpi-online::before { background: var(--online); }
.kpi-warning::before { background: var(--warning); }
.kpi-offline::before { background: var(--offline); }
.kpi-avail::before { background: #a78bfa; }
.kpi-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.kpi-val { font-size: 2.3rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.kpi-online .kpi-val { color: var(--online); }
.kpi-warning .kpi-val { color: var(--warning); }
.kpi-offline .kpi-val { color: var(--offline); }
.kpi-offline.alarm { background: rgba(239, 68, 68, .16); border-color: var(--offline); animation: glow 1.6s ease-in-out infinite; }
.kpi.zero .kpi-val { color: var(--muted); }

.kpis { align-items: stretch; }
.type-kpis { display: flex; gap: .5rem; padding-right: .7rem; margin-right: .1rem; border-right: 1px solid var(--border); }
.type-kpi {
  font: inherit; color: var(--text); cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: .6rem; position: relative;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .85rem .5rem .7rem;
  border-top: 3px solid var(--tc); transition: opacity .2s, filter .2s;
}
.type-kpi:disabled { cursor: default; }
.type-kpi > .ti { width: 2rem; height: 2rem; color: var(--tc); flex: none; }
.type-kpi .tk-body { display: flex; flex-direction: column; }
.type-kpi .tk-val { font-size: 1.75rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.type-kpi .tk-val small { font-size: .78rem; font-weight: 500; color: var(--muted); margin-left: .4rem; }
.type-kpi .tk-down {
  position: absolute; top: -.6rem; right: -.4rem; background: var(--offline); color: #fff; font-weight: 800; font-size: .78rem;
  padding: .08rem .45rem; border-radius: 999px; box-shadow: 0 0 0 2px var(--bg); animation: glow 1.6s ease-in-out infinite;
}
.type-kpi.off { opacity: .35; filter: grayscale(.8); border-top-color: var(--border); }
.type-kpi.off .tk-down { animation: none; }
.t-gateway { --tc: var(--t-gateway); }
.t-switch { --tc: var(--t-switch); }
.t-ap { --tc: var(--t-ap); }

.ti { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.14em; flex: none; }
.ti-gateway { color: var(--t-gateway); }
.ti-switch { color: var(--t-switch); }
.ti-ap { color: var(--t-ap); }
.cnt { display: inline-flex; align-items: center; gap: .2rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cnt + .cnt { margin-left: .55rem; }
.cnt-warn { color: #fcd34d; }

.clock { text-align: right; flex: none; }
#time { font-size: 2.3rem; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
#date { font-size: .95rem; text-transform: capitalize; }
.collector { display: inline-flex; align-items: center; gap: .45rem; font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.collector i { width: .55rem; height: .55rem; border-radius: 50%; background: var(--unknown); }
.collector.ok i { background: var(--online); box-shadow: 0 0 0 0 rgba(34,197,94,.6); animation: beat 2s infinite; }
.collector.ko { color: var(--offline); }
.collector.ko i { background: var(--offline); }

.incident {
  background: rgba(255, 45, 85, .2); border: 2px solid var(--critical); color: #fff; border-radius: 10px;
  padding: .6rem 1rem; font-size: 1.1rem; display: flex; flex-direction: column; gap: .2rem; animation: glow 1.6s ease-in-out infinite;
}
.incident b { color: #ffd1da; letter-spacing: .05em; margin-right: .5rem; }
.banner {
  background: rgba(245, 158, 11, .14); border: 1px solid rgba(245, 158, 11, .5); color: #fcd34d;
  border-radius: 10px; padding: .5rem 1rem; font-size: .95rem;
}

/* ------------------------------------------------------------ Corps */
.body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(24rem, 1fr); gap: .9rem; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); backdrop-filter: blur(6px); }
.panel h2 {
  margin: 0; padding: .75rem 1rem .55rem; font-size: .9rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .09em; color: var(--muted); display: flex; align-items: center; gap: .5rem;
}

.map-wrap { position: relative; overflow: hidden; }
#map { position: absolute; inset: 0; background: #1b1b1d; }
/* Libellés de la carte sombre un peu atténués pour laisser ressortir les marqueurs */
body[data-tiles=dark] .leaflet-shadow-pane img { opacity: .75; }
.legend {
  position: absolute; left: 1rem; bottom: 1rem; z-index: 500; display: flex; gap: 1.1rem;
  background: rgba(7, 13, 26, .85); border: 1px solid var(--border); border-radius: 10px; padding: .5rem .9rem; font-size: .85rem;
}
.legend span { display: inline-flex; align-items: center; gap: .4rem; }
.nolocation {
  position: absolute; right: 1rem; bottom: 1rem; z-index: 500; font-size: .8rem; color: var(--muted);
  background: rgba(7, 13, 26, .85); border: 1px solid var(--border); border-radius: 10px; padding: .45rem .8rem;
}
.dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; flex: none; }
.dot.online { background: var(--online); }
.dot.warning { background: var(--warning); }
.dot.offline { background: var(--offline); }
.dot.unknown { background: var(--unknown); }
.dot.critical { background: var(--critical); box-shadow: 0 0 0 2px rgba(255, 45, 85, .35); }

.side { display: flex; flex-direction: column; gap: .9rem; min-height: 0; }
.side .panel { display: flex; flex-direction: column; min-height: 0; }
.alerts-panel { flex: 0 1 auto; max-height: 30%; }
.fleet-panel { flex: 1 1 0; }
.events-panel { flex: 0 0 26%; }
/* En cas d'alertes, le panneau Alertes prend la place du parc */
.side.has-alerts .alerts-panel { max-height: 62%; }
.side.has-alerts .events-panel { flex-basis: 20%; }
.panel h2 .h2-sub { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--text); font-size: .85rem; display: inline-flex; align-items: center; gap: .3rem; flex-wrap: wrap; }
.pages { margin-left: auto; display: inline-flex; align-items: center; gap: .3rem; letter-spacing: 0; }
.pages i { width: .45rem; height: .45rem; border-radius: 50%; background: var(--border); }
.pages i.on { background: var(--accent); }
.pages span { margin-left: .3rem; font-variant-numeric: tabular-nums; }

.badge { background: var(--unknown); color: #fff; border-radius: 999px; padding: .05rem .55rem; font-size: .8rem; letter-spacing: 0; }
.badge.alarm { background: var(--offline); }
.badge.warn { background: var(--warning); color: #111; }

/* Alertes (une carte par site) */
.alerts { padding: 0 .8rem .8rem; display: flex; flex-direction: column; gap: .5rem; overflow: hidden; flex: 1; min-height: 0; }
.alert {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: .25rem .8rem; align-items: center;
  border-radius: 10px; padding: .6rem .8rem; border: 1px solid; flex: none;
}
.alert.lv-critical { background: rgba(255, 45, 85, .17); border-color: var(--critical); animation: glow 1.8s ease-in-out infinite; }
.alert.lv-offline { background: rgba(239, 68, 68, .1); border-color: rgba(239, 68, 68, .5); }
.alert.lv-warning { background: rgba(245, 158, 11, .09); border-color: rgba(245, 158, 11, .45); }
.alert.lv-unknown { background: rgba(100, 116, 139, .12); border-color: rgba(100, 116, 139, .45); }
.alert .icon { grid-row: span 3; font-size: 1.4rem; width: 2.3rem; height: 2.3rem; display: grid; place-items: center; border-radius: 50%; font-weight: 800; }
.lv-critical .icon { background: var(--critical); }
.lv-offline .icon { background: var(--offline); }
.lv-warning .icon { background: var(--warning); color: #111; }
.lv-unknown .icon { background: var(--unknown); }
.alert .site { font-weight: 800; font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.alert .devs { grid-column: 2; display: flex; gap: .35rem; flex-wrap: wrap; overflow: hidden; max-height: 3.6rem; }
.dev {
  display: inline-flex; align-items: center; gap: .3rem; font-size: .8rem; font-weight: 600; padding: .1rem .45rem;
  border-radius: 6px; background: rgba(7, 13, 26, .55); border: 1px solid var(--border); max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dev-offline { border-color: rgba(239, 68, 68, .45); }
.dev-warning { border-color: rgba(245, 158, 11, .45); }
.dev.more { color: var(--muted); }
.alert .meta { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; grid-column: 2; }
.alert .dur { grid-row: span 3; text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.1rem; white-space: nowrap; }
.alert .dur small { display: block; font-weight: 600; font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.lv-critical .dur, .lv-critical .dur small { color: #ffb3c1; }
.lv-offline .dur { color: #fca5a5; }
.lv-warning .dur { color: #fcd34d; }

/* Mode compact : une ligne par site */
.alerts.compact { gap: .3rem; }
.alert.compact { grid-template-columns: auto minmax(0, 1fr) auto 4.6rem; padding: .38rem .7rem; gap: .7rem; animation: none; }
.alert.compact .site { font-size: .98rem; }
.alert.compact .dur { grid-row: auto; font-size: .9rem; }
.alert.compact .cnts { font-size: .9rem; }
.alert.compact.lv-critical { border-left: 4px solid var(--critical); padding-top: .55rem; padding-bottom: .55rem; }
.tag-crit { margin-left: .6rem; font-size: .66rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; background: var(--critical); color: #fff; padding: .1rem .4rem; border-radius: 4px; vertical-align: middle; }

.all-ok {
  display: flex; align-items: center; gap: 1rem; padding: 1rem 1.1rem; border-radius: 10px;
  background: rgba(34, 197, 94, .1); border: 1px solid rgba(34, 197, 94, .4);
}
.all-ok .icon { width: 2.6rem; height: 2.6rem; border-radius: 50%; background: var(--online); display: grid; place-items: center; font-size: 1.4rem; color: #052e16; font-weight: 800; }
.all-ok b { display: block; font-size: 1.1rem; }
.all-ok span { color: var(--muted); font-size: .85rem; }

/* Sites */
.fleet { overflow: hidden; padding: 0 .5rem .5rem; flex: 1; min-height: 0; }
.fleet-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto 3.8rem; gap: .7rem; align-items: center;
  padding: .38rem .5rem; border-bottom: 1px solid rgba(28, 41, 68, .7); font-size: .9rem;
}
.fleet-row:last-child { border-bottom: 0; }
.fleet-row .n { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fleet-row .tcs { display: grid; grid-template-columns: repeat(var(--tcols, 3), 2.9rem); gap: .3rem; }
.tc { display: inline-flex; align-items: center; gap: .2rem; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 2.2rem; }
.tc .ti { width: 1.05em; height: 1.05em; }
.tc.bad { color: #fca5a5; font-weight: 700; }
.tc.warn { color: #fcd34d; }
.fleet-row .a { font-variant-numeric: tabular-nums; font-size: .82rem; text-align: right; }
.fleet-row.lv-critical .n, .fleet-row.lv-offline .n { color: #fca5a5; }
.fleet-row.lv-warning .n { color: #fcd34d; }
.src { font-size: .65rem; text-transform: uppercase; letter-spacing: .06em; padding: .05rem .35rem; border-radius: 4px; border: 1px solid var(--border); color: var(--muted); margin-left: .35rem; vertical-align: middle; }

/* Journal */
.events { list-style: none; margin: 0; padding: 0 .9rem .6rem; overflow: hidden; flex: 1; min-height: 0; }
.events li { display: grid; grid-template-columns: auto auto auto 1fr; gap: .6rem; align-items: baseline; padding: .3rem 0; font-size: .85rem; border-bottom: 1px solid rgba(28, 41, 68, .6); }
.events time { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.events .dot { width: .55rem; height: .55rem; transform: translateY(-.05rem); }
.events li.new { animation: flash 2.5s ease-out; }

/* Coin */
.corner { position: fixed; right: .6rem; bottom: .5rem; display: flex; gap: .3rem; opacity: .25; transition: opacity .2s; z-index: 1000; }
.corner:hover { opacity: 1; }
.corner a, .corner button {
  background: var(--panel); border: 1px solid var(--border); color: var(--text); border-radius: 8px;
  width: 2.2rem; height: 2.2rem; display: grid; place-items: center; text-decoration: none; cursor: pointer; font-size: 1rem;
}

/* ------------------------------------------------------------ Carte */
.leaflet-container { font-family: inherit; }
.mk { border-radius: 50%; border: 2px solid rgba(255, 255, 255, .85); box-shadow: 0 0 8px rgba(0, 0, 0, .6); }
.mk-online { background: var(--online); }
.mk-warning { background: var(--warning); }
.mk-unknown { background: var(--unknown); }
.mk-offline { background: var(--offline); }
.mk-critical { background: var(--critical); position: relative; }
.mk-critical::before, .mk-critical::after {
  content: ""; position: absolute; inset: -2px; border-radius: 50%; border: 3px solid var(--critical); animation: ripple 2s ease-out infinite;
}
.mk-critical::after { animation-delay: 1s; }
.leaflet-tooltip.tt {
  background: rgba(7, 13, 26, .92); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .5); font-size: .85rem; padding: .35rem .6rem;
}
.leaflet-tooltip.tt-critical { border-color: var(--critical); color: #ffd1da; font-weight: 700; }
.leaflet-tooltip.tt-offline { border-color: rgba(239, 68, 68, .6); color: #fecaca; font-weight: 600; font-size: .78rem; }
.tt-cnt { margin-left: .4rem; }
.tt-cnt .cnt + .cnt { margin-left: .35rem; }
.pop-title { font-weight: 800; font-size: 1.05rem; margin-bottom: .15rem; }
.pop-extra { color: var(--muted); font-size: .8rem; margin-bottom: .4rem; }
.pop-list { display: flex; flex-direction: column; gap: .2rem; max-height: 14rem; overflow: auto; }
.pop-dev { display: grid; grid-template-columns: auto 1fr auto; gap: .45rem; align-items: center; font-size: .85rem; }
.pop-dev .pop-n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pop-dev .pop-s { font-size: .75rem; color: var(--muted); white-space: nowrap; }
.pop-dev.offline .pop-s { color: #fca5a5; font-weight: 700; }
.pop-dev.warning .pop-s { color: #fcd34d; }
.leaflet-tooltip.tt::before { display: none; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: #0f1830; color: var(--text); border: 1px solid var(--border); }
.leaflet-popup-content { margin: .7rem .9rem; font-size: .9rem; line-height: 1.45; }
.leaflet-popup-content b { font-size: 1rem; }
.leaflet-control-attribution { background: rgba(7, 13, 26, .7) !important; color: #556 !important; font-size: 9px; }
.leaflet-control-attribution a { color: #678 !important; }

@keyframes ripple { 0% { transform: scale(1); opacity: .9; } 100% { transform: scale(3.2); opacity: 0; } }
@keyframes glow { 0%, 100% { box-shadow: 0 0 0 rgba(239, 68, 68, 0); } 50% { box-shadow: 0 0 20px rgba(239, 68, 68, .5); } }
@keyframes beat { 0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .6); } 70% { box-shadow: 0 0 0 .5rem rgba(34, 197, 94, 0); } 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); } }
@keyframes flash { 0% { background: rgba(56, 189, 248, .25); } 100% { background: transparent; } }

/* Écrans étroits (consultation sur portable / mobile) */
@media (max-width: 1100px) {
  body { overflow: auto; }
  .screen { height: auto; }
  .top { flex-wrap: wrap; }
  .kpis { flex-wrap: wrap; }
  .clock { text-align: left; }
  .body { grid-template-columns: 1fr; }
  .map-wrap { height: 60vh; }
  .side .panel { max-height: none !important; flex: none !important; }
  .type-kpis { border-right: 0; padding-right: 0; flex-wrap: wrap; }
  .fleet, .events { max-height: 50vh; overflow: auto; }
}
