/* =========================================================================
   Benchmark immobilier La Rochelle — thème "carte marine éditoriale"
   Palette : papier crème · encre bleu-nuit · corail (toits) · teal (mer)
   ========================================================================= */

:root {
  /* Couleurs */
  --paper:      #f3ede1;   /* fond papier crème */
  --paper-2:    #ece4d4;   /* crème ombré */
  --ink:        #14283a;   /* encre bleu-nuit */
  --ink-soft:   #3c5266;   /* encre adoucie */
  --ink-faint:  #7d8b97;   /* gris-bleu léger */
  --coral:      #d9573d;   /* accent corail (référence / toits) */
  --coral-deep: #b8472f;
  --teal:       #1f6f6b;   /* mer */
  --teal-soft:  #4f9a92;
  --gold:       #c69a3f;   /* laiton / boussole */
  --line:       #c9bda6;   /* filets type carte */
  --line-soft:  #d8cfbc;
  --card:       #faf6ec;   /* surface panneau */
  --card-edge:  #e0d6c2;

  /* Typo */
  --display: "Fraunces", Georgia, serif;
  --body:    "Hanken Grotesk", system-ui, sans-serif;
  --mono:    "Spline Sans Mono", ui-monospace, monospace;

  --shadow:   0 1px 0 rgba(255,255,255,.6), 0 18px 40px -24px rgba(20,40,58,.45);
  --shadow-sm: 0 8px 22px -18px rgba(20,40,58,.5);
  --r: 14px;
  --maxw: 1200px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--body);
  color: var(--ink);
  background:
    radial-gradient(120% 80% at 80% -10%, rgba(79,154,146,.10), transparent 60%),
    radial-gradient(90% 70% at -10% 0%, rgba(217,87,61,.08), transparent 55%),
    var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* ---- Textures d'ambiance ---- */
