/* Permit results page (/resultats-permis/). Sequential ramp is one hue — the
   brand deep blue (--color-accent) — light to dark; status colours are reserved
   for permit states and always ship with a text label. */
:root {
  --seq-0: #f1f2f4;
  --seq-1: #d6deef;
  --seq-2: #a8b8db;
  --seq-3: #7790c2;
  --seq-4: #4d66a0;
  --seq-5: #2b3d6b;
  --st-granted: #0ca30c;
  --st-pending: #8a94a6;
  --st-referral: #5b6577;
  --st-appeal: #fab219;
  --st-cancelled: #d03b3b;
  --grid: #e1e0d9;
}

.ps-intro { padding-block: var(--space-4) var(--space-3); }
.ps-eyebrow {
  margin: 0 0 var(--space-1);
  font-size: var(--fs-300);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-accent);
}
.ps-intro h1 { margin: 0 0 var(--space-2); font-size: clamp(1.75rem, 4vw, var(--fs-900)); line-height: var(--lh-tight); color: var(--color-ink); }
.ps-lede { max-width: 62ch; margin: 0; color: var(--color-text); }
.ps-kpis + .ps-lede { margin-top: var(--space-2); }
.ps-lede--note { margin-bottom: var(--space-2); font-size: var(--fs-300); color: var(--color-muted); }
.ps-lede a { color: var(--color-accent); }

.ps-kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
  margin: var(--space-4) 0 0;
  padding: 0;
  list-style: none;
}
.ps-kpis li {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: var(--space-2) var(--space-3);
  border-left: 4px solid var(--color-primary);
  background: var(--color-surface);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.ps-kpi-value { font-size: clamp(1.75rem, 4vw, 2.5rem); font-weight: 700; line-height: 1.1; color: var(--color-ink); font-variant-numeric: tabular-nums; }
.ps-kpi-label { font-size: var(--fs-300); color: var(--color-muted); }
.ps-kpi-label a { color: inherit; text-decoration: none; }

/* ---- Map + panel ---- */
.ps-explore {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: var(--space-3);
  padding-block: var(--space-3);
}
.ps-map {
  position: relative;
  z-index: 0; /* keep Leaflet's panes (z 400+) under the sticky header */
  height: 560px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--seq-0);
  overflow: hidden;
}
.ps-map .leaflet-interactive:focus { outline: none; }
.ps-map-host { width: 100%; height: 100%; }

