:root {
  --bg: #0b1322;
  --panel: #0f1c32;
  --text: #fff;
  --muted: #aab7cf;
  --gold: #d3a90b;
  --line: rgba(255, 255, 255, 0.12);
  --ok: #26c281;
  --bad: #ff6b6b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#map { position: fixed; inset: 0; z-index: 0; }

#haGlbLoadingOverlay.ha-glb-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 10080;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.42);
  pointer-events: none;
}
#haGlbLoadingOverlay.ha-glb-loading-overlay.is-visible {
  display: flex;
}
/* Atelier ouvert : ne pas masquer la carte / l’iframe */
body:has(.ha-atelier-window.window:not(.hidden)) #haGlbLoadingOverlay.ha-glb-loading-overlay {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
}
#haGlbLoadingOverlay .ha-glb-loading-box {
  max-width: min(360px, calc(100vw - 40px));
  padding: 18px 22px;
  border-radius: 10px;
  background: rgba(15, 20, 25, 0.96);
  border: 1px solid rgba(245, 196, 0, 0.45);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  text-align: center;
  color: #e8edf2;
  font-size: 12px;
}
#haGlbLoadingOverlay .ha-glb-loading-name {
  font-size: 15px;
  font-weight: 700;
  color: #f5c400;
  margin: 0 0 10px;
  line-height: 1.35;
}
#haGlbLoadingOverlay .ha-glb-loading-line {
  font-size: 12px;
  line-height: 1.45;
  opacity: 0.92;
}
#haGlbLoadingOverlay .ha-glb-loading-line + .ha-glb-loading-line {
  margin-top: 2px;
}
#haGlbLoadingOverlay .ha-glb-loading-stage {
  font-size: 12px;
  line-height: 1.45;
  opacity: 0.92;
  margin: 0 0 8px;
}
#haGlbLoadingOverlay .ha-glb-loading-meta {
  font-size: 13px;
  line-height: 1.4;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #f5c400;
  min-height: 1.35em;
  margin-top: 4px;
}
#haGlbLoadingOverlay .ha-glb-loading-meta:empty,
#haGlbLoadingOverlay .ha-glb-loading-meta[hidden] {
  display: none;
}
#haGlbLoadingOverlay .ha-glb-loading-progress {
  display: block;
  width: 100%;
  height: 14px;
  margin: 0 0 8px;
  accent-color: #f5c400;
  border: none;
  border-radius: 7px;
  overflow: hidden;
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.08);
}
#haGlbLoadingOverlay .ha-glb-loading-progress::-webkit-progress-bar {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 7px;
}
#haGlbLoadingOverlay .ha-glb-loading-progress::-webkit-progress-value {
  background: linear-gradient(90deg, #c9a227, #f5c400);
  border-radius: 7px;
  transition: width 0.12s ease-out;
}
#haGlbLoadingOverlay .ha-glb-loading-progress::-moz-progress-bar {
  background: linear-gradient(90deg, #c9a227, #f5c400);
  border-radius: 7px;
}
#haGlbLoadingOverlay .ha-glb-loading-progress.is-indeterminate {
  accent-color: #c9a227;
}
#haGlbLoadingOverlay .ha-glb-loading-progress.is-indeterminate::-webkit-progress-bar {
  background: rgba(255, 255, 255, 0.08);
}
#haGlbLoadingOverlay .ha-glb-loading-progress.is-indeterminate::-webkit-progress-value {
  animation: ha-glb-progress-indeterminate 1.2s ease-in-out infinite;
}
#haGlbLoadingOverlay .ha-glb-loading-progress.is-indeterminate::-moz-progress-bar {
  animation: ha-glb-progress-indeterminate 1.2s ease-in-out infinite;
}
@keyframes ha-glb-progress-indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}

.topbar {
  position: fixed;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 50;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.map-logo-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  padding: 6px 10px 5px;
  border-radius: 12px;
  background: rgba(15, 28, 50, 0.96);
  border: 1px solid var(--line);
  gap: 3px;
}

