/* Layout et composants. Ne contient aucune couleur en dur : tout vient de tokens.css. */

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

html,
body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* ── Coquille ─────────────────────────────────────────────────────────────── */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100dvh;
  overflow: hidden;
}

.map {
  position: relative;
  height: 100%;
}

#map {
  position: absolute;
  inset: 0;
}

/* ── Barre latérale ───────────────────────────────────────────────────────── */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: 20px 16px;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 2;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.brand h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: -0.02em;
}

.brand span {
  font-size: 12px;
  color: var(--ink-faint);
}

.tagline {
  margin: 0 0 8px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-soft);
}

.card {
  padding: 14px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}

.card h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* ── Calques ──────────────────────────────────────────────────────────────── */

.layers {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.layer-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  text-align: left;
  background: none;
  border: 0;
  border-radius: var(--r-sm);
  transition: background 0.15s ease;
}

.layer-toggle:hover {
  background: var(--surface);
}

.layer-toggle[aria-pressed="true"] {
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.layer-toggle .dot {
  width: 9px;
  height: 9px;
  flex: none;
  border-radius: var(--r-pill);
  background: var(--border);
  transition: background 0.15s ease;
}

.layer-toggle[aria-pressed="true"] .dot {
  background: var(--accent);
}

.layer-toggle .label {
  font-size: 13.5px;
}

.layer-toggle .hint {
  margin-left: auto;
  font-size: 11px;
  color: var(--ink-faint);
}

/* ── Échelle du calque actif ──────────────────────────────────────────────── */

.scale {
  margin-top: 12px;
}

/* ── Taille de logement ───────────────────────────────────────────────────── */

/* Ce sélecteur commande la carte entière : il est plus haut et plus contrasté
   qu'un simple réglage, parce que tout le calque loyers en dépend. */
.types {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
}

.type {
  flex: 1;
  padding: 6px 2px;
  font: inherit;
  font-size: 12px;
  line-height: 1.25;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  transition:
    background 0.15s ease,
    border-color 0.15s ease;
}

.type small {
  display: block;
  font-size: 10px;
  color: var(--ink-faint);
}

.type:hover {
  border-color: var(--ink-faint);
}

.type[aria-pressed="true"] {
  color: #fff;
  background: var(--ink);
  border-color: var(--ink);
}

.type[aria-pressed="true"] small {
  color: rgb(255 255 255 / 0.7);
}

.scale-bar {
  height: 8px;
  border-radius: var(--r-pill);
  background: linear-gradient(90deg, #f2ece2, #dbe4ee, #bacee4, #91b1d5, #6791c3, #4a76ab);
}

.scale-ends {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  font-size: 11px;
  color: var(--ink-faint);
}

/* ── Panneau d'information ────────────────────────────────────────────────── */

#info-panel {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 3;
  width: 320px;
  max-width: calc(100% - 32px);
  max-height: calc(100% - 32px);
  overflow-y: auto;
  padding: 18px 20px 20px;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
}

#info-panel h3 {
  margin: 0 32px 2px 0;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.panel-sub {
  margin: 0 0 14px;
  font-size: 12.5px;
  color: var(--ink-faint);
}

.panel-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  font-size: 20px;
  line-height: 1;
  color: var(--ink-faint);
  background: none;
  border: 0;
  border-radius: var(--r-pill);
}

.panel-close:hover {
  background: var(--surface-sunken);
  color: var(--ink);
}

.stat {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin-bottom: 14px;
}

