/* Tableau de bord Synchrone X82 — affinage visuel et adaptation mobile/tablette
 *
 * À charger APRÈS synchrone-x82.css (même spécificité : c'est l'ordre qui décide).
 * Fichier volontairement séparé : il ne dépend que des noms de classes du tableau de bord
 * et se retire en supprimant simplement le <link>.
 *
 * Saisie horaire : elle suit la largeur RÉELLE du panneau (container query), pas celle de la fenêtre.
 *            panneau ≥ 900 px  les 8 cadres tiennent sur une ligne et se resserrent (96 → 80 px) au lieu de défiler
 *            panneau < 900 px  les cadres se replient en 2 colonnes, une pause = une rangée pleine largeur
 *            (un écran de 1366 px réglé à 125 %, ou une fenêtre avec ascenseur, ne laisse que ~950 px)
 *
 * Paliers :  ≥ 1041 px  bureau
 *            ≤ 1040 px  tablette : cumul collé en bas de l'écran, champs plus grands
 *            ≤  860 px  récapitulation en fiches (2 par ligne, puis 1 seule)
 *            ≤  640 px  téléphone : onglets en grille, champs plus grands
 */

/* ---------- Fond : même quadrillage de plan que la page de statistiques ---------- */
#synchrone-x82.wrap { background: transparent; --radius: 14px; }

main.app-main:has(#synchrone-x82) {
  --st-grid: rgba(47, 95, 219, 0.075);
  background-image:
    linear-gradient(to bottom, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 240px, var(--app-bg) 600px),
    linear-gradient(var(--st-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--st-grid) 1px, transparent 1px);
  background-size: 100% 100%, 32px 32px, 32px 32px;
  background-repeat: no-repeat, repeat, repeat;
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) main.app-main:has(#synchrone-x82) { --st-grid: rgba(109, 147, 255, 0.09); }
}
html[data-theme="dark"] main.app-main:has(#synchrone-x82) { --st-grid: rgba(109, 147, 255, 0.09); }

#synchrone-x82 header.top h1 { font-size: 22px; letter-spacing: -0.4px; }

/* ---------- Pauses : un trait pointillé et une étiquette posée dessus, qui ne déborde plus ---------- */
#synchrone-x82 .break-sep {
  position: relative;
  width: 58px;
  justify-content: center;
  gap: 0;
}
#synchrone-x82 .break-sep .bar { display: none; }
#synchrone-x82 .break-sep::before {
  content: "";
  position: absolute;
  top: 6px; bottom: 6px; left: 50%;
  border-left: 2px dotted var(--border);
}
#synchrone-x82 .break-sep .lbl {
  position: relative;
  white-space: normal;
  max-width: 42px;        /* « Pause » puis « 10 min » : deux lignes, jamais plus large que la colonne */
  padding: 5px 0;
  background: var(--panel);
  font-size: 10px;
  line-height: 1.25;
  font-weight: 600;
}

/* ---------- Cartes des heures ---------- */
/* La ligne ne défile jamais de côté. Les cadres (96 px) et les pauses (58 px) peuvent se resserrer
   jusqu'à 80 px / 46 px ; quand le panneau est trop étroit même ainsi, on passe en grille (plus bas).
   Le préfixe #entryPanel garantit la priorité sur synchrone-x82.css, quel que soit l'ordre des règles. */
#synchrone-x82 #entryPanel { container: entry / inline-size; }
#synchrone-x82 #entryPanel .hours-row { overflow: visible; }
#synchrone-x82 #entryPanel .hour-card { flex: 0 1 96px; min-width: 80px; }
#synchrone-x82 #entryPanel .break-sep { flex: 0 1 58px; min-width: 46px; }

#synchrone-x82 .hour-card input { font-size: 15px; }
#synchrone-x82 .hour-card input:focus-visible,
#synchrone-x82 .field-group input:focus-visible,
#synchrone-x82 .field-group textarea:focus-visible,
#synchrone-x82 .justification-other:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- Récapitulation : en-têtes en minuscules, plus calmes ---------- */
#synchrone-x82 table.recap th { text-transform: none; letter-spacing: 0; font-size: 12px; }
#synchrone-x82 #recapTableWrap { overflow-x: auto; }
#synchrone-x82 table.recap tbody tr:not(.recap-synthesis) td:first-child { font-weight: 600; }