.map-logo-link {
  display: inline-flex;
  line-height: 0;
  text-decoration: none;
}

.map-logo-img {
  height: 34px;
  width: auto;
  max-width: 160px;
  object-fit: contain;
}

.map-monuments-count {
  font-size: 10px;
  font-weight: 700;
  color: #94a3b8;
  white-space: nowrap;
}

.ctrl, .btn {
  background: rgba(15, 28, 50, 0.96);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
}

.ctrl.search {
  width: 100%;
  min-width: 0;
  padding-right: 42px;
}

.search-wrap {
  flex: 1;
  min-width: 240px;
  position: relative;
  z-index: 80;
}

.search-wrap .suggest {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: min(280px, 42vh);
}

.search-wrap .search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  font: 700 16px/1 system-ui, sans-serif;
  cursor: pointer;
}

.search-wrap .search-clear:disabled {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.btn { cursor: pointer; font-weight: 700; }
.btn.gold { background: var(--gold); color: #111; border-color: transparent; }
.btn.ghost { background: rgba(255, 255, 255, 0.05); }
.btn.bad { background: var(--bad); color: #2a0606; border-color: transparent; }

.window {
  position: fixed;
  z-index: 60;
  background: rgba(15, 28, 50, 0.98);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  overflow: auto;
  resize: both;
}

.window.hidden { display: none; }

#popupWindow.window:not(.hidden) {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#popupWindow.window:not(.hidden) > #popupContent {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

@media (min-width: 901px) {
  #popupWindow.window.ha-popup-dock-left:not(.hidden) {
    left: 12px !important;
    right: auto !important;
    top: 88px !important;
    width: min(460px, calc(100vw - 380px)) !important;
    max-height: min(74vh, calc(100vh - 100px)) !important;
    z-index: 9998;
  }
}

.window-header {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: rgba(9, 18, 34, 0.98);
  border-bottom: 1px solid var(--line);
  cursor: move;
}

.window-header h3 { margin: 0; font-size: 15px; }

.window-header__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.window-header__logo {
  height: 26px;
  width: auto;
  max-width: 100px;
  object-fit: contain;
}

.window-actions { display: flex; gap: 6px; }

.iconbtn {
  background: var(--gold);
  color: #111;
  border: none;
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
  font-weight: 700;
}

.window-body { padding: 12px; }

.popup-content iframe {
  width: 100%;
  height: 280px;
  border: none;
  border-radius: 10px;
  background: #000;
  margin: 8px 0;
}

.popup-content .actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 12px 0;
}

.popup-content .actions-row { display: contents; }

.popup-content .actions-row .btn {
  min-height: 34px;
  padding: 7px 9px;
  font-size: 12px;
  text-align: center;
}

.popup-content h2 { margin: 0 0 8px; font-size: 20px; }

.popup-content {
  color: rgba(255, 255, 255, 0.92);
}

.popup-content p {
  margin: 0 0 12px;
  line-height: 1.5;
}

.popup-content a.mdlink {
  color: var(--gold);
  font-weight: 700;
}

.linkcard {
  display: block;
  margin: 10px 0;
  padding: 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  text-decoration: none;
}

.list-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.list-card__body {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.list-card:last-child { border-bottom: none; }
.list-card:hover { background: rgba(255, 255, 255, 0.04); }
.list-card h4 { margin: 0 0 6px; font-size: 15px; }
.list-card .meta { font-size: 12px; opacity: 0.85; }

.list-card__actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.list-card__btn {
  display: inline-block;
  padding: 5px 8px;
  font-size: 11px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  text-align: center;
  text-decoration: none;
  color: inherit;
  line-height: 1.2;
}

.suggest {
  display: none;
  overflow: auto;
  background: rgba(15, 28, 50, 0.98);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
}

.suggest.visible { display: block; }

.suggest button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding: 10px 12px;
  cursor: pointer;
}

.suggest__section {
  padding: 6px 12px 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--gold);
}

