*, *::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); }

.btn-batiment {
  display: block;
  width: 100%;
  padding: 1.1rem;
  font-size: 1.25rem;
  font-weight: 700;
  background: var(--bleu);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  letter-spacing: .03em;
}
.btn-batiment:hover { background: var(--bleu-2); }
.btn-batiment-b10 { background: #1e7e34; }
.btn-batiment-b10:hover { background: #27a447; }

/* ── 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; }

.badge-batiment {
  display: inline-block;
  background: rgba(255,255,255,.2);
  color: #fff;
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 5px;
  padding: .15rem .55rem;
  font-size: .8rem;
  font-weight: 700;
  text-decoration: none;
  margin-left: .6rem;
  vertical-align: middle;
  letter-spacing: .04em;
}
.badge-batiment:hover { background: rgba(255,255,255,.32); }

.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: .55rem 1.2rem;
  font-size: .95rem;
  font-weight: 700;
  border: 2px solid #9aa3af;
  border-radius: 8px;
  background: #fff;
  color: #3a4555;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
}

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

.btn-poste.actif-matin {
  background: var(--matin); border-color: var(--matin); color: #fff;
  font-size: 1.05rem; box-shadow: 0 3px 10px rgba(217,119,6,.45);
  transform: translateY(-1px);
}
.btn-poste.actif-aprem {
  background: var(--aprem); border-color: var(--aprem); color: #fff;
  font-size: 1.05rem; box-shadow: 0 3px 10px rgba(37,99,235,.45);
  transform: translateY(-1px);
}
.btn-poste.actif-nuit {
  background: var(--nuit); border-color: var(--nuit); color: #fff;
  font-size: 1.05rem; box-shadow: 0 3px 10px rgba(49,46,129,.45);
  transform: translateY(-1px);
}
.btn-poste.actif-soir {
  background: var(--soir); border-color: var(--soir); color: #fff;
  font-size: 1.05rem; box-shadow: 0 3px 10px rgba(124,58,237,.45);
  transform: translateY(-1px);
}

/* Total */
.ctx-total {
  align-items: center;
  background: var(--bleu);
  border-left: none !important;
  padding: .7rem 1.4rem;
}

.ctx-total .ctx-label {
  color: rgba(255,255,255,.75);
}

.valeur-total {
  font-size: 2.2rem;
  font-weight: 900;
  color: #fff;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
}

/* ── 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: minmax(0, 2.5fr) minmax(0, 3fr) minmax(0, 8fr);
  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: .5rem 1rem;
  font-size: .82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

.bloc-titre-total {
  font-size: .95rem;
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  letter-spacing: .02em;
  text-transform: none;
  opacity: .92;
}

.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: 2fr minmax(8.2rem, 2.6fr) 0.7fr 0.6fr; }
.row-entetes.entetes-improd { grid-template-columns: 2.5fr minmax(8.2rem, 2.6fr) 0.6fr; }
.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: 3fr 1.5fr 1fr 0.8fr; }
.ligne-donnees.ligne-improd { grid-template-columns: 4fr 1.5fr 0.8fr; align-items: start; }

.ligne-improd .saisie-temps { font-size: 1.15rem; }

/* ── Saisie temps : [00] h [00] min sur une ligne ──── */
.saisie-temps {
  display: flex;
  align-items: center;
  gap: .2rem;
  white-space: nowrap;
}

.saisie-temps .input-temps {
  width: 3rem;
  min-width: 0;
  min-height: 36px;
  padding: .3rem .2rem;
  text-align: center;
  flex-shrink: 0;
}

.temps-label {
  font-size: .75rem;
  font-weight: 600;
  color: var(--gris);
  margin-right: .25rem;
}

.improd-nature {
  font-size: .78rem;
  resize: none;
  line-height: 1.4;
  padding: .35rem .45rem;
  min-height: unset;
}

.input-texte,
.input-temps {
  width: 100%;
  padding: .4rem .45rem;
  font-size: .88rem;
  border: 2px solid var(--border);
  border-radius: 6px;
  min-height: 38px;
  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;
  padding: .4rem .2rem;
  font-size: .85rem;
  min-height: 36px;
}

.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: 28px;
  height: 28px;
  background: #fde8e8;
  color: var(--rouge);
  border: 1px solid #f5c6c6;
  border-radius: 6px;
  font-size: .75rem;
  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);
}

