:root {
  --forest: #1f4d3a;
  --forest-2: #2b6650;
  --todo: #f5c400;
  --sold: #2e9e44;
  --refused: #d63b3b;
  --ink: #1b1f1d;
  --muted: #6b726e;
  --paper: #ffffff;
  --line: #e4e7e5;
  --shadow: 0 6px 20px rgba(0, 0, 0, .18);
  --top: calc(52px + env(safe-area-inset-top));
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--paper);
  overflow: hidden;
}

.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 1000;
  height: var(--top);
  padding: env(safe-area-inset-top) 12px 0;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--forest); color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .2);
}
.topbar h1 { font-size: 17px; margin: 0; letter-spacing: .2px; }
.counters { display: flex; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(255, 255, 255, .14); border-radius: 999px;
  padding: 4px 10px; font-size: 14px; font-variant-numeric: tabular-nums;
}
.chip i { width: 10px; height: 10px; border-radius: 50%; display: block; border: 1.5px solid rgba(0,0,0,.35); }
.chip.sold i { background: var(--sold); }
.chip.refused i { background: var(--refused); }

#map { position: fixed; inset: var(--top) 0 0 0; }

.hint {
  position: fixed; z-index: 999; left: 50%; transform: translateX(-50%);
  top: calc(var(--top) + 10px);
  background: rgba(27, 31, 29, .85); color: #fff;
  padding: 7px 14px; border-radius: 999px; font-size: 13px; white-space: nowrap;
  pointer-events: none;
}

.fabs {
  position: fixed; z-index: 1000; right: 14px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px;
}
.fab {
  width: 52px; height: 52px; border-radius: 50%; border: 0;
  background: var(--paper); color: var(--forest);
  box-shadow: var(--shadow); cursor: pointer;
  display: grid; place-items: center;
}
.fab.primary { background: var(--forest); color: #fff; }
.fab.active { color: #1a73e8; }

/* Popup maison */
.leaflet-popup-content { margin: 12px 14px; min-width: 220px; }
.pop-title { font-weight: 650; font-size: 15px; margin-bottom: 2px; padding-right: 18px; }
.pop-city { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.pop-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pop-actions button {
  border: 2px solid transparent; border-radius: 10px; padding: 10px 4px;
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  color: var(--ink); background: #f1f3f2;
}
.pop-actions button[data-s="todo"].on { background: var(--todo); }
.pop-actions button[data-s="sold"].on { background: var(--sold); color: #fff; }
.pop-actions button[data-s="refused"].on { background: var(--refused); color: #fff; }
.pop-amount {
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 8px 10px;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line);
}
.pop-amount label { font-size: 13px; font-weight: 600; }
.pop-amount-input { display: flex; align-items: center; gap: 6px; font-weight: 600; justify-self: end; }
.pop-amount input {
  width: 90px; font: inherit; font-size: 18px; font-weight: 650; text-align: right;
  padding: 6px 8px; border: 1.5px solid var(--line); border-radius: 10px;
}
.pop-amount input:focus { outline: none; border-color: var(--sold); }
.pop-quick { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.pop-quick button {
  border: 1.5px solid var(--sold); background: #fff; color: var(--sold);
  border-radius: 10px; padding: 8px 0; font: inherit; font-size: 13px; font-weight: 650; cursor: pointer;
}
.pop-quick button:active { background: var(--sold); color: #fff; }
.pop-del { margin-top: 10px; background: none; border: 0; color: var(--refused); font: inherit; font-size: 13px; padding: 0; cursor: pointer; }

/* Choix de l'affichage */
.modes {
  position: fixed; z-index: 1000; left: 12px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  display: flex; background: var(--paper); border-radius: 999px; padding: 4px;
  box-shadow: var(--shadow);
}
.modes button {
  border: 0; background: none; font: inherit; font-size: 14px; font-weight: 600; color: var(--muted);
  padding: 9px 14px; border-radius: 999px; cursor: pointer; min-width: 44px;
}
.modes button.on { background: var(--forest); color: #fff; }

.legend {
  position: fixed; z-index: 1000; left: 12px;
  bottom: calc(80px + env(safe-area-inset-bottom));
  background: var(--paper); border-radius: 12px; padding: 8px 12px; box-shadow: var(--shadow);
  font-size: 12px; font-weight: 600; display: flex; flex-direction: column; gap: 4px;
}
.legend .ramp { display: flex; align-items: center; gap: 6px; font-weight: 400; color: var(--muted); }
.legend .ramp b { width: 90px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, blue, cyan, lime, yellow, red); }
.legend .ramp i { font-style: normal; }

.commune-label {
  font-size: 13px; font-weight: 700; color: var(--forest); white-space: nowrap;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff;
  transform: translate(-50%, -50%);
}

/* Position utilisateur */
.me-dot {
  width: 18px; height: 18px; border-radius: 50%;
  background: #1a73e8; border: 3px solid #fff;
  box-shadow: 0 0 0 2px rgba(26, 115, 232, .35), 0 1px 4px rgba(0,0,0,.4);
}

/* Panneau stats */
.sheet {
  position: fixed; z-index: 1100; background: var(--paper);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  inset: auto 0 0 0; max-height: 82vh; border-radius: 18px 18px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 760px) {
  .sheet { inset: var(--top) 0 0 auto; width: 420px; max-height: none; border-radius: 0; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.close { border: 0; background: #f1f3f2; width: 34px; height: 34px; border-radius: 50%; font-size: 15px; cursor: pointer; }
.sheet-body { overflow-y: auto; padding: 4px 16px 20px; }
.sheet-body h3 { font-size: 15px; margin: 22px 0 4px; }

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 6px; }
.kpi { background: #f4f6f5; border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; }
.kpi-v { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-l { color: var(--muted); font-size: 13px; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; margin-top: 6px; }
.table th { text-align: right; color: var(--muted); font-weight: 500; font-size: 12px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.table td { text-align: right; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.table th:first-child, .table td:first-child { text-align: left; }
.table .city { font-weight: 600; }
.table .sub { color: var(--muted); font-size: 12px; }
.table .track { height: 4px; border-radius: 2px; background: #e9ecea; margin-top: 5px; }
.table .bar { height: 100%; border-radius: 2px; background: var(--forest-2); }
.table .empty { text-align: center; color: var(--muted); padding: 16px; }

.muted { color: var(--muted); }
.small { font-size: 12px; margin: 0; }
.btn { margin-top: 20px; width: 100%; padding: 12px; border-radius: 12px; font: inherit; font-weight: 600; cursor: pointer; }
.btn.ghost { background: none; border: 1.5px solid var(--forest); color: var(--forest); }

.toast {
  position: fixed; z-index: 1200; left: 50%; transform: translateX(-50%);
  bottom: calc(100px + env(safe-area-inset-bottom));
  background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: var(--shadow); max-width: 90vw;
}
