:root {
  --accent: #0f5b66;
  --accent-ink: #ffffff;
  --bar: #0f5b66;
  --panel-bg: #ffffff;
  --ink: #1d2327;
  --muted: #5f6b73;
  --line: #d9dee2;
  --warn-bg: #fff6e5;
  --warn-ink: #7a4b00;
  --shadow: 0 2px 10px rgba(0, 0, 0, .18);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Noto Kufi Arabic", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; color: var(--ink); background: #e9ecef; }
body { display: flex; flex-direction: column; }

/* ---------- top bar ---------- */
.bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--bar); color: var(--accent-ink);
  box-shadow: var(--shadow); z-index: 1000;
}
.brand { font-weight: 700; font-size: 17px; white-space: nowrap; margin-right: 6px; }
.brand span { font-weight: 400; opacity: .85; }
.bar select, .bar input {
  height: 36px; border: 0; border-radius: 6px; padding: 0 10px;
  font: inherit; font-size: 14px; color: var(--ink); background: #fff;
}
.bar select { min-width: 170px; }
#search { display: flex; flex: 1 1 320px; gap: 6px; min-width: 0; }
#search input { flex: 1; min-width: 0; }
.bar button {
  height: 36px; border: 0; border-radius: 6px; padding: 0 14px;
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  background: #ffd166; color: #3b2b00;
}
.bar button.icon { background: rgba(255,255,255,.16); color: #fff; font-size: 18px; padding: 0 12px; }

/* ---------- layout ---------- */
main { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#map { position: absolute; inset: 0; background: #cfd6db; }

#panel {
  position: absolute; top: 10px; right: 10px; bottom: 10px; width: 300px;
  overflow-y: auto; background: var(--panel-bg); border-radius: 10px;
  box-shadow: var(--shadow); z-index: 900; padding: 4px 14px 14px;
  font-size: 13.5px; transition: transform .2s ease;
}
#panel:not(.open) { transform: translateX(calc(100% + 20px)); }
#panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 0 6px; }
#panel label { display: block; margin: 4px 0; cursor: pointer; }
#panel select { width: 100%; height: 32px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
#panel small { color: var(--muted); }
.note { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.disclaimer {
  margin-top: 14px; padding: 10px; border-radius: 8px; line-height: 1.4;
  background: var(--warn-bg); color: var(--warn-ink); font-size: 12.5px;
}

/* legend + stats */
.legend-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.swatch { width: 22px; height: 14px; border-radius: 3px; flex: none; border: 2px solid; }
.stat { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.stat b { font-variant-numeric: tabular-nums; }

/* map tools */
.map-tools {
  position: absolute; left: 10px; bottom: 28px; z-index: 900;
  display: flex; flex-direction: column; gap: 6px;
}
.tool {
  width: 42px; height: 42px; border: 0; border-radius: 8px; cursor: pointer;
  background: #fff; box-shadow: var(--shadow); font-size: 19px;
}
.tool.active { background: var(--accent); color: #fff; }

#zoom-hint, #loading {
  position: absolute; left: 50%; transform: translateX(-50%); z-index: 900;
  padding: 7px 14px; border-radius: 20px; font-size: 13px; box-shadow: var(--shadow);
}
#zoom-hint { top: 12px; background: rgba(15, 91, 102, .92); color: #fff; }
#loading { top: 48px; background: #fff; color: var(--ink); }
#toast {
  position: absolute; left: 50%; bottom: 30px; transform: translateX(-50%); z-index: 1100;
  background: #222; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px;
  box-shadow: var(--shadow); max-width: 90vw;
}

/* popups */
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; line-height: 1.35; }
.pp-h { font-size: 15px; margin-bottom: 6px; }
.pp table { border-collapse: collapse; width: 100%; }
.pp th { text-align: left; font-weight: 500; color: var(--muted); padding: 2px 10px 2px 0; white-space: nowrap; vertical-align: top; }
.pp td { padding: 2px 0; }
.pp .ar { font-family: "Noto Kufi Arabic", "Segoe UI", sans-serif; }
.pp-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.pp-links a, .pp-links button {
  font: inherit; font-size: 12.5px; text-decoration: none; cursor: pointer;
  padding: 5px 9px; border-radius: 6px; border: 1px solid var(--accent); color: var(--accent); background: #fff;
}
.pp-links a.primary { background: var(--accent); color: #fff; }
.pp-note { margin-top: 8px; font-size: 11.5px; color: var(--warn-ink); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }

.m-label {
  background: rgba(15, 91, 102, .85); color: #fff; border: 0; border-radius: 4px;
  font-weight: 600; font-size: 12px; box-shadow: none; padding: 2px 6px;
}
.m-label::before { display: none; }
.measure-label { background: #222; color: #fff; border: 0; font-weight: 600; }
.measure-label::before { display: none; }

/* phones */
@media (max-width: 720px) {
  .brand { width: 100%; }
  .bar select { flex: 1 1 100%; }
  #search { flex: 1 1 100%; }
  #toggle-panel { position: absolute; top: 8px; right: 12px; }
  #panel { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 55%; }
  #panel:not(.open) { transform: translateY(calc(100% + 20px)); }
}

/* popup: proximity + small notes */
.pp-sub { margin-top: 8px; font-weight: 600; font-size: 12.5px; }
.pp-sub small { font-weight: 400; color: var(--muted); }
.prox-wrap { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; font-size: 12.5px; }
.prox { white-space: nowrap; }
.pp-note.small { color: var(--muted); font-size: 11px; }
.pp small { color: var(--muted); }

/* lotissements */
.lts-label {
  background: rgba(59, 43, 0, .82); color: #ffe7a6; border: 0; border-radius: 4px;
  font-size: 11.5px; font-weight: 600; padding: 1px 5px; box-shadow: none;
}
.lts-label::before { display: none; }
.lts-tools { display: flex; gap: 6px; margin-bottom: 6px; }
.lts-tools input { flex: 1; min-width: 0; height: 30px; border: 1px solid var(--line); border-radius: 6px; padding: 0 8px; font: inherit; }
.lts-tools select { width: auto; height: 30px; }
.lts-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; }
.lts-item {
  display: flex; justify-content: space-between; gap: 8px; width: 100%; text-align: left;
  border: 0; border-bottom: 1px solid var(--line); background: #fff; padding: 6px 8px;
  font: inherit; font-size: 12.5px; cursor: pointer;
}
.lts-item:hover { background: #f3f6f7; }
.lts-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lts-n { white-space: nowrap; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { background: #eef1f3; border-radius: 10px; padding: 1px 7px; font-size: 11.5px; }

/* ---------- HADDOU MAP branding + dashboard ---------- */
.brand { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; letter-spacing: .05em; }
.brand .mark { width: 30px; height: 30px; color: #fff; flex: none; }
.brand b { color: #ffd166; }
.bar #ilot { height: 36px; border: 0; border-radius: 6px; padding: 0 8px; font: inherit; font-size: 14px; max-width: 170px; }
.bar #ilot:disabled { opacity: .55; }

.dash { margin: 10px -14px 4px; padding: 12px 14px 14px; background: #0f5b66; color: #eef6f7; border-radius: 10px 10px 0 0; }
.dash .eyebrow { display: flex; align-items: center; gap: 6px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; opacity: .85; }
.dash .swatch-m { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.dash h2 { margin: 4px 0 10px; font-size: 19px; line-height: 1.2; }
.dash h2 .ar { font-size: 16px; opacity: .85; margin-left: 4px; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tile { background: rgba(255,255,255,.1); border-radius: 8px; padding: 8px 6px; text-align: center; }
.tile b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; color: #ffd166; }
.tile small { font-size: 11px; opacity: .85; }
.dash .sub-tiles { display: flex; justify-content: space-between; gap: 6px; margin-top: 8px; font-size: 12px; opacity: .92; }
.dash .sub-tiles b { color: #fff; }
.dash p { font-size: 12.5px; margin: 10px 0 0; opacity: .9; line-height: 1.4; }
.dash .kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 0 0 8px; font-size: 13px; }
.dash .kv dt { opacity: .75; }
.dash .kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.dash .chips { margin: 6px 0; }
.dash .chip { border: 1px solid rgba(255,255,255,.35); background: transparent; color: #eef6f7; cursor: pointer; font: inherit; font-size: 11.5px; }
.dash .chip.on { background: #ffd166; color: #3b2b00; border-color: #ffd166; }
.dash .chip.hp { border-style: dashed; cursor: default; opacity: .8; }
.dash .dash-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.dash .dash-links a, .dash .dash-links button {
  font: inherit; font-size: 12px; text-decoration: none; cursor: pointer; padding: 5px 9px; border-radius: 6px;
  border: 1px solid rgba(255,255,255,.5); color: #fff; background: transparent;
}
.dash .dash-links a.primary { background: #ffd166; color: #3b2b00; border-color: #ffd166; }
.dash .note { color: #d8ecef; font-size: 11.5px; }
.corr { font-size: 11px; color: var(--muted); }
@media (max-width: 720px) { .bar #ilot { flex: 1 1 40%; max-width: none; } }
.brand span { font-weight: 700; opacity: 1; font-size: 17px; }
/* phones: search box full width, sous-ilot + button on the next line */
@media (max-width: 720px) {
  #search { flex-wrap: wrap; }
  #search input { flex: 1 1 100%; }
  #search #ilot { flex: 1 1 auto; max-width: none; }
}
#panel .dash small, .dash .tile small { color: #d8ecef; opacity: 1; }

/* certified plan */
.cert-label {
  background: transparent; border: 0; box-shadow: none; padding: 0;
  color: #06361a; font-size: 11px; font-weight: 700;
  text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 3px #fff;
}
.cert-label::before { display: none; }
.cert-badge {
  display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 10px;
  background: #1a9850; color: #fff; font-size: 11px; font-weight: 600; vertical-align: 1px;
}
.pp td.warn { color: #9a3412; }
.pp td.warn a { color: #9a3412; font-weight: 600; }
.cert-badge.draft { background: #b45309; }
.legend-row .line { display: inline-block; width: 22px; height: 0; margin-right: 8px; vertical-align: middle; }
.hv-label { background: transparent; border: 0; box-shadow: none; padding: 0; color: #ffff00; font-weight: 700;
  font-size: 12px; text-shadow: 0 0 2px #000, 0 0 2px #000, 0 0 3px #000; }
.hv-label::before { display: none; }