.grain {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: .035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.contours {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: .5;
  background-image:
    repeating-linear-gradient(0deg, transparent 0 79px, rgba(201,189,166,.18) 79px 80px),
    repeating-linear-gradient(90deg, transparent 0 79px, rgba(201,189,166,.14) 79px 80px);
  mask-image: radial-gradient(120% 90% at 50% 0%, #000 30%, transparent 85%);
}

main, .site-head, .site-foot { position: relative; z-index: 1; }

/* =========================================================================
   HEADER
   ========================================================================= */
.site-head {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.head-inner {
  max-width: var(--maxw); margin: 0 auto; padding: .85rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.brand { display: flex; align-items: center; gap: .7rem; }
.brand-mark {
  font-size: 1.4rem; color: var(--coral);
  filter: drop-shadow(0 2px 4px rgba(217,87,61,.3));
}
.brand-txt { display: flex; flex-direction: column; line-height: 1.05; }
.brand-kicker {
  font-size: .62rem; letter-spacing: .22em; text-transform: uppercase;
  color: var(--ink-faint); font-weight: 600;
}
.brand-title { font-family: var(--display); font-weight: 600; font-size: 1.15rem; }
.brand-title em { color: var(--coral); font-style: normal; }

.topnav { display: flex; gap: .3rem; }
.topnav a {
  font-size: .82rem; font-weight: 500; color: var(--ink-soft);
  text-decoration: none; padding: .45rem .8rem; border-radius: 999px;
  transition: background .2s, color .2s;
}
.topnav a:hover { color: var(--ink); background: var(--paper-2); }
.topnav a.active { color: var(--coral); background: color-mix(in srgb, var(--coral) 12%, transparent); }

/* =========================================================================
   HERO
   ========================================================================= */
.hero { max-width: var(--maxw); margin: 0 auto; padding: 4rem 1.5rem 2rem; }
.hero-grid {
  display: grid; grid-template-columns: 1.5fr .9fr; gap: 3rem; align-items: center;
}
.eyebrow {
  font-size: .68rem; letter-spacing: .24em; text-transform: uppercase;
  color: var(--teal); font-weight: 700; margin: 0 0 1rem;
  display: inline-flex; align-items: center; gap: .6rem;
}
.eyebrow::before { content: ""; width: 28px; height: 1px; background: var(--teal); }

.hero-title {
  font-family: var(--display); font-weight: 600; font-size: clamp(2.2rem, 5vw, 3.6rem);
  line-height: 1.04; letter-spacing: -.015em; margin: 0 0 1.2rem;
  font-optical-sizing: auto;
}
.hero-title em { font-style: italic; color: var(--coral); font-weight: 500; }
.hero-sub { font-size: 1.05rem; color: var(--ink-soft); max-width: 42ch; margin: 0 0 1.6rem; }
.hero-sub strong { color: var(--ink); font-variant-numeric: tabular-nums; }

.ref-meta-label {
  font-size: .7rem; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-faint); font-weight: 700; margin: 0 0 .6rem;
}
.ref-meta { display: flex; flex-wrap: wrap; gap: .5rem; }
.ref-chip {
  font-size: .8rem; padding: .4rem .75rem; border-radius: 999px;
  background: var(--card); border: 1px solid var(--card-edge); color: var(--ink-soft);
  display: inline-flex; gap: .4rem; align-items: baseline;
}
.ref-chip b { color: var(--ink); font-family: var(--mono); font-weight: 600; }

/* Jauge */
.gauge-card {
  background: var(--card); border: 1px solid var(--card-edge); border-radius: var(--r);
  padding: 1.8rem; box-shadow: var(--shadow); text-align: center;
  position: relative; overflow: hidden;
}
.gauge-card::before {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(45deg, transparent 0 12px, rgba(201,189,166,.12) 12px 13px);
  pointer-events: none;
}
.gauge-wrap { position: relative; width: 220px; height: 220px; margin: 0 auto; }
.gauge-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; pointer-events: none;
}
.gauge-num {
  font-family: var(--display); font-size: 3.2rem; font-weight: 600; line-height: 1;
  color: var(--coral);
}
.gauge-lbl { font-size: .66rem; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-faint); margin-top: .3rem; }
.gauge-caption { font-size: .82rem; line-height: 1.5; color: var(--ink-soft); margin: 1.2rem 0 0; text-align: left; }
.gauge-caption strong { color: var(--ink); }

/* KPI strip */
.kpi-strip {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 1px;
  margin-top: 3rem; background: var(--line-soft);
  border: 1px solid var(--line-soft); border-radius: var(--r); overflow: hidden;
}
.kpi {
  background: var(--card); padding: 1.3rem 1.2rem; text-align: left;
}
.kpi-val {
  font-family: var(--mono); font-size: 1.5rem; font-weight: 600; color: var(--ink);
  font-variant-numeric: tabular-nums; line-height: 1;
}
.kpi-val .unit { font-size: .8rem; color: var(--ink-faint); font-weight: 400; }
.kpi-lbl { font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); margin-top: .5rem; }
.kpi-delta { font-size: .74rem; font-weight: 600; margin-top: .35rem; }
.kpi-delta.up { color: var(--coral-deep); }
.kpi-delta.down { color: var(--teal); }

/* =========================================================================
   BANDS / SECTIONS
   ========================================================================= */
.band { max-width: var(--maxw); margin: 0 auto; padding: 3.5rem 1.5rem; }
.band-alt {
  max-width: none; margin: 0; padding-left: 0; padding-right: 0;
  background:
    linear-gradient(var(--paper-2), var(--paper-2));
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.band-alt > * { max-width: var(--maxw); margin-left: auto; margin-right: auto; padding-left: 1.5rem; padding-right: 1.5rem; }

.section-head { margin-bottom: 2rem; }
.section-title {
  font-family: var(--display); font-weight: 600; font-size: clamp(1.7rem, 3.5vw, 2.5rem);
  letter-spacing: -.01em; margin: .2rem 0 .6rem; line-height: 1.05;
}
.section-desc { color: var(--ink-soft); max-width: 60ch; margin: 0; font-size: .98rem; }

.band-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 1.5rem; align-items: stretch; }
.band-grid-2 { grid-template-columns: 1fr 1fr; }
/* Empêche le "grid blowout" : un canvas/tableau plus large que l'écran
   ne doit pas forcer l'élargissement de la colonne (min-width:auto par défaut). */
