@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700;800;900&family=Plus+Jakarta+Sans:wght@700;800;900&display=swap');

:root {
  --petrol:    #004a60;
  --petrol-d:  #003548;
  --petrol-l:  #005a75;
  --teal:      #008593;
  --cyan:      #3aa9d8;
  --green:     #9bc83d;
  --orange:    #f39100;
  --magenta:   #d91668;
  --aubergine: #9c1b62;

  --ink:   #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --line:  #e2e8f0;
  --bg:    #f8fafc;
  --white: #ffffff;

  --stripe: linear-gradient(90deg,
    var(--cyan) 0%, var(--green) 28%,
    var(--orange) 54%, var(--magenta) 78%,
    var(--aubergine) 100%);

  --shadow-xs: 0 1px 2px rgba(15,23,42,.05);
  --shadow-sm: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
  --shadow:    0 4px 16px rgba(15,23,42,.08), 0 1px 4px rgba(15,23,42,.04);
  --shadow-lg: 0 16px 48px rgba(15,23,42,.14), 0 4px 16px rgba(15,23,42,.06);

  --r: 10px;
  --ease: 140ms cubic-bezier(.4,0,.2,1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; scroll-behavior: smooth; }

body {
  height: 100%;
  color: var(--ink);
  background: var(--petrol-d);
  font-family: 'Poppins', ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-weight: 500;
  font-size: 0.9375rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; border: 0; }

/* ══ Transitions de page ══ */
@view-transition { navigation: auto; }

::view-transition-old(root) { animation: 180ms ease both fade-out; }
::view-transition-new(root) { animation: 220ms ease both fade-in; }

@keyframes fade-out { from { opacity: 1 } to { opacity: 0 } }
@keyframes fade-in  { from { opacity: 0; transform: translateY(6px) } to { opacity: 1; transform: none } }

/* ══ Barre signature ══ */
body::before {
  content: "";
  display: block;
  height: 4px;
  background: var(--stripe);
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 200;
}

/* ══ Shell ══ */
.shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  height: 100vh;
  padding-top: 4px; /* stripe */
}

/* ══ Sidebar ══ */
.sidebar {
  background: var(--petrol);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Logo ── */
.brand {
  display: block;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}

.brand-logo {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 0;
}

.brand-text strong {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--white);
  line-height: 1.3;
}
.brand-text small {
  display: block;
  font-size: 0.7rem;
  color: rgba(255,255,255,.45);
  margin-top: 1px;
}

/* ── Navigation territoriale ── */
.territory-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.territory-header {
  padding: 10px 14px 8px;
  flex-shrink: 0;
}

.territory-back {
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  color: rgba(255,255,255,.5);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
  margin-bottom: 4px;
  transition: color var(--ease);
}
.territory-back:hover { color: var(--white); }
.territory-back.hidden { display: none; }

.territory-crumb {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: rgba(255,255,255,.35);
  margin: 0;
}

.territory-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 4px 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.territory-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 10px;
  background: transparent;
  border: none;
  border-radius: 7px;
  color: rgba(255,255,255,.8);
  font: inherit;
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
  transition: background var(--ease), color var(--ease);
}
.territory-item:hover { background: rgba(255,255,255,.08); color: var(--white); }
.territory-item.active { background: rgba(255,255,255,.12); color: var(--white); }

.territory-item-main { flex: 1; min-width: 0; }
.territory-item-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.territory-item-sub  { font-size: 0.72rem; color: rgba(255,255,255,.38); margin-top: 1px; }
.territory-item-num  { font-family: 'Plus Jakarta Sans', ui-sans-serif, system-ui, sans-serif; font-size: 0.88rem; font-weight: 700; color: rgba(255,255,255,.55); flex-shrink: 0; margin-left: 8px; }
.territory-item-arrow { color: rgba(255,255,255,.25); margin-left: 4px; flex-shrink: 0; }

