/* ==========================================================================
   Design tokens — "Perruches de Bruxelles"
   Concept: organic / nature. Parakeet green primary, warm parchment surfaces,
   collar-red + cavity-blue as data accents.
   ========================================================================== */

:root {
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.0625rem);
  --text-lg: clamp(1.125rem, 1rem + 0.6vw, 1.375rem);
  --text-xl: clamp(1.375rem, 1.1rem + 1vw, 1.875rem);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  --radius-sm: 0.375rem;
  --radius-md: 0.625rem;
  --radius-lg: 1rem;
  --radius-full: 9999px;

  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  --font-display: 'Zodiak', Georgia, serif;
  --font-body: 'Work Sans', 'Helvetica Neue', sans-serif;
}

:root,
[data-theme='light'] {
  --color-bg: #f6f4ec;
  --color-surface: #fffefb;
  --color-surface-2: #fbfaf3;
  --color-surface-offset: #eeead9;
  --color-border: #ddd6bf;
  --color-divider: #e6e1cd;

  --color-text: #22281d;
  --color-text-muted: #5c6353;
  --color-text-faint: #9a9c86;
  --color-text-inverse: #fbfaf3;

  --color-primary: #2f7a3d;
  --color-primary-hover: #235e2f;
  --color-primary-active: #194522;
  --color-primary-highlight: #d7e8d2;

  --color-notification: #b5423a;
  --color-notification-highlight: #f0d8d3;

  --color-gold: #c48a12;
  --color-gold-highlight: #ecdfbc;

  --color-blue: #4a6f92;
  --color-blue-highlight: #d6e2ec;

  --color-purple: #7c5aa6;
  --color-purple-highlight: #e3d9ee;

  --color-orange: #c56a25;
  --color-orange-highlight: #ecd9c4;

  --color-citizen: #c2368a;
  --color-citizen-highlight: #f3d9e8;

  --shadow-sm: 0 1px 2px rgba(30, 30, 20, 0.08);
  --shadow-md: 0 6px 20px rgba(30, 30, 20, 0.1);
  --shadow-lg: 0 16px 40px rgba(30, 30, 20, 0.16);
}

[data-theme='dark'] {
  --color-bg: #14180f;
  --color-surface: #191e13;
  --color-surface-2: #1d2216;
  --color-surface-offset: #232a1a;
  --color-border: #33402a;
  --color-divider: #2a3321;

  --color-text: #e4e6d8;
  --color-text-muted: #a3ab92;
  --color-text-faint: #6a7360;
  --color-text-inverse: #14180f;

  --color-primary: #6fbf6f;
  --color-primary-hover: #8bd28b;
  --color-primary-active: #a3dea3;
  --color-primary-highlight: #29391f;

  --color-notification: #e1857b;
  --color-notification-highlight: #3d2624;

  --color-gold: #e0b24d;
  --color-gold-highlight: #3d3320;

  --color-blue: #8fb0cf;
  --color-blue-highlight: #24303c;

  --color-purple: #b79bdb;
  --color-purple-highlight: #322a3e;

  --color-orange: #e0985a;
  --color-orange-highlight: #3d2f1e;

  --color-citizen: #e57ab5;
  --color-citizen-highlight: #3d2530;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.45);
}

/* ==========================================================================
   Base
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  overflow-y: auto;
  font-family: var(--font-body, sans-serif);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-bg);
  transition: background var(--transition-interactive), color var(--transition-interactive);
}

.app-viewport {
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

button { cursor: pointer; background: none; border: none; font: inherit; color: inherit; }
ul { list-style: none; }
a { color: var(--color-primary); }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.15; text-wrap: balance; }

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ==========================================================================
   Header
   ========================================================================== */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-6);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  z-index: 40;
  flex: 0 0 auto;
}

.brand { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.brand-mark { color: var(--color-primary); flex: none; }
.brand-text h1 {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  line-height: 1.25;
}
.brand-sub {
  font-size: var(--text-xs);
  font-weight: 400;
  color: var(--color-text-muted);
}
.brand-text p {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
}
.brand-text p em { font-style: italic; }

.topbar-actions { display: flex; align-items: center; gap: var(--space-2); flex: none; }

.icon-btn {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-full);
  color: var(--color-text-muted);
  transition: background var(--transition-interactive), color var(--transition-interactive);
}
.icon-btn:hover { background: var(--color-surface-offset); color: var(--color-text); }
.mobile-only { display: none; }