/* ============================================================
   Saisie horaire repliée : grille de 2 colonnes, chaque pause occupe une rangée pleine largeur.
   Même bloc deux fois : selon la largeur du panneau (container query), et selon celle de la fenêtre
   pour les très vieux navigateurs qui ne connaissent pas les container queries.
   ============================================================ */
@container entry (max-width: 899px) {
  #synchrone-x82 #entryPanel .hours-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    overflow: visible;
    padding-bottom: 0;
  }
  #synchrone-x82 #entryPanel .hour-card { flex: none; min-width: 0; padding: 10px; }
  #synchrone-x82 .hour-card input { font-size: 16px; padding: 9px 6px; scroll-margin-bottom: 120px; }
  #synchrone-x82 .hour-card .h-label { font-size: 12px; }
  #synchrone-x82 .hour-card .h-target { font-size: 11.5px; }
  #synchrone-x82 .hour-card .h-label-num { font-size: 12px; padding: 5px 4px; }
  #synchrone-x82 .hour-card .h-comment { font-size: 11px; min-height: 14px; }

  #synchrone-x82 #entryPanel .break-sep { grid-column: 1 / -1; flex: none; width: auto; min-width: 0; flex-direction: row; padding: 0; }
  #synchrone-x82 .break-sep::before {
    top: 50%; bottom: auto; left: 0; right: 0;
    border-left: 0;
    border-top: 2px dotted var(--border);
  }
  #synchrone-x82 .break-sep .lbl { max-width: none; white-space: nowrap; padding: 2px 12px; font-size: 11.5px; }
}

/* ============================================================
   Tablette et en dessous (≤ 1040 px)
   ============================================================ */
@media (max-width: 1040px) {
  #synchrone-x82 #entryPanel .hours-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    overflow: visible;
    padding-bottom: 0;
  }
  #synchrone-x82 #entryPanel .hour-card { flex: none; min-width: 0; padding: 10px; }
  #synchrone-x82 .hour-card input { font-size: 16px; padding: 9px 6px; scroll-margin-bottom: 120px; }
  #synchrone-x82 .hour-card .h-label { font-size: 12px; }
  #synchrone-x82 .hour-card .h-target { font-size: 11.5px; }
  #synchrone-x82 .hour-card .h-label-num { font-size: 12px; padding: 5px 4px; }
  #synchrone-x82 .hour-card .h-comment { font-size: 11px; min-height: 14px; }

  #synchrone-x82 #entryPanel .break-sep { grid-column: 1 / -1; flex: none; width: auto; min-width: 0; flex-direction: row; padding: 0; }
  #synchrone-x82 .break-sep::before {
    top: 50%; bottom: auto; left: 0; right: 0;
    border-left: 0;
    border-top: 2px dotted var(--border);
  }
  #synchrone-x82 .break-sep .lbl { max-width: none; white-space: nowrap; padding: 2px 12px; font-size: 11.5px; }

  /* Le cumul reste visible en bas de l'écran pendant qu'on saisit les heures. */
  #synchrone-x82 .cumul-row {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin: 12px -12px 0;
    padding: 10px 12px max(10px, env(safe-area-inset-bottom));
    gap: 8px 16px;
    background: var(--panel);
    border-top: 1px solid var(--border);
    box-shadow: 0 -8px 14px -10px rgba(0, 0, 0, 0.35);
  }
  #synchrone-x82 .cumul-box .val { font-size: 18px; }
  #synchrone-x82 .cumul-comment { font-size: 12px; padding: 4px 9px; }
  #synchrone-x82 .today-btn { padding: 8px 12px; }

  #synchrone-x82 .field-group input:not([type="checkbox"]) { font-size: 16px; min-height: 42px; }
  #synchrone-x82 .justification-other { font-size: 16px; }
}

