/* ============================================================
   DPE Finder — feuille de style mobile-first
   ============================================================ */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f0f3f6;
  --border: #dde3ea;
  --text: #16202b;
  --text-soft: #5b6b7c;
  --text-faint: #8b9aa9;
  --accent: #0f766e;
  --accent-soft: #d6f0ec;
  --accent-strong: #0b5c56;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --lab: #7c3aed;
  --lab-soft: #f3e8ff;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 43, .06), 0 6px 18px rgba(16, 32, 43, .07);
  --tabbar-h: 60px;
  --topbar-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1418;
    --surface: #161f26;
    --surface-2: #1e2932;
    --border: #2b3843;
    --text: #e8eef3;
    --text-soft: #9db0c0;
    --text-faint: #6f8394;
    --accent: #2dd4bf;
    --accent-soft: #10312e;
    --accent-strong: #5eead4;
    --warn: #fbbf24;
    --warn-soft: #382c11;
    --danger: #fca5a5;
    --danger-soft: #3b1717;
    --ok: #4ade80;
    --ok-soft: #10301c;
    --lab: #c4b5fd;
    --lab-soft: #291f45;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

/* `hidden` doit l'emporter sur les `display` posés par les composants. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
a { color: var(--accent); }

/* ---------------- Barre supérieure ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-t);
}
.topbar-inner {
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 0 14px;
  max-width: 900px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  background: var(--accent-soft); border-radius: 10px; font-size: 18px;
}
.brand h1 { font-size: 16px; font-weight: 700; letter-spacing: -.2px; }
.brand p {
  margin: 1px 0 0; font-size: 11.5px; color: var(--text-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  width: 36px; height: 36px; flex: none; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-soft); font-size: 16px; font-weight: 700; cursor: pointer;
}
.icon-btn:active { transform: scale(.94); }

/* ---------------- Zone principale ---------------- */
#main {
  max-width: 900px; margin: 0 auto;
  padding: 12px 12px calc(var(--tabbar-h) + var(--safe-b) + 20px);
}
.view { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
.view-map { padding: 0; }

/* ---------------- Cartes ---------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card-title { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.card-sub { margin: 0 0 12px; font-size: 12.5px; color: var(--text-soft); }

/* ---------------- Bandeau expérimental ---------------- */
.lab-banner {
  background: var(--lab-soft); border: 1px solid var(--lab);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px;
}
.lab-banner strong { display: block; color: var(--lab); font-size: 13.5px; }
.lab-banner p { margin: 6px 0 0; font-size: 12.5px; color: var(--text-soft); }

/* ---------------- Formulaires ---------------- */
.field-label {
  display: block; font-size: 12.5px; font-weight: 600;
  color: var(--text-soft); margin: 12px 0 6px;
}
.card > .field-label:first-of-type, .card .seg + div .field-label { margin-top: 0; }

input[type=text], input[type=url], input[type=number], textarea, select {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  font-size: 16px; /* évite le zoom automatique sur iOS */
  font-family: inherit;
}
input:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; line-height: 1.45; }
input[type=number] { -moz-appearance: textfield; }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.input-row { position: relative; }
.btn-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; border: 0; border-radius: 50%;
  background: transparent; color: var(--text-faint);
  font-size: 15px; cursor: pointer;
}
.unit-input { position: relative; }
.unit-input .unit {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  font-size: 11px; color: var(--text-faint); pointer-events: none;
  background: var(--surface-2); padding-left: 6px;
}
.unit-input input { padding-right: 92px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1.2fr .8fr 1fr; gap: 8px; }
@media (max-width: 380px) { .grid-2 { grid-template-columns: 1fr; } }

input[type=range] {
  width: 100%; height: 34px; -webkit-appearance: none; background: transparent;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 5px; border-radius: 3px; background: var(--border);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 26px; height: 26px; margin-top: -10px;
  border-radius: 50%; background: var(--accent); border: 3px solid var(--surface);
  box-shadow: var(--shadow);
}
input[type=range]::-moz-range-track { height: 5px; border-radius: 3px; background: var(--border); }
input[type=range]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--surface);
}
output { font-weight: 700; color: var(--accent); }

.hint { margin: 8px 0 0; font-size: 12px; color: var(--text-faint); line-height: 1.5; }

