*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bleu:      #1d3f6e;
  --bleu-2:    #2660a4;
  --vert:      #1e7e34;
  --rouge:     #c0392b;
  --orange:    #c05000;
  --bg:        #eef1f5;
  --card:      #ffffff;
  --border:    #c8cdd4;
  --texte:     #1a1a2e;
  --gris:      #6c757d;
  --radius:    10px;
  --shadow:    0 2px 12px rgba(0,0,0,.10);

  /* couleurs postes */
  --matin:     #d97706;
  --aprem:     #2563eb;
  --nuit:      #312e81;
  --soir:      #7c3aed;
}

html { font-size: 17px; height: 100%; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--texte);
  line-height: 1.4;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Login ──────────────────────────────────────────── */
body.page-login {
  overflow: auto;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  height: auto;
  min-height: 100%;
}

.login-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.5rem 2rem 2rem;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-logo { font-size: 3rem; margin-bottom: .5rem; }

.login-card h1 {
  font-size: 1.5rem;
  color: var(--bleu);
  margin-bottom: 1.8rem;
}

.login-card label {
  display: block;
  text-align: left;
  font-weight: 600;
  margin-bottom: .4rem;
}

.login-card input {
  display: block;
  width: 100%;
  padding: .75rem 1rem;
  font-size: 1.4rem;
  letter-spacing: .15em;
  border: 2px solid var(--border);
  border-radius: 8px;
  margin-bottom: 1.2rem;
  text-align: center;
}

.login-card input:focus {
  outline: none;
  border-color: var(--bleu-2);
  box-shadow: 0 0 0 3px rgba(38,96,164,.2);
}