/* ── Recherche ── */
.search-zone {
  padding: 14px 14px 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
  position: relative;
  width: 100%;
  box-sizing: border-box;
}

.search-row {
  display: flex;
  gap: 7px;
  width: 100%;
  box-sizing: border-box;
}

.search-input {
  flex: 1;
  height: 38px;
  background: rgba(255,255,255,.1);
  border: 1.5px solid rgba(255,255,255,.14);
  border-radius: 8px;
  padding: 0 11px;
  color: var(--white);
  font: inherit;
  font-size: 0.85rem;
  transition: background var(--ease), border-color var(--ease);
}
.search-input::placeholder { color: rgba(255,255,255,.38); }
.search-input:focus {
  outline: none;
  background: rgba(255,255,255,.15);
  border-color: rgba(255,255,255,.35);
}

.btn-search {
  width: 38px;
  height: 38px;
  background: rgba(255,255,255,.12);
  color: var(--white);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--ease);
}
.btn-search:hover { background: rgba(255,255,255,.2); }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 9px;
}
.chips button {
  height: 25px;
  padding: 0 10px;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 999px;
  color: rgba(255,255,255,.7);
  font-size: 0.75rem;
  font-weight: 500;
  transition: background var(--ease), color var(--ease);
}
.chips button:hover {
  background: rgba(255,255,255,.18);
  color: var(--white);
}

/* ── Dropdown résultats ── */
.results-list {
  display: none;
  flex-direction: column;
  position: absolute;
  top: calc(100% - 1px);
  left: 0; right: 0;
  z-index: 50;
  padding: 5px;
  gap: 2px;
  background: var(--petrol-d);
  border-top: 1px solid rgba(255,255,255,.08);
  box-shadow: 0 20px 40px rgba(0,0,0,.35);
  max-height: 300px;
  overflow-y: auto;
}
.results-list.open { display: flex; }

.result-card {
  width: 100%;
  padding: 9px 11px;
  text-align: left;
  background: transparent;
  border-radius: 7px;
  color: rgba(255,255,255,.8);
  font-size: 0.85rem;
  display: block;
  transition: background var(--ease), color var(--ease);
}
.result-card:hover { background: rgba(255,255,255,.08); color: var(--white); }
.result-card.active { background: rgba(255,255,255,.12); color: var(--white); }
.result-card strong { display: block; font-weight: 600; color: var(--white); }
.result-card span   { display: block; margin-top: 1px; font-size: 0.76rem; color: rgba(255,255,255,.45); }

.no-result { color: rgba(255,255,255,.4); font-size: 0.85rem; padding: 8px 4px; }