/* ============================================================
   Récapitulation en fiches (≤ 860 px)
   Les libellés des colonnes sont ajoutés par CSS (aucune modification du JavaScript).
   ============================================================ */
@media (max-width: 860px) {
  #synchrone-x82 #recapTableWrap { overflow-x: visible; }
  #synchrone-x82 table.recap,
  #synchrone-x82 table.recap tbody { display: block; }
  #synchrone-x82 table.recap tbody {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  /* En-têtes masqués visuellement, mais gardés pour les lecteurs d'écran */
  #synchrone-x82 table.recap thead {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }

  #synchrone-x82 table.recap tr {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-areas:
      "line  team  team"
      "state state state"
      "tags  qty   obj"
      "reb   ops   ."
      "just  just  just";
    gap: 6px 10px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--panel-alt);
    min-width: 0;
  }
  #synchrone-x82 table.recap td {
    display: block;
    padding: 0;
    border: 0;
    min-width: 0;
    overflow-wrap: anywhere;
  }
  #synchrone-x82 table.recap td:nth-child(1) { grid-area: line; color: var(--text-muted); font-weight: 600; }
  #synchrone-x82 table.recap td:nth-child(2) { grid-area: team; font-weight: 700; }
  #synchrone-x82 table.recap td:nth-child(8) { grid-area: state; margin-bottom: 2px; }
  #synchrone-x82 table.recap td:nth-child(3) { grid-area: tags; }
  #synchrone-x82 table.recap td:nth-child(4) { grid-area: qty; font-size: 18px; line-height: 1.1; }
  #synchrone-x82 table.recap td:nth-child(5) { grid-area: obj; }
  #synchrone-x82 table.recap td:nth-child(6) { grid-area: reb; }
  #synchrone-x82 table.recap td:nth-child(7) { grid-area: ops; }
  #synchrone-x82 table.recap td:nth-child(9) { grid-area: just; max-width: none; }
  #synchrone-x82 table.recap td:nth-child(9):empty { display: none; }

  #synchrone-x82 table.recap td:nth-child(n+3):not(:nth-child(8))::before {
    display: block;
    margin-bottom: 1px;
    color: var(--text-muted);
    font-size: 10.5px;
    font-style: normal;
    font-weight: 600;
    line-height: 1.3;
  }
  #synchrone-x82 table.recap td:nth-child(3)::before { content: "Plage d'étiquettes"; }
  #synchrone-x82 table.recap td:nth-child(4)::before { content: "Quantité produite"; font-size: 10.5px; }
  #synchrone-x82 table.recap td:nth-child(5)::before { content: "Objectif"; }
  #synchrone-x82 table.recap td:nth-child(6)::before { content: "Rebut"; }
  #synchrone-x82 table.recap td:nth-child(7)::before { content: "Opérateurs"; }
  #synchrone-x82 table.recap td:nth-child(9)::before { content: "Justification"; }

  /* Fiches colorées par équipe : on garde les fonds du tableau de bord */
  #synchrone-x82 table.recap tbody tr[data-team="equipe1"] { background: var(--team1-bg); border-color: var(--team1-strong); }
  #synchrone-x82 table.recap tbody tr[data-team="equipe2"] { background: var(--team2-bg); border-color: var(--team2-strong); }
  #synchrone-x82 table.recap tbody tr[data-team="nuit"]    { background: var(--team3-bg); border-color: var(--team3-strong); }
  #synchrone-x82 table.recap tr.recap-synthesis { background: var(--panel); border-width: 2px; }
  #synchrone-x82 table.recap tr.recap-synthesis td { background: transparent; border-top: 0; }

  #synchrone-x82 .recap-totals { display: grid; grid-template-columns: 1fr; gap: 6px; }
  #synchrone-x82 .recap-totals .t { display: flex; justify-content: space-between; gap: 12px; }
}

@media (max-width: 560px) {
  #synchrone-x82 table.recap tbody { grid-template-columns: 1fr; }
}

/* ============================================================
   Téléphone (≤ 640 px)
   ============================================================ */
