:root {
  --panel-width: 385px;
  --bg: #f6f8fb;
  --panel: rgba(255, 255, 255, 0.97);
  --text: #172033;
  --muted: #5d6b82;
  --border: #e2e8f0;
  --accent: #FA9E3B;
  --official: #0f766e;
  --north: #16a34a;
  --south: #7201A8;
  --sunset: #D8576B;
  --shadow: 0 18px 55px rgba(15, 23, 42, 0.18);
}
* { box-sizing: border-box; }
html, body, #app, #mapWrap, #map { height: 100%; }
body {
  margin: 0;
  direction: rtl;
  font-family: Tahoma, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text);
  background: var(--bg);
}
#app { display: flex; min-height: 100vh; }
#panel {
  width: var(--panel-width);
  max-width: 94vw;
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 22px 20px;
  z-index: 700;
  overflow: auto;
  box-shadow: -4px 0 30px rgba(15, 23, 42, 0.08);
  transition: width .2s ease, padding .2s ease;
}
#panel.hidden { width: 0; padding: 0; overflow: hidden; border: 0; }
section { padding: 15px 0; border-top: 1px solid var(--border); }
section h2 { margin: 0 0 8px; font-size: 1rem; }
section p { color: var(--muted); margin: 0 0 7px; line-height: 1.45; }
.notice {
  margin: 14px 0;
  padding: 12px 13px;
  border: 1px solid #99f6e4;
  background: #f0fdfa;
  color: #134e4a;
  border-radius: 12px;
  font-size: .92rem;
  line-height: 1.4;
}
.legend-row { display: flex; gap: 10px; align-items: center; margin: 9px 0; color: var(--muted); }
.legend-line { display: inline-block; width: 42px; height: 0; border-top: 3px solid #111827; }
.legend-line.center { border-top-style: dashed; }
.legend-line.sunset { border-top-color: var(--sunset); border-top-style: dashed; }
.legend-line.partial-visibility { border-top-color: #f97316; border-top-style: dashed; }

/* Isocourbes de l’obscuration maximale réellement observable. */
.legend-line.obsc-95 { border-top-color: #15803D; border-top-width: 3px; }
.legend-line.obsc-90 { border-top-color: #22C55E; border-top-width: 3px; }
.legend-line.obsc-85 { border-top-color: #84CC16; border-top-width: 3px; }
.legend-line.obsc-80 { border-top-color: #EAB308; }
.legend-line.obsc-60 { border-top-color: #F59E0B; }
.legend-line.obsc-40 { border-top-color: #F97316; }
.legend-line.obsc-20 { border-top-color: #EF4444; }
.legend-line.obsc-0 { border-top-color: #B91C1C; border-top-style: dashed; }

.legend-box { display: inline-block; width: 42px; height: 16px; border-radius: 6px; }
.legend-box.totality { background: rgba(15, 23, 42, 0.20); border: 0; }
.legend-dot { width: 13px; height: 13px; border-radius: 50%; background: #111827; box-shadow: 0 0 0 3px rgba(15, 23, 42, .15); margin-left: 14px; margin-right: 15px; }
.coords-box p { font-variant-numeric: tabular-nums; }
.buttons { display: flex; gap: 10px; margin-top: 18px; }
button {
  appearance: none;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #111827;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 600;
}
button:hover { background: #f8fafc; }
#mapWrap { position: relative; flex: 1; min-width: 0; }
#map { width: 100%; }
.map-title {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 650;
  display: flex;
  gap: 12px;
  align-items: center;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(203, 213, 225, 0.85);
  border-radius: 999px;
  padding: 9px 15px;
  box-shadow: var(--shadow);
  white-space: nowrap;
}
.map-title span { color: var(--muted); font-size: .92rem; }

.eclipse-status {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 650;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(128, 67, 159, 0.92);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.98rem;
  line-height: 1.2;
  box-shadow: 0 14px 35px rgba(15, 23, 42, 0.22);
  white-space: nowrap;
  pointer-events: none;
}
.eclipse-status.total { background: rgba(15, 118, 110, 0.94); }
.eclipse-status.partial { background: rgba(128, 67, 159, 0.92); }
.eclipse-status.none { background: rgba(71, 85, 105, 0.92); }
.eclipse-popup { padding-top: 2px; }
.popup-heading-wrap { display: flex; justify-content: center; margin: 0 0 10px; }
.popup-heading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 8px 14px;
  border-radius: 999px;
  color: #fff;
  font-size: 1.02rem;
  line-height: 1.2;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.16);
}
.badge-total { background: #059669; }
.badge-partial { background: #D8576B; }
.badge-none { background: #7201A8; }
.eclipse-table { width: 100%; border-collapse: collapse; margin: 8px 0 12px; font-size: .91rem; }
.eclipse-table td { padding: 3px 0; vertical-align: top; }
.eclipse-table td:first-child { font-weight: 700; color: #334155; padding-left: 15px; }
.eclipse-table td:last-child { text-align: left; direction: ltr; font-variant-numeric: tabular-nums; color: #111827; }
.eclipse-divider { border-top: 1px solid #d1d5db; margin: 10px 0; }
.small-note { margin-top: 10px; color: #64748b; font-size: .82rem; line-height: 1.35; }
.visibility-ok { color: #047857; font-weight: 800; }
.visibility-partial { color: #D8576B; font-weight: 800; }
.visibility-no { color: #b91c1c; font-weight: 800; }
.path-label { padding: 3px 8px; background: rgba(255, 255, 255, 0.88); border: 1px solid rgba(100, 116, 139, 0.35); border-radius: 999px; color: #334155; font-weight: 700; font-size: 12px; box-shadow: 0 3px 12px rgba(15, 23, 42, 0.12); }
@media (max-width: 850px) {
  #app { display: block; }

  #panel {
    position: absolute;
    inset: 0 auto auto 0;
    width: var(--panel-width);
    max-width: 94vw;
    height: auto;
    max-height: 54vh;
    padding: 22px 20px;
    border-left: 0;
    border-bottom: 1px solid var(--border);
  }

  #panel.hidden { display: none; }
  #mapWrap, #map { height: 100vh; }
  .map-title { top: auto; bottom: 14px; max-width: calc(100vw - 20px); white-space: normal; justify-content: center; }
  .eclipse-status { top: 12px; max-width: calc(100vw - 20px); white-space: normal; text-align: center; }
}

.path-label { direction: rtl; }




/* MapLibre + OpenFreeMap */
#map .maplibregl-canvas {
  direction: ltr !important;
}

.maplibregl-popup {
  z-index: 9999;
}

.maplibregl-popup-content {
  border-radius: 18px;
  padding: 16px 18px 14px;
  box-shadow: 0 18px 60px rgba(15, 23, 42, 0.22);
  direction: rtl;
  text-align: right;
  min-width: 390px;
  max-width: calc(100vw - 72px);
}

.maplibregl-popup-close-button {
  font-size: 22px;
  color: #64748b;
  padding: 4px 8px;
}

.maplibregl-ctrl button {
  background: rgba(255,255,255,0.96);
}

.maplibregl-ctrl-scale {
  color: #111827;
  background: rgba(255,255,255,0.78);
  border-color: #111827;
}

@media (max-width: 520px) {
  .maplibregl-popup-content {
    min-width: 300px;
    max-width: calc(100vw - 32px);
  }
}


/* Curseur flèche sur la carte, au lieu de la main */
#map,
#map canvas,
.maplibregl-map,
.maplibregl-canvas,
.maplibregl-canvas-container,
.maplibregl-canvas-container.maplibregl-interactive,
.maplibregl-canvas-container.maplibregl-touch-zoom-rotate,
.maplibregl-canvas-container.maplibregl-touch-drag-pan {
  cursor: default !important;
}


/* Actions placées sur la carte, sous les contrôles MapTiler du côté droit. */
.map-actions {
  display: none !important;
  position: absolute;
  top: 138px;
  right: 10px;
  z-index: 690;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 46px;
  overflow: hidden;
  border: 1px solid rgba(15, 23, 42, .16);
  border-radius: 10px;
  background: rgba(255, 255, 255, .97);
  box-shadow: 0 7px 24px rgba(15, 23, 42, .22);
}
.map-actions button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #111827;
  text-align: center;
}
.map-actions button + button {
  border-top: 1px solid rgba(15, 23, 42, .12);
}
.map-actions button:hover {
  background: #f1f5f9;
}
.map-actions .action-icon {
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: #e8eefc;
  color: #1d4ed8;
  font-size: 16px;
  line-height: 1;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.14);
}
.map-actions .action-label {
  display: none;
}
@media (max-width: 850px) {
  .map-actions {
    top: 132px;
    right: 8px;
    width: 42px;
  }
  .map-actions button {
    min-height: 40px;
  }
  .map-actions .action-icon {
    width: 22px;
    height: 22px;
    flex-basis: 22px;
    font-size: 15px;
  }
}


/* Boutons Recentrer / Panneau intégrés dans la même colonne que + et −. */
#map .maplibregl-ctrl-group.map-actions-control-group > .map-integrated-action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 29px;
  min-width: 29px;
  height: 29px;
  min-height: 29px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: rgba(255,255,255,.96);
  color: #1f2937;
  box-shadow: none;
}
#map .maplibregl-ctrl-group.map-actions-control-group > .map-integrated-action + .map-integrated-action,
#map .maplibregl-ctrl-group.map-actions-control-group > button + .map-integrated-action {
  border-top: 1px solid #ddd;
}
#map .maplibregl-ctrl-group.map-actions-control-group > .map-integrated-action:hover {
  background: #f1f5f9;
}
#map .maplibregl-ctrl-group.map-actions-control-group > .map-integrated-action .action-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 29px;
  height: 29px;
  flex: 0 0 29px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #1f2937;
  box-shadow: none;
  font-size: 17px;
  line-height: 1;
}


/* Masquer complètement l'icône de localisation / boussole native. */
#map .maplibregl-ctrl-geolocate,
#map .maplibregl-ctrl-compass {
  display: none !important;
}


/* Mobile : le groupe complet + / − / recentrer / panneau est réellement
   placé dans le conteneur MapLibre inférieur droit. */
@media (max-width: 850px) {
  #map .maplibregl-ctrl-bottom-right {
    right: 8px !important;
    bottom: 12px !important;
  }

  #map .maplibregl-ctrl-bottom-right .map-actions-control-group {
    margin: 0 !important;
  }
}


/* Mobile : boutons de navigation réellement collés en bas à droite,
   attribution juste en dessous. */
@media (max-width: 850px) {
  #map .maplibregl-ctrl-bottom-right {
    position: absolute !important;
    inset: auto 0 0 0 !important;
    width: 100% !important;
    height: 132px !important;
    pointer-events: none !important;
  }

  #map .maplibregl-ctrl-bottom-right > * {
    pointer-events: auto !important;
  }

  #map .maplibregl-ctrl-bottom-right .map-actions-control-group {
    position: absolute !important;
    right: 8px !important;
    bottom: 30px !important;
    left: auto !important;
    top: auto !important;
    margin: 0 !important;
    width: auto !important;
    float: none !important;
    clear: none !important;
  }

  #map .maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib {
    position: absolute !important;
    right: 8px !important;
    bottom: 0 !important;
    left: auto !important;
    top: auto !important;
    width: auto !important;
    max-width: min(240px, calc(100vw - 16px)) !important;
    margin: 0 !important;
    padding: 2px 6px !important;
    text-align: right !important;
    white-space: nowrap !important;
    font-size: 11px !important;
    background: rgba(255,255,255,0.92) !important;
    border-radius: 8px !important;
    float: none !important;
    clear: none !important;
  }
}



/* Recherche de lieux sur la carte. */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.map-search-panel {
  position: absolute;
  top: 10px;
  right: 52px;
  z-index: 720;
  width: min(380px, calc(100% - 74px));
  padding: 10px;
  border: 1px solid rgba(15, 23, 42, .18);
  border-radius: 10px;
  background: rgba(255, 255, 255, .98);
  box-shadow: 0 10px 30px rgba(15, 23, 42, .25);
  direction: inherit;
}
.map-search-panel[hidden] { display: none !important; }
.map-search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 6px;
  align-items: center;
}
.map-search-form input {
  min-width: 0;
  height: 38px;
  padding: 0 11px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: #fff;
  color: #0f172a;
  font: inherit;
}
.map-search-form input:focus {
  outline: 2px solid rgba(37, 99, 235, .28);
  border-color: #D8576B;
}
.map-search-submit,
.map-search-close {
  height: 38px;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}
.map-search-submit {
  padding: 0 12px;
  background: #1d4ed8;
  color: #fff;
}
.map-search-close {
  width: 38px;
  background: #e2e8f0;
  color: #0f172a;
  font-size: 22px;
  line-height: 1;
}
.map-search-status {
  margin: 8px 2px 0;
  color: #475569;
  font-size: .88rem;
}
.map-search-status:empty { display: none; }
.map-search-results {
  display: grid;
  gap: 4px;
  max-height: min(320px, 45vh);
  margin-top: 8px;
  overflow-y: auto;
}
.map-search-results:empty { display: none; }
.map-search-result {
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 7px;
  background: #f1f5f9;
  color: #0f172a;
  text-align: start;
  cursor: pointer;
  font: inherit;
}
.map-search-result:hover,
.map-search-result:focus-visible { background: #dbeafe; }

#map .maplibregl-ctrl-group.map-actions-control-group > .map-integrated-action + button {
  border-top: 1px solid #ddd;
}

@media (max-width: 850px) {
  .map-search-panel {
    top: 10px;
    right: 10px;
    width: calc(100% - 20px);
  }
  .map-search-form {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .map-search-close {
    position: absolute;
    top: 14px;
    right: 14px;
  }
  html[dir="rtl"] .map-search-close {
    right: auto;
    left: 14px;
  }
  .map-search-form input {
    padding-inline-end: 44px;
  }
}
