/* Theme "AGRI" : apparence sobre commune aux plateformes AirSkan (fond neutre, un seul accent, bordures fines).
   Charge APRES style.css ; ne s'applique qu'a l'ecran (impression et PDF inchanges).
   Pour revenir a l'ancien style : retirer la ligne <link ... theme-agri.css> de templates/base.html. */
@media screen {
  :root {
    --bg: #f5f6f3; --card: #ffffff; --ink: #1d2a1f; --muted: #66736a; --border: #dfe4dc;
    --green: #1e7a45; --green-dark: #165c34; --green-soft: #e6f2e9; --btn: #1e7a45; --btn-hover: #165c34;
    --shadow-sm: none; --shadow-md: 0 2px 10px rgba(20, 40, 28, 0.06); --radius: 10px;
  }
  html, body { background: var(--bg); color: var(--ink); }
  body { font-family: -apple-system, "Helvetica Neue", Arial, sans-serif; font-size: 15px; line-height: 1.45; }
  h1 { font-size: 1.55rem; letter-spacing: -0.01em; }
  h3 { font-weight: 600; }
  a { color: var(--green-dark); }
  code { background: var(--green-soft); border-radius: 4px; padding: 1px 5px; }

  /* Barre du haut : sobre, blanche, marque a gauche */
  .topbar {
    background: var(--card); color: var(--ink); border-bottom: 1px solid var(--border); box-shadow: none;
    padding: 0.55rem 1.1rem; justify-content: flex-start; text-align: left; position: relative; gap: 0.3rem 0.8rem;
  }
  .topbar .brand { color: var(--ink); font-size: 1.1rem; font-weight: 700; letter-spacing: 0.2px; }
  .topbar .brand span { color: var(--green); }
  .topbar .brand-icon { color: var(--green); }
  .topbar .tagline {
    font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
    border: 1px solid var(--border); border-radius: 999px; padding: 1px 9px; opacity: 1;
  }
  .user-chip { gap: 0.9rem; font-size: 0.82rem; }
  .user-chip a { color: var(--muted); opacity: 1; }
  .user-chip a:hover { color: var(--green-dark); text-decoration: none; }
  .user-chip .uc-name { color: var(--ink); font-weight: 600; }
  .container { padding: 1.25rem 1.5rem; }
  @media (max-width: 900px) { .topbar { justify-content: center; text-align: center; } }

  /* Cartes : bordure fine, pas d'ombre */
  .card { border-radius: 10px; box-shadow: none; padding: 1.1rem; }
  .card + .card, section.card + section.card { margin-top: 1rem; }
  .card > h2, section.card > h2 {
    font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); font-weight: 700; margin: 0 0 0.7rem;
  }
  .parcelle-card:hover, a.card:hover { border-color: var(--green); }
  /* le nom d'une parcelle reste un vrai titre */
  .card.parcelle-card > h2, section.card.parcelle-card > h2 { font-size: 1.2rem; text-transform: none; letter-spacing: 0; color: var(--ink); font-weight: 700; }
  .parcelle-card .cover-empty { background: var(--green-soft); color: var(--muted); }

  /* Boutons */
  button, .button {
    background: var(--btn); color: #fff; border: 0; border-radius: 8px; padding: 0.5rem 1rem; font-size: 0.92rem;
    font-weight: 600; box-shadow: none; letter-spacing: 0;
  }
  button:hover, .button:hover { background: var(--btn-hover); box-shadow: none; transform: none; }
  .shiftbtn, .selact, #undoOverride, #clearOverrides {
    background: transparent !important; color: var(--green-dark) !important; border: 1px solid var(--border) !important;
  }
  .shiftbtn:hover, .selact:hover { background: var(--green-soft) !important; border-color: var(--green) !important; }

  /* Formulaires */
  form label { color: var(--muted); font-size: 0.85rem; font-weight: 500; }
  form input, form select, form textarea {
    border: 1px solid var(--border); border-radius: 8px; background: var(--card); color: var(--ink); font-size: 0.95rem;
    box-shadow: none;
  }
  form input:focus, form select:focus, form textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); outline: none; }

  /* Tableaux */
  .table th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; background: transparent; }
  .table th, .table td { border-bottom: 1px solid var(--border); }
  .table tbody tr:hover { background: var(--green-soft); }

  /* Chiffres cles */
  .kpi { border: 1px solid var(--border); border-top: 1px solid var(--border); border-radius: 10px; box-shadow: none; background: var(--card); }
  .kpi:has(.kpi-value.bad), .kpi:has(.kpi-value.warn) { border-top: 1px solid var(--border); }
  .kpi-value { font-weight: 700; }
  .kpi-label { color: var(--muted); font-size: 0.8rem; }

  /* Bandeaux d'information */
  .notice, .flash, .insight { border-radius: 10px; box-shadow: none; }
  .badge { font-weight: 600; }

  /* Onglets principaux : soulignement discret */
  .tabs { gap: 0.2rem; margin: 1rem 0 1.1rem; border-bottom: 1px solid var(--border); }
  .tab {
    padding: 0.6rem 1.05rem; font-size: 0.95rem; font-weight: 600; letter-spacing: 0; color: var(--muted); background: transparent;
    border: 0; border-bottom: 2px solid transparent; border-radius: 6px 6px 0 0; margin-bottom: -1px; box-shadow: none; gap: 0.5rem;
  }
  .tab svg { width: 18px; height: 18px; }
  .tab:hover { background: var(--green-soft); color: var(--green-dark); }
  .tab.active { background: transparent; color: var(--green-dark); border-bottom-color: var(--green); box-shadow: none; }
  .tab.active .tab-sub { color: var(--green-dark); opacity: 0.8; }
  .tab-sub { font-size: 0.78rem; font-weight: 500; opacity: 0.75; }

  /* Choix cartes / analyse / meteo et indices : controle segmente */
  .section-tabs, .subtabs {
    display: inline-flex; flex-wrap: nowrap; gap: 0; background: var(--card); border: 1px solid var(--border); border-radius: 8px;
    overflow: hidden; margin: 0.2rem 0 1rem; padding: 0;
  }
  .subtabs { margin-top: -0.2rem; max-width: 100%; overflow-x: auto; }
  .subtabs-label { padding: 0 0.8rem; font-size: 0.7rem; color: var(--muted); align-self: center; white-space: nowrap; }
  .stab, .pill {
    background: transparent; color: var(--ink); border: 0; border-right: 1px solid var(--border); border-radius: 0; padding: 0.5rem 1rem;
    font-size: 0.9rem; font-weight: 600; box-shadow: none; white-space: nowrap;
  }
  .stab:last-child, .pill:last-child { border-right: 0; }
  .stab:hover, .pill:hover { background: var(--green-soft); color: var(--green-dark); }
  .stab.active, .pill.active { background: var(--btn); color: #fff; }

  /* Selecteur de parcelle et comparaison */
  .ps-item { border-radius: 8px; box-shadow: none; }
  .ps-item.active { background: var(--btn); border-color: var(--btn); color: #fff; }
  .cmp-check { border-radius: 8px; box-shadow: none; }
  .cmp-cell { border-radius: 10px; box-shadow: none; }
  .cmp-map { border-radius: 8px; }

  /* Cartes Leaflet */
  #map { border-radius: 10px; box-shadow: none; border: 1px solid var(--border); }

  /* Connexion */
  .auth-box .card { box-shadow: none; }

  @media (max-width: 760px) {
    .container { padding: 1rem 0.9rem; }
    .tab { padding: 0.55rem 0.7rem; }
  }
}

/* ---------- Mode sombre (suit le reglage du systeme, comme AGRI) ---------- */
@media screen and (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #131a14; --card: #1b241c; --ink: #e8eee9; --muted: #98a69b; --border: #2b372d;
    --green: #6bc07a; --green-dark: #8fd3a0; --green-soft: #223a26; --btn: #2d8a50; --btn-hover: #37a060;
    --shadow-md: none;
  }
  a { color: var(--green); }
  .card.error, #progressError, .auth-error, .weather-balance.deficit { background: #3a1f1c; color: #f1b9b0; border-color: #7a3a33; }
  .weather-balance.surplus, .flash { background: #1f3a28; color: #bfe6c9; }
  .weather-balance-value.deficit { color: #f1b9b0; }
  .weather-icon.rain { background: #1d3346; }
  .weather-icon.et0 { background: #3a3020; }
  .notice { background: #352d1a; color: #f0dfa8; border-color: #6b5a28; }
  .notice strong { color: #f7e8b8; }
  .insight { background: #202b21; }
  #selBar { background: #17333a; }
  .table th { background: transparent; }
  .table tbody tr:hover { background: var(--green-soft); }
  .index-help { color: var(--ink); border-color: var(--border); background: transparent; }
  .shiftbtn { border-color: var(--border) !important; }
  .tab:hover, .stab:hover, .pill:hover { background: var(--green-soft); color: var(--green-dark); }
  /* Onglets principaux en blanc (plus lisibles sur fond sombre) ; l'onglet actif garde son soulignement vert */
  .tab, .tab.active, .tab:hover, .tab .tab-sub, .tab.active .tab-sub { color: #fff; }
  .ps-label, .subtabs-label { color: #fff; }  /* intitules Date, Parcelle, Indice */
  .section-tabs, .subtabs, .ps-item, .cmp-check, .cmp-cell, .pill { background: var(--card); }
  .cmp-check:has(input:checked) { background: var(--green-soft); }
  code { background: var(--green-soft); }
  .topbar .brand-icon { color: var(--green); }
  .kpi-value.warn { color: #e0b24a; }
  .badge.good { background: #1f3a28; color: #9be0ae; }
  .badge.warn { background: #3a3020; color: #e8c26a; }
  .badge.bad { background: #3a1f1c; color: #f1b9b0; }
  .parcelle-card .cover { background: #0f1511; }
  .parcelle-card .cover-empty { background: var(--green-soft); }
  [style*="#fff4d6"] { background: #352d1a !important; border-color: #6b5a28 !important; color: #f0dfa8 !important; }
  [style*="#eef7f0"] { background: #1f3a28 !important; border-color: #2f5a3b !important; color: #cfe9d6 !important; }
  [style*="#fffaf0"] { background: #352d1a !important; }
  img { opacity: 0.95; }
}

/* ---------- Page de vol : panneau a gauche, carte en grand a droite (comme AGRI) ---------- */
@media screen {
  .workspace { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 1rem; align-items: start; margin-bottom: 1rem; }
  .wpanel {
    background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px 20px;
    max-height: calc(100vh - 140px); overflow-y: auto; position: sticky; top: 8px;
  }
  .stage { height: calc(100vh - 140px); min-height: 520px; position: sticky; top: 8px; }
  .stage #map { height: 100%; min-height: 0; background: var(--mapbg, #000); }
  .wp-h {
    font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); font-weight: 700; margin: 16px 0 8px;
  }
  .wpanel .kpi-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 4px; }
  .wpanel .kpi { padding: 10px 12px; text-align: left; }
  .wpanel .kpi-value { font-size: 1.45rem; line-height: 1.15; }
  .wpanel .kpi-label { font-size: 0.75rem; line-height: 1.25; }
  .wpanel .kpi .small { font-size: 0.7rem; }
  .wp-controls { display: flex; flex-direction: column; gap: 8px; margin: 0 0 6px; }
  .wp-controls label { display: flex !important; justify-content: space-between; align-items: center; gap: 8px; font-weight: 600; color: var(--ink); }
  .wp-controls select { width: auto !important; max-width: 62%; min-width: 0; }
  .wpanel .legend { margin-top: 10px; flex-wrap: wrap; }
  .wpanel .index-help { margin-top: 12px; padding: 10px 12px; font-size: 0.86rem; }
  .wpanel .index-help summary { cursor: pointer; font-weight: 600; display: flex; gap: 6px; align-items: center; list-style: none; }
  .wpanel .index-help summary::-webkit-details-marker { display: none; }
  .wpanel .index-help p, .wpanel .index-help li { font-size: 0.84rem; line-height: 1.4; }
  @media (max-width: 900px) {
    .workspace { grid-template-columns: 1fr; }
    .stage { order: -1; height: 60vh; min-height: 320px; position: static; }
    .wpanel { max-height: none; position: static; }
  }
}
@media print {
  .workspace { display: block; }
  .wpanel { border: 0; padding: 0; max-height: none; overflow: visible; }
  .stage { height: auto; }
  .stage #map { height: 480px; }
  .wpanel .kpi-row { display: flex; }
}

/* ---------- En-tete compact de la page de vol ---------- */
@media screen {
  .page-bar { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; justify-content: space-between; margin: 0 0 0.3rem; }
  .pb-left, .pb-right { display: flex; flex-wrap: wrap; gap: 0.5rem 0.8rem; align-items: center; }
  .pb-left .parcelle-switch { margin: 0; }
  .pb-back { font-size: 0.85rem; color: var(--muted); }
  .pb-right .section-tabs, .pb-center .section-tabs { margin: 0; }
  /* Page du vol : Cartes / Analyse / Meteo au milieu, entre la date/parcelle et les boutons */
  .page-bar:has(.pb-center) { display: grid; grid-template-columns: 1fr auto 1fr; }
  .pb-center { display: flex; justify-content: center; }
  .page-bar:has(.pb-center) .pb-right { justify-content: flex-end; }
  @media (max-width: 900px) {
    .page-bar:has(.pb-center) { grid-template-columns: 1fr; }
    .page-bar:has(.pb-center) .pb-right { justify-content: center; }
  }
  .pb-right .button, .pb-right button.button { padding: 0.4rem 0.8rem; font-size: 0.85rem; }
  .page-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.8rem; margin: 0.1rem 0 0.2rem; }
  .page-title h1 { font-size: 1.35rem; margin: 0; }
  .page-title p { margin: 0; font-size: 0.85rem; }
  .tabs { margin-top: 0.5rem; margin-bottom: 0.7rem; }
  .subtabs { margin-bottom: 0.7rem; }
  .stage, .wpanel { top: 6px; }
  .stage { height: calc(100vh - 225px); min-height: 520px; }
  .wpanel { max-height: calc(100vh - 225px); }
  @media (max-width: 900px) { .stage { height: 60vh; } .wpanel { max-height: none; } }
}

/* Curseurs d'opacite (photo de fond / couleurs de l'indice) */
@media screen {
  .wp-controls .slider, .cmp-check.cmp-photo { color: var(--ink); font-weight: 600; }
  .wp-controls .slider input[type=range], .cmp-photo input[type=range] { flex: 1; max-width: 58%; margin: 0; padding: 0; accent-color: var(--green); background: none; border: 0; }
  .cmp-photo { gap: 0.6rem; }
  .cmp-map { background: var(--mapbg, #000); }
}

/* Choix du fond de carte (controle segmente) */
@media screen {
  :root { --mapbg: #000; }
  .seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--card); }
  .seg button { background: transparent; color: var(--ink); border: 0; border-right: 1px solid var(--border); border-radius: 0; padding: 0.3rem 0.8rem; font-size: 0.82rem; font-weight: 600; }
  .seg button:last-child { border-right: 0; }
  .seg button:hover { background: var(--green-soft); color: var(--green-dark); }
  .seg button.on { background: var(--btn); color: #fff; }
  .wp-controls .seg-row { gap: 8px; }
  .cmp-bg { gap: 0.6rem; padding: 0.3rem 0.8rem; }
}

/* Comptage des pieds : panneau d'outils a gauche */
@media screen {
  .wp-block { margin: 0 0 10px; }
  .wp-block .notice { font-size: 0.78rem; padding: 0.55rem 0.7rem; margin: 0; }
  .wp-block .notice svg { display: none; }
  .wp-block label { margin: 0; }
  .wp-block select { width: 100%; max-width: none; }
  .wp-tools { display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
  .wp-tools label { display: flex !important; justify-content: space-between; align-items: center; gap: 8px; font-weight: 600; color: var(--ink); }
  .wp-tools select { width: auto !important; max-width: 60%; margin: 0; }
  .wp-tools button { text-align: center; }
  .wp-tools .muted { font-size: 0.78rem; font-weight: 400; }
  #selBar { margin: 8px 0 0; }
  .wpanel .legend { flex-direction: column; align-items: flex-start; gap: 6px; font-size: 0.82rem; }
  .wpanel .kpi-label .muted { display: block; font-size: 0.68rem; }
}