@media (max-width: 640px) {
  #synchrone-x82.wrap { padding: 12px 12px 40px; }
  #synchrone-x82 header.top { margin-bottom: 12px; }
  #synchrone-x82 header.top h1 { font-size: 18px; }

  #synchrone-x82 .date-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px 10px;
    padding: 12px;
  }
  #synchrone-x82 .date-row input[type="date"] { width: 100%; min-width: 0; min-height: 42px; font-size: 16px; }
  #synchrone-x82 .date-row .today-btn { min-height: 42px; }
  #synchrone-x82 .rotation-control {
    grid-column: 1 / -1;
    margin-left: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  #synchrone-x82 .rotation-control label { grid-column: 1 / -1; }
  #synchrone-x82 .rotation-btn { min-height: 42px; }

  #synchrone-x82 #lineTabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  #synchrone-x82 #teamTabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  #synchrone-x82 .tab-btn { min-height: 44px; padding: 8px 6px; line-height: 1.2; text-align: center; }
  #synchrone-x82 .tab-btn.sub { padding: 8px 4px; font-size: 12.5px; }

  /* Barre du cumul plus compacte : elle recouvre une partie de l'écran pendant la saisie. */
  #synchrone-x82 .cumul-row { padding-top: 8px; gap: 4px 14px; }
  #synchrone-x82 .cumul-box .val { font-size: 17px; }
  #synchrone-x82 .cumul-row button { padding: 5px 10px; font-size: 12.5px; }

  #synchrone-x82 .panel { padding: 12px; margin-bottom: 16px; }
  #synchrone-x82 #entryPanel h2 { font-size: 14.5px; line-height: 1.3; }
  #synchrone-x82 .panel .meta { font-size: 12px; margin-bottom: 12px; }

  #synchrone-x82 .extra-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
  }
  #synchrone-x82 .field-group { min-width: 0; }
  #synchrone-x82 .field-group.grow { grid-column: 1 / -1; }

  /* Motifs : de vraies zones à toucher, au lieu de petites cases isolées */
  #synchrone-x82 .justification-checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  #synchrone-x82 .justification-check {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-alt);
    line-height: 1.2;
  }
  #synchrone-x82 .justification-check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
  #synchrone-x82 .justification-check input { width: 18px; height: 18px; flex-shrink: 0; padding: 0; }

  #synchrone-x82 .help-overlay { padding: 8px; }
  #synchrone-x82 .help-modal { max-height: 94vh; }
  #synchrone-x82 footer.hint { margin-top: 16px; }
}

@media (max-width: 360px) {
  #synchrone-x82 .justification-checks { grid-template-columns: 1fr; }
  #synchrone-x82 .tab-btn.sub { font-size: 12px; }
}

/* ============================================================
   Verrouillage : le cadenas doit se voir du premier coup d'œil
   (classes posées par synchrone-x82.js : .is-locked, .lock-banner, .lock-mark)
   ============================================================ */
#synchrone-x82 {
  --lock-bg: #fff6e0;
  --lock-text: #7a4e00;
  --lock-border: #e8b84b;
  --lock-strong: #b07400;
  --lock-hatch: rgba(176, 116, 0, 0.07); /* hachures du panneau : très discrètes, la saisie reste lisible */
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) #synchrone-x82 {
    --lock-bg: #3a2c0c;
    --lock-text: #f3c969;
    --lock-border: #8a6a1f;
    --lock-strong: #ffc94d;
    --lock-hatch: rgba(255, 201, 77, 0.035);
  }
}
html[data-theme="dark"] #synchrone-x82 {
  --lock-bg: #3a2c0c;
  --lock-text: #f3c969;
  --lock-border: #8a6a1f;
  --lock-strong: #ffc94d;
  --lock-hatch: rgba(255, 201, 77, 0.035);
}