/* 3D / 2D switch + interaction hint above the map */
.ps-maptop { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); margin-bottom: var(--space-1); }
.ps-mode { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--color-surface); border: 1px solid var(--color-border); }
.ps-mode button {
  min-width: 3.25rem;
  padding: 0.35rem 0.9rem;
  border: 0;
  border-radius: 999px;
  background: none;
  font: 600 var(--fs-300) / 1 var(--font-body);
  color: var(--color-text);
  cursor: pointer;
}
.ps-mode button[aria-pressed='true'] { background: var(--color-ink); color: #fff; }
.ps-mode button:disabled { opacity: 0.4; cursor: not-allowed; }
.ps-hint { margin: 0; font-size: var(--fs-300); color: var(--color-muted); }
@media (pointer: coarse) { .ps-hint { display: none; } }

/* 3D: permit counts floating over each commune */
.ps-count {
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  font: 700 12px/1.4 var(--font-body);
  color: var(--color-ink);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  transition: opacity 0.2s;
}
/* !important: MapLibre writes an inline opacity on marker elements. */
.ps-count.is-dim { opacity: 0.3 !important; }

/* 3D tooltips (MapLibre popup) styled like the 2D ones */
.ps-ml-tip .maplibregl-popup-content {
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  background: #1b1f2a;
  color: #fff;
  font: 600 13px/1.4 var(--font-body);
  box-shadow: var(--shadow);
}
.ps-ml-tip .maplibregl-popup-content span { display: block; font-weight: 400; color: #cfd5e2; }
.ps-ml-tip .maplibregl-popup-tip { display: none; }
.ps-ml-tip { pointer-events: none; }
.ps-mapbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  margin-top: var(--space-1);
  font-size: var(--fs-300);
  color: var(--color-muted);
}
.ps-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
.ps-legend-title { font-weight: 600; color: var(--color-text); margin-right: 0.25rem; }
.ps-legend span + .ps-swatch { margin-left: 0.4rem; }
.ps-swatch { width: 14px; height: 14px; border-radius: 3px; background: var(--c); }
.ps-swatch--zero { background: var(--seq-0); border: 1px dashed #b9bcc3; }
.ps-dotlegend { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.75rem; }
.ps-dotkey { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0.3rem; }
.ps-dotkey .ps-dot { margin: 0 0 0 0.35rem; }
.ps-dot--none { background: #fff; box-shadow: inset 0 0 0 2px #1b1f2a; }
.ps-toggle { display: inline-flex; align-items: center; gap: 0.4rem; cursor: pointer; color: var(--color-text); }
.ps-toggle input { accent-color: var(--color-accent); width: 16px; height: 16px; }

.ps-tip {
  padding: 0.4rem 0.6rem;
  border: 0;
  border-radius: 6px;
  background: #1b1f2a;
  color: #fff;
  font: 600 13px/1.4 var(--font-body);
  box-shadow: var(--shadow);
}
.ps-tip::before { display: none; }
.ps-tip span { display: block; font-weight: 400; color: #cfd5e2; }

.ps-panel {
  align-self: start;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
  box-shadow: var(--shadow);
}
.ps-panel h2 { margin: 0; font-size: var(--fs-600); line-height: var(--lh-tight); color: var(--color-ink); }
.ps-panel-kicker { margin: 0 0 0.25rem; font-size: var(--fs-300); color: var(--color-muted); }
.ps-panel-big { display: flex; align-items: baseline; gap: 0.5rem; margin: var(--space-2) 0 0.25rem; }
.ps-panel-big strong { font-size: 2.75rem; line-height: 1; color: var(--color-ink); font-variant-numeric: tabular-nums; }
.ps-panel-big span { color: var(--color-text); }
.ps-panel-sub { margin: 0; font-size: var(--fs-300); color: var(--color-muted); }
.ps-panel h3 { margin: var(--space-3) 0 var(--space-1); font-size: var(--fs-300); text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-muted); }
.ps-reset {
  margin-top: var(--space-2);
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-accent);
  font: inherit;
  font-size: var(--fs-300);
  cursor: pointer;
  text-decoration: underline;
}

/* Status stack: segments separated by a 2px surface gap. */
.ps-stack { display: flex; gap: 2px; height: 12px; }
.ps-stack span { border-radius: 3px; background: var(--c); min-width: 4px; }
.ps-status { display: grid; grid-template-columns: auto 1fr auto; gap: 0.3rem 0.5rem; margin: var(--space-1) 0 0; padding: 0; list-style: none; font-size: var(--fs-300); }
.ps-status li { display: contents; }
.ps-dot { width: 10px; height: 10px; margin-top: 0.4em; border-radius: 50%; background: var(--c); }
.ps-status b { font-variant-numeric: tabular-nums; color: var(--color-ink); }

.ps-projects { margin: 0; padding: 0; list-style: none; font-size: var(--fs-300); }
.ps-projects li { display: flex; align-items: baseline; gap: 0.5rem; padding: 0.35rem 0; border-top: 1px solid var(--color-border); }
.ps-projects a { flex: 1; color: var(--color-ink); text-decoration: none; text-transform: capitalize; }
.ps-projects a:hover { color: var(--color-accent); text-decoration: underline; }
.ps-projects small { color: var(--color-muted); white-space: nowrap; }
.ps-more { margin: var(--space-1) 0 0; font-size: var(--fs-300); color: var(--color-muted); }
.ps-hubs { display: flex; flex-direction: column; gap: 0.4rem; margin-top: var(--space-2); }
.ps-hubs a {
  display: inline-block;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  background: var(--color-primary);
  color: var(--color-ink);
  font-weight: 600;
  font-size: var(--fs-300);
  text-align: center;
  text-decoration: none;
}
.ps-hubs a:hover { filter: brightness(0.95); }

/* ---- Why our applications succeed ---- */
.ps-key { padding-block: 0 var(--space-3); }
.ps-key h2 { font-size: clamp(1.25rem, 2.6vw, var(--fs-700, 1.6rem)); line-height: var(--lh-tight); }
.ps-why { padding-block: var(--space-2) var(--space-4); }
.ps-why h2 { margin: 0 0 var(--space-2); font-size: var(--fs-500); color: var(--color-ink); }
.ps-why-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-3); }
.ps-why-grid > div { padding: var(--space-2) var(--space-2) var(--space-2) var(--space-2); border-top: 4px solid var(--color-brand, #ffe32b); background: var(--color-surface); border-radius: 0 0 8px 8px; }
.ps-why h3 { margin: 0 0 0.5rem; font-size: var(--fs-400, 1.05rem); line-height: 1.3; color: var(--color-ink); }
.ps-why p { margin: 0; font-size: var(--fs-300); color: var(--color-text); }

/* ---- Charts ---- */
.ps-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  padding-block: var(--space-4) var(--space-5);
}
.ps-figure { margin: 0; }
.ps-figure h2 { margin: 0 0 0.25rem; font-size: var(--fs-500); color: var(--color-ink); }
.ps-figure figcaption p { margin: 0 0 var(--space-2); font-size: var(--fs-300); color: var(--color-muted); }

.ps-bars { margin: 0; padding: 0; list-style: none; }
.ps-bar-row {
  display: grid;
  grid-template-columns: 11rem minmax(0, 1fr) 13rem;
  align-items: center;
  gap: var(--space-1);
  width: 100%;
  padding: 0.3rem 0.25rem;
  border: 0;
  border-radius: 6px;
  background: none;
  font: inherit;
  font-size: var(--fs-300);
  text-align: left;
  color: var(--color-text);
  cursor: pointer;
}
.ps-bar-row:hover:not(:disabled), .ps-bar-row[aria-pressed='true'] { background: var(--color-surface); }
.ps-bar-row[aria-pressed='true'] .ps-bar-name { font-weight: 700; color: var(--color-ink); }
.ps-bar-row:disabled { cursor: default; }
.ps-bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ps-bar-track { height: 10px; border-bottom: 1px solid var(--grid); }
.ps-bar { display: block; height: 10px; border-radius: 0 4px 4px 0; background: var(--color-accent); }
.ps-bar-value { text-align: right; font-variant-numeric: tabular-nums; }
.ps-bar-value strong { color: var(--color-ink); }
.ps-muted { color: var(--color-muted); font-style: italic; }

.ps-cols {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 220px;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid #c3c2b7;
}
.ps-col { position: relative; display: flex; flex: 1; align-items: flex-end; height: 100%; outline: none; }
.ps-col::after { content: ''; position: absolute; inset: 0 -1px; }
.ps-col-bar { display: block; width: 100%; border-radius: 4px 4px 0 0; background: var(--color-accent); }
.ps-col:hover .ps-col-bar, .ps-col:focus .ps-col-bar { background: var(--seq-5); }
.ps-col-year { position: absolute; left: 50%; bottom: -1.5rem; transform: translateX(-50%); font-size: 12px; color: var(--color-muted); }
.ps-col-tip {
  position: absolute;
  z-index: 2;
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  background: #1b1f2a;
  color: #fff;
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, -100%);
}