.lang-switch {
  display: flex;
  align-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: 2px;
  gap: 2px;
  flex: none;
}
.lang-btn {
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 5px 10px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--transition-interactive), color var(--transition-interactive);
}
.lang-btn:hover { color: var(--color-text); }
.lang-btn.is-active {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}

/* ==========================================================================
   Layout
   ========================================================================== */

.layout { flex: 1 1 auto; display: flex; min-height: 0; }

.sidebar {
  width: 328px;
  flex: none;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow: hidden;
  display: flex;
}
.sidebar-scroll {
  overflow-y: auto;
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  width: 100%;
}

.panel {
  background: var(--color-surface-2);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.panel h2 {
  font-size: var(--text-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-3);
  font-family: var(--font-body);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--text-sm);
  padding: var(--space-1) 0;
}
.filter-row { margin-top: var(--space-2); }
.filter-row:first-of-type { margin-top: 0; }
.filter-label { display: flex; align-items: center; gap: var(--space-2); font-weight: 500; }
.filter-desc {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin: var(--space-1) 0 var(--space-3) var(--space-6);
  line-height: 1.5;
}

.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot-occupation { background: var(--color-gold); }
.dot-nidification { background: #2f8f7e; }
.dot-exotiques { background: var(--color-notification); }
.dot-autres { background: var(--color-orange); }

/* Toggle switch look for checkboxes */
input[type="checkbox"] {
  appearance: none;
  width: 36px; height: 21px;
  background: var(--color-border);
  border-radius: var(--radius-full);
  position: relative;
  flex: none;
  transition: background var(--transition-interactive);
}
input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 17px; height: 17px;
  border-radius: 50%;
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-interactive);
}
input[type="checkbox"]:checked { background: var(--color-primary); }
input[type="checkbox"]:checked::after { transform: translateX(15px); }

.legend-list { display: flex; flex-direction: column; gap: var(--space-2); margin: var(--space-3) 0; }
.legend-list li { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-xs); color: var(--color-text-muted); }
.legend-swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.legend-swatch-citizen { border-radius: 50%; background: var(--color-citizen); }

.btn-report {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  margin-top: var(--space-3);
  padding: var(--space-2) var(--space-4);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: 600;
  transition: background var(--transition-interactive);
}
.btn-report:hover { background: var(--color-primary-hover); }

.panel-note { font-size: var(--text-xs); color: var(--color-text-faint); line-height: 1.5; }
.panel-placeholder { font-size: var(--text-xs); color: var(--color-text-faint); line-height: 1.5; }

.sponsor-panel {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.sponsor-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-faint);
  flex: none;
}
.sponsor-link {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #fff;
  padding: var(--space-2) var(--space-3);
  transition: opacity var(--transition-interactive);
}
.sponsor-link:hover { opacity: 0.85; }
.sponsor-logo {
  display: block;
  width: 100%;
  height: auto;
  max-height: 28px;
  object-fit: contain;
}

#detail-panel { flex: 1 1 auto; min-height: 180px; }
.detail-title { font-family: var(--font-display); font-size: var(--text-lg); margin-bottom: var(--space-1); color: var(--color-text); }
.detail-tag {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  margin: var(--space-1) var(--space-1) var(--space-2) 0;
}
.detail-commune { font-size: var(--text-xs); color: var(--color-text-muted); margin-bottom: var(--space-3); }
.detail-summary { font-size: var(--text-sm); font-weight: 500; margin-bottom: var(--space-2); }
.detail-body { font-size: var(--text-xs); color: var(--color-text-muted); line-height: 1.6; margin-bottom: var(--space-3); }
.detail-sources { font-size: var(--text-xs); display: flex; flex-direction: column; gap: var(--space-1); }
.detail-sources a { text-decoration: underline; color: var(--color-primary); }

/* ==========================================================================
   Map
   ========================================================================== */

.map-wrap { position: relative; flex: 1 1 auto; min-width: 0; }
#map { position: absolute; inset: 0; background: var(--color-surface-offset); }

.map-hint {
  position: absolute;
  bottom: var(--space-4);
  left: 50%;
  transform: translateX(-50%);
  background: color-mix(in srgb, var(--color-surface) 92%, transparent);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  box-shadow: var(--shadow-md);
  pointer-events: none;
  z-index: 5;
}

.report-fab {
  position: absolute;
  right: var(--space-4);
  bottom: var(--space-4);
  z-index: 6;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-size: var(--text-sm);
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  transition: background var(--transition-interactive), transform var(--transition-interactive);
}
.report-fab:hover { transform: translateY(-2px); }
.report-fab.is-active { background: var(--color-notification); }