.disclosure {
  margin-top: 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface-2); overflow: hidden;
}
.disclosure > summary {
  padding: 12px 14px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; list-style: none; display: flex;
  align-items: center; justify-content: space-between; gap: 8px;
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::after { content: "▾"; color: var(--text-faint); }
.disclosure[open] > summary::after { content: "▴"; }
.disclosure > :not(summary) { margin: 0 14px 14px; width: calc(100% - 28px); }

/* ---------------- Boutons ---------------- */
.btn {
  appearance: none; border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 13px 18px; font-size: 15px; font-weight: 650; font-family: inherit;
  cursor: pointer; min-height: 46px; transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-primary { color: #06231f; } }
.btn-ghost { background: var(--surface-2); border-color: var(--border); color: var(--text-soft); }
.btn-block { display: block; width: 100%; margin-top: 14px; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn.is-busy .btn-label { opacity: .35; }

.sticky-actions {
  position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-b) + 8px);
  display: grid; grid-template-columns: 1fr 2fr; gap: 10px;
  padding: 10px; margin-top: 4px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-radius: var(--radius);
}

/* ---------------- Segments ---------------- */
.seg {
  display: flex; gap: 4px; padding: 4px; margin-bottom: 14px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.seg-wrap { flex-wrap: wrap; }
.seg-btn {
  flex: 1 1 auto; min-height: 38px; padding: 8px 10px; border: 0;
  border-radius: 8px; background: transparent; color: var(--text-soft);
  font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.seg-btn.is-active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }

/* ---------------- Autocomplétion ---------------- */
.suggest {
  margin-top: 6px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); overflow: hidden; box-shadow: var(--shadow);
}
.suggest-item {
  display: block; width: 100%; text-align: left; padding: 12px 14px;
  border: 0; border-bottom: 1px solid var(--border);
  background: transparent; color: var(--text); font: inherit; cursor: pointer;
}
.suggest-item:last-child { border-bottom: 0; }
.suggest-item:active { background: var(--surface-2); }
.suggest-item b { display: block; font-size: 14px; }
.suggest-item span { font-size: 12px; color: var(--text-faint); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-strong);
  font-size: 12.5px; font-weight: 600;
}
.chip button {
  border: 0; background: transparent; color: inherit;
  font-size: 14px; cursor: pointer; padding: 0 2px; line-height: 1;
}
.picked {
  margin-top: 8px; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--accent-soft); color: var(--accent-strong);
  font-size: 13px; font-weight: 600;
}