.ps-bar-sub { display: block; font-size: 12px; color: var(--color-muted); }
.ps-sr {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---- Delay chart: median bar, one dot per permit, regional median line ---- */
.ps-figure--wide { grid-column: 1 / -1; }
.ps-delay { position: relative; padding-top: 1.5rem; }
.ps-delay-axis { position: relative; height: 1.25rem; margin-left: 11rem; margin-right: 10rem; font-size: 12px; color: var(--color-muted); }
.ps-delay-axis span { position: absolute; top: -1.25rem; transform: translateX(-50%); white-space: nowrap; }
.ps-delay-row {
  display: grid;
  grid-template-columns: 11rem minmax(0, 1fr) 10rem;
  align-items: center;
  gap: 0;
  padding: 0.35rem 0;
  font-size: var(--fs-300);
}
.ps-delay-name { color: var(--color-text); text-decoration: none; }
.ps-delay-name:hover { color: var(--color-accent); text-decoration: underline; }
.ps-delay-track { position: relative; height: 18px; border-bottom: 1px solid var(--grid); }
.ps-delay-bar { position: absolute; top: 4px; left: 0; height: 10px; border-radius: 0 4px 4px 0; background: var(--seq-2); }
.ps-delay-dot {
  position: absolute; top: 5px; width: 8px; height: 8px; margin-left: -4px; border-radius: 50%;
  background: var(--color-accent); opacity: 0.75; box-shadow: 0 0 0 1px #fff;
}
.ps-delay-ref { position: absolute; top: -4px; bottom: -4px; width: 0; border-left: 2px dashed var(--seq-5); }
.ps-delay-value { padding-left: var(--space-1); text-align: right; font-variant-numeric: tabular-nums; }
.ps-delay-value strong { color: var(--color-ink); }
.ps-delay-table { width: 100%; max-width: 46rem; margin-top: var(--space-3); border-collapse: collapse; font-size: var(--fs-300); font-variant-numeric: tabular-nums; }
.ps-delay-table th, .ps-delay-table td { padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--grid); text-align: right; }
.ps-delay-table th[scope='row'], .ps-delay-table thead th:first-child { text-align: left; }
.ps-delay-table thead th { font-weight: 700; color: var(--color-ink); }
.ps-delay-total th, .ps-delay-total td { font-weight: 700; }
.ps-note { margin: var(--space-2) 0 0; font-size: var(--fs-300); color: var(--color-muted); }