.result-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  vertical-align: middle;
  margin-left: 5px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.result-badge--region { background: var(--color-region); color: #fff; }
.result-badge--dept   { background: var(--color-dept);   color: #fff; }

.result-separator {
  padding: 6px 11px 4px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: rgba(255,255,255,.25);
  border-top: 1px solid rgba(255,255,255,.08);
  margin-top: 4px;
}

/* ── Stats sidebar ── */
.sidebar-stats {
  padding: 16px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.sidebar-stat {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 6px;
}
.sidebar-stat:last-child { margin-bottom: 0; }
.sidebar-stat strong {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--white);
  letter-spacing: -0.02em;
}
.sidebar-stat span {
  font-size: 0.76rem;
  color: rgba(255,255,255,.45);
}

/* ── Hint ── */
.sidebar-hint {
  padding: 12px 18px;
  font-size: 0.76rem;
  color: rgba(255,255,255,.3);
  line-height: 1.5;
  flex-shrink: 0;
}
.sidebar-hint strong { color: rgba(255,255,255,.5); font-weight: 600; }

/* ── Fil d'Ariane principal ── */
.main-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 16px 24px 0;
  margin-bottom: 20px;
  font-size: 0.78rem;
  color: var(--muted);
  flex-wrap: wrap;
  flex-shrink: 0;
}
.main-breadcrumb a,
.main-breadcrumb button {
  background: none;
  border: none;
  font: inherit;
  font-size: inherit;
  color: var(--petrol);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.main-breadcrumb a:hover,
.main-breadcrumb button:hover { color: var(--petrol-d); }
.main-breadcrumb .bc-sep { color: var(--faint); }
.main-breadcrumb .bc-current { color: var(--ink); font-weight: 600; }

/* ── Nav sidebar ── */
.sidebar-nav {
  margin-top: auto;
  padding: 12px 10px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}
.sidebar-nav a {
  display: block;
  padding: 7px 10px;
  border-radius: 7px;
  color: rgba(255,255,255,.5);
  font-size: 0.8rem;
  font-weight: 500;
  transition: color var(--ease), background var(--ease);
}
.sidebar-nav a:hover { color: var(--white); background: rgba(255,255,255,.08); }
.sidebar-nav a.active { color: var(--white); }
.sidebar-nav-back { display: flex !important; align-items: center; gap: 5px; }

.btn-back {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px clamp(20px, 3vw, 40px);
  background: none;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  border-bottom: 1px solid var(--line);
  width: 100%;
  transition: color var(--ease), background var(--ease);
}
.btn-back:hover { color: var(--teal); background: color-mix(in srgb, var(--teal) 5%, transparent); }
.btn-back svg { flex-shrink: 0; }

/* ── Fil d'Ariane ── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.crumb-link {
  background: none;
  padding: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  transition: color var(--ease);
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 2px;
}
.crumb-link:hover {
  color: var(--teal);
  text-decoration-color: var(--teal);
}
.crumb-sep {
  color: var(--faint);
  font-size: 0.78rem;
  user-select: none;
}
.crumb-current {
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 600;
}

/* ══ Panneau principal ══ */
.main-panel {
  position: relative;
  background: var(--bg);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ── État vide ── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(40px, 6vw, 80px);
}

.empty-illustration {
  display: flex;
  gap: 10px;
  margin-bottom: 36px;
}

.empty-dot {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  opacity: 0.9;
}

.eyebrow {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--teal);
  margin-bottom: 14px;
}

.empty-state h1 {
  font-size: clamp(28px, 4vw, 48px);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.1;
  color: var(--ink);
  max-width: 520px;
  margin-bottom: 18px;
}

.empty-state > p {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.75;
  max-width: 440px;
}

.hidden { display: none !important; }

/* ── Écran de chargement skeleton ── */
.loading-screen {
  position: absolute;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  overflow-y: auto;
  pointer-events: none;
}

.skel-wrap {
  padding: clamp(28px, 4vw, 52px);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Blocs skeleton de base */
.skel {
  border-radius: 8px;
  background: linear-gradient(
    90deg,
    #e2e8f0 0%,
    #f1f5f9 40%,
    #e2e8f0 80%
  );
  background-size: 300% 100%;
  animation: shimmer 1.6s ease-in-out infinite;
}

@keyframes shimmer {
  0%   { background-position: 200% center; }
  100% { background-position: -200% center; }
}

/* Header */
.skel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
  gap: 16px;
}
.skel-eyebrow   { height: 14px; width: 160px; margin-bottom: 10px; }
.skel-title     { height: 32px; width: 280px; margin-bottom: 8px; border-radius: 6px; }
.skel-subtitle  { height: 14px; width: 220px; }
.skel-btns      { display: flex; gap: 10px; flex-shrink: 0; padding-top: 4px; }
.skel-btn       { height: 36px; width: 80px; border-radius: 6px; }
.skel-btn--primary { width: 104px; }

/* Mini carte */
.skel-map {
  height: 180px;
  border-radius: var(--r);
}

/* Hero stat */
.skel-hero {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 28px 32px;
  background: #f1f5f9;
  border-radius: var(--r);
  border-left: 4px solid #e2e8f0;
}
.skel-hero-num   { height: 56px; width: 140px; border-radius: 6px; flex-shrink: 0; }
.skel-hero-divider { width: 1px; align-self: stretch; background: #e2e8f0; flex-shrink: 0; }
.skel-hero-label { height: 18px; width: 200px; margin-bottom: 8px; }
.skel-hero-sub   { height: 13px; width: 140px; }

/* Métriques grid */
.skel-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.skel-metric {
  height: 96px;
  border-radius: var(--r);
}

/* Cartes détail */
.skel-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.skel-detail-card {
  padding: 20px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--r);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.skel-card-title       { height: 18px; width: 55%; }
.skel-card-line        { height: 13px; width: 100%; }
.skel-card-line--short { width: 60%; }
.skel-card-line--med   { width: 80%; }

/* ══ Fiche commune ══ */
.commune-detail {
  flex: 1;
  padding: clamp(28px, 4vw, 52px);
}

/* ── En-tête commune ── */
.detail-header {
  margin-bottom: 28px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--line);
}

.detail-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.detail-meta .eyebrow { margin: 0; }
.detail-meta .breadcrumb { margin-bottom: 0; }

.code-badge {
  padding: 3px 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.detail-title-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.detail-title-row > div:first-child {
  flex: 1 1 0;
  min-width: 0;
}

.export-group {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  align-self: flex-end;
}

.export-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  border-radius: 8px;
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--ease), color var(--ease), border-color var(--ease);
  background: var(--white);
  color: var(--muted);
  border: 1.5px solid var(--line);
}
.export-btn:hover {
  background: var(--bg);
  color: var(--ink);
  border-color: #94a3b8;
}
.export-btn--primary {
  background: var(--petrol);
  color: var(--white);
  border-color: var(--petrol);
}
.export-btn--primary:hover {
  background: var(--petrol-l);
  border-color: var(--petrol-l);
  color: var(--white);
}

