:root {
  --ink: #1B1D21;
  --ink-2: #33363C;
  --muted: #4A4E55;
  --line: #E2E0DB;
  --line-2: #C9CCD1;
  --bg: #F4F2EE;
  --card: #FFFFFF;
  --red: #B3261E;
  --red-dark: #8E1D17;
  --red-soft: #FBE9E7;
  --green: #2E7D4F;
  --green-ink: #226B40;
  --green-soft: #E2F1E7;
  --orange: #B8590A;
  --orange-ink: #8F4507;
  --orange-soft: #FBEBDD;
  --blue-ink: #1F5FAE;
  --blue-soft: #E3ECF7;
  --grey-soft: #ECEDEF;
  --radius: 14px;
  --font: 'Archivo', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--red); }
a:hover { color: var(--red-dark); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* Barre du haut */
.topbar {
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 800; font-size: 18px; }
.brand:hover { color: #fff; }
.brand img { width: 34px; height: 34px; border-radius: 8px; }
.nav { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; }
.nav a {
  min-height: 44px; padding: 0 12px; display: flex; align-items: center;
  color: #C9CCD1; text-decoration: none; font-weight: 600; font-size: 15px; border-radius: 8px;
}
.nav a.on { background: #33363C; color: #fff; }
.nav a:hover { color: #fff; }

.live { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: #C9CCD1; }
.live .dot { width: 9px; height: 9px; border-radius: 50%; background: #E89A3C; }
.live.on .dot { background: #4CAF78; }

/* Mise en page */
.container { max-width: 1240px; margin: 0 auto; padding: 20px 16px 48px; display: flex; flex-direction: column; gap: 16px; }
.narrow { max-width: 460px; }
.eyebrow { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--red); }
h1 { margin: 0; font-size: 28px; font-weight: 800; }
h2 { margin: 0; font-size: 18px; font-weight: 800; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spread { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 520px) { .grid2.collapse { grid-template-columns: 1fr; } }

.card { background: var(--card); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 12px; }

/* Formulaires */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.field input, .field select, .field textarea {
  min-height: 44px; border-radius: 10px; border: 1px solid var(--line-2); padding: 0 12px;
  font-size: 15px; font-weight: 400; background: #fff; color: var(--ink); width: 100%;
}
.field input:focus, .field select:focus { outline: 2px solid var(--ink); outline-offset: 1px; }
fieldset { margin: 0; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
legend { padding: 0 4px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.check { display: flex; align-items: center; gap: 8px; min-height: 40px; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--ink); }

.btn {
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line-2);
  background: #fff; color: var(--ink); font-weight: 600; font-size: 15px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
}
.btn:hover { color: var(--ink); border-color: var(--ink); }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); border-color: var(--red-dark); color: #fff; }
.btn-dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-dark:hover { color: #fff; background: #000; }
.btn[disabled] { opacity: 0.5; cursor: default; }
.btn-icon { width: 44px; padding: 0; }
.btn-call { background: var(--green); border-color: var(--green); color: #fff; }
.btn-call:hover { color: #fff; background: var(--green-ink); }

.chip {
  min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-2);
  background: #fff; font-weight: 600; font-size: 14px; cursor: pointer;
}
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }

.badge { display: inline-block; padding: 3px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge-ink { background: var(--ink); color: #fff; }
.badge-soft { background: var(--bg); color: var(--ink); }
.badge-green { background: var(--green-soft); color: var(--green-ink); }
.badge-orange { background: var(--orange-soft); color: var(--orange-ink); }
.badge-blue { background: var(--blue-soft); color: var(--blue-ink); }
.badge-grey { background: var(--grey-soft); color: var(--muted); }

.alert { border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.alert-error { background: var(--red-soft); color: #6E1712; }
.alert-ok { background: var(--green-soft); color: var(--green-ink); }
.alert-info { background: var(--blue-soft); color: #173F73; }

/* Liste de l'effectif */
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.person {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 12px 16px;
  border-top: 1px solid #EEECE8; text-decoration: none; color: inherit;
}
.person:first-child { border-top: 0; }
a.person:hover { background: #FAF9F7; color: inherit; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; background: var(--line); flex: none;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px;
}
.person .who { flex: 1 1 200px; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.person .name { font-weight: 700; font-size: 16px; }
.person .meta { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 13px; color: var(--muted); }
.person .side { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.empty { padding: 24px 16px; color: var(--muted); text-align: center; }

.linkbox {
  display: flex; gap: 8px; align-items: center; background: var(--bg); border-radius: 10px; padding: 8px;
}
.linkbox input { flex: 1; min-width: 0; min-height: 40px; border: 0; background: transparent; font-size: 13px; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px; font-weight: 600; z-index: 50;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2); max-width: calc(100% - 32px);
}

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-head { display: flex; align-items: center; gap: 12px; }
.login-head img { width: 48px; height: 48px; border-radius: 12px; }

/* ---------- Étape 2 : statuts, piquets, dashboard ---------- */
.line { padding: 8px 0; border-top: 1px solid #EEECE8; }
.card .line:first-of-type { border-top: 0; }

.banner { display: flex; align-items: center; gap: 12px; border-radius: var(--radius); padding: 12px 14px; }
.banner-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex: none; color: #fff; }
.banner-title { font-size: 16px; font-weight: 800; }
.banner-sub { font-size: 13px; }
.banner-piquet { background: var(--orange-soft); border: 2px solid var(--orange); color: #6B3205; }
.banner-piquet .banner-icon { background: var(--orange); }
.banner-nuit { background: #1F2A44; color: #fff; }
.banner-nuit .banner-icon { background: #34406A; }
.banner-nuit .banner-sub { color: #C7D0E6; }

.statuts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.statut-btn {
  min-height: 64px; border-radius: 12px; border: 2px solid var(--line); background: #fff; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  font-weight: 600; font-size: 14px; padding: 0 6px; text-align: center;
}
.statut-btn .dot { width: 10px; height: 10px; border-radius: 50%; }
.statut-btn.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.statut-btn[disabled] { opacity: 0.7; }

.badge-piquet { background: var(--orange); color: #fff; }
.badge-night { background: #1F2A44; color: #fff; }
.badge-alert { background: var(--red); color: #fff; }

.pill { display: inline-flex; align-items: center; gap: 8px; background: #fff; border-radius: 999px; padding: 8px 12px; font-size: 14px; color: var(--ink-2); }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: #E89A3C; }
.live-dot.on { background: var(--green); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tile {
  background: #fff; border-radius: 12px; padding: 12px 14px; border: 0; border-top: 4px solid var(--line);
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; cursor: pointer; text-align: left;
  outline: 2px solid transparent;
}
.tile span { font-size: 14px; color: var(--muted); font-weight: 600; }
.tile strong { font-size: 30px; font-weight: 800; }
.tile.on { outline-color: var(--ink); }

.split { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.split-main { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.split-side { flex: 1 1 300px; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.pcard { background: #fff; border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 10px; border: 2px solid transparent; }
.pcard-piquet { border-color: var(--orange); }
.pcard .name { font-weight: 700; font-size: 16px; }

.card-night { background: #1F2A44; color: #fff; }
.card-night .line { border-top-color: #34406A; }
.btn-ghost-light { background: transparent; color: #fff; border-color: #4A5680; min-height: 36px; }
.btn-ghost-light:hover { color: #fff; border-color: #fff; }

.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.checklist { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 12px; max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; }

.grid-piquet { width: 100%; min-width: 820px; border-collapse: separate; border-spacing: 4px; font-size: 14px; }
.grid-piquet th { text-align: center; font-size: 13px; padding: 6px 4px; font-weight: 700; color: var(--muted); }
.grid-piquet tbody th { text-align: left; color: var(--ink); font-size: 15px; width: 110px; }
.grid-piquet th.now { color: var(--orange-ink); }
.grid-piquet td { background: var(--green-soft); border-radius: 8px; padding: 6px; vertical-align: top; min-width: 90px; }
.grid-piquet td.now { box-shadow: inset 0 0 0 2px var(--orange); }
.grid-piquet td.vide { background: var(--red-soft); color: var(--red-dark); text-align: center; }
.grid-piquet td.clic { cursor: pointer; }
.pchip { display: inline-flex; align-items: center; gap: 2px; background: #fff; border-radius: 6px; padding: 2px 4px 2px 8px; margin: 2px; font-weight: 600; font-size: 13px; color: #1E5A36; white-space: nowrap; }
.pchip-x { border: 0; background: transparent; font-size: 16px; line-height: 1; width: 24px; height: 24px; border-radius: 4px; cursor: pointer; color: var(--muted); }
.pchip-x:hover { background: var(--red-soft); color: var(--red); }

/* ---------- Étape 3 : échanges, génération ---------- */
.card-demande { border: 2px solid var(--orange); }
.swap { display: grid; grid-template-columns: minmax(0, 1fr) 24px minmax(0, 1fr); align-items: center; gap: 6px; text-align: center; }
.swap-box { background: var(--bg); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.panel { background: var(--bg); border-radius: 12px; padding: 12px; }
.banner-demande { background: #fff; border: 2px solid var(--orange); color: var(--ink); text-decoration: none; }
.banner-demande:hover { color: var(--ink); }
.banner-demande .banner-icon { background: var(--orange); }