.band-grid > * { min-width: 0; }

/* Panels */
.panel {
  background: var(--card); border: 1px solid var(--card-edge); border-radius: var(--r);
  padding: 1.5rem; margin: 0; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column;
  min-width: 0;
}
/* Les graphiques Chart.js ne débordent jamais de leur panneau */
.chart-box, .panel canvas { max-width: 100%; }
.panel-head { margin-bottom: 1.1rem; }
.panel-head h2 {
  font-family: var(--display); font-weight: 600; font-size: 1.15rem; margin: 0;
  letter-spacing: -.01em;
}
.panel-head h2 .sep { color: var(--coral); font-style: italic; padding: 0 .15em; }
.panel-note { font-size: .78rem; color: var(--ink-faint); margin: .3rem 0 0; }
.panel-foot {
  font-size: .76rem; line-height: 1.5; color: var(--ink-soft); margin: 1rem 0 0;
  padding: .8rem .9rem; background: color-mix(in srgb, var(--gold) 9%, transparent);
  border-left: 2px solid var(--gold); border-radius: 0 8px 8px 0;
}
.panel-foot strong { color: var(--ink); }
.ref-dot { color: var(--coral); }

/* Panneau pleine largeur posé sous une grille (ex. graphe DPE) */
.panel-standalone { margin-top: 2.5rem; }

.chart-box { position: relative; flex: 1; min-height: 260px; }
.chart-tall { min-height: 340px; }

/* Filtres du scatter */
.scatter-filters {
  display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end;
  margin-bottom: 1.1rem; padding-bottom: 1.1rem; border-bottom: 1px dashed var(--line-soft);
}
.scatter-filters .field select { min-width: 130px; }
.btn-reset {
  font-family: var(--body); font-size: .8rem; font-weight: 600; color: var(--ink-soft);
  background: transparent; border: 1px solid var(--card-edge); border-radius: 8px;
  padding: .5rem .9rem; cursor: pointer; transition: border-color .2s, color .2s;
}
.btn-reset:hover { border-color: var(--teal); color: var(--teal); }

/* Comparatif table */
.cmp-table { display: grid; grid-template-columns: 1fr auto auto; column-gap: 1rem; }
.cmp-row { display: contents; }
.cmp-row > * { padding: .7rem .2rem; border-bottom: 1px dashed var(--line-soft); align-self: baseline; }
.cmp-row:last-child > * { border-bottom: none; }
.cmp-row.head > * { border-bottom: 1px solid var(--line) !important; padding-bottom: .5rem; font-size: .66rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); font-weight: 500; align-self: end; }
.cmp-k { color: var(--ink-soft); font-size: .9rem; }
.cmp-ref, .cmp-mkt { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: .92rem; text-align: right; }
.cmp-ref { color: var(--coral-deep); font-weight: 600; }
.cmp-mkt { color: var(--ink); }

/* Carte */
.map-box { flex: 1; min-height: 380px; border-radius: 10px; overflow: hidden; border: 1px solid var(--card-edge); }
.leaflet-container { background: #dfe7e4; font-family: var(--body); }
.q-marker-label {
  font-family: var(--mono); font-size: .7rem; font-weight: 600; color: var(--ink);
  background: var(--card); border: 1px solid var(--card-edge); border-radius: 6px;
  padding: 1px 5px; white-space: nowrap; box-shadow: var(--shadow-sm);
}

/* =========================================================================
   TOOLBAR + TABLE
   ========================================================================= */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end;
  margin-bottom: 1.2rem;
}
.field { display: flex; flex-direction: column; gap: .35rem; }
.field label { font-size: .66rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); font-weight: 600; }
.field input[type="search"], .field select {
  font-family: var(--body); font-size: .9rem; color: var(--ink);
  background: var(--card); border: 1px solid var(--card-edge); border-radius: 8px;
  padding: .5rem .7rem; min-width: 160px;
}
.field input:focus, .field select:focus { outline: 2px solid var(--teal-soft); outline-offset: 1px; }
.range-inputs { display: flex; align-items: center; gap: .4rem; }
.range-inputs input[type="number"] {
  font-family: var(--body); font-size: .9rem; color: var(--ink);
  background: var(--card); border: 1px solid var(--card-edge); border-radius: 8px;
  padding: .5rem .55rem; width: 84px;
  /* iOS Safari : sans ce reset, les boutons spin réservent de la place et
     empêchent l'input de rétrécir sous min-width:0 → débordement à droite. */
  -webkit-appearance: none; appearance: none; margin: 0;
}
.range-inputs input[type="number"]::-webkit-outer-spin-button,
.range-inputs input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.range-inputs input[type="number"]:focus { outline: 2px solid var(--teal-soft); outline-offset: 1px; }
.range-sep { color: var(--ink-faint); font-size: .9rem; }
.field-check { justify-content: flex-end; }
.field-check label { display: flex; align-items: center; gap: .45rem; text-transform: none; letter-spacing: 0; font-size: .85rem; color: var(--ink-soft); font-weight: 500; }
.field-check input { accent-color: var(--teal); width: 16px; height: 16px; }