/* ---------------- Étiquettes DPE ---------------- */
.label-picker { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.lbl {
  min-height: 42px; border: 2px solid transparent; border-radius: 8px;
  font: inherit; font-size: 14px; font-weight: 800; cursor: pointer;
  color: #1a1a1a; display: grid; place-items: center;
}
.lbl[data-v=""] { background: var(--surface-2); color: var(--text-faint); font-size: 11px; font-weight: 600; }
.lbl.is-active { border-color: var(--text); transform: scale(1.06); }
.lbl-a { background: #319834; color: #fff; }
.lbl-b { background: #33cc31; }
.lbl-c { background: #cbfc34; }
.lbl-d { background: #fbfe06; }
.lbl-e { background: #fbcc05; }
.lbl-f { background: #fc9935; }
.lbl-g { background: #fc0205; color: #fff; }
.ges-a { background: #f0ecf8; }
.ges-b { background: #ddd2ee; }
.ges-c { background: #c4b0e0; }
.ges-d { background: #a98cd2; }
.ges-e { background: #8b64bf; color: #fff; }
.ges-f { background: #6b3fa8; color: #fff; }
.ges-g { background: #4a2483; color: #fff; }

.badge-dpe {
  display: inline-grid; place-items: center; width: 30px; height: 30px;
  border-radius: 8px; font-weight: 800; font-size: 15px; color: #1a1a1a; flex: none;
}

/* ---------------- Résultats ---------------- */
.res-head {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px;
}
.res-head h2 { font-size: 15px; }
.res-head p { margin: 6px 0 0; font-size: 12.5px; color: var(--text-soft); }
.pill {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; background: var(--surface-2); color: var(--text-soft);
}
.pill-exact { background: var(--ok-soft); color: var(--ok); }
.pill-proche { background: var(--accent-soft); color: var(--accent-strong); }
.pill-elargi, .pill-large { background: var(--warn-soft); color: var(--warn); }
.pill-minimal { background: var(--danger-soft); color: var(--danger); }

.res-card {
  display: flex; gap: 12px; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; margin-bottom: 10px;
  box-shadow: var(--shadow); cursor: pointer; font: inherit; color: inherit;
  position: relative; overflow: hidden;
}
.res-card:active { transform: scale(.995); }
.res-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--sc, var(--border));
}
.res-rank {
  flex: none; width: 46px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
}
.res-score { font-size: 17px; font-weight: 800; color: var(--sc, var(--text)); line-height: 1; }
.res-score-u { font-size: 9px; color: var(--text-faint); letter-spacing: .04em; }
.res-main { flex: 1; min-width: 0; }
.res-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.res-addr { font-size: 14.5px; font-weight: 700; line-height: 1.3; min-width: 0; }
.res-city { font-size: 12px; color: var(--text-faint); margin-top: 1px; }
.res-facts {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px;
  font-size: 11.5px; color: var(--text-soft);
}
.fact {
  background: var(--surface-2); border-radius: 6px; padding: 3px 7px;
  white-space: nowrap;
}
.fact.f-ok { background: var(--ok-soft); color: var(--ok); }
.fact.f-ecart { background: var(--danger-soft); color: var(--danger); }
.fact.f-proche { background: var(--warn-soft); color: var(--warn); }
.res-labels { display: flex; gap: 3px; align-items: center; flex: none; }

.conf {
  display: inline-block; padding: 3px 8px; border-radius: 999px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .01em;
}
.conf-tres_probable { background: var(--ok-soft); color: var(--ok); }
.conf-probable { background: var(--accent-soft); color: var(--accent-strong); }
.conf-possible { background: var(--warn-soft); color: var(--warn); }
.conf-peu_probable, .conf-indicatif { background: var(--surface-2); color: var(--text-faint); }

.empty {
  text-align: center; padding: 40px 20px; color: var(--text-faint);
}
.empty-ico { font-size: 40px; display: block; margin-bottom: 10px; }
.empty h3 { font-size: 15px; color: var(--text); margin-bottom: 6px; }
.empty p { font-size: 13px; margin: 0 auto; max-width: 34ch; }

.skeleton {
  height: 78px; border-radius: var(--radius); margin-bottom: 10px;
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 400% 100%; animation: shimmer 1.2s infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* ---------------- Carte ---------------- */
#map {
  height: calc(100dvh - var(--topbar-h) - var(--tabbar-h) - var(--safe-b) - var(--safe-t));
  width: 100%; background: var(--surface-2);
}
.map-controls {
  position: absolute; right: 12px;
  top: calc(var(--topbar-h) + var(--safe-t) + 12px);
  display: flex; flex-direction: column; gap: 8px; z-index: 500;
}
.map-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); font-size: 18px; cursor: pointer; box-shadow: var(--shadow);
}
.map-hint {
  position: absolute; left: 12px; right: 66px;
  top: calc(var(--topbar-h) + var(--safe-t) + 12px); z-index: 500;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; font-size: 11.5px;
  color: var(--text-soft); box-shadow: var(--shadow);
}
.leaflet-container { font: inherit; }
.marker-pin {
  display: grid; place-items: center; width: 26px; height: 26px;
  border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35);
  font-size: 11px; font-weight: 800; color: #1a1a1a;
}
.marker-pin span { transform: rotate(45deg); }

/* ---------------- Feuille inférieure ---------------- */
.sheet { position: fixed; inset: 0; z-index: 100; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(8, 14, 20, .5); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 92dvh; display: flex; flex-direction: column;
  background: var(--surface); border-radius: 18px 18px 0 0;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, .3);
  animation: rise .22s cubic-bezier(.2, .8, .2, 1);
  padding-bottom: var(--safe-b);
}
@keyframes rise { from { transform: translateY(100%); } }
@media (min-width: 720px) {
  .sheet-panel { left: 50%; right: auto; transform: translateX(-50%); width: 680px; border-radius: 18px 18px 0 0; }
  @keyframes rise { from { transform: translate(-50%, 100%); } }
}
.sheet-grip { padding: 10px 0 6px; cursor: pointer; }
.sheet-grip::before {
  content: ""; display: block; width: 40px; height: 4px; margin: 0 auto;
  border-radius: 2px; background: var(--border);
}
.sheet-head { padding: 4px 16px 12px; border-bottom: 1px solid var(--border); }
.sheet-tabs { display: flex; gap: 4px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.sheet-tab {
  flex: 1; min-height: 38px; border: 0; border-radius: 8px;
  background: var(--surface-2); color: var(--text-soft);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.sheet-tab.is-active { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .sheet-tab.is-active { color: #06231f; } }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 16px 24px; }
.help-body h2 { font-size: 18px; margin-bottom: 10px; }
.help-body h3 { font-size: 14px; margin: 18px 0 6px; color: var(--accent); }
.help-body p, .help-body li { font-size: 13.5px; color: var(--text-soft); }
.help-body ol, .help-body ul { padding-left: 20px; margin: 6px 0; }
.help-body li { margin-bottom: 5px; }
.legend { list-style: none; padding: 0; }
.legend li { display: flex; align-items: center; gap: 8px; }

.addr-big { font-size: 18px; font-weight: 750; line-height: 1.25; }
.addr-sub { font-size: 12.5px; color: var(--text-faint); margin-top: 2px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.kpi {
  background: var(--surface-2); border-radius: var(--radius-sm);
  padding: 10px 8px; text-align: center;
}
.kpi b { display: block; font-size: 16px; }
.kpi span { font-size: 10.5px; color: var(--text-faint); }
.actions-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions-row .btn { flex: 1 1 auto; padding: 10px 12px; font-size: 13px; min-height: 42px; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.kv:last-child { border-bottom: 0; }
.kv dt { font-size: 12.5px; color: var(--text-soft); flex: 1 1 50%; }
.kv dd { margin: 0; font-size: 13px; font-weight: 600; text-align: right; flex: 1 1 50%; word-break: break-word; }
.group-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--accent); margin: 18px 0 2px;
}
.group-title:first-child { margin-top: 0; }

.match-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.match-row:last-child { border-bottom: 0; }
.match-ico { width: 22px; text-align: center; font-size: 14px; flex: none; }
.match-txt { flex: 1; font-size: 13px; }
.match-txt small { display: block; color: var(--text-faint); font-size: 11.5px; }

.notice {
  border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 10px;
  font-size: 12.5px; line-height: 1.5;
}
.notice-warn { background: var(--warn-soft); color: var(--warn); }
.notice-info { background: var(--accent-soft); color: var(--accent-strong); }
.notice-err { background: var(--danger-soft); color: var(--danger); }
.notice ul { margin: 6px 0 0; padding-left: 18px; }

.tag {
  display: inline-block; padding: 2px 7px; border-radius: 999px;
  font-size: 10px; font-weight: 700; background: var(--surface); color: var(--text-faint);
}
.tag-reco { background: var(--ok-soft); color: var(--ok); }

/* ---------------- Barre d'onglets ---------------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b);
  backdrop-filter: blur(10px);
}
.tab {
  flex: 1; height: var(--tabbar-h); border: 0; background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--text-faint); font: inherit; cursor: pointer; position: relative;
}
.tab-ico { font-size: 19px; line-height: 1; }
.tab-txt { font-size: 10px; font-weight: 600; }
.tab.is-active { color: var(--accent); }
.tab.is-active .tab-ico { transform: translateY(-1px); }
.tab-badge {
  position: absolute; top: 6px; right: 50%; margin-right: -22px;
  min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 10px; font-weight: 700;
  display: grid; place-items: center;
}
.tab-dot {
  position: absolute; top: 9px; right: 50%; margin-right: -20px;
  width: 7px; height: 7px; border-radius: 50%; background: var(--lab);
}

/* ---------------- Notifications ---------------- */
.toast-zone {
  position: fixed; left: 12px; right: 12px;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px);
  z-index: 200; display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--text); color: var(--bg);
  border-radius: var(--radius-sm); padding: 11px 14px; font-size: 13px;
  box-shadow: var(--shadow); animation: fade .2s ease;
}
.toast-err { background: var(--danger); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition: none !important; }
}
