:root {
  color-scheme: light dark;
  --border: #d0d0d0;
  --accent: #2f6f3e;
  --accent-hover: #24592f;
  --accent-soft: #e3f1e5;
  --bg: #ffffff;
  --fg: #1a1a1a;
  --bg-alt: #f4f4f2;
  --flash-bg: #eaf6ea;
  --shadow: 0 1px 3px rgba(20, 20, 15, 0.12);
  --shadow-md: 0 4px 12px rgba(20, 20, 15, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --border: #4a4a4a;
    --accent: #5fae74;
    --accent-hover: #74c088;
    --accent-soft: #26382a;
    --bg: #1c1c1c;
    --fg: #eaeaea;
    --bg-alt: #2b2b2b;
    --flash-bg: #1f3324;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
  }
}

/* Palette de bandes : mêmes familles de teintes que la version pastel d'origine
   (vert/jaune/bleu/orange/violet/rose, préférée par l'utilisateur) mais saturation
   x1.5-1.6 et luminosité resserrée pour que les bandes adjacentes restent nettement
   distinctes (contraste texte vérifié ≥ 8:1 en clair, ≥ 5:1 en sombre). */
:root {
  --band-0: #befba9;
  --band-1: #ffefa6;
  --band-2: #acdbff;
  --band-3: #ffd1a1;
  --band-4: #d4b2ff;
  --band-5: #f8b5d7;
}

@media (prefers-color-scheme: dark) {
  :root {
    --band-0: #2f5d26;
    --band-1: #60571b;
    --band-2: #1d4160;
    --band-3: #5f3d1e;
    --band-4: #402d5b;
    --band-5: #5b2d40;
  }
}

* { box-sizing: border-box; }

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

main {
  width: 100%;
  padding: 1rem 1.25rem;
}

h1 {
  font-size: 1.4rem;
  margin: 0.5rem 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 3px solid var(--accent-soft);
}

h2 {
  font-size: 1.1rem;
  color: var(--accent);
  margin: 1.75rem 0 0.6rem;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-alt);
  padding: 0.9rem 1rem 1.1rem;
  margin: 0 0 1rem;
  box-shadow: var(--shadow);
}

legend {
  font-weight: 600;
  padding: 0 0.4rem;
}

.topbar {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
  padding: 0.6rem 0.75rem 0;
  position: relative;
}

