/* ------------------------------------------------------------------ */
/*  Planning Usine — feuille de style (mobile d'abord)                 */
/* ------------------------------------------------------------------ */
:root {
  --bleu: #0f3d5c;
  --bleu-clair: #1d6fa5;
  --fond: #eef1f4;
  --carte: #ffffff;
  --texte: #1c2733;
  --texte-doux: #6b7884;
  --bordure: #dde3e9;
  --ombre: 0 6px 24px rgba(15, 61, 92, .12);
  --vert: #1faa59;
  --orange: #e8820c;
  --rouge: #d64545;
  --rayon: 18px;
  --tab-h: 62px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--fond);
  color: var(--texte);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  background: var(--fond);
}

.hidden { display: none !important; }

/* ----------------------------- En-tête ---------------------------- */
.topbar {
  background: linear-gradient(135deg, var(--bleu), var(--bleu-clair));
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .15);
  z-index: 5;
}
.topbar-title {
  display: flex; align-items: center; gap: 9px;
  font-size: 19px; font-weight: 700; letter-spacing: .2px;
}
.topbar-title .dot {
  width: 11px; height: 11px; border-radius: 50%;
  background: #5fd0a0; box-shadow: 0 0 0 4px rgba(95, 208, 160, .25);
}

/* Sélecteur de rôle (segmenté) */
.role-selector {
  display: flex; gap: 6px; margin-top: 12px;
  background: rgba(255, 255, 255, .15);
  padding: 4px; border-radius: 12px;
}
.role-selector button {
  flex: 1; border: 0; background: transparent; color: #eaf3fa;
  padding: 9px 6px; border-radius: 9px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: .15s; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.role-selector button.is-active {
  background: #fff; color: var(--bleu); box-shadow: 0 2px 6px rgba(0, 0, 0, .15);
}

/* ----------------------------- Contenu ---------------------------- */
.content { flex: 1; position: relative; overflow: hidden; display: flex; }
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; width: 100%; }

/* État chargement / erreur */
.status-screen {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px; padding: 24px; text-align: center;
}
.status-screen p { color: var(--texte-doux); margin: 0; max-width: 320px; line-height: 1.5; }
.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 4px solid var(--bordure); border-top-color: var(--bleu-clair);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.status-actions { display: flex; flex-direction: column; gap: 10px; }

/* ----------------------------- Boutons ---------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--bleu); color: #fff; border: 0; border-radius: 12px;
  padding: 12px 18px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn-ghost { background: #fff; color: var(--bleu); border: 1px solid var(--bordure); }

/* --------------------------- Carrousel ---------------------------- */
.carousel { flex: 1; display: flex; align-items: stretch; position: relative; min-height: 0; }
.viewport { flex: 1; overflow: hidden; position: relative; }
.track { display: flex; height: 100%; will-change: transform; }
.slide {
  flex: 0 0 100%; height: 100%;
  padding: 16px; display: flex;
}

.nav-arrow {
  border: 0; background: transparent; color: var(--bleu);
  font-size: 34px; line-height: 1; width: 40px; flex: 0 0 40px;
  cursor: pointer; opacity: .55; align-self: center;
}
.nav-arrow:active { opacity: 1; }
.nav-arrow:disabled { opacity: .15; cursor: default; }
@media (max-width: 480px) { .carousel .nav-arrow { display: none; } }

/* Carte d'un poste */
.poste {
  flex: 1; background: var(--carte); border-radius: var(--rayon);
  box-shadow: var(--ombre); display: flex; flex-direction: column;
  overflow: hidden; position: relative;
}
.poste-top { height: 8px; flex: 0 0 8px; }
.poste-body {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  padding: 22px 18px; gap: 8px;
}
.poste-statut {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
  padding: 6px 12px; border-radius: 999px;
}
.poste-statut.encours { background: rgba(31, 170, 89, .14); color: var(--vert); }
.poste-statut.encours .pulse {
  width: 9px; height: 9px; border-radius: 50%; background: var(--vert);
  animation: pulse 1.6s infinite;
}
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(31, 170, 89, .5);} 70%{ box-shadow: 0 0 0 9px rgba(31,170,89,0);} 100%{box-shadow:0 0 0 0 rgba(31,170,89,0);} }
.poste-statut.avenir { background: rgba(29, 111, 165, .12); color: var(--bleu-clair); }
.poste-statut.passe { background: #eef1f4; color: var(--texte-doux); }

.poste-periode {
  font-size: 15px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  padding: 5px 14px; border-radius: 999px; color: #fff;
}
.poste-heures { font-size: 14px; color: var(--texte-doux); font-weight: 600; }
.poste-noms { display: flex; flex-direction: column; gap: 6px; margin: 6px 0; }
.poste-nom { font-size: clamp(30px, 9vw, 46px); font-weight: 800; line-height: 1.05; color: var(--texte); }
.poste-date { font-size: 16px; color: var(--texte-doux); font-weight: 600; text-transform: capitalize; }

/* Aperçu des autres postes du même jour */
.poste-autres {
  border-top: 1px solid var(--bordure); padding: 12px 16px;
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; background: #fafbfc;
}
.mini {
  display: flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--texte-doux); font-weight: 600;
}
.mini .pin { width: 9px; height: 9px; border-radius: 3px; }

.now-footer { padding: 10px 16px calc(env(safe-area-inset-bottom) + 6px); text-align: center; }
.now-footer .hint { font-size: 12.5px; color: var(--texte-doux); margin: 8px 0 0; }

/* ---------------------------- Planning ---------------------------- */
.month-bar {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 12px 8px; background: var(--fond);
}
.month-bar h2 {
  margin: 0; font-size: 17px; min-width: 170px; text-align: center;
  text-transform: capitalize; color: var(--bleu); font-weight: 700;
}
.grid-wrap { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 0 8px; }

table.grid { border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.grid th, table.grid td {
  border-bottom: 1px solid var(--bordure); border-right: 1px solid var(--bordure);
  text-align: center; white-space: nowrap;
}
table.grid thead th {
  position: sticky; top: 0; z-index: 3; background: #fff;
  padding: 5px 0; font-weight: 700; color: var(--texte-doux);
}
table.grid thead th small { display: block; font-size: 10px; font-weight: 600; color: var(--texte-doux); }
table.grid th.namecol, table.grid td.namecol {
  position: sticky; left: 0; z-index: 2; background: #fff;
  text-align: left; padding: 8px 10px; font-weight: 700; color: var(--texte);
  min-width: 92px; box-shadow: 2px 0 4px rgba(0, 0, 0, .04);
}
table.grid thead th.namecol { z-index: 4; }
table.grid td.cell { width: 30px; height: 34px; font-weight: 700; color: #fff; }
table.grid col.today, table.grid td.is-today { outline: 2px solid var(--bleu); outline-offset: -2px; }
table.grid th.is-today { color: var(--bleu); background: #eaf3fb; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px); }
.legend .item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--texte-doux); }
.legend .sw { width: 16px; height: 16px; border-radius: 5px; }

/* ----------------------------- Onglets ---------------------------- */
.tabbar {
  flex: 0 0 auto; display: flex; background: #fff;
  border-top: 1px solid var(--bordure);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 12px rgba(0, 0, 0, .05);
}
.tab {
  flex: 1; border: 0; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 0; height: var(--tab-h); justify-content: center;
  color: var(--texte-doux); font-size: 12px; font-weight: 600;
}
.tab .tab-ico { font-size: 21px; line-height: 1; filter: grayscale(.4); }
.tab.is-active { color: var(--bleu); }
.tab.is-active .tab-ico { filter: none; }
