:root {
  --bg: #0d1117;
  --panel: #161b22cc;
  --panel-solid: #161b22;
  --border: #2a3038;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #ff6b35;
  --danger: #ff3b30;
  --ok: #2ecc71;
  --warn: #ffb020;
  --topbar-a: #0d1117ee;
  --topbar-b: #0d111700;
  --input: #21262d;
}
:root[data-theme="light"] {
  --bg: #e9eef3;
  --panel: #ffffffdd;
  --panel-solid: #ffffff;
  --border: #cdd6df;
  --text: #1b2530;
  --muted: #5b6875;
  --topbar-a: #ffffffe6;
  --topbar-b: #ffffff00;
  --input: #eef2f7;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

#map {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: var(--bg);
}

/* Barre du haut */
#topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: linear-gradient(180deg, var(--topbar-a), var(--topbar-b));
  pointer-events: none;
}
.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.icon-btn {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-solid);
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover {
  border-color: var(--accent);
}
.icon-btn .ic {
  width: 18px;
  height: 18px;
}
.icon-btn .ic-moon {
  display: none;
}
:root[data-theme="light"] .icon-btn .ic-sun {
  display: none;
}
:root[data-theme="light"] .icon-btn .ic-moon {
  display: inline;
}

/* Toggles de couches (mêmes ronds que le bouton thème = uniforme) */
.layer-toggle {
  color: var(--muted);
}
.layer-toggle input {
  display: none;
}
.layer-toggle svg {
  width: 18px;
  height: 18px;
}
.layer-toggle:has(input:checked) {
  color: var(--accent);
  border-color: var(--accent);
  background: #ff6b3522;
}

/* Légende carte */
.map-legend {
  position: absolute;
  left: 12px;
  bottom: 24px;
  z-index: 900;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  backdrop-filter: blur(8px);
  color: var(--text);
  font-size: 11px;
  box-shadow: 0 4px 14px #0006;
  pointer-events: none;
}
.map-legend span {
  display: flex;
  align-items: center;
  gap: 7px;
}
.lg {
  width: 13px;
  height: 13px;
  display: inline-block;
  flex: none;
}
.lg-active {
  background: #ff3c1e;
  border-radius: 50%;
  box-shadow: 0 0 4px #ff3c1e;
}
.lg-zone {
  background: #e8590c30;
  border: 1.5px dashed #e8590c;
  border-radius: 3px;
}
.lg-burnt {
  background: #5a1e0a;
  border: 1.5px dashed #8a2b12;
  border-radius: 3px;
}
.lg-plane {
  background: #22d3ee;
  clip-path: polygon(50% 0, 100% 100%, 50% 78%, 0 100%);
}
@media (max-width: 620px) {
  .map-legend {
    bottom: 58px;
    font-size: 10px;
    padding: 7px 9px;
  }
  .layer-toggle span {
    display: none;
  }
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.brand-flame {
  width: 23px;
  height: 23px;
  filter: drop-shadow(0 0 5px #ff6b3566);
}
.brand-name {
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -0.3px;
  color: var(--text);
  text-shadow: 0 1px 3px #0005;
}
.brand-name .hot {
  color: var(--accent);
}
.pill {
  pointer-events: auto;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-solid);
}
.pill-live {
  color: var(--ok);
  border-color: #1f6f43;
}
.pill-demo {
  color: var(--warn);
  border-color: #7a5a1a;
}
.pill-muted {
  color: var(--muted);
}

/* Panneau latéral */
#panel {
  position: absolute;
  top: 52px;
  left: 12px;
  z-index: 1000;
  width: 320px;
  max-height: calc(100% - 72px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 2px;
}
.card {
  background: var(--panel);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 8px 24px #0008;
}
.card h2 {
  margin: 0 0 10px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}
.row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
}
label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}
select,
.btn {
  background: var(--input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover {
  border-color: var(--accent);
}
.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}
.btn-danger {
  width: 100%;
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  font-weight: 600;
  padding: 10px;
}
.btn-danger:hover {
  filter: brightness(1.1);
}
.muted {
  color: var(--muted);
  font-size: 12px;
}
.mono {
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

/* Liste des zones de feu */
.zones {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}
.fire-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.fire-item:hover {
  background: #ffffff10;
}
.fire-item.active {
  background: #ff6b3522;
}
.fi-main {
  min-width: 0;
}
.fi-title {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fi-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.fi-badge {
  flex: none;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

/* Métadonnées simulation */
.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}
.meta-grid .m {
  background: #ffffff08;
  border-radius: 8px;
  padding: 6px 8px;
}
.meta-grid .m b {
  display: block;
  font-size: 16px;
}
.meta-grid .m span {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
}

/* Timeline */
.timeline input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.timeline-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
}

/* Légende */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
  font-size: 11px;
  color: var(--muted);
}
.legend span {
  display: flex;
  align-items: center;
  gap: 4px;
}
.sw {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}
.sw-burn {
  background: #78140a;
}
.sw-1 {
  background: #ff3c1e;
}
.sw-3 {
  background: #ff7814;
}
.sw-6 {
  background: #ffbe1e;
}
.sw-12 {
  background: #ffeb78;
}

/* Résultat évacuation */
#evacResult {
  margin-top: 10px;
}
.alert {
  border-radius: 10px;
  padding: 12px;
  border: 1px solid;
  animation: pop 0.2s ease;
}
@keyframes pop {
  from {
    transform: scale(0.97);
    opacity: 0;
  }
}
.alert h3 {
  margin: 0 0 6px;
  font-size: 15px;
}
.alert p {
  margin: 4px 0;
  font-size: 13px;
  line-height: 1.4;
}
.alert .eta {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.a-danger {
  background: #3a0d0a;
  border-color: var(--danger);
  color: #ffd7d2;
}
.a-warning {
  background: #3a2a0a;
  border-color: var(--warn);
  color: #ffe9c2;
}
.a-watch {
  background: #2a2a0a;
  border-color: #b8b020;
  color: #f5f0c0;
}
.a-safe {
  background: #0d2a18;
  border-color: var(--ok);
  color: #c8f5db;
}
.advice {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed #ffffff30;
  font-style: italic;
  font-size: 12px;
}

.aqi {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.4;
}
.aqi b {
  font-weight: 700;
}

.switch {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  margin-bottom: 6px;
}
.switch input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
}