/* ── Consigne manager (encart bleu) ─────────────────── */
.cons-mgr {
  background: #eff6ff;
  border: 1px solid #93c5fd;
  border-left: 3px solid #2563eb;
  border-radius: 8px;
  padding: .55rem .75rem;
  flex-shrink: 0;
}

.cons-mgr-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .35rem;
}

.cons-mgr-titre {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: #1d4ed8;
  flex: 1;
}

.cons-mgr-meta {
  font-size: .68rem;
  color: #60a5fa;
}

.cons-mgr-save {
  font-size: .7rem;
  font-weight: 700;
  padding: .2rem .6rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

.cons-mgr-save:hover { background: #1d4ed8; }

.cons-mgr-textarea {
  width: 100%;
  font-size: .82rem;
  font-family: inherit;
  border: 1px solid #93c5fd;
  border-radius: 6px;
  padding: .4rem .5rem;
  resize: none;
  min-height: 56px;
  background: #fff;
  line-height: 1.45;
}

.cons-mgr-textarea:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37,99,235,.15);
}

.cons-mgr-texte {
  font-size: .82rem;
  color: #1e40af;
  line-height: 1.5;
}

/* ── Consignes précédentes (lecture seule) ───────────── */
.cons-prev {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-left: 3px solid #94a3b8;
  border-radius: 8px;
  padding: .55rem .75rem;
  flex-shrink: 0;
}

.cons-prev-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .4rem;
}

.cons-prev-titre {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: #64748b;
}

.cons-prev-meta {
  font-size: .68rem;
  color: #94a3b8;
  flex: 1;
}

.cons-prev-nav {
  display: flex;
  align-items: center;
  gap: .25rem;
  flex-shrink: 0;
}

.cons-nav-btn {
  width: 22px;
  height: 22px;
  background: #e2e8f0;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #475569;
}

.cons-nav-btn:hover:not(:disabled) { background: #cbd5e1; }
.cons-nav-btn:disabled { opacity: .35; cursor: default; }

.cons-nav-pos {
  font-size: .68rem;
  color: #94a3b8;
  min-width: 28px;
  text-align: center;
}

.cons-prev-fields {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  margin-bottom: .35rem;
}

.cons-prev-pill {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  background: #e2e8f0;
  border-radius: 5px;
  padding: .15rem .5rem;
  font-size: .78rem;
  color: #334155;
}

.cons-prev-pill-lbl {
  font-weight: 700;
  color: #64748b;
  font-size: .68rem;
  text-transform: uppercase;
}

.cons-prev-texte {
  font-size: .78rem;
  color: #475569;
  line-height: 1.45;
  white-space: pre-wrap;
}

.cons-prev-lignes {
  margin-top: .4rem;
}

.cons-prev-section-titre {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #94a3b8;
  margin: .45rem 0 .2rem;
}

.cons-prev-ligne {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  padding: .18rem 0;
  border-bottom: 1px solid #f1f5f9;
  font-size: .78rem;
}

.cons-prev-ligne:last-child { border-bottom: none; }

.cpll-of, .cpll-nature {
  flex: 1;
  color: #1e293b;
  font-weight: 600;
}

.cpll-nature { font-weight: 400; color: #475569; }

.cpll-temps {
  font-variant-numeric: tabular-nums;
  color: #64748b;
  white-space: nowrap;
  font-size: .73rem;
}

.cpll-badge {
  font-size: .65rem;
  background: #dcfce7;
  color: #15803d;
  border-radius: 4px;
  padding: .1rem .35rem;
  font-weight: 700;
  white-space: nowrap;
}

/* ── Section consignes ───────────────────────────────── */
.cons-section {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: .65rem .8rem;
  flex-shrink: 0;
}

.cons-section-titre {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--gris);
  margin-bottom: .5rem;
}

.cons-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: .5rem;
}

.cons-label {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  font-size: .72rem;
  font-weight: 700;
  color: var(--gris);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.cons-input {
  padding: .5rem .6rem;
  font-size: .92rem;
  border: 2px solid var(--border);
  border-radius: 7px;
  width: 100%;
  min-height: 42px;
  font-family: inherit;
  transition: border-color .15s;
}

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

/* ── 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; }
}