/* Bandeau en haut du panneau de saisie */
#synchrone-x82 .lock-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
  padding: 11px 13px;
  border: 1px solid var(--lock-border);
  border-radius: 10px;
  background: var(--lock-bg);
  color: var(--lock-text);
}
#synchrone-x82 .lock-banner .lock-icon { font-size: 20px; line-height: 1.1; flex-shrink: 0; }
#synchrone-x82 .lock-banner .lock-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
#synchrone-x82 .lock-banner strong { font-size: 14px; letter-spacing: -0.1px; }
#synchrone-x82 .lock-banner .lock-sub { font-size: 12.5px; line-height: 1.4; opacity: 0.92; }

/* Le panneau entier change d'allure : liseré ambré et fines hachures */
#synchrone-x82 .panel.is-locked {
  border-color: var(--lock-border);
  box-shadow: inset 4px 0 0 var(--lock-strong), var(--shadow);
  background-image: repeating-linear-gradient(135deg, var(--lock-hatch) 0 8px, transparent 8px 20px);
}
/* Champs figés : grisés, curseur « interdit », mais toujours lisibles */
#synchrone-x82 .panel.is-locked input:disabled,
#synchrone-x82 .panel.is-locked textarea:disabled {
  cursor: not-allowed;
  opacity: 0.75;
  background: var(--panel-alt);
}

/* Bouton « Déverrouiller », posé à droite dans le bandeau */
#synchrone-x82 .lock-banner .unlock-btn {
  margin-left: auto;
  flex-shrink: 0;
  align-self: center;
  padding: 7px 13px;
  border: 1px solid var(--lock-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--lock-text);
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
#synchrone-x82 .lock-banner .unlock-btn:hover { background: var(--lock-strong); color: #fff; }

/* Clôture de poste : en bas du panneau, discret mais à portée de main */
#synchrone-x82 .lock-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
}
#synchrone-x82 .lock-btn {
  padding: 9px 15px;
  border: 1px solid var(--lock-border);
  border-radius: 8px;
  background: var(--lock-bg);
  color: var(--lock-text);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
#synchrone-x82 .lock-btn:hover { background: var(--lock-strong); border-color: var(--lock-strong); color: #fff; }
#synchrone-x82 .lock-actions-note { font-size: 12px; color: var(--text-muted); }
#synchrone-x82 .lock-btn:focus-visible,
#synchrone-x82 .lock-banner .unlock-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Plage d'étiquettes qui franchit 999 : « 960–999 puis 1–226 » ne se coupe qu'avant « puis » */
#synchrone-x82 .tag-cell .nb { white-space: nowrap; }

/* Cadenas dans la récapitulation et sur les onglets */
#synchrone-x82 .lock-mark { font-size: 12px; margin-left: 2px; vertical-align: middle; }
#synchrone-x82 .tab-btn.sub.is-locked { border-color: var(--lock-border); }
#synchrone-x82 .tab-btn.sub.is-locked:not(.active) { background: var(--lock-bg); color: var(--lock-text); }

@media (max-width: 640px) {
  #synchrone-x82 .lock-banner { padding: 10px; gap: 8px; flex-wrap: wrap; }
  #synchrone-x82 .lock-banner .lock-icon { font-size: 18px; }
  #synchrone-x82 .lock-banner strong { font-size: 13.5px; }
  #synchrone-x82 .lock-banner .lock-sub { font-size: 12px; }
  /* Doigts : le bouton passe en pleine largeur sous le texte */
  #synchrone-x82 .lock-banner .unlock-btn { width: 100%; margin-left: 0; min-height: 42px; }
  #synchrone-x82 .lock-btn { width: 100%; min-height: 44px; }
  #synchrone-x82 .lock-actions-note { font-size: 11.5px; }
}

@media print {
  #synchrone-x82 .lock-banner { border-color: #999; background: #f4f4f4; color: #000; }
  #synchrone-x82 .lock-actions, #synchrone-x82 .lock-banner .unlock-btn { display: none; }
}

/* Lien vers l'affichage de la rotation, dans l'en-tête du tableau de bord */
#synchrone-x82 .rotation-link {
  padding: 6px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-alt);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
#synchrone-x82 .rotation-link:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
@media (max-width: 640px) {
  #synchrone-x82 .rotation-link { font-size: 12px; padding: 5px 9px; }
}
@media print { #synchrone-x82 .rotation-link { display: none; } }