.btn-export {
  margin-left: auto; font-family: var(--body); font-size: .85rem; font-weight: 600;
  color: var(--paper); background: var(--ink); border: none; border-radius: 8px;
  padding: .6rem 1.1rem; cursor: pointer; transition: background .2s, transform .1s;
}
.btn-export:hover { background: var(--teal); }
.btn-export:active { transform: translateY(1px); }

.table-scroll { overflow-x: auto; border: 1px solid var(--card-edge); border-radius: var(--r); background: var(--card); }
.data-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.data-table thead th {
  position: sticky; top: 0; background: var(--card);
  text-align: left; font-size: .66rem; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-faint); font-weight: 700; padding: .8rem 1rem; cursor: pointer;
  border-bottom: 2px solid var(--line); white-space: nowrap; user-select: none;
}
.data-table thead th.num { text-align: right; }
.data-table thead th:hover { color: var(--ink); }
.data-table thead th.sorted-asc::after { content: " ↑"; color: var(--coral); }
.data-table thead th.sorted-desc::after { content: " ↓"; color: var(--coral); }
.data-table tbody td { padding: .7rem 1rem; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.data-table tbody td.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.data-table tbody tr:hover { background: color-mix(in srgb, var(--teal) 6%, transparent); }
.data-table tbody tr.is-ref { background: color-mix(in srgb, var(--coral) 9%, transparent); }
.td-title { font-weight: 500; color: var(--ink); max-width: 32ch; }
.q-tag {
  font-size: .72rem; padding: .2rem .55rem; border-radius: 999px;
  background: color-mix(in srgb, var(--teal) 14%, transparent); color: var(--teal);
  white-space: nowrap; font-weight: 600;
}
.na { color: var(--ink-faint); font-style: italic; }
.row-link { color: var(--coral); text-decoration: none; font-weight: 600; white-space: nowrap; }
.row-link:hover { text-decoration: underline; }
.dpe-badge {
  display: inline-block; min-width: 1.5em; text-align: center; font-weight: 700;
  border-radius: 5px; padding: .1rem .35rem; font-size: .78rem; color: #fff;
}

/* =========================================================================
   FOOTER
   ========================================================================= */
.site-foot { border-top: 1px solid var(--line); margin-top: 2rem; }
.foot-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 1.6rem 1.5rem;
  display: flex; flex-wrap: wrap; gap: .6rem; align-items: center;
  font-size: .8rem; color: var(--ink-faint);
}
.foot-inner strong { color: var(--ink-soft); }
.foot-sep { opacity: .5; }

/* =========================================================================
   ANIMATIONS (page load staggered)
   ========================================================================= */
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.hero-lede > *, .gauge-card, .kpi { opacity: 0; animation: rise .7s cubic-bezier(.2,.7,.3,1) forwards; }
.hero-lede > *:nth-child(1) { animation-delay: .05s; }
.hero-lede > *:nth-child(2) { animation-delay: .13s; }
.hero-lede > *:nth-child(3) { animation-delay: .21s; }
.hero-lede > *:nth-child(4) { animation-delay: .29s; }
.hero-lede > *:nth-child(5) { animation-delay: .37s; }
.gauge-card { animation-delay: .25s; }
.kpi:nth-child(1){animation-delay:.30s} .kpi:nth-child(2){animation-delay:.36s}
.kpi:nth-child(3){animation-delay:.42s} .kpi:nth-child(4){animation-delay:.48s}
.kpi:nth-child(5){animation-delay:.54s}

