/* Plateforme d'irrigation de la Dordogne : interface sobre, lisible au soleil, utilisable au pouce. */
:root {
  --fond: #f3f6f5;
  --surface: #ffffff;
  --surface-douce: #eaf1ef;
  --texte: #12211d;
  --texte-doux: #44574f;
  --bordure: #d3dfdb;
  --primaire: #0f5c4d;
  --primaire-fonce: #0a4338;
  --primaire-clair: #d7ece6;
  --eau: #1b6fa8;
  --eau-clair: #dcecf7;
  --pluie: #2f7fc1;
  --etp: #b8631b;
  --normal: #2d7a46;
  --vigilance: #8a6a00;
  --vigilance-fond: #fdf3c8;
  --alerte: #a8480f;
  --alerte-fond: #fde3cf;
  --renforcee: #a52626;
  --renforcee-fond: #fbd8d8;
  --crise: #5b1b52;
  --crise-fond: #ecd4ea;
  --inconnu: #55645e;
  --focus: #0b57d0;
  --rayon: 14px;
  --rayon-petit: 9px;
  --ombre: 0 1px 2px rgba(18, 33, 29, .08), 0 8px 24px rgba(18, 33, 29, .08);
  --largeur-panneau: 440px;
  --entete: 60px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--texte); background: var(--fond); -webkit-text-size-adjust: 100%; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.saut { position: absolute; left: 8px; top: -60px; z-index: 100; background: var(--primaire); color: #fff; padding: 10px 14px; border-radius: 8px; }
.saut:focus { top: 8px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
button, input, select { font: inherit; color: inherit; }
.icone { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* En-tête */
.entete { height: var(--entete); display: flex; align-items: center; gap: 14px; padding: 0 16px; background: var(--primaire); color: #fff; position: relative; z-index: 30; }
.marque { display: flex; align-items: center; gap: 10px; min-width: 0; }
.marque-icone { width: 30px; height: 30px; fill: #fff; stroke: none; flex: none; }
.marque-texte { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.marque-texte strong { font-size: 1.05rem; letter-spacing: .01em; white-space: nowrap; }
.marque-texte span { font-size: .78rem; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recherche { position: relative; flex: 1; min-width: 0; max-width: 520px; display: flex; align-items: center; background: #fff; color: var(--texte); border-radius: 12px; padding: 0 4px 0 12px; height: 42px; margin-left: auto; }
.recherche .icone { color: var(--texte-doux); width: 20px; height: 20px; }
.recherche input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 0 10px; height: 100%; outline: none; }
.recherche:focus-within { box-shadow: 0 0 0 3px var(--focus); }
.bouton-icone { width: 38px; height: 38px; border: 0; border-radius: 10px; background: transparent; color: var(--primaire); display: grid; place-items: center; cursor: pointer; }
.bouton-icone:hover { background: var(--primaire-clair); }
.suggestions { position: absolute; top: 46px; left: 0; right: 0; margin: 0; padding: 6px; list-style: none; background: #fff; border-radius: 12px; box-shadow: var(--ombre); max-height: 320px; overflow: auto; z-index: 40; }
.suggestions li { padding: 10px 12px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.suggestions li[aria-selected="true"], .suggestions li:hover { background: var(--primaire-clair); }
.suggestions small { color: var(--texte-doux); }
.profil { display: flex; background: rgba(255, 255, 255, .16); border-radius: 11px; padding: 3px; flex: none; }
.profil-bouton { border: 0; background: transparent; color: #fff; padding: 7px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: .9rem; }
.profil-bouton[aria-pressed="true"] { background: #fff; color: var(--primaire); }
.bandeau-hors-ligne { display: flex; gap: 10px; align-items: center; padding: 8px 16px; background: #fff4d6; color: #5c4500; font-size: .92rem; z-index: 25; position: relative; }

/* Mise en page */
.espace { display: grid; grid-template-columns: var(--largeur-panneau) 1fr; height: calc(100dvh - var(--entete)); }
.carte-zone { grid-column: 2; grid-row: 1; position: relative; min-height: 0; }
.carte { position: absolute; inset: 0; background: #dfe8e4; }
.panneau { grid-column: 1; grid-row: 1; display: flex; flex-direction: column; background: var(--fond); border-right: 1px solid var(--bordure); min-height: 0; outline: none; box-shadow: var(--ombre); z-index: 10; }
.poignee { display: none; }
.onglets { display: flex; gap: 4px; padding: 10px 10px 0; background: var(--surface); border-bottom: 1px solid var(--bordure); }
.onglets button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 10px; border: 0; border-bottom: 3px solid transparent; background: transparent; cursor: pointer; color: var(--texte-doux); font-size: .78rem; font-weight: 600; min-height: 56px; border-radius: 8px 8px 0 0; }
.onglets button[hidden] { display: none; }
.onglets button[aria-selected="true"] { color: var(--primaire); border-bottom-color: var(--primaire); background: var(--primaire-clair); }
.onglets button:hover { background: var(--surface-douce); }
.vues { flex: 1; overflow-y: auto; padding: 14px 14px 8px; overscroll-behavior: contain; }
.vue[hidden] { display: none; }
.pied summary { cursor: pointer; font-weight: 600; }
.pied details[open] summary { margin-bottom: 6px; }
.pied { padding: 8px 16px 10px; font-size: .74rem; color: var(--texte-doux); background: var(--surface); border-top: 1px solid var(--bordure); }
.pied p { margin: 0; }

/* Cartes d'information */
.carte-info { background: var(--surface); border: 1px solid var(--bordure); border-radius: var(--rayon); padding: 14px 16px; margin-bottom: 12px; }
.carte-info h2, .carte-info h3 { margin: 0 0 8px; font-size: 1rem; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.carte-info p { margin: 6px 0; }
.titre-vue { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 2px 0 12px; }
.titre-vue h1 { margin: 0; font-size: 1.2rem; }
.position { display: flex; align-items: center; gap: 8px; color: var(--texte-doux); font-size: .88rem; }
.mini { font-size: .8rem; color: var(--texte-doux); }
.fraicheur { font-size: .76rem; color: var(--texte-doux); display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.fraicheur.perime { color: #7a4b00; font-weight: 600; }
.pastille { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .82rem; font-weight: 700; border: 1px solid transparent; white-space: nowrap; }
.pastille::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.n-normal, .n-aucune, .n-visible { color: var(--normal); background: #e1f2e6; }
.n-vigilance, .n-faible { color: var(--vigilance); background: var(--vigilance-fond); }
.n-alerte, .n-non-visible { color: var(--alerte); background: var(--alerte-fond); }
.n-alerte_renforcee { color: var(--renforcee); background: var(--renforcee-fond); }
.n-crise, .n-assec { color: var(--crise); background: var(--crise-fond); }
.n-inconnu { color: var(--inconnu); background: #e8eceb; }
.gros-niveau { font-size: 1.25rem; font-weight: 800; margin: 2px 0 6px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Boutons et champs */
.bouton { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 11px; border: 1px solid var(--primaire); background: var(--primaire); color: #fff; font-weight: 700; cursor: pointer; text-decoration: none; }
.bouton:hover { background: var(--primaire-fonce); }
.bouton.secondaire { background: var(--surface); color: var(--primaire); }
.bouton.secondaire:hover { background: var(--primaire-clair); }
.bouton.petit { min-height: 36px; padding: 0 12px; font-size: .88rem; }
.bouton[disabled] { opacity: .55; cursor: progress; }
.lien { color: var(--eau); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; background: none; border: 0; padding: 0; cursor: pointer; }
.champ { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.champ label, .champ .etiquette { font-weight: 600; font-size: .9rem; }
.champ input, .champ select { min-height: 44px; border: 1px solid #aebdb8; border-radius: 10px; padding: 0 12px; background: #fff; width: 100%; }
.champ small { color: var(--texte-doux); }
.grille-champs { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.segment { display: inline-flex; background: var(--surface-douce); border-radius: 11px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segment button { border: 0; background: transparent; padding: 7px 12px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--texte-doux); min-height: 36px; }
.segment button[aria-pressed="true"], .segment button[aria-selected="true"] { background: #fff; color: var(--primaire); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

/* Indicateurs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 8px 0; }
.kpi { background: var(--surface-douce); border-radius: 11px; padding: 10px 12px; }
.kpi .valeur { font-size: 1.45rem; font-weight: 800; line-height: 1.15; }
.kpi .valeur small { font-size: .8rem; font-weight: 600; color: var(--texte-doux); }
.kpi .libelle { font-size: .78rem; color: var(--texte-doux); }
.barre-empilee { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--surface-douce); margin: 8px 0; }
.barre-empilee span { display: block; height: 100%; }
.legende-ligne { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: .8rem; color: var(--texte-doux); }
.legende-ligne i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.tableau { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tableau th, .tableau td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--bordure); vertical-align: top; }
.tableau th { font-size: .78rem; color: var(--texte-doux); font-weight: 700; }
.tableau td.nombre, .tableau th.nombre { text-align: right; font-variant-numeric: tabular-nums; }
.defile-x { overflow-x: auto; }

/* Listes de stations */
.liste { list-style: none; margin: 0; padding: 0; }
.liste li > button { width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; padding: 11px 12px; border: 1px solid var(--bordure); background: var(--surface); border-radius: 12px; margin-bottom: 8px; cursor: pointer; min-height: 56px; }
.liste li > button:hover { border-color: var(--primaire); }
.liste li > button[aria-current="true"] { border-color: var(--primaire); box-shadow: inset 0 0 0 1px var(--primaire); }
.liste .nom { flex: 1; min-width: 0; }
.liste .nom strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.liste .nom small { color: var(--texte-doux); }
.liste .valeur { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }

/* Graphiques */
.graphique { width: 100%; position: relative; touch-action: pan-y; }
.graphique svg { width: 100%; height: auto; display: block; overflow: visible; }
.graphique .axe text { font-size: 11px; fill: var(--texte-doux); }
.graphique .grille line { stroke: #e2eae7; stroke-width: 1; }
.graphique .ligne-ref text { font-size: 10.5px; font-weight: 700; }
.info-bulle { position: absolute; pointer-events: none; background: var(--texte); color: #fff; padding: 8px 10px; border-radius: 9px; font-size: .8rem; line-height: 1.35; z-index: 5; max-width: 220px; box-shadow: var(--ombre); }
.info-bulle b { display: block; margin-bottom: 2px; }
.legende-graphique { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .8rem; color: var(--texte-doux); margin-top: 6px; }
.legende-graphique i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -2px; }
details.donnees { margin-top: 8px; font-size: .86rem; }
details.donnees summary { cursor: pointer; color: var(--eau); font-weight: 600; padding: 6px 0; }

/* Carte : outils, légende, marqueurs */
.carte-outils { position: absolute; top: 12px; right: 12px; z-index: 5; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.outil { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border: 0; border-radius: 12px; background: var(--surface); box-shadow: var(--ombre); cursor: pointer; font-weight: 700; color: var(--primaire); }
.menu-couches { background: var(--surface); border-radius: var(--rayon); box-shadow: var(--ombre); padding: 12px 14px; width: 250px; max-height: 70dvh; overflow: auto; }
.menu-couches fieldset { border: 0; padding: 0; margin: 0 0 10px; }
.menu-couches legend { font-weight: 800; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; color: var(--texte-doux); padding: 0; margin-bottom: 4px; }
.menu-couches label { display: flex; align-items: center; gap: 10px; min-height: 36px; cursor: pointer; }
.menu-couches input { width: 20px; height: 20px; accent-color: var(--primaire); }
.legende { position: absolute; left: 12px; bottom: 28px; z-index: 4; background: rgba(255, 255, 255, .94); border-radius: 12px; padding: 8px 12px; box-shadow: var(--ombre); font-size: .8rem; max-width: 260px; }
.legende:empty { display: none; }
.legende b { display: block; margin-bottom: 4px; }
.legende .ligne { display: flex; align-items: center; gap: 8px; margin: 2px 0; }
.legende .pt { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .35); flex: none; }
.maplibregl-ctrl-bottom-right { margin-bottom: 6px; }
.maplibregl-popup-content { border-radius: 12px; padding: 10px 12px; font: .86rem/1.4 system-ui, sans-serif; }
.repere { width: 26px; height: 26px; }

.notification { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--texte); color: #fff; padding: 11px 18px; border-radius: 12px; z-index: 60; box-shadow: var(--ombre); max-width: 90vw; }
.attente { display: flex; align-items: center; gap: 10px; color: var(--texte-doux); padding: 16px 4px; }
.rond { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--primaire-clair); border-top-color: var(--primaire); animation: tourne .8s linear infinite; }
@keyframes tourne { to { transform: rotate(360deg); } }
.vide, .erreur { padding: 18px 14px; border-radius: var(--rayon); background: var(--surface-douce); color: var(--texte-doux); }
.erreur { background: var(--alerte-fond); color: var(--alerte); }
.avertissement { background: var(--vigilance-fond); color: #5d4700; border-radius: 10px; padding: 8px 12px; font-size: .86rem; margin: 8px 0; }
.sous-titre { color: var(--texte-doux); font-size: .88rem; margin: -6px 0 12px; }
.ligne-irrigation { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--bordure); }
.rangee-edition { display: grid; grid-template-columns: 1fr 1fr auto auto; gap: 6px 8px; align-items: end; margin-bottom: 10px; padding: 10px; background: var(--surface-douce); border-radius: 11px; }
.rangee-edition > .champ:first-child { grid-column: 1 / -1; }
.rangee-edition label { font-size: .78rem; }
.rangee-edition .champ { margin: 0; }
.rangee-edition input, .rangee-edition select { min-height: 40px; padding: 0 8px; }
.planning { display: grid; grid-template-columns: 96px repeat(14, minmax(24px, 1fr)); gap: 2px; font-size: .72rem; min-width: 470px; }
.planning .nom-ligne { position: sticky; left: 0; background: var(--surface); z-index: 1; padding-right: 4px; }
.planning button.cellule { border: 0; cursor: pointer; font: inherit; font-size: .72rem; padding: 0; color: inherit; }
.planning .cellule { min-height: 28px; display: grid; place-items: center; border-radius: 5px; background: var(--surface-douce); }
.planning .entete-col { font-weight: 700; color: var(--texte-doux); text-align: center; line-height: 1.1; padding: 2px 0; }
.planning .nom-ligne { display: flex; align-items: center; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.planning .occupe { background: var(--primaire); color: #fff; font-weight: 700; }
.planning .nuit { background: #e0e7ea; }

/* Mobile : carte plein écran, panneau en feuille basculante */
@media (max-width: 899px) {
  :root { --entete: 56px; }
  .entete { gap: 8px; padding: 0 10px; }
  .marque-texte { display: none; }
  .recherche { margin-left: 0; }
  body[data-panneau="mi"] .legende, body[data-panneau="haut"] .legende { display: none; }
  .rangee-edition { grid-template-columns: 1fr 1fr auto auto; }
  .marque-texte span { display: none; }
  .profil-bouton { padding: 6px 9px; font-size: .82rem; }
  .espace { display: block; position: relative; }
  .carte-zone { position: absolute; inset: 0; }
  .panneau { position: absolute; left: 0; right: 0; bottom: 0; height: 52dvh; border-radius: 20px 20px 0 0; border-right: 0; transition: height .22s ease; box-shadow: 0 -6px 24px rgba(18, 33, 29, .18); }
  .panneau[data-etat="bas"] { height: 168px; }
  .panneau[data-etat="haut"] { height: calc(100dvh - var(--entete) - 12px); }
  .poignee { display: grid; place-items: center; width: 100%; height: 26px; border: 0; background: var(--surface); border-radius: 20px 20px 0 0; cursor: pointer; flex: none; }
  .poignee span { width: 44px; height: 5px; border-radius: 3px; background: #b4c3be; }
  .onglets { order: 3; border-top: 1px solid var(--bordure); border-bottom: 0; padding: 0 6px; }
  .onglets button { min-height: 54px; padding-bottom: 8px; border-bottom: 0; border-top: 3px solid transparent; border-radius: 0 0 8px 8px; }
  .onglets button[aria-selected="true"] { border-top-color: var(--primaire); }
  .vues { order: 2; }
  .pied { display: none; }
  .carte-outils { top: 8px; right: 8px; }
  .legende { bottom: 190px; left: 8px; }
  .panneau[data-etat="bas"] ~ * .legende { bottom: 190px; }
  .recherche { max-width: none; }
}
@media (max-width: 520px) {
  .marque-icone { width: 26px; height: 26px; }
  .grille-champs { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media print { .entete, .onglets, .carte-zone, .poignee { display: none; } body { overflow: visible; } .espace { display: block; height: auto; } .panneau { box-shadow: none; } }

.titre-vue h2 { font-size: 1.1rem; }

details.parcelle { background: var(--surface); border: 1px solid var(--bordure); border-radius: var(--rayon); margin-bottom: 12px; }
details.parcelle > summary { list-style: none; cursor: pointer; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 52px; }
details.parcelle > summary::-webkit-details-marker { display: none; }
details.parcelle > summary .resume { display: flex; flex-direction: column; min-width: 0; }
details.parcelle > summary .resume small { color: var(--texte-doux); }
details.parcelle > summary .modifier { color: var(--eau); font-weight: 700; flex: none; }
details.parcelle[open] > summary .modifier::after { content: " (fermer)"; font-weight: 500; }
details.parcelle > .corps { padding: 0 16px 14px; }