.detail-header h2 {
  font-size: clamp(36px, 5vw, 62px);
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 0.95;
  color: var(--petrol);
}

.detail-mission-name {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 500;
  margin-top: 10px;
}

/* ── Hero stat ── */
.hero-stat {
  background: var(--petrol);
  border-radius: var(--r);
  padding: 24px 28px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 24px;
  position: relative;
  overflow: hidden;
}

.hero-stat::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: var(--stripe);
}

.hero-number {
  font-family: 'Plus Jakarta Sans', ui-sans-serif, system-ui, sans-serif;
  font-size: clamp(44px, 6vw, 68px);
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--white);
  flex-shrink: 0;
}

.hero-divider {
  width: 1px;
  height: 52px;
  background: rgba(255,255,255,.15);
  flex-shrink: 0;
}

.hero-label strong {
  display: block;
  font-size: 1rem;
  font-weight: 700;
  color: var(--white);
  margin-bottom: 3px;
}
.hero-label span {
  font-size: 0.82rem;
  color: rgba(255,255,255,.55);
  line-height: 1.4;
}

/* ── Métriques ── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.metric {
  background: var(--white);
  border-radius: var(--r);
  padding: 18px 20px 16px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--ease), transform var(--ease);
  position: relative;
  overflow: hidden;
}
.metric::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.metric:nth-child(1)::before { background: var(--teal); }
.metric:nth-child(2)::before { background: var(--orange); }
.metric:nth-child(3)::before { background: var(--green); }
.metric:nth-child(4)::before { background: var(--magenta); }
.metric:nth-child(5)::before { background: var(--cyan); }
.metric:nth-child(6)::before { background: var(--aubergine); }
.metric:nth-child(7)::before { background: var(--orange); }

.metric:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.metric strong {
  display: block;
  font-family: 'Plus Jakarta Sans', ui-sans-serif, system-ui, sans-serif;
  font-size: 1.9rem;
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--ink);
  margin-bottom: 6px;
}
.metric span {
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.35;
  display: block;
}

/* ── Détail contact + actions ── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.detail-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 22px 24px;
  box-shadow: var(--shadow-xs);
}

.detail-card h3 {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--faint);
  margin-bottom: 16px;
}

.definition-list {}
.definition-list div {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.875rem;
  align-items: baseline;
}
.definition-list div:last-child { border-bottom: 0; padding-bottom: 0; }
.definition-list dt { color: var(--muted); font-weight: 500; font-size: 0.82rem; }
.definition-list dd { color: var(--ink); }

.actions-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.actions-list li {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--ink);
}
.actions-list li::before {
  content: "";
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 7px;
  background: var(--green);
}
.actions-list li:nth-child(2)::before { background: var(--orange); }
.actions-list li:nth-child(3)::before { background: var(--magenta); }

/* ══ Illustration cartographique ══ */
.map-illustration {
  display: flex;
  justify-content: flex-end;
  position: absolute;
  top: 24px;
  right: 24px;
  width: 110px;
  height: 122px;
  pointer-events: none;
  opacity: .85;
}