@media (prefers-reduced-motion: reduce) {
  .hero-lede > *, .gauge-card, .kpi { animation: none; opacity: 1; }
  html { scroll-behavior: auto; }
}

/* =========================================================================
   RESPONSIVE
   ========================================================================= */

/* Décalage d'ancre : compense le header sticky lors des sauts de nav */
main section[id] { scroll-margin-top: 84px; }

/* ---- Tablette large ---- */
@media (max-width: 1040px) {
  .band-grid { grid-template-columns: 1.4fr 1fr; }
}

/* ---- Tablette ---- */
@media (max-width: 920px) {
  .hero { padding-top: 3rem; }
  .hero-grid { grid-template-columns: 1fr; gap: 2rem; }
  .gauge-card { max-width: 340px; width: 100%; margin: 0 auto; }
  .band-grid, .band-grid-2 { grid-template-columns: 1fr; }
  .kpi-strip { grid-template-columns: repeat(3, 1fr); }

  /* Nav : les 4 onglets répartis sur une seule ligne (police/padding fluides) */
  .head-inner { flex-wrap: wrap; gap: .55rem 1rem; }
  .topnav {
    width: 100%;
    justify-content: space-between;
    gap: .2rem;
  }
  .topnav a {
    flex: 0 1 auto;
    white-space: nowrap;
    font-size: clamp(.63rem, 3.05vw, .82rem);
    padding: .4rem clamp(.3rem, 1.8vw, .7rem);
  }

  /* Header sur deux lignes → ancres plus basses */
  main section[id] { scroll-margin-top: 120px; }
}

/* ---- Mobile ---- */
@media (max-width: 680px) {
  .head-inner { padding: .7rem 1.1rem; }
  .hero { padding: 2.5rem 1.1rem 1.5rem; }
  .band { padding: 2.5rem 1.1rem; }
  .band-alt > * { padding-left: 1.1rem; padding-right: 1.1rem; }
  .kpi-strip { grid-template-columns: repeat(2, 1fr); margin-top: 2rem; }
  .panel { padding: 1.1rem; }
  .section-head { margin-bottom: 1.5rem; }

  /* Champs de formulaire en pleine largeur, empilés */
  .toolbar, .scatter-filters { gap: .8rem; }
  .toolbar .field, .scatter-filters .field { flex: 1 1 100%; min-width: 0; }
  .field input[type="search"], .field select { width: 100%; min-width: 0; }
  .scatter-filters .field select { min-width: 0; width: 100%; }
  /* min / max empilés verticalement : aucun risque de débordement horizontal */
  .range-inputs { width: 100%; min-width: 0; flex-direction: column; align-items: stretch; gap: .5rem; }
  .range-inputs input[type="number"] { width: 100%; min-width: 0; }
  .range-sep { display: none; }
  .btn-export { margin-left: 0; width: 100%; text-align: center; }
  .btn-reset { width: 100%; }
  .field-check { justify-content: flex-start; }

  /* Tableau : texte resserré (défilement horizontal conservé) */
  .data-table { font-size: .82rem; }
  .data-table thead th { padding: .65rem .7rem; }
  .data-table tbody td { padding: .6rem .7rem; }
  .td-title { max-width: 22ch; }

  .foot-inner { font-size: .76rem; gap: .4rem; }
}

/* ---- Petit mobile ---- */
@media (max-width: 460px) {
  .kpi-strip { grid-template-columns: 1fr; }
  .hero-title { font-size: clamp(1.9rem, 8vw, 2.4rem); }
  .brand-title { font-size: 1.02rem; }
  .brand-kicker { font-size: .58rem; }
  .gauge-card { padding: 1.3rem; }
  .gauge-num { font-size: 2.8rem; }
}