.login-card button {
  display: block;
  width: 100%;
  padding: .85rem;
  font-size: 1.1rem;
  font-weight: 700;
  background: var(--bleu);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.login-card button:hover { background: var(--bleu-2); }

/* ── Alertes ─────────────────────────────────────────── */
.alerte {
  padding: .55rem 1rem;
  border-radius: 7px;
  margin-bottom: .6rem;
  font-size: .9rem;
  flex-shrink: 0;
}

.alerte-erreur  { background: #fde8e8; color: var(--rouge); border-left: 4px solid var(--rouge); }
.alerte-succes  { background: #d4edda; color: var(--vert);  border-left: 4px solid var(--vert);  }

.badge-correction {
  display: inline-block;
  background: #fff3cd;
  color: var(--orange);
  border: 1px solid #ffc107;
  border-radius: 6px;
  padding: .25rem .7rem;
  font-size: .85rem;
  font-weight: 600;
  margin-bottom: .6rem;
  flex-shrink: 0;
}

/* ── Topbar ──────────────────────────────────────────── */
.topbar {
  background: var(--bleu);
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .6rem 1.2rem;
  flex-shrink: 0;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}

.topbar-nom     { font-weight: 700; font-size: 1rem; }
.topbar-mat     { font-size: .82rem; opacity: .7; margin-left: .4rem; }

.btn-logout {
  background: rgba(255,255,255,.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 6px;
  padding: .35rem .85rem;
  text-decoration: none;
  font-size: .88rem;
}

.btn-logout:hover { background: rgba(255,255,255,.28); }

/* ── Indicateur auto-save ────────────────────────────*/
.save-status {
  font-size: .82rem;
  font-weight: 600;
  padding: .2rem .7rem;
  border-radius: 20px;
  transition: all .3s;
  white-space: nowrap;
}

.save-status.pending { background: rgba(255,255,255,.12); color: #fde68a; }
.save-status.saving  { background: rgba(255,255,255,.12); color: #fde68a; }
.save-status.saved   { background: rgba(110,231,183,.2);  color: #6ee7b7; }
.save-status.error   { background: rgba(252,165,165,.2);  color: #fca5a5; }

/* ── Bandeau machines ────────────────────────────────*/
.barre-machines {
  background: #f0f4f8;
  border-bottom: 2px solid var(--border);
  padding: .4rem .9rem;
  display: flex;
  align-items: center;
  gap: .7rem;
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: thin;
}

.machine-label {
  font-size: .75rem;
  font-weight: 700;
  color: var(--gris);
  text-transform: uppercase;
  letter-spacing: .07em;
  white-space: nowrap;
  flex-shrink: 0;
}

.machine-liste {
  display: flex;
  gap: .4rem;
  flex-wrap: nowrap;
}

.btn-machine {
  padding: .38rem .85rem;
  font-size: .9rem;
  font-weight: 700;
  border: 2px solid var(--border);
  border-radius: 7px;
  background: var(--card);
  color: var(--texte);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all .15s;
  letter-spacing: .02em;
}

.btn-machine:hover { border-color: var(--bleu-2); color: var(--bleu-2); }

.btn-machine.actif {
  background: var(--bleu);
  border-color: var(--bleu);
  color: #fff;
  box-shadow: 0 2px 6px rgba(29,63,110,.35);
}

/* ── Barre contextuelle (date / poste / total) ───────── */
.barre-ctx {
  background: var(--card);
  border-bottom: 2px solid var(--border);
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.07);
}

.ctx-section {
  padding: .6rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
}

.ctx-section + .ctx-section {
  border-left: 1px solid var(--border);
}

.ctx-label {
  font-size: .75rem;
  font-weight: 700;
  color: var(--gris);
  text-transform: uppercase;
  letter-spacing: .07em;
}

/* Date */
.ctx-date input[type="date"] {
  padding: .45rem .7rem;
  font-size: .95rem;
  border: 2px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  cursor: pointer;
  min-height: 44px;
  width: 100%;
  max-width: 200px;
}

.ctx-date input[type="date"]:focus {
  outline: none;
  border-color: var(--bleu-2);
  box-shadow: 0 0 0 3px rgba(38,96,164,.2);
}

/* Poste (centre, dominant) */
.ctx-poste { align-items: center; }

.ctx-poste-label {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .75rem;
  font-weight: 700;
  color: var(--gris);
  text-transform: uppercase;
  letter-spacing: .07em;
}

.badge-auto {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #6ee7b7;
  border-radius: 20px;
  padding: .1rem .55rem;
  font-size: .72rem;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
}

.poste-boutons {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-poste {
  padding: .5rem 1.1rem;
  font-size: .95rem;
  font-weight: 700;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--gris);
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}

.btn-poste:hover { border-color: var(--bleu-2); color: var(--bleu-2); }

.btn-poste.actif-matin { background: var(--matin); border-color: var(--matin); color: #fff; font-size: 1.05rem; }
.btn-poste.actif-aprem { background: var(--aprem); border-color: var(--aprem); color: #fff; font-size: 1.05rem; }
.btn-poste.actif-nuit  { background: var(--nuit);  border-color: var(--nuit);  color: #fff; font-size: 1.05rem; }
.btn-poste.actif-soir  { background: var(--soir);  border-color: var(--soir);  color: #fff; font-size: 1.05rem; }

/* Total */
.ctx-total { align-items: flex-end; }

.valeur-total {
  font-size: 2rem;
  font-weight: 900;
  color: var(--bleu);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

/* ── Contenu (plein écran) ───────────────────────────── */
.contenu {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: .6rem .8rem .5rem;
  max-width: 100%;
}

/* ── Formulaire plein écran ──────────────────────────── */
.form-pointage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ── Grille 3 colonnes ───────────────────────────────── */
.grille-blocs {
  flex: 1;
  display: grid;
  grid-template-columns: 3fr 3fr 2fr;
  gap: .8rem;
  align-items: stretch;
  min-height: 0;
}

/* ── Blocs ───────────────────────────────────────────── */
.bloc {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.bloc-titre {
  background: var(--bleu);
  color: #fff;
  padding: .55rem 1rem;
  font-size: .88rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  flex-shrink: 0;
}

.bloc-titre.titre-improd { background: var(--orange); }
.bloc-titre.titre-divers { background: var(--gris); }

.bloc-corps {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: .6rem .8rem .8rem;
  display: flex;
  flex-direction: column;
}

/* ── En-têtes colonnes ───────────────────────────────── */
.row-entetes {
  display: grid;
  gap: .4rem;
  padding-bottom: .35rem;
  font-size: .75rem;
  font-weight: 700;
  color: var(--gris);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
  margin-bottom: .4rem;
  flex-shrink: 0;
}

.row-entetes.entetes-prod   { grid-template-columns: 1fr 100px 60px 40px; }
.row-entetes.entetes-improd { grid-template-columns: 1fr 100px 40px; }
.col-centre { text-align: center; }

/* ── Lignes de données ───────────────────────────────── */
.ligne-donnees {
  display: grid;
  gap: .4rem;
  margin-bottom: .4rem;
  align-items: center;
}

.ligne-donnees.ligne-prod   { grid-template-columns: 1fr 100px 60px 40px; }
.ligne-donnees.ligne-improd { grid-template-columns: 1fr 100px 40px; }

.input-texte,
.input-temps {
  width: 100%;
  padding: .55rem .65rem;
  font-size: .95rem;
  border: 2px solid var(--border);
  border-radius: 7px;
  min-height: 46px;
  transition: border-color .15s;
}

.input-texte:focus,
.input-temps:focus {
  outline: none;
  border-color: var(--bleu-2);
  box-shadow: 0 0 0 3px rgba(38,96,164,.18);
}

.input-temps {
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.case-termine {
  display: flex;
  justify-content: center;
  align-items: center;
}

.case-termine input[type="checkbox"] {
  width: 24px;
  height: 24px;
  cursor: pointer;
  accent-color: var(--vert);
}

.btn-suppr {
  width: 40px;
  height: 40px;
  background: #fde8e8;
  color: var(--rouge);
  border: 1px solid #f5c6c6;
  border-radius: 7px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-suppr:hover { background: #f8b4b4; }

.btn-ajouter {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  margin-top: .5rem;
  padding: .45rem 1rem;
  font-size: .88rem;
  font-weight: 600;
  background: #eef4fb;
  color: var(--bleu-2);
  border: 2px dashed var(--bleu-2);
  border-radius: 7px;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-ajouter:hover { background: #ddeaf8; }

/* ── Ligne sous-total dans chaque bloc ───────────────*/
.ligne-sous-total {
  display: grid;
  gap: .4rem;
  align-items: center;
  margin-top: .5rem;
  padding: .45rem .6rem;
  background: var(--bg);
  border-radius: 7px;
  border: 1px solid var(--border);
  font-size: .88rem;
  font-weight: 700;
  color: var(--bleu);
  flex-shrink: 0;
}

.bloc:has(#prod-rows) .ligne-sous-total  { grid-template-columns: 1fr 100px 60px 40px; }
.bloc:has(#improd-rows) .ligne-sous-total { grid-template-columns: 1fr 100px 40px; }

.sous-total-valeur {
  text-align: center;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  color: var(--bleu);
}

/* ── Textarea divers ─────────────────────────────────── */
.textarea-divers {
  flex: 1;
  width: 100%;
  padding: .65rem .8rem;
  font-size: .95rem;
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: 7px;
  resize: none;
  line-height: 1.5;
  min-height: 80px;
}

.textarea-divers:focus {
  outline: none;
  border-color: var(--bleu-2);
  box-shadow: 0 0 0 3px rgba(38,96,164,.18);
}

/* ── Bouton enregistrer ──────────────────────────────── */
.btn-enregistrer {
  display: block;
  width: 100%;
  padding: .75rem;
  font-size: 1.05rem;
  font-weight: 700;
  background: var(--vert);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  margin-top: .5rem;
  flex-shrink: 0;
  box-shadow: 0 3px 10px rgba(30,126,52,.3);
  transition: background .15s;
}

.btn-enregistrer:hover  { background: #176a2b; }
.btn-enregistrer:active { transform: scale(.99); }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 900px) {
  body { overflow: auto; }

  .barre-ctx { grid-template-columns: 1fr; }
  .ctx-section + .ctx-section { border-left: none; border-top: 1px solid var(--border); }
  .ctx-total { align-items: flex-start; }

  .grille-blocs { grid-template-columns: 1fr; }
  .bloc { min-height: 200px; }
}