.map-illustration svg {
  width: 110px;
  height: 122px;
  filter: drop-shadow(0 2px 6px rgba(15,23,42,.12));
}

.detail-header {
  position: relative;
}

/* ══ Code couleur territorial ══ */
:root {
  --color-region:  #3aa9d8;
  --color-dept:    #f39100;
  --color-commune: #9bc83d;
  --color-epci:    #9c1b62;
}

/* Eyebrow coloré */
[data-territory="region"]  .eyebrow { color: var(--color-region); }
[data-territory="dept"]    .eyebrow { color: var(--color-dept); }
[data-territory="commune"] .eyebrow { color: var(--color-commune); }
[data-territory="epci"]    .eyebrow { color: var(--color-epci); }

/* Barre colorée en haut du hero */
[data-territory="region"]  .hero-stat { border-top: 3px solid var(--color-region); }
[data-territory="dept"]    .hero-stat { border-top: 3px solid var(--color-dept); }
[data-territory="commune"] .hero-stat { border-top: 3px solid var(--color-commune); }
[data-territory="epci"]    .hero-stat { border-top: 3px solid var(--color-epci); }

/* Badge type dans le header */
.territory-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 8px;
  vertical-align: middle;
}
[data-territory="region"]  .territory-badge { background: color-mix(in srgb, var(--color-region) 15%, transparent); color: var(--color-region); }
[data-territory="dept"]    .territory-badge { background: color-mix(in srgb, var(--color-dept) 15%, transparent); color: var(--color-dept); }
[data-territory="commune"] .territory-badge { background: color-mix(in srgb, var(--color-commune) 15%, transparent); color: var(--color-commune); }
[data-territory="epci"]    .territory-badge { background: color-mix(in srgb, var(--color-epci) 15%, transparent); color: var(--color-epci); }

/* Badge résultat EPCI */
.result-badge--epci { background: var(--color-epci); color: #fff; }

/* Liste des communes de l'EPCI */
.epci-communes {
  margin-top: 8px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.epci-communes-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin-bottom: 10px;
}
.epci-communes-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.epci-ml-group {
  margin-bottom: 14px;
}
.epci-ml-group:last-child {
  margin-bottom: 0;
}
.epci-ml-name {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 6px;
}
.epci-ml-name--btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  padding: 0;
  cursor: pointer;
  transition: color var(--ease);
}
.epci-ml-name--btn:hover { color: var(--teal); }
.epci-ml-name--btn svg { transition: transform var(--ease); }
.epci-ml-name--btn.open svg { transform: rotate(180deg); }
.epci-ml-details {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.78rem;
  color: var(--muted);
  padding: 8px 12px;
  margin-bottom: 8px;
  border-left: 2px solid var(--color-epci);
  background: color-mix(in srgb, var(--color-epci) 4%, transparent);
  border-radius: 0 6px 6px 0;
}
.epci-ml-details a { color: var(--teal); text-decoration: none; }
.epci-ml-details a:hover { text-decoration: underline; }
.epci-commune-tag {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--color-epci) 10%, transparent);
  color: var(--color-epci);
  border: 1px solid color-mix(in srgb, var(--color-epci) 20%, transparent);
}