.burger {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  margin-bottom: 0.5rem;
  box-shadow: var(--shadow);
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.burger:hover {
  background: var(--accent-soft);
  box-shadow: var(--shadow-md);
}

.burger span {
  display: block;
  width: 20px;
  height: 2px;
  border-radius: 2px;
  background: var(--fg);
  transition: transform 0.25s ease, opacity 0.15s ease;
}

.burger[aria-expanded="true"] {
  background: var(--accent-soft);
}

.burger[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.burger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.burger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

nav.tabs {
  display: flex;
  flex: 1;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tabs-sheets, .tabs-secondary {
  display: flex;
  align-items: flex-end;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.tabs-secondary {
  margin-left: auto;
  align-items: center;
  padding-bottom: 0.5rem;
}

/* Onglets façon classeur : coins arrondis en haut, l'onglet actif "fusionne" avec le contenu */
.sheet-tab {
  padding: 0.6rem 1.1rem;
  text-decoration: none;
  color: var(--fg);
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  font-size: 0.95rem;
  position: relative;
  top: 1px;
  opacity: 0.8;
}

.sheet-tab.active {
  background: var(--bg);
  font-weight: 600;
  border-color: var(--accent);
  border-top-width: 3px;
  box-shadow: 0 -3px 6px rgba(0, 0, 0, 0.08);
  opacity: 1;
}

.secondary-link {
  font-size: 0.85rem;
  color: var(--fg);
  text-decoration: none;
  opacity: 0.7;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  padding: 0.3rem 0.4rem;
}

.secondary-link:hover, .secondary-link.active { opacity: 1; }
.secondary-link.active { font-weight: 600; }

.logout-form { display: inline; }

@media (max-width: 700px) {
  .burger { display: flex; }

  nav.tabs {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 12px 12px;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 20;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    visibility: hidden;
    box-shadow: var(--shadow-md);
    transition: max-height 0.28s ease, opacity 0.2s ease, visibility 0s linear 0.28s;
  }

  nav.tabs.open {
    max-height: 26rem;
    opacity: 1;
    visibility: visible;
    transition: max-height 0.28s ease, opacity 0.2s ease;
  }

  .tabs-sheets, .tabs-secondary {
    flex-direction: column;
    align-items: stretch;
    margin-left: 0;
    padding-bottom: 0;
  }

  .sheet-tab {
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--border);
    top: 0;
    padding: 0.85rem 1.1rem;
    transition: background 0.12s ease;
  }

  .sheet-tab:hover { background: var(--accent-soft); }

  .sheet-tab.active {
    box-shadow: none;
    border-left: 4px solid var(--accent);
    background: var(--accent-soft);
  }

  .tabs-secondary {
    border-top: 1px solid var(--border);
    background: var(--bg-alt);
    border-radius: 0 0 11px 11px;
  }

  .secondary-link {
    transition: background 0.12s ease;
  }

  .secondary-link:hover { background: var(--accent-soft); }

  .secondary-link {
    padding: 0.6rem 1.1rem;
    text-align: left;
  }
}

.link-btn {
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}

table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 0;
}

th, td {
  border: 1px solid var(--border);
  padding: 0.55rem 0.65rem;
  text-align: left;
  font-size: 0.9rem;
  background: var(--bg);
}

.table-wrap table { border: none; }
.table-wrap th:first-child, .table-wrap td:first-child { border-left: none; }
.table-wrap th:last-child, .table-wrap td:last-child { border-right: none; }
.table-wrap thead tr:first-child th { border-top: none; }
.table-wrap tbody tr:last-child td { border-bottom: none; }

th {
  background: var(--accent-soft);
  color: var(--fg);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Zèbre + survol sur les tableaux "classiques" (pas le tableau de saisie, déjà
   coloré ligne par ligne via .band-N et qui n'a pas besoin d'un second système). */
tbody tr:not([class*="band-"]):nth-child(even) td {
  background: var(--bg-alt);
}

tbody tr:not([class*="band-"]):hover td {
  background: var(--accent-soft);
}

/* Ligne de tableau entièrement cliquable (ex: liste des salariés → fiche détail) :
   le lien remplit toute la cellule plutôt que de ne couvrir que le texte. */
.row-link-cell { padding: 0 !important; }

.row-link {
  display: block;
  padding: 0.55rem 0.65rem;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

input[type=number], input[type=text], input[type=date], input[type=password] {
  width: 100%;
  padding: 0.45rem 0.55rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

input[type=number]:focus, input[type=text]:focus, input[type=date]:focus, input[type=password]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

button:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input.heures-input {
  width: 4.5rem;
  text-align: right;
}

button, .btn {
  display: inline-block;
  padding: 0.55rem 1.1rem;
  font-size: 1rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, box-shadow 0.15s ease, background 0.15s ease;
  text-decoration: none;
}

button:hover, .btn:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

button:active, .btn:active {
  transform: translateY(0);
  box-shadow: var(--shadow);
}

button.secondary, .btn.secondary {
  background: var(--bg);
  color: var(--accent);
}

button.secondary:hover, .btn.secondary:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.actions-row {
  margin: 1rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

.name-pad {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-width: 280px;
  margin: 1.25rem auto;
}

.name-btn {
  padding: 0.9rem;
  font-size: 1.1rem;
  border-radius: 10px;
  background: var(--bg-alt);
  color: var(--fg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.name-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
  transform: translateY(-1px);
}

#pin-who {
  text-align: center;
  font-weight: 600;
  font-size: 1.1rem;
  margin-bottom: 0;
}

#pin-back {
  display: block;
  margin: 0.5rem auto 0;
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.7rem;
  max-width: 280px;
  margin: 1.25rem auto;
}

.pin-pad button {
  aspect-ratio: 1;
  padding: 0;
  font-size: 1.5rem;
  border-radius: 50%;
  background: var(--bg-alt);
  color: var(--fg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.pin-pad button:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.pin-pad #pin-ok {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  font-size: 1rem;
  font-weight: 600;
}

.pin-pad #pin-ok:hover { background: var(--accent-hover); }

.pin-display {
  text-align: center;
  font-size: 2.2rem;
  letter-spacing: 0.5rem;
  margin: 1rem 0;
  min-height: 2.5rem;
  font-variant-numeric: tabular-nums;
}

.login-wrap {
  max-width: 320px;
  margin: 3rem auto;
  text-align: center;
  padding: 2rem 1.5rem;
  background: var(--bg-alt);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
}

.error { color: #c0392b; font-weight: 600; }

.flashes {
  list-style: none;
  padding: 0.6rem 1rem;
  margin: 0 0 1rem;
  background: var(--flash-bg);
  color: var(--fg);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.flashes li::before { content: "✓ "; color: var(--accent); font-weight: 700; }

.group-title {
  margin-top: 1.5rem;
  margin-bottom: 0.4rem;
}

.checkbox-line {
  display: block;
  padding: 0.3rem 0;
}

.badge-inactive, .badge-active {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-inactive {
  color: #888;
  background: rgba(136, 136, 136, 0.15);
}

.badge-active {
  color: var(--accent);
  background: var(--accent-soft);
}

.filters {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.filters label { display: block; font-size: 0.85rem; margin-bottom: 0.2rem; }

.audit {
  font-size: 0.75rem;
  color: #666;
}

.band-0 td { background: var(--band-0); }
.band-1 td { background: var(--band-1); }
.band-2 td { background: var(--band-2); }
.band-3 td { background: var(--band-3); }
.band-4 td { background: var(--band-4); }
.band-5 td { background: var(--band-5); }

.date-cell, .parcelle-cell {
  font-weight: 600;
  vertical-align: middle;
  background: var(--bg);
  text-align: center;
  overflow: hidden;
}

/* Texte en biais pour gagner de la place dans les colonnes Date/Parcelle, rétrécies. */
.slant {
  display: inline-block;
  transform: rotate(-25deg);
  white-space: nowrap;
}

/* Colonnes figées (Date/Parcelle/Sous-parcelle à gauche, Total à droite) pendant le
   défilement horizontal du tableau de saisie — seules les colonnes salariés défilent. */
.sticky-date, .sticky-parcelle, .sticky-sp, .sticky-total {
  position: sticky;
  z-index: 2;
}

.sticky-date { left: 0; width: 3rem; min-width: 3rem; }
.sticky-parcelle { left: 3rem; width: 4rem; min-width: 4rem; }
.sticky-sp { left: 7rem; width: 6rem; min-width: 6rem; }
.sticky-total { right: 0; width: 4.5rem; min-width: 4.5rem; font-weight: 600; }

thead .sticky-date, thead .sticky-parcelle, thead .sticky-sp, thead .sticky-total {
  z-index: 3;
  background: var(--accent-soft);
}

/* Même principe pour le tableau pivot de la Synthèse : Parcelle figée à gauche,
   Total parcelle et Total H/Ha figés à droite. */
.synth-sticky-parcelle, .synth-sticky-total, .synth-sticky-ha {
  position: sticky;
  z-index: 2;
  font-weight: 600;
}

.synth-sticky-parcelle { left: 0; min-width: 8rem; }
.synth-sticky-total { right: 5.5rem; min-width: 5.5rem; }
.synth-sticky-ha { right: 0; min-width: 5.5rem; }

thead .synth-sticky-parcelle, thead .synth-sticky-total, thead .synth-sticky-ha {
  z-index: 3;
  background: var(--accent-soft);
}

/* Même principe pour le tableau de l'onglet Contrôle : Bloc/Rang/Date castration/Salarié
   figés à gauche pendant le défilement horizontal des colonnes de repasse. */
.rang-sticky-0, .rang-sticky-1, .rang-sticky-2, .rang-sticky-3 {
  position: sticky;
  z-index: 2;
}

.rang-sticky-0 { left: 0; width: 3rem; min-width: 3rem; font-weight: 600; }
.rang-sticky-1 { left: 3rem; width: 3rem; min-width: 3rem; font-weight: 600; }
.rang-sticky-2 { left: 6rem; width: 8rem; min-width: 8rem; }
.rang-sticky-3 { left: 14rem; width: 9rem; min-width: 9rem; }

thead .rang-sticky-0, thead .rang-sticky-1, thead .rang-sticky-2, thead .rang-sticky-3 {
  z-index: 3;
  background: var(--accent-soft);
}

@media (max-width: 700px) {
  /* Le numéro de rang individuel n'est pas indispensable sur mobile — le bloc suffit
     à se repérer. La date de castration se remplit automatiquement dès qu'on
     affecte un salarié (voir save_cell) : pas besoin de la voir/modifier au champ,
     ça se fait sur ordinateur si besoin — les deux colonnes sont masquées ici,
     ce qui laisse toute la place à Salarié et aux repasses. */
  .rang-sticky-1, .rang-sticky-2 { display: none; }

  .rang-sticky-0 { width: 2.3rem; min-width: 2.3rem; padding-left: 0.3rem; padding-right: 0.2rem; }
  .rang-sticky-3 { left: 2.3rem; width: 8rem; min-width: 8rem; }

  select.rang-salarie {
    font-size: 0.85rem;
    padding: 0.3rem 0.2rem;
  }
}

/* Vue cartes de la saisie (mobile) : un tableau large avec 3 colonnes figées + une
   colonne par salarié n'a jamais assez de place sur un téléphone, quel que soit le
   rétrécissement — on bascule donc sur des cartes empilées, une par jour/parcelle,
   avec les salariés listés verticalement plutôt qu'en colonnes. */
.saisie-cards-view { display: none; }

.card-date-heading {
  color: var(--accent);
  font-size: 1rem;
  margin: 1.25rem 0 0.5rem;
}

.saisie-card {
  border-radius: 10px;
  padding: 0.8rem 0.9rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.saisie-card.band-0 { background: var(--band-0); }
.saisie-card.band-1 { background: var(--band-1); }
.saisie-card.band-2 { background: var(--band-2); }
.saisie-card.band-3 { background: var(--band-3); }
.saisie-card.band-4 { background: var(--band-4); }
.saisie-card.band-5 { background: var(--band-5); }

.card-heading {
  font-weight: 700;
  margin-bottom: 0.6rem;
}

.card-fields {
  display: flex;
  flex-direction: column;
}

/* Ligne de séparation fine entre chaque salarié, pour éviter de se tromper de case
   en sautant une ligne des yeux — sans ajouter de hauteur (juste 1px + le padding
   déjà nécessaire pour que la case reste confortable au doigt). */
.card-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}

.card-field:last-child { border-bottom: none; }
.card-field:nth-child(even) { background: rgba(127, 127, 127, 0.06); }

.card-field input.heures-input { width: 5.5rem; flex-shrink: 0; }

.card-field-name {
  font-size: 0.9rem;
}

.card-total {
  margin-top: 0.7rem;
  padding-top: 0.6rem;
  border-top: 1px solid rgba(0, 0, 0, 0.12);
  font-weight: 700;
  text-align: right;
}

@media (max-width: 700px) {
  .saisie-table-view { display: none; }
  .saisie-cards-view { display: block; }
}

.save-status {
  font-size: 0.85rem;
  color: var(--accent);
  align-self: center;
}

.save-status.error { color: #c0392b; }

input.heures-input.cell-saving {
  opacity: 0.6;
}

input.heures-input.cell-error {
  border-color: #c0392b;
  background: #fdecea;
}
