:root {
  --green: #1e8449;
  --green-light: #82c341;
  --yellow: #f1c40f;
  --red: #c0392b;
  --ink: #1c2b25;
  --muted: #64766c;
  --border: #dfe6e0;
  --bg: #f6f8f6;
  --card: #ffffff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.topbar {
  background: var(--green);
  color: white;
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  text-align: center;
}
.topbar .brand { color: white; font-weight: 700; font-size: 1.2rem; text-decoration: none; display: inline-flex; align-items: center; gap: 0.45rem; }
.topbar .brand-icon { flex-shrink: 0; }
.topbar .tagline { font-size: 0.85rem; opacity: 0.9; }

.container { max-width: none; margin: 0 auto; padding: 1.5rem 2rem; }

h1 { margin: 0.2rem 0; }
h2 { margin-top: 0; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.2rem;
}
.card.error { border-color: var(--red); background: #fdecea; color: #7a2018; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
}
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }

form label {
  display: block;
  margin-bottom: 0.8rem;
  font-size: 0.9rem;
  font-weight: 600;
}
form input, form select, form textarea {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
}

button, .button {
  display: inline-block;
  background: var(--green);
  color: white;
  border: none;
  padding: 0.6rem 1.1rem;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
button:hover, .button:hover { background: #166a3a; }

.table { width: 100%; border-collapse: collapse; margin-top: 0.5rem; }
.table th, .table td {
  text-align: left;
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
.table th { color: var(--muted); font-weight: 600; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  color: white;
}
.badge.good { background: var(--green); }
.badge.warn { background: #c98a12; }
.badge.bad { background: var(--red); }

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin: 1.2rem 0;
}
@media (max-width: 760px) { .kpi-row { grid-template-columns: 1fr 1fr; } }
.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  text-align: center;
}
.kpi-value { font-size: 1.8rem; font-weight: 800; color: var(--green); }
.kpi-value.warn { color: #c98a12; }
.kpi-value.bad { color: var(--red); }
.kpi-unit { font-size: 1rem; color: var(--muted); font-weight: 500; }
.kpi-label { font-size: 0.82rem; color: var(--muted); margin-top: 0.2rem; }
.kpi-delta { font-size: 0.8rem; margin-top: 0.4rem; font-weight: 700; }
.kpi-delta.good { color: var(--green); }
.kpi-delta.bad { color: var(--red); }

.legend { display: flex; gap: 1rem; margin-top: 0.8rem; font-size: 0.85rem; flex-wrap: wrap; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 0.35rem; vertical-align: middle; }

.report-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }

.insight {
  border-left: 4px solid var(--border);
  padding: 0.5rem 0.9rem;
  margin-bottom: 0.7rem;
  border-radius: 0 6px 6px 0;
  background: var(--bg);
}
.insight:last-child { margin-bottom: 0; }
.insight p { margin: 0.2rem 0 0; font-size: 0.9rem; color: var(--muted); }
.insight-critique { border-left-color: var(--red); }
.insight-warn { border-left-color: #c98a12; }
.insight-good { border-left-color: var(--green); }
.insight-info { border-left-color: #2f6fa8; }

.zone-label {
  background: rgba(255,255,255,0.85);
  border: none;
  box-shadow: none;
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--ink);
}

@media print {
  .topbar, .no-print, a.button { display: none !important; }
  .container { max-width: 100%; }
}

/* Masque spotlight (carte vol) : evenodd ignore le sens de tracage de
   chaque contour (horaire/antihoraire), sinon un trou du masque dessine
   dans le "mauvais" sens s'affiche plein au lieu d'etre decoupe. */
.spotlight-mask { fill-rule: evenodd; }

.weather-card { margin-bottom: 1.5rem; }
.weather-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}
.weather-head h2 { margin: 0; }
.weather-period { font-size: 0.85rem; color: var(--muted); }

.weather-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.4rem;
}
@media (max-width: 600px) { .weather-metrics { grid-template-columns: 1fr; } }

.weather-metric { display: flex; align-items: center; gap: 0.8rem; }
.weather-icon {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.weather-icon svg { width: 20px; height: 20px; }
.weather-icon.rain { background: #e5f0fa; color: #2f6fa8; }
.weather-icon.et0 { background: #fdf1de; color: #c98a12; }

.weather-metric-body { flex: 1; min-width: 0; }
.weather-metric-top { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.weather-metric-value { font-size: 1.25rem; font-weight: 800; }
.weather-metric-label { font-size: 0.78rem; color: var(--muted); }
.weather-bar-track { position: relative; background: var(--bg); border-radius: 999px; height: 7px; margin-top: 0.4rem; }
.weather-bar-fill { height: 100%; border-radius: 999px; transition: width 0.3s ease; }
.weather-bar-fill.rain { background: #2f6fa8; }
.weather-bar-fill.et0 { background: #c98a12; }
.weather-bar-normal {
  position: absolute; top: -3px; bottom: -3px; width: 2px;
  background: var(--ink); opacity: 0.5; border-radius: 1px;
}
.weather-normal-note { font-size: 0.78rem; color: var(--muted); margin-top: 0.35rem; }

.weather-balance {
  margin-top: 1.1rem;
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
}
.weather-balance.deficit { background: #fdecea; }
.weather-balance.surplus { background: #eaf7ee; }
.weather-balance.neutral { background: var(--bg); }
.weather-balance-label { font-size: 0.85rem; color: var(--muted); }
.weather-balance-value { font-size: 1.15rem; font-weight: 800; }
.weather-balance-value.deficit { color: var(--red); }
.weather-balance-value.surplus { color: var(--green); }

.flash { background: #eaf7ee; border: 1px solid var(--green); color: var(--green); border-radius: 8px; padding: 0.7rem 1rem; margin-bottom: 1rem; font-weight: 600; transition: opacity 0.6s; }

/* Barre d'avancement de l'import d'un vol */
.progress-box { margin-top: 1rem; }
.progress-title { font-weight: 600; margin-bottom: 0.4rem; }
.progress-track { background: var(--border); border-radius: 999px; height: 14px; overflow: hidden; margin-bottom: 0.4rem; }
.progress-bar { height: 100%; width: 0; background: var(--green); transition: width 0.4s ease; }
.progress-bar.working {
  background-image: linear-gradient(45deg, rgba(255,255,255,0.25) 25%, transparent 25%, transparent 50%, rgba(255,255,255,0.25) 50%, rgba(255,255,255,0.25) 75%, transparent 75%);
  background-size: 28px 28px;
  animation: progress-stripes 1s linear infinite;
}
@keyframes progress-stripes { from { background-position: 0 0; } to { background-position: 28px 0; } }
#progressError { margin-top: 1rem; padding: 0.8rem 1rem; border-radius: 8px; border: 1px solid #c0392b; background: #fdecea; color: #7b241c; }

/* ===== Refonte visuelle (surcharges) ===== */
:root {
  --green: #1b7f4a;
  --green-dark: #14633a;
  --green-soft: #e8f4ec;
  --ink: #17251e;
  --muted: #5f7167;
  --border: #e2e8e3;
  --bg: #f4f7f4;
  --shadow-sm: 0 1px 2px rgba(20, 40, 28, 0.06), 0 1px 3px rgba(20, 40, 28, 0.04);
  --shadow-md: 0 4px 14px rgba(20, 40, 28, 0.08);
  --radius: 14px;
}
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased;
  background: var(--bg);
}
h1 { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.02em; margin: 0.4rem 0 0.2rem; }
h2 { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 0.8rem; }
h3 { font-weight: 700; }
a { color: var(--green-dark); text-underline-offset: 2px; }
a:hover { color: var(--green); }

.topbar {
  background: linear-gradient(135deg, #14633a 0%, #1b7f4a 55%, #3f9b52 100%);
  padding: 0.85rem 2rem; box-shadow: 0 2px 10px rgba(20, 60, 36, 0.25);
  position: sticky; top: 0; z-index: 1100;
}
.topbar .brand { font-size: 1.15rem; font-weight: 800; letter-spacing: -0.01em; }
.topbar .tagline { font-size: 0.82rem; opacity: 0.88; font-weight: 500; }
.container { padding: 1.6rem 2rem 3rem; }

.card {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 1.3rem 1.4rem;
  box-shadow: var(--shadow-sm); background: var(--card);
}
.card + .card, section.card + section.card { margin-top: 1rem; }

button, .button {
  background: var(--green); border-radius: 9px; padding: 0.55rem 1.05rem; font-family: inherit;
  font-weight: 600; font-size: 0.9rem; box-shadow: 0 1px 2px rgba(20,60,36,.2);
  transition: background .15s, box-shadow .15s, transform .05s;
}
button:hover, .button:hover { background: var(--green-dark); box-shadow: 0 3px 8px rgba(20,60,36,.22); }
button:active, .button:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: not-allowed; }
form input, form select, form textarea {
  border: 1px solid #d3dcd5; border-radius: 9px; padding: 0.55rem 0.7rem; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
form input:focus, form select:focus, form textarea:focus {
  outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(27,127,74,.15);
}

.table th {
  font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 700;
  background: #f8faf8; border-bottom: 1px solid var(--border);
}
.table td { border-bottom: 1px solid #edf1ee; }
.table tbody tr:hover { background: #f7faf7; }

.badge { letter-spacing: 0.01em; padding: 0.2rem 0.65rem; }

.kpi-row { gap: 0.9rem; }
.kpi {
  border-radius: var(--radius); padding: 1.05rem 0.9rem; box-shadow: var(--shadow-sm);
  border-top: 3px solid var(--green);
}
.kpi:has(.kpi-value.bad) { border-top-color: var(--red); }
.kpi:has(.kpi-value.warn) { border-top-color: #c98a12; }
.kpi-value { font-size: 1.75rem; letter-spacing: -0.02em; }
.kpi-label { font-size: 0.78rem; line-height: 1.3; }

/* Avertissement */
.notice {
  display: flex; gap: 0.8rem; align-items: flex-start; margin: 1rem 0;
  padding: 0.9rem 1.1rem; border-radius: var(--radius);
  background: #fff8e8; border: 1px solid #f0d9a0; border-left: 5px solid #d99a1d; color: #6b4b0a;
  font-size: 0.9rem; line-height: 1.5; box-shadow: var(--shadow-sm);
}
.notice svg { flex-shrink: 0; margin-top: 1px; color: #d99a1d; }
.notice strong { color: #5a3d05; }

/* Cartes Leaflet */
#map { border: 1px solid var(--border); box-shadow: var(--shadow-sm); border-radius: var(--radius) !important; }
.leaflet-bar a { border-radius: 8px !important; }
.legend { gap: 1.2rem; font-size: 0.82rem; color: var(--muted); }

.insight { border-radius: 0 10px 10px 0; background: #f7faf7; }
.flash { border-radius: 12px; }
.weather-card { border-radius: var(--radius); }

/* Barre d'outils de la carte par pied */
#selBar { background: #ecfbfd; border-radius: 12px !important; }
.kpi-row + p { margin-top: .4rem; }

@media (max-width: 760px) {
  .container { padding: 1rem; }
  .topbar { padding: 0.7rem 1rem; }
  h1 { font-size: 1.4rem; }
}
@media print {
  .topbar { display: none !important; }
  .card, .kpi, .notice { box-shadow: none; break-inside: avoid; }
  body { background: #fff; }
}

/* Boutons secondaires (decalage, corrections) */
.shiftbtn, .selact, #undoOverride, #clearOverrides {
  box-shadow: none; font-size: 0.8rem; padding: 0.25rem 0.6rem !important; border-radius: 7px;
}
.shiftbtn { background: var(--green-soft) !important; color: var(--green-dark) !important; border: 1px solid #cfe6d6; }
.shiftbtn:hover { background: #d8eddf !important; }

/* Onglets du vol */
.tabs { display: flex; gap: 0.3rem; margin: 1rem 0 1.2rem; border-bottom: 2px solid var(--border); }
.tab {
  display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.65rem 1.15rem; margin-bottom: -2px;
  font-weight: 600; font-size: 0.95rem; color: var(--muted); text-decoration: none;
  border-bottom: 3px solid transparent; border-radius: 10px 10px 0 0; transition: color .15s, background .15s;
}
.tab:hover { color: var(--green-dark); background: var(--green-soft); }
.tab.active { color: var(--green-dark); border-bottom-color: var(--green); background: #fff; }
@media print { .tabs { display: none; } }
.tab-sub { font-weight: 500; font-size: 0.8rem; opacity: 0.75; }
@media (max-width: 560px) { .tab-sub { display: none; } }

/* Pas de cadre de focus du navigateur autour des formes de la carte (le rectangle bleu qui entoure un ilot clique) */
.leaflet-container path.leaflet-interactive,
.leaflet-container .leaflet-interactive,
.leaflet-container svg:focus,
.leaflet-container path:focus,
.leaflet-container .leaflet-marker-icon:focus { outline: none !important; }
.leaflet-container { -webkit-tap-highlight-color: transparent; }

/* Onglets Vigueur / CEP : plus grands et bien visibles */
.tabs { gap: 0.6rem; margin: 1.2rem 0 1.5rem; border-bottom: 3px solid var(--border); }
.tab {
  padding: 0.95rem 1.8rem; font-size: 1.2rem; font-weight: 800; letter-spacing: -0.01em;
  color: #3d5247; background: #eef3ee; border: 1px solid var(--border); border-bottom: none;
  border-radius: 14px 14px 0 0; margin-bottom: -3px; gap: 0.7rem;
}
.tab svg { width: 24px; height: 24px; }
.tab:hover { background: var(--green-soft); color: var(--green-dark); }
.tab.active {
  background: var(--green); color: #fff; border-color: var(--green); box-shadow: 0 -3px 12px rgba(27,127,74,.25);
}
.tab.active .tab-sub { opacity: 0.9; color: #fff; }
.tab-sub { font-size: 0.9rem; font-weight: 500; }
@media (max-width: 560px) { .tab { padding: 0.7rem 1rem; font-size: 1rem; } }

/* Explication de l'indice sous la carte */
.index-help {
  margin-top: 1rem; padding: 0.9rem 1.1rem; border-radius: var(--radius);
  background: var(--green-soft); border: 1px solid #cfe6d6; border-left: 5px solid var(--green);
  font-size: 0.9rem; line-height: 1.55; color: #1d3a29;
}
.index-help p { margin: 0.35rem 0; }
.index-help-title { display: flex; align-items: center; gap: 0.5rem; font-weight: 800; font-size: 1rem; color: var(--green-dark); }
.index-help ul { margin: 0.4rem 0; padding: 0; list-style: none; }
.index-help li { display: flex; align-items: flex-start; gap: 0.55rem; margin: 0.25rem 0; }
.index-help .dot { flex: 0 0 12px; height: 12px; border-radius: 3px; margin-top: 0.35rem; }
.index-help .muted { color: #4d6a58; }

/* Espace client : photo de parcelle en grand */
.parcelle-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.parcelle-card > :not(.cover) { margin-left: 1.4rem; margin-right: 1.4rem; }
.parcelle-card > .cover + h2 { margin-top: 1.1rem; }
.parcelle-card > .button { align-self: flex-start; margin-bottom: 1.4rem; }
.parcelle-card .cover { display: block; width: 100%; aspect-ratio: 4 / 3; background: #1b221e; overflow: hidden; }
.parcelle-card .cover img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .4s ease; }
.parcelle-card .cover:hover img { transform: scale(1.03); }
.parcelle-card .cover-empty { display: flex; align-items: center; justify-content: center; color: #9db0a5; font-size: 0.9rem; }
.grid-2:has(.parcelle-card) { align-items: stretch; }
.parcelle-card { height: 100%; }
.grid-2 > .card, .grid-2 > section.card + section.card { margin-top: 0 !important; }

/* Photo de la parcelle en tete de page */
.parcelle-hero { margin: 1rem 0 0.4rem; border-radius: var(--radius); overflow: hidden; background: #1b221e; box-shadow: var(--shadow-md); max-height: 480px; }
.parcelle-hero img { display: block; width: 100%; max-height: 480px; object-fit: cover; }
.photo-actions { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; margin: 0.6rem 0 1.2rem; }
.photo-actions form { margin: 0; }

/* Selecteur de parcelle */
.parcelle-switch { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin: 0.2rem 0 1rem; }
.ps-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; margin-right: 0.2rem; }
.ps-item { padding: 0.45rem 1.1rem; border-radius: 999px; font-weight: 700; font-size: 0.95rem; text-decoration: none; border: 1px solid var(--border); background: #fff; color: var(--green-dark); box-shadow: var(--shadow-sm); }
a.ps-item:hover { background: var(--green-soft); }
.ps-item.active { background: var(--green-dark); color: #fff; border-color: var(--green-dark); }

/* Onglets de sections (Cartes / Analyse / Meteo) */
.section-tabs { display: inline-flex; gap: 0.25rem; padding: 0.3rem; margin: 0.8rem 0 0.2rem; background: #e9efe9; border-radius: 12px; }
.stab { background: transparent; color: var(--green-dark); box-shadow: none; padding: 0.55rem 1.5rem; border-radius: 9px; font-size: 1rem; font-weight: 700; }
.stab:hover { background: #dbe7dd; box-shadow: none; }
.stab.active { background: #fff; color: var(--green-dark); box-shadow: var(--shadow-sm); }
.pane[hidden] { display: none !important; }
@media print { .pane[hidden] { display: block !important; } }

/* Connexion et comptes */
.topbar { position: sticky; }
.user-chip { position: absolute; right: 1.2rem; top: 50%; transform: translateY(-50%); display: flex; gap: 0.9rem; align-items: center; font-size: 0.82rem; }
.user-chip a { color: #fff; opacity: 0.88; text-decoration: none; }
.user-chip a:hover { opacity: 1; text-decoration: underline; }
.user-chip .uc-name { font-weight: 700; opacity: 1; }
@media (max-width: 900px) { .user-chip { position: static; transform: none; width: 100%; justify-content: center; } }
.auth-box { max-width: 420px; margin: 3rem auto; }
.auth-box h1 { margin-bottom: 0.2rem; }
.auth-error { background: #fdecea; border: 1px solid #e6b0aa; color: #7b241c; border-radius: 10px; padding: 0.7rem 1rem; margin: 0.8rem 0; font-weight: 600; }
code { background: #f1f5f2; padding: 0.1rem 0.4rem; border-radius: 5px; }