/* Barometer of the 19 communes (regional open data). */
.ps-baro { width: 100%; border-collapse: collapse; font-size: var(--fs-300); font-variant-numeric: tabular-nums; }
.ps-baro th, .ps-baro td { padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--grid); text-align: right; white-space: nowrap; }
.ps-baro th[scope='row'], .ps-baro thead th:first-child { text-align: left; }
.ps-baro thead th { font-weight: 700; color: var(--color-ink); vertical-align: bottom; }
.ps-baro th[scope='row'] a { color: inherit; }
.ps-baro-chartcol { width: 38%; }
.ps-baro-sub { display: block; font-weight: 400; font-size: 12px; color: var(--color-muted); }
.ps-baro-axis { position: relative; display: block; height: 1.1em; font-weight: 400; font-size: 12px; color: var(--color-muted); }
.ps-baro-axis span { position: absolute; transform: translateX(-50%); }
.ps-baro-axis span:first-child { transform: none; }
.ps-baro-axis span:last-child { transform: translateX(-100%); }
.ps-baro-track { position: relative; display: block; height: 14px; background: var(--color-surface); border-radius: 3px; }
.ps-baro-range { position: absolute; top: 2px; bottom: 2px; background: var(--color-brand, #ffe32b); border-radius: 3px; }
.ps-baro-median { position: absolute; top: -2px; bottom: -2px; width: 3px; margin-left: -1.5px; background: var(--color-ink); border-radius: 1px; }
.ps-baro-ref { position: absolute; top: -6px; bottom: -6px; border-left: 1px dashed var(--color-muted); }
.ps-baro-refusal { display: inline-flex; align-items: center; justify-content: flex-end; gap: 0.4rem; width: 100%; }
.ps-baro-reftrack { display: block; flex: 0 0 4rem; height: 8px; }
.ps-baro-refbar { display: block; height: 100%; background: var(--st-cancelled); border-radius: 2px; opacity: 0.75; }
.ps-cmp { width: 100%; max-width: 46rem; border-collapse: collapse; font-size: var(--fs-300); font-variant-numeric: tabular-nums; }
.ps-cmp th, .ps-cmp td { padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--grid); text-align: left; vertical-align: middle; }
.ps-cmp th[scope='row'] { width: 11rem; }
.ps-cmp-value strong { font-size: var(--fs-500); }
.ps-cmp thead th { font-weight: 700; color: var(--color-ink); }
.ps-cmp th[scope='row'] a { color: inherit; }
.ps-cmp-cell { display: flex; align-items: center; gap: 0.6rem; }
.ps-cmp-track { flex: 1 1 auto; height: 14px; background: var(--color-surface); border-radius: 3px; overflow: hidden; }
.ps-cmp-bar { display: block; height: 100%; background: var(--st-pending); border-radius: 3px; }
.ps-cmp-bar--galant { background: var(--color-brand, #ffe32b); box-shadow: inset 0 0 0 1px var(--color-ink); }
.ps-cmp-value { flex: 0 0 7.5rem; white-space: nowrap; }
.ps-cmp-n { display: block; font-size: 12px; color: var(--color-muted); }
@media (max-width: 700px) {
  .ps-baro-chartcol { display: none; }
  .ps-baro { font-size: 13px; }
  .ps-baro th, .ps-baro td { padding: 0.4rem 0.25rem; }
  .ps-baro th[scope='row'], .ps-baro thead th { white-space: normal; }
  .ps-baro-reftrack { display: none; }
  .ps-cmp { font-size: 13px; }
  .ps-cmp th, .ps-cmp td { padding: 0.5rem 0.25rem; }
  .ps-cmp th[scope='row'] { width: 6.5rem; }
  .ps-cmp-cell { flex-direction: column; align-items: stretch; gap: 0.3rem; }
  .ps-cmp-track { flex: 0 0 14px; }
  .ps-cmp-value { flex: 0 0 auto; }
}

.ps-method { grid-column: 1 / -1; max-width: 90ch; margin: 0; font-size: var(--fs-300); color: var(--color-muted); }

@media (max-width: 900px) {
  .ps-explore, .ps-charts { grid-template-columns: 1fr; }
  .ps-kpis { grid-template-columns: repeat(2, 1fr); }
  .ps-why-grid { grid-template-columns: 1fr; }
  .ps-map { height: 60vh; min-height: 380px; }
}
@media (max-width: 480px) {
  .ps-bar-row { grid-template-columns: 7.5rem minmax(0, 1fr) 8rem; }
  .ps-delay-row { grid-template-columns: 6.5rem minmax(0, 1fr) 6rem; }
  .ps-delay-axis { margin-left: 6.5rem; margin-right: 6rem; }
  .ps-delay-value { font-size: 12px; }
  .ps-delay-n, .ps-tick-minor { display: none; }
  .ps-delay-table { font-size: 13px; }
  .ps-delay-table th, .ps-delay-table td { padding: 0.35rem 0.25rem; }
  .ps-bar-value .ps-muted { font-size: 12px; white-space: nowrap; }
}