.ha-search-result-pin {
  width: 22px;
  height: 22px;
  border-radius: 50% 50% 50% 0;
  background: var(--gold);
  border: 3px solid #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  transform: rotate(-45deg);
}

.empty { color: var(--muted); }

.ha-glb-toast {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom, 0px));
  left: 50%;
  z-index: 10060;
  transform: translateX(-50%) translateY(12px);
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(15, 20, 25, 0.96);
  border: 1px solid rgba(245, 196, 0, 0.45);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  font-size: 12px;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
}

.ha-glb-toast.ha-glb-toast--center {
  top: 50%;
  bottom: auto;
  max-width: min(360px, calc(100vw - 40px));
  padding: 18px 22px;
  transform: translate(-50%, -50%) scale(0.96);
}

.ha-glb-toast-loading__name {
  font-size: 15px;
  font-weight: 700;
  color: #f5c400;
  margin: 0 0 10px;
  line-height: 1.35;
}

.ha-glb-toast-loading__line {
  font-size: 12px;
  line-height: 1.45;
  opacity: 0.92;
}

.ha-glb-toast-loading__line + .ha-glb-toast-loading__line {
  margin-top: 2px;
}

/* map.php : au-dessus du pied de page fixe (.map-footer z-index 40) */
body:has(.map-footer) .ha-glb-toast {
  bottom: calc(58px + env(safe-area-inset-bottom, 0px));
}

body:has(.map-footer) .ha-glb-toast.ha-glb-toast--center {
  bottom: auto;
  top: 50%;
}

.ha-glb-toast.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.ha-glb-toast.ha-glb-toast--center.is-visible {
  transform: translate(-50%, -50%) scale(1);
}

.ha-glb-toast strong { color: #f5c400; }

body.ha-terra-cognita .ha-glb-toast {
  color: #f4efe6;
  background: rgba(26, 43, 74, 0.96);
  border-color: rgba(196, 165, 116, 0.55);
}

body.ha-terra-cognita .ha-glb-toast strong {
  color: #e8c547;
}

.ha-popup-sf-details {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.ha-popup-sf-details-title {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 8px;
  color: rgba(255, 255, 255, 0.88);
}

.ha-popup-sf-details-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ha-popup-sf-detail-frame {
  margin-top: 12px;
}

.ha-popup-sf-detail-label {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 8px;
}

.ha-popup-sf-detail-frame iframe {
  width: 100%;
  min-height: 240px;
  border: 0;
  border-radius: 10px;
  background: #111;
}

#routeWindow.window:not(.hidden) {
  z-index: 9997;
  right: 12px;
  left: auto;
  top: 88px;
  width: min(380px, calc(100vw - 24px));
  max-height: min(70vh, calc(100vh - 100px));
}

.ha-atelier-window.window:not(.hidden) {
  top: 56px;
  left: 10px;
  right: 10px;
  bottom: 10px;
  width: auto;
  max-height: none;
  resize: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Au-dessus du toast de chargement (10060) */
  z-index: 10070;
}

.ha-atelier-window.window:not(.hidden) > .window-header {
  flex-shrink: 0;
}

.ha-atelier-window.window:not(.hidden) > .window-body.ha-atelier-body {
  flex: 1 1 0%;
  min-height: 0;
  padding: 0 !important;
}

.ha-atelier-body {
  flex: 1 1 0%;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  position: relative;
}

#atelierFrame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 200px;
  border: 0;
  display: block;
  background: #0f1419;
}

@media (max-width: 900px) {
  .search-wrap { min-width: 160px; }
  .topbar .btn:not(.gold) { padding: 8px 10px; font-size: 13px; }
  .iconbtn {
    min-width: 44px;
    min-height: 44px;
    padding: 10px 12px;
    font-size: 17px;
  }
}