.report-banner {
  position: absolute;
  top: var(--space-4);
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: color-mix(in srgb, var(--color-surface) 94%, transparent);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4);
  font-size: var(--text-xs);
  color: var(--color-text);
  box-shadow: var(--shadow-md);
  max-width: min(92vw, 460px);
}
.report-banner[hidden] { display: none; }
.report-banner button {
  flex: none;
  padding: 4px var(--space-3);
  border-radius: var(--radius-full);
  background: var(--color-surface-offset);
  font-size: var(--text-xs);
  font-weight: 600;
}
.report-banner button:hover { background: var(--color-border); }

.popup-note {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin-top: var(--space-2);
  font-style: italic;
}

.maplibregl-popup-content {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-lg) !important;
  padding: var(--space-4) !important;
  font-family: var(--font-body);
  max-width: 260px;
}
.maplibregl-popup-tip { border-top-color: var(--color-surface) !important; border-bottom-color: var(--color-surface) !important; }
.popup-title { font-family: var(--font-display); font-size: var(--text-base); margin-bottom: var(--space-1); }
.popup-summary { font-size: var(--text-xs); color: var(--color-text-muted); line-height: 1.5; }
.maplibregl-ctrl-attrib { font-size: 10px !important; }

/* ==========================================================================
   Modal
   ========================================================================== */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 18, 10, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-6);
  z-index: 100;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  max-width: 640px;
  width: 100%;
  max-height: 84vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow-lg);
}
.modal h2 { font-size: var(--text-xl); margin-bottom: var(--space-4); }
.modal h3 { font-size: var(--text-base); margin: var(--space-5) 0 var(--space-2); }
.modal p { font-size: var(--text-sm); color: var(--color-text-muted); line-height: 1.65; margin-bottom: var(--space-3); }
.modal ul { padding-left: var(--space-5); list-style: disc; margin-bottom: var(--space-3); }
.modal li { font-size: var(--text-sm); color: var(--color-text-muted); line-height: 1.65; margin-bottom: var(--space-2); }
.source-list { padding-left: 0; list-style: none; }
.source-list li { margin-bottom: var(--space-1); }
.source-list a { font-size: var(--text-sm); word-break: break-word; }
.modal-close {
  position: absolute; top: var(--space-4); right: var(--space-4);
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; color: var(--color-text-muted);
}
.modal-close:hover { background: var(--color-surface-offset); color: var(--color-text); }

/* ==========================================================================
   Content article (SEO)
   ========================================================================== */

.content-article {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
}
.content-article-inner {
  max-width: 920px;
  margin: 0 auto;
  padding: var(--space-12) var(--space-6) var(--space-12);
}
.content-article h2 {
  font-size: var(--text-xl);
  margin-bottom: var(--space-4);
  color: var(--color-text);
}
.content-lead {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.7;
  max-width: 68ch;
  margin-bottom: var(--space-8);
}
.content-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-5);
  margin-bottom: var(--space-10);
}
.content-card {
  background: var(--color-surface-2);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}
.content-card h3 {
  font-size: var(--text-sm);
  margin-bottom: var(--space-2);
  color: var(--color-text);
}
.content-card p {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: 1.6;
}
.content-faq-title {
  font-size: var(--text-lg);
  margin-bottom: var(--space-4);
  color: var(--color-text);
}
.content-faq {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-8);
}
.content-faq details {
  background: var(--color-surface-2);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
}
.content-faq summary {
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  list-style: none;
}
.content-faq summary::-webkit-details-marker { display: none; }
.content-faq summary::before {
  content: '+';
  display: inline-block;
  width: 1em;
  color: var(--color-primary);
  font-weight: 700;
}
.content-faq details[open] summary::before { content: '\2212'; }
.content-faq p {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: 1.6;
  margin-top: var(--space-2);
  padding-left: 1em;
}
.content-sources {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  line-height: 1.6;
}
.content-sources a { color: var(--color-text-faint); text-decoration: underline; }

@media (max-width: 860px) {
  .content-grid { grid-template-columns: 1fr; }
  .content-article-inner { padding: var(--space-10) var(--space-4); }
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 860px) {
  .mobile-only { display: flex; }
  .layout { position: relative; }
  .sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(86vw, 360px);
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    transition: transform var(--transition-interactive);
  }
  .sidebar.open { transform: translateX(0); }
  .map-hint { display: none; }
  .brand-text p { display: none; }
  .brand-sub { display: none; }
  .report-fab span { display: none; }
  .report-fab { padding: var(--space-3); }
  .report-banner { top: auto; bottom: var(--space-4); font-size: 11px; }
}