.plane {
  line-height: 0;
}
.plane svg {
  filter: drop-shadow(0 0 2px #000);
}

.disclaimer {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
  padding: 0 4px;
}

.spin {
  display: inline-block;
  animation: sp 0.8s linear infinite;
}
@keyframes sp {
  to {
    transform: rotate(360deg);
  }
}

/* Badge "zone estimée de l'incendie" (façon Google) */
.fz-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  pointer-events: none;
}
.fz-dot {
  font-size: 18px;
  filter: drop-shadow(0 0 3px #000a);
}
.fz-label {
  background: #c1121f;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2px;
  padding: 2px 7px;
  border-radius: 6px;
  box-shadow: 0 1px 4px #0007;
}

/* Marqueur position */
.me-dot {
  width: 16px;
  height: 16px;
  background: #2f80ed;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 4px #2f80ed55;
}

/* Panneau repliable (poignée) */
#panel {
  transition: transform 0.28s ease, opacity 0.2s ease;
}
.panel-handle {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 30px;
  margin-bottom: 2px;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.panel-handle:hover {
  border-color: var(--accent);
}
.panel-handle .grabber {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--muted);
  opacity: 0.5;
}
.panel-reopen {
  position: absolute;
  top: 52px;
  left: 12px;
  z-index: 1001;
  display: none;
  align-items: center;
  gap: 6px;
  padding: 9px 15px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-solid);
  color: var(--text);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 6px 18px #0007;
}
.panel-reopen:hover {
  border-color: var(--accent);
}

/* Desktop : replié = escamoté à gauche + bouton de réouverture */
@media (min-width: 621px) {
  .panel-handle .grabber {
    display: none;
  }
  body.panel-collapsed #panel {
    transform: translateX(calc(-100% - 24px));
    opacity: 0;
    pointer-events: none;
  }
  body.panel-collapsed .panel-reopen {
    display: inline-flex;
  }
}

/* Mobile */
@media (max-width: 620px) {
  #panel {
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    width: 100%;
    max-height: 72%;
    border-radius: 16px 16px 0 0;
    background: var(--panel-solid);
    padding: 8px 10px 16px;
  }
  .card {
    backdrop-filter: none;
  }
  .handle-label {
    display: none;
  }
  .panel-handle {
    height: 26px;
  }
  /* replié = bottom-sheet réduit à la poignée (peek) */
  body.panel-collapsed #panel {
    transform: translateY(calc(100% - 46px));
  }
}
