/* ===== Variables ===== */
:root {
  --color-primary: #0d6efd;
  --color-bg: #f8f9fa;
  --color-surface: #ffffff;
  --color-border: #dee2e6;
  --color-text: #212529;
  /* #5a6270 sur fond blanc = ratio ~5.07:1, conforme RGAA AA (min 4.5:1) */
  /* Ancienne valeur #6c757d = ~4.48:1, insuffisant pour texte normal < 18px */
  --color-text-muted: #5a6270;

  --header-height: 56px;
  --filters-width: 280px;
  --chart-panel-width: 380px;
  --spacing: 1rem;
  --radius: 6px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 1rem;
  color: var(--color-text);
  background: var(--color-bg);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== Header ===== */
.he-header {
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--spacing);
  gap: var(--spacing);
  flex-shrink: 0;
  box-shadow: var(--shadow);
  z-index: 1000;
}

.he-header__brand { display: flex; align-items: baseline; gap: 0.5rem; }
.he-header__title { font-size: 1.25rem; font-weight: 700; color: var(--color-primary); }
.he-header__subtitle { font-size: 0.8rem; color: var(--color-text-muted); }
.he-header__actions { display: flex; gap: 0.5rem; }

/* ===== Main layout ===== */
.he-main {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.he-map-container {
  flex: 1;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
}

/* ===== Boutons ===== */
.he-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.9rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.he-btn:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

.he-btn--secondary {
  background: var(--color-surface);
  border-color: var(--color-border);
  color: var(--color-text);
}

.he-btn--secondary:hover { background: var(--color-bg); }

.he-btn--ghost {
  background: transparent;
  color: var(--color-text-muted);
  border-color: var(--color-border);
  width: 100%;
  justify-content: center;
  margin-top: var(--spacing);
}

.he-btn--ghost:hover { background: var(--color-bg); }

.he-btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: none;
  background: transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
  color: var(--color-text-muted);
}

.he-btn-icon:hover { background: var(--color-bg); }
.he-btn-icon:focus-visible { outline: 3px solid var(--color-primary); outline-offset: 2px; }

/* ===== Panneaux latéraux ===== */
.he-filters,
.he-chart-panel {
  position: absolute;
  top: 0;
  height: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow);
  overflow-y: auto;
  z-index: 500;
  padding: var(--spacing);
  display: flex;
  flex-direction: column;
  gap: var(--spacing);
}

.he-filters[hidden],
.he-chart-panel[hidden] { display: none; }

.he-filters { left: 0; width: var(--filters-width); }
.he-chart-panel { right: 0; width: var(--chart-panel-width); }

/* ===== Form elements ===== */
.he-filters__title,
.he-chart-panel__title {
  font-size: 1rem;
  font-weight: 600;
}

.he-filters__group { display: flex; flex-direction: column; gap: 0.3rem; }

.he-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text);
}

.he-select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
}

.he-select:focus-visible { outline: 3px solid var(--color-primary); outline-offset: 2px; }

/* ===== Panneau graphique ===== */
.he-chart-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.he-chart { min-height: 250px; }
.he-chart-panel__meta { font-size: 0.8rem; color: var(--color-text-muted); }

/* ===== Statut carte ===== */
.he-map-status {
  position: absolute;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  padding: 0.4rem 1rem;
  border-radius: 20px;
  font-size: 0.8rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 400;
}

.he-map-status--visible { opacity: 1; }

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .he-header__subtitle { display: none; }
  .he-filters { width: 100%; }
  .he-chart-panel { width: 100%; left: 0; }
  .he-btn { min-height: 44px; }
}

/* ===== RGAA : focus visible universel ===== */
:focus-visible { outline: 3px solid var(--color-primary); outline-offset: 2px; }

/* ===== PWA : Badge hors-ligne ===== */
.he-offline-badge {
  position: fixed;
  top: calc(var(--header-height) + 0.5rem);
  right: var(--spacing);
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffc107;
  border-radius: 12px;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  z-index: 2000;
  box-shadow: var(--shadow);
}

.he-offline-badge[hidden] { display: none; }

/* ===== PWA : Bandeau installation ===== */
.he-install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-primary);
  color: #fff;
  padding: 0.8rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  z-index: 2000;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.2);
}

.he-install-banner[hidden] { display: none; }

.he-install-banner__info {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.he-install-banner__icon { font-size: 1.5rem; }

.he-install-banner__info strong {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
}

.he-install-banner__info span {
  display: block;
  font-size: 0.75rem;
  opacity: 0.85;
}

.he-install-banner__actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

.he-install-btn {
  padding: 0.4rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 500;
  min-height: 36px;
}

.he-install-btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

.he-install-btn--later {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.he-install-btn--later:hover { background: rgba(255, 255, 255, 0.25); }

.he-install-btn--now {
  background: #fff;
  color: var(--color-primary);
  border: none;
  font-weight: 700;
}

.he-install-btn--now:hover { background: #e8f0fe; }

@media (max-width: 640px) {
  .he-install-banner { flex-direction: column; align-items: flex-start; }
}

/* ===== Barre de recherche ===== */
.he-search {
  position: relative;
  display: flex;
  align-items: center;
}

.he-search__input {
  width: 220px;
  max-width: 100%;
  padding: 0.4rem 2rem 0.4rem 0.75rem;
  border: 1px solid #ced4da;
  border-radius: 4px;
  font-size: 0.875rem;
  background: #fff;
  color: #212529;
}

.he-search__input:focus-visible {
  outline: 2px solid #0d6efd;
  outline-offset: 1px;
}

.he-search__clear {
  position: absolute;
  right: 0.4rem;
  background: none;
  border: none;
  cursor: pointer;
  color: #6c757d;
  padding: 0.2rem;
  line-height: 1;
  font-size: 0.875rem;
}

.he-search__clear:focus-visible {
  outline: 2px solid #0d6efd;
  border-radius: 2px;
}

.he-search__clear:hover {
  color: #212529;
}

@media (max-width: 640px) {
  .he-search__input {
    width: 140px;
  }
}

/* ===== Stats graphique ===== */
.he-chart-stats {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  color: #495057;
  border-top: 1px solid #dee2e6;
  background: #f8f9fa;
}

.he-chart-stats__item {
  white-space: nowrap;
}

/* ===== Toggle H/Q ===== */
.he-chart-toggle {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
  margin-right: 0.5rem;
}

.he-chart-toggle__opt {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.875rem;
  cursor: pointer;
  color: #495057;
}

.he-chart-toggle__opt input[type="radio"] {
  accent-color: #0d6efd;
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

.he-chart-toggle__opt input[type="radio"]:focus-visible {
  outline: 2px solid #0d6efd;
  outline-offset: 2px;
  border-radius: 50%;
}

/* ===== Marker piézométrique ===== */
.piezo-marker {
  width: 10px;
  height: 10px;
  background: #8e44ad;
  border: 1px solid #fff;
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
