:root {
  --bg: #0c0f14;
  --surface: #151a23;
  --surface-2: #1c2431;
  --border: #2a3548;
  --text: #e8edf5;
  --muted: #8b9bb5;
  --accent: #3d8bfd;
  --accent-2: #22c55e;
  --danger: #f87171;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --header-h: 72px;
  --quality-h: 88px;
  --panel-w: min(420px, 92vw);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

a {
  color: var(--accent);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Loader */
.loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  background: rgba(12, 15, 20, 0.92);
  backdrop-filter: blur(8px);
  transition: opacity 0.4s, visibility 0.4s;
}

.loader.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader__card {
  width: min(320px, 90vw);
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}

.loader__spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto 1rem;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loader progress {
  width: 100%;
  height: 6px;
  margin-top: 0.75rem;
  accent-color: var(--accent);
}

/* Header */
.header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: var(--header-h);
  padding: 0 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.header__logo {
  font-size: 1.75rem;
}

.header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header__sub {
  margin: 0.1rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.header__stats {
  display: flex;
  gap: 1rem;
}

.stat {
  text-align: center;
  min-width: 4rem;
}

.stat span {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent-2);
}

.stat small {
  color: var(--muted);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Qualité des données */
.quality-bar {
  flex-shrink: 0;
  padding: 0.45rem 1.25rem 0.55rem;
  background: #111620;
  border-bottom: 1px solid var(--border);
}

.quality-bar__intro {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1rem;
  margin-bottom: 0.4rem;
  font-size: 0.75rem;
}

.quality-bar__intro strong {
  color: var(--accent-2);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.68rem;
}

.quality-bar__updated {
  color: var(--muted);
  font-size: 0.72rem;
}

.quality-bar__grid {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.45rem;
  overflow-x: auto;
  padding-bottom: 0.15rem;
  scrollbar-width: thin;
}

.q-stat {
  flex: 0 0 auto;
  min-width: 5.5rem;
  padding: 0.35rem 0.55rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-align: center;
  line-height: 1.2;
}

.q-stat__icon {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 0.1rem;
}

.q-stat__value {
  display: block;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

.q-stat__pct {
  display: block;
  font-size: 0.68rem;
  color: var(--accent-2);
  font-weight: 600;
}

.q-stat__label {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.58rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Layout */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  min-height: 0;
}

.layout.panel-hidden {
  grid-template-columns: 1fr;
}

.layout.panel-hidden .panel {
  display: none;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.panel__search {
  position: relative;
  padding: 0.75rem;
}

.panel__search--ac {
  z-index: 600;
}

.search-ac {
  position: absolute;
  left: 0.75rem;
  right: 0.75rem;
  top: calc(100% - 0.35rem);
  margin: 0;
  padding: 0.25rem 0;
  list-style: none;
  max-height: 280px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 610;
}

.search-ac__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
  border-bottom: 1px solid rgba(42, 53, 72, 0.5);
}

.search-ac__item:last-child {
  border-bottom: none;
}

.search-ac__item:hover,
.search-ac__item[aria-selected="true"] {
  background: #243044;
}

.search-ac__text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-ac__kind {
  flex-shrink: 0;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 0.12rem 0.35rem;
  border-radius: 4px;
  background: var(--surface-2);
}

.panel__search input {
  width: 100%;
  padding: 0.85rem 2.5rem 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.panel__search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(61, 139, 253, 0.25);
}

.btn-icon {
  position: absolute;
  right: 1.1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--border);
  color: var(--text);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

.panel__filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  padding: 0 0.75rem 0.5rem;
}

.panel__filters select {
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.8rem;
}

.panel__filters select:first-child {
  grid-column: 1 / -1;
}

.panel__dates {
  padding: 0 0.75rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.filter-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  cursor: pointer;
  margin-bottom: 0.45rem;
}

.filter-check input {
  accent-color: var(--accent-2);
}

.panel__dates-range {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.panel__dates-range label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.panel__dates-range input[type="date"] {
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.8rem;
}

.badge--new {
  color: #fde68a;
  background: rgba(251, 191, 36, 0.15);
}

.badge--date {
  font-size: 0.6rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 0.75rem 0.5rem;
}

.btn {
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  border-color: var(--accent);
  background: #243044;
}

.btn--ghost {
  background: transparent;
}

.btn--accent {
  border-color: var(--accent-2);
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
  font-weight: 600;
}

.btn--accent:hover:not(:disabled) {
  background: rgba(34, 197, 94, 0.28);
  border-color: var(--accent-2);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--fab {
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 1.1rem;
  border-radius: 50%;
  box-shadow: var(--shadow);
}

.file-btn {
  cursor: pointer;
}

.panel__hint {
  margin: 0;
  padding: 0.35rem 0.85rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.results {
  flex: 1;
  margin: 0;
  padding: 0.25rem 0.5rem 0.75rem;
  list-style: none;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.result-item {
  padding: 0.75rem;
  margin-bottom: 0.35rem;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.result-item:hover,
.result-item.is-active {
  border-color: var(--accent);
  transform: translateX(2px);
}

.result-item__title {
  margin: 0 0 0.25rem;
  font-weight: 600;
  font-size: 0.9rem;
}

.result-item__addr {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.result-item__meta {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.4rem;
  flex-wrap: wrap;
}

.badge {
  font-size: 0.65rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: #243044;
  color: var(--muted);
}

.badge--dep {
  color: var(--accent-2);
  background: rgba(34, 197, 94, 0.12);
}

/* Map */
.map-wrap {
  position: relative;
  min-height: 0;
}

#map {
  width: 100%;
  height: 100%;
  background: #1a2030;
}

.map-tools {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 500;
}

.leaflet-popup-content-wrapper {
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.leaflet-popup-content {
  margin: 0.75rem 1rem;
  font-size: 0.85rem;
  line-height: 1.45;
  max-width: 280px;
}

.popup-card {
  min-width: 260px;
  max-width: 320px;
}

.popup-card__head {
  margin-bottom: 0.5rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--border);
}

.popup-card__title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
}

.popup-card__addr {
  margin: 0 0 0.65rem;
  font-size: 0.9rem;
  line-height: 1.4;
  color: #c8d4e8;
}

.popup-card__muted {
  color: var(--muted);
  font-style: italic;
}

.popup-row {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
  font-size: 0.82rem;
  line-height: 1.35;
}

.popup-label {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.popup-card__section {
  margin: 0.5rem 0;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border);
}

.popup-hours {
  margin: 0.25rem 0 0;
  padding-left: 1rem;
  font-size: 0.78rem;
  line-height: 1.45;
  color: #b8c5da;
}

.popup-hours li {
  margin-bottom: 0.2rem;
}

.popup-card__links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.55rem;
}

.popup-link {
  font-size: 0.8rem;
  font-weight: 600;
}

.popup-link--muted {
  color: var(--muted);
  font-weight: 400;
}

.popup-card__foot {
  margin-top: 0.6rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border);
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.35;
}

.marker-pin {
  width: 14px;
  height: 14px;
  border-radius: 50% 50% 50% 0;
  background: var(--accent);
  border: 2px solid #fff;
  transform: rotate(-45deg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.marker-pin.is-bank {
  background: var(--accent-2);
}

.marker-pin.is-active {
  background: #fbbf24;
  transform: rotate(-45deg) scale(1.25);
}

/* Footer */
.footer {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.4rem 1rem;
  font-size: 0.7rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* Mobile */
@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 42vh 1fr;
  }

  .layout.panel-hidden {
    grid-template-rows: 1fr;
  }

  .panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .header__stats {
    display: none;
  }

  .quality-bar__grid {
    gap: 0.35rem;
  }

  .q-stat {
    min-width: 4.8rem;
    padding: 0.3rem 0.4rem;
  }
}