/* Notice anonymat EPCI */
.epci-notice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: color-mix(in srgb, var(--color-epci) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-epci) 25%, transparent);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 0.78rem;
  color: var(--color-epci);
  line-height: 1.5;
  margin-top: 8px;
}
.epci-notice svg { flex-shrink: 0; margin-top: 2px; }

/* ══ Contenu principal ══ */
#main-content { flex: 1; }

/* ══ Grille territoire (régions / depts) ══ */
.territory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.territory-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px 20px 16px;
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  transition: box-shadow var(--ease), transform var(--ease);
  position: relative;
  overflow: hidden;
}
.territory-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--stripe);
}
.territory-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}
.territory-card h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 4px;
  line-height: 1.3;
}
.territory-card .t-sub {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 14px;
}
.territory-card .t-num {
  font-family: 'Plus Jakarta Sans', ui-sans-serif, system-ui, sans-serif;
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: -0.04em;
  color: var(--petrol);
  line-height: 1;
  margin-bottom: 3px;
}
.territory-card .t-lbl {
  font-size: 0.72rem;
  color: var(--muted);
}
.territory-card .t-stats {
  display: flex;
  gap: 14px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.territory-card .t-stat strong {
  display: block;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink);
}
.territory-card .t-stat span {
  font-size: 0.68rem;
  color: var(--muted);
}

/* Vue nationale hero */
.national-hero {
  background: var(--petrol);
  border-radius: var(--r);
  padding: 28px 32px;
  color: var(--white);
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
}
.national-hero::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 4px;
  background: var(--stripe);
}
.national-hero .nh-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: rgba(255,255,255,.5);
  margin-bottom: 10px;
}
.national-hero .nh-num {
  font-family: 'Plus Jakarta Sans', ui-sans-serif, system-ui, sans-serif;
  font-size: clamp(44px, 6vw, 72px);
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 1;
  margin-bottom: 6px;
}
.national-hero .nh-sub { font-size: 0.9rem; color: rgba(255,255,255,.6); }

/* ══ Responsive ══ */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; height: auto; }
  .sidebar { height: auto; position: relative; z-index: 20; }
  .main-panel { min-height: 100vh; }
  .sidebar-stats, .sidebar-nav { display: none; }
  .results-list { max-height: 240px; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-grid  { grid-template-columns: 1fr; }
  .brand-logo { max-width: 180px; }

  /* Les coordonnées de la Mission Locale remontent avant la grille de métriques,
     pour ne pas les enterrer sous plusieurs écrans de défilement sur mobile. */
  #commune-detail { display: flex; flex-direction: column; }
  #commune-detail .detail-header { order: 1; }
  #commune-detail #map-commune   { order: 2; }
  #commune-detail #hero-stat     { order: 3; }
  #commune-detail .detail-grid   { order: 4; }
  #commune-detail #metrics-grid  { order: 5; }
}

@media (max-width: 560px) {
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-title-row { flex-direction: column; align-items: flex-start; gap: 8px; }
  .definition-list div { grid-template-columns: 1fr; gap: 2px; }
  .hero-stat { flex-direction: column; align-items: flex-start; gap: 12px; }
  .hero-divider { display: none; }

  /* Cibles tactiles agrandies et champ de recherche sans zoom automatique iOS (16px min) */
  .search-input { height: 44px; font-size: 16px; }
  .btn-search { width: 44px; height: 44px; }
  .chips button { height: 34px; padding: 0 12px; font-size: 0.78rem; }
  .export-btn { min-height: 40px; }
  .crumb-link { padding: 4px 0; }
  .epci-ml-name--btn { padding: 6px 0; }

  /* Titres moins imposants sur petit écran pour limiter le retour à la ligne */
  .detail-header h2 { font-size: clamp(26px, 8vw, 36px); }

  .export-group { width: 100%; }
  .export-btn { flex: 1; justify-content: center; }
}
