/* Résil'Eau — feuille de style */

:root {
  --green: #2e7d32;
  --light-green: #7cb342;
  --orange: #fb8c00;
  --red: #c62828;
  --blue: #1565c0;
  --bg: #f4f7f4;
  --panel: #ffffff;
  --border: #dde4dd;
  --text: #1f2a1f;
  --muted: #6b7a6b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* ---------- En-tête ---------- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: linear-gradient(90deg, #1b5e20, #2e7d32);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.brand { display: flex; align-items: center; gap: 0.75rem; }
.logo { font-size: 1.9rem; }
header h1 { margin: 0; font-size: 1.4rem; letter-spacing: .5px; }
.vtag { font-size: .75rem; vertical-align: middle; background: rgba(255,255,255,.22); padding: .1rem .45rem; border-radius: 999px; margin-left: .35rem; font-weight: 600; }
.tagline { margin: 0; font-size: .82rem; opacity: .9; }
.header-right { display: flex; align-items: center; gap: 1rem; }
.data-source { font-size: .72rem; padding: .2rem .55rem; border-radius: 999px; background: var(--border, #e8ece8); color: var(--muted, #667); }
.data-source.live { background: #dcedc8; color: #33691e; }
.farm-name { font-weight: 600; font-size: .9rem; opacity: .95; }
.version { font-size: .8rem; opacity: .8; }

/* ---------- Disposition ---------- */
main {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 0;
  height: calc(100vh - 70px);
}
@media (max-width: 900px) {
  main { grid-template-columns: 1fr; height: auto; }
  #map { min-height: 320px; }
}

/* ---------- Barre latérale ---------- */
#sidebar {
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--bg);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem;
}
.panel h2 {
  margin: 0 0 0.6rem;
  font-size: .95rem;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--blue);
}

/* Toggles de la barre latérale (panneaux repliables) */
.panel-toggle > summary {
  list-style: none;
  cursor: pointer;
  margin: 0;
  font-size: .95rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  user-select: none;
}
.panel-toggle > summary::-webkit-details-marker { display: none; }
.panel-toggle > summary::after {
  content: "▾";
  color: var(--muted);
  font-size: .9rem;
  transition: transform .18s ease;
}
.panel-toggle[open] > summary { margin-bottom: 0.6rem; }
.panel-toggle[open] > summary::after { transform: rotate(180deg); }
.panel-toggle > summary:hover { color: #0d47a1; }
label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  margin: 0.6rem 0;
  color: var(--text);
}
label select, label input {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.45rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .9rem;
  background: #fff;
}
label.check {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-weight: 500;
  margin: .5rem 0;
}
label.check input {
  width: auto;
  margin: 0;
}
.slider-row { display: flex; align-items: center; gap: .6rem; }
.slider-row input[type=range] { flex: 1; }
.slider-row span { font-size: .85rem; font-weight: 700; min-width: 3rem; }

.btn-row { display: flex; gap: .4rem; flex-wrap: wrap; }
button {
  cursor: pointer;
  border: none;
  border-radius: 7px;
  padding: .55rem .8rem;
  font-size: .85rem;
  font-weight: 600;
  transition: filter .15s, transform .05s;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--green); color: #fff; width: 100%; padding: .8rem; font-size: .95rem; }
button.secondary { background: #e3f2fd; color: var(--blue); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.actions { display: flex; flex-direction: column; gap: .5rem; }

.hint { font-size: .78rem; color: var(--muted); margin: .4rem 0 0; }

.plot-list { list-style: none; padding: 0; margin: .6rem 0 0; }
.plot-list li {
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem .6rem; margin-bottom: .35rem;
  border: 1px solid var(--border); border-radius: 7px;
  cursor: pointer; font-size: .88rem; background: #fff;
}
.plot-list li:hover { border-color: var(--blue); }
.plot-list li.active { border-color: var(--blue); box-shadow: 0 0 0 2px #1565c033; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }

/* ---------- Carte ---------- */
#content { position: relative; display: flex; flex-direction: column; min-width: 0; }
#map { flex: 1; min-height: 300px; }
.map-hint {
  position: absolute; bottom: 12px; left: 12px; z-index: 500;
  background: rgba(255,255,255,.94); padding: .5rem .7rem;
  border-radius: 8px; font-size: .8rem; color: var(--muted);
  box-shadow: 0 2px 8px rgba(0,0,0,.15); max-width: 340px;
}

/* ---------- Résultats (page plein écran) ---------- */
.results-page {
  position: fixed; inset: 0; z-index: 2000;
  background: var(--bg);
  display: flex; flex-direction: column;
}
.results-page[hidden] { display: none; }
.results-page-bar {
  display: flex; align-items: center; gap: .75rem;
  padding: .7rem 1rem; background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
}
.results-page-title { font-weight: 700; font-size: 1rem; }
.results-page-body { flex: 1; overflow-y: auto; padding: 1.25rem; }
.results-page-bar .ghost { margin-left: auto; }

.result-card {
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  padding: 1rem; display: grid; gap: 1rem;
}
.result-top { display: flex; gap: 1.25rem; align-items: center; flex-wrap: wrap; }
.gauge {
  width: 118px; height: 118px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.gauge-inner {
  width: 88px; height: 88px; border-radius: 50%; background: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.gauge-inner .score { font-size: 1.7rem; font-weight: 800; line-height: 1; }
.gauge-inner .unit { font-size: .7rem; color: var(--muted); }
.class-badge {
  padding: .3rem .8rem; border-radius: 999px; color: #fff;
  font-weight: 700; font-size: .9rem;
}
.result-title { font-size: 1.05rem; font-weight: 700; }
.result-sub { color: var(--muted); font-size: .85rem; }

.metrics {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem;
}
.metric { background: #f7faf7; border-radius: 8px; padding: .6rem .75rem; }
.metric .value { font-size: 1.15rem; font-weight: 700; }
.metric .label { font-size: .75rem; color: var(--muted); }

.result-bottom { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 900px) { .result-bottom { grid-template-columns: 1fr; } }
.radar-box { margin-top: .5rem; }
.recos h3, .radar-box h3 { margin: 0 0 .6rem; font-size: .9rem; color: var(--blue); text-transform: uppercase; }
.recos ul { margin: 0; padding-left: 1.1rem; }
.recos li { margin-bottom: .45rem; font-size: .88rem; }

/* Lexique des indicateurs */
.lexique { border-top: 1px solid var(--border); margin-top: .75rem; }
.lexique > summary {
  list-style: none; cursor: pointer; padding: .6rem 0;
  font-weight: 600; font-size: .88rem; color: var(--blue);
  display: flex; align-items: center; gap: .4rem; user-select: none;
}
.lexique > summary::-webkit-details-marker { display: none; }
.lexique > summary::after {
  content: "▾"; margin-left: auto; color: var(--muted); transition: transform .18s ease;
}
.lexique[open] > summary::after { transform: rotate(180deg); }
.lexique-body dl {
  display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0 0 .4rem;
}
.lexique-body dt { font-weight: 700; color: var(--text); }
.lexique-body dd { margin: 0; color: var(--muted); font-size: .85rem; line-height: 1.45; }
@media (max-width: 600px) {
  .lexique-body dl { grid-template-columns: 1fr; }
  .lexique-body dd { margin-top: -.2rem; }
}

.rank-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.rank-table th, .rank-table td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--border); }
.rank-table th { background: #f0f5f0; font-size: .78rem; text-transform: uppercase; color: var(--muted); }
.rank-table tr.best { background: #e8f5e9; }

footer { padding: .6rem 1.2rem; font-size: .75rem; color: var(--muted); border-top: 1px solid var(--border); }

/* ---------- Contrôles sur la carte ---------- */
.map-search-control,
.map-draw-control {
  background: #fff;
  padding: 8px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 260px;
}
.search-row { display: flex; gap: 4px; }
.search-row input {
  flex: 1;
  min-width: 160px;
  padding: 7px 8px;
  border: 1px solid #c5ccc5;
  border-radius: 5px;
  font-size: .85rem;
}
.search-row button,
.quick-btn,
.map-draw-control button {
  cursor: pointer;
  border: 1px solid #c5ccc5;
  background: #fff;
  border-radius: 5px;
  padding: 7px 9px;
  font-size: .82rem;
  font-weight: 600;
  white-space: nowrap;
}
.search-row button:hover,
.quick-btn:hover,
.map-draw-control button:hover { filter: brightness(.96); }
.quick-btn { background: #e3f2fd; border-color: #1565c0; color: #1565c0; }
.map-draw-control button.primary-draw {
  background: #2e7d32;
  color: #fff;
  border-color: #2e7d32;
}
.map-draw-control button:disabled { opacity: .5; cursor: not-allowed; }
.draw-info { font-size: .82rem; font-weight: 700; color: #1b5e20; min-height: 1.1em; }

/* ---------- Écran d'accès par jeton ---------- */
.token-gate {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1b5e20, #2e7d32);
  padding: 1rem;
}
/* Masque réellement l'écran d'accès quand l'attribut `hidden` est présent
   (sinon `display: flex` ci-dessus l'emporte sur le style par défaut). */
.token-gate[hidden] { display: none; }
.token-card {
  background: #fff; border-radius: 16px; padding: 2.2rem 2rem;
  max-width: 440px; width: 100%; text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.token-card .logo { font-size: 3rem; }
.token-card h1 { margin: .5rem 0 0; font-size: 1.6rem; color: #1b5e20; }
.token-card .sub { color: #333; font-weight: 600; margin: .5rem 0; }
.token-card .hint { color: #667; font-size: .85rem; margin: 0 0 1rem; }
.token-card input {
  width: 100%; box-sizing: border-box; padding: .8rem;
  border: 1px solid #c5ccc5; border-radius: 8px; font-size: 1rem;
  margin-bottom: .8rem;
}
.token-card .primary {
  width: 100%; padding: .8rem; font-size: 1rem;
}
.token-card .error { color: #c62828; font-size: .85rem; min-height: 1.2em; margin: .6rem 0 0; }

/* ---------- Clients agriculteurs & import PAC ---------- */
.client-list { list-style: none; padding: 0; margin: .5rem 0 0; max-height: 220px; overflow-y: auto; }
.client-list li {
  display: flex; align-items: center; gap: .5rem;
  padding: .45rem .55rem; margin-bottom: .35rem;
  border: 1px solid var(--border); border-radius: 7px;
  font-size: .82rem; background: #fff; flex-wrap: wrap;
}
.client-list li .info { flex: 1; min-width: 140px; line-height: 1.35; }
.client-list li button { padding: .25rem .5rem; font-size: .75rem; width: auto; }
.client-list li.hint { border: none; background: transparent; }
.mini-danger { background: #c62828; color: #fff; }
#client-search,
#pac-file {
  width: 100%; padding: .45rem; margin-top: .3rem;
  border: 1px solid var(--border); border-radius: 6px;
  font-size: .85rem; background: #fff;
}
textarea {
  width: 100%; padding: .45rem; border: 1px solid var(--border);
  border-radius: 6px; font-size: .85rem; resize: vertical; background: #fff;
}
#pac-status { margin: .5rem 0; }

/* ---------- Panneau parcelle (toggles / accordéons) ---------- */
.plot-panel { background: #fff; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.plot-panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .8rem 1rem; border-bottom: 1px solid var(--border); background: #f7faf7;
  flex-wrap: wrap;
}
.plot-panel-head .dot { display: inline-block; vertical-align: middle; margin-right: .4rem; }
.plot-panel-head strong { font-size: 1rem; }

.toggle { border-bottom: 1px solid var(--border); }
.toggle:last-child { border-bottom: none; }
.toggle > summary {
  list-style: none; cursor: pointer; padding: .7rem 1rem;
  font-weight: 600; font-size: .9rem;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  user-select: none;
}
.toggle > summary::-webkit-details-marker { display: none; }
.toggle > summary:hover { background: #f0f5f0; }
.toggle > summary::after {
  content: "▾"; color: var(--muted); font-size: .9rem; transition: transform .18s ease;
}
.toggle[open] > summary { background: #f0f5f0; }
.toggle[open] > summary::after { transform: rotate(180deg); }
.toggle-body { padding: .8rem 1rem; }

.radar-canvas-wrap { height: 280px; position: relative; }

.synth-summary { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .6rem; font-size: .82rem; }
.synth-summary .chip { padding: .15rem .5rem; border-radius: 999px; background: #f0f5f0; font-weight: 700; }
.synth-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.synth-table th, .synth-table td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--border); }
.synth-table th { background: #f0f5f0; font-size: .74rem; text-transform: uppercase; color: var(--muted); }