.stat-value {
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.stat-unit {
  font-size: 12px;
  color: var(--ink-faint);
}

.rooms {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.rooms th {
  padding-bottom: 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.rooms td {
  padding: 6px 0;
  border-bottom: 1px solid var(--surface-sunken);
}

.rooms .num {
  padding-right: 2px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.rooms .muted {
  color: var(--ink-faint);
}

/* La taille de logement sélectionnée dans la sidebar est rappelée ici : la
   fiche et la carte doivent parler du même logement. */
.rooms tr.on td {
  font-weight: 600;
  background: var(--accent-soft);
}

.rooms td small {
  display: block;
  font-size: 10.5px;
  color: var(--ink-faint);
}

.modes {
  margin: 0;
  font-size: 14px;
}

.empty {
  margin: 0 0 10px;
  padding: 12px;
  font-size: 13px;
  color: var(--ink-soft);
  background: var(--surface-sunken);
  border-radius: var(--r-sm);
}

.source {
  margin: 12px 0 0;
  font-size: 11px;
  line-height: 1.55;
  color: var(--ink-faint);
}

.source a {
  color: var(--ink-faint);
}

/* ── Filtre budget ────────────────────────────────────────────────────────── */

.budget {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.budget-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.budget-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.budget-row output {
  min-width: 62px;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ── Fiche de zone : le bandeau « en un coup d'œil » ──────────────────────── */

/* Deux faits mesurés, hauteur fixe, aucune note ni étoile : c'est ce qui rend
   les fiches comparables entre elles sans introduire de classement. */
.glance {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 8px 10px;
  margin: 0 0 14px;
  padding: 11px 12px;
  font-size: 12.5px;
  background: var(--surface-sunken);
  border-radius: var(--r-sm);
}

.glance dt {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding-top: 2px;
}

.glance dd {
  margin: 0;
  line-height: 1.35;
}

.glance dd small {
  display: block;
  margin-top: 1px;
  font-size: 11px;
  color: var(--ink-faint);
}

/* ── Fiche de zone ────────────────────────────────────────────────────────── */

.zone-summary {
  margin: 0 0 12px;
  font-size: 13.5px;
  line-height: 1.55;
}

#info-panel h4 {
  margin: 12px 0 5px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

#info-panel ul {
  margin: 0;
  padding-left: 17px;
  font-size: 13px;
  line-height: 1.6;
}

#info-panel ul.heads {
  color: var(--ink-soft);
}

/* ── Légende ──────────────────────────────────────────────────────────────── */

.legend {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  color: var(--ink-soft);
}

.legend-item .swatch {
  width: 14px;
  height: 14px;
  flex: none;
  border-radius: 5px;
  box-shadow: inset 0 0 0 1px rgb(29 27 24 / 0.08);
}

.legend-item .swatch.round {
  width: 10px;
  height: 10px;
  margin: 0 2px;
  border-radius: var(--r-pill);
}

.legend-note {
  margin: 10px 0 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ink-faint);
}

/* ── Pied de barre latérale ───────────────────────────────────────────────── */

.sidebar-foot {
  margin-top: auto;
  padding-top: 12px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--ink-faint);
}

.sidebar-foot a {
  color: var(--ink-faint);
}

/* ── Contrôles MapLibre, adoucis ──────────────────────────────────────────── */

.maplibregl-ctrl-group {
  border-radius: var(--r-sm) !important;
  box-shadow: var(--shadow-sm) !important;
  border: 1px solid var(--border) !important;
}

.maplibregl-ctrl-attrib {
  border-radius: var(--r-pill) 0 0 0 !important;
  font-size: 10px !important;
}

/* ── Mobile : la carte prend tout, les calques passent en chips ───────────── */

@media (max-width: 800px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }

  .map {
    grid-row: 1;
  }

  /* Sur un petit écran, chaque ligne compte : on garde les calques, la légende
     et le budget, on retire le discours. */
  .tagline,
  .sidebar-foot,
  .legend-note:not(.key) {
    display: none;
  }

  /* Sauf l'avertissement sur ce que le loyer affiché ne comprend PAS : c'est
     une règle du site, pas du remplissage — il reste visible partout. */
  .legend-note.key {
    font-size: 10.5px;
  }

  .sidebar {
    grid-row: 2;
    gap: 10px;
    max-height: 42dvh;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
    border-right: 0;
    border-top: 1px solid var(--border);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    box-shadow: var(--shadow-lg);
  }

  .brand h1 {
    font-size: 16px;
  }

  .card {
    padding: 10px;
  }

  /* Les calques deviennent une rangée de chips défilante. */
  .layers {
    flex-direction: row;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .layers::-webkit-scrollbar {
    display: none;
  }

  .layer-toggle {
    width: auto;
    flex: 0 0 auto;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--r-pill);
    white-space: nowrap;
  }

  .layer-toggle[aria-pressed="true"] {
    color: #fff;
    background: var(--ink);
    border-color: var(--ink);
  }

  .layer-toggle[aria-pressed="true"] .dot {
    background: #fff;
  }

  .layer-toggle .hint {
    display: none;
  }

  /* La légende passe en rangée compacte, elle aussi défilante. */
  .legend {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 12px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .legend::-webkit-scrollbar {
    display: none;
  }

  .legend-item {
    flex: 0 0 auto;
    font-size: 12px;
    white-space: nowrap;
  }

  /* Le panneau d'info devient une feuille qui remonte du bas de la carte. */
  #info-panel {
    top: auto;
    bottom: 12px;
    left: 12px;
    right: 12px;
    width: auto;
    max-width: none;
    max-height: 55dvh;
  }
}
