:root {
  --rouge: #b71c1c;
  --rouge-clair: #fdecea;
  --ok: #2e7d32;
  --ok-bg: #e3f4e4;
  --partiel: #ef6c00;
  --partiel-bg: #fff1e0;
  --ko: #c62828;
  --ko-bg: #fde4e4;
  --bg: #f4f5f7;
  --card: #ffffff;
  --texte: #1d1f23;
  --gris: #6b7280;
  --bord: #e2e5ea;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316;
    --card: #1c1e22;
    --texte: #eceef1;
    --gris: #9aa1ab;
    --bord: #2c2f35;
    --ok-bg: #16301a;
    --partiel-bg: #3a2610;
    --ko-bg: #3b1616;
    --rouge-clair: #3b1616;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--texte);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body { padding-bottom: calc(72px + var(--safe-bottom)); }

button, input, select { font: inherit; color: inherit; }

/* ---------- En-tête ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--rouge); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { border-radius: 8px; }
.brand strong { display: block; font-size: 17px; line-height: 1.1; }
.brand small { opacity: .85; font-size: 12px; }
.who { font-size: 13px; opacity: .9; text-align: right; }

main { max-width: 760px; margin: 0 auto; padding: 16px; }
.loading { text-align: center; color: var(--gris); margin-top: 40px; }

h2 { font-size: 20px; margin: 4px 0 12px; }
h3 { font-size: 16px; margin: 18px 0 8px; }

.card {
  background: var(--card); border: 1px solid var(--bord);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}

/* ---------- Boutons & formulaires ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--bord); background: var(--card); cursor: pointer;
}
.btn.primary { background: var(--rouge); border-color: var(--rouge); color: #fff; font-weight: 600; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; font-weight: 600; }
.btn.danger { color: var(--ko); border-color: var(--ko); background: transparent; }
.btn.block { width: 100%; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 14px; }
.btn:disabled { opacity: .5; }

label { display: block; font-size: 14px; color: var(--gris); margin: 12px 0 4px; }
input[type=text], input[type=tel], input[type=password], input[type=date], input[type=time], select {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--bord); border-radius: 10px; background: var(--bg);
}
.check { display: flex; align-items: center; gap: 10px; color: var(--texte); font-size: 15px; margin: 12px 0; }
.check input { width: 22px; height: 22px; accent-color: var(--rouge); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.muted { color: var(--gris); font-size: 14px; }
.error { color: var(--ko); font-size: 14px; min-height: 18px; margin-top: 8px; }

/* ---------- Alerte de couverture ---------- */
.alerte {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px; border-radius: var(--radius); margin-bottom: 14px; font-size: 15px;
}
.alerte.ko { background: var(--ko-bg); color: var(--ko); }
.alerte.ok { background: var(--ok-bg); color: var(--ok); }
.alerte b { display: block; font-size: 16px; }
.alerte .jours { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.alerte .jours button {
  border: 0; border-radius: 999px; padding: 4px 10px; font-size: 13px; cursor: pointer;
  background: var(--ko); color: #fff;
}

/* ---------- Calendrier ---------- */
.mois-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.mois-nav h2 { margin: 0; text-transform: capitalize; }
.mois-nav .btn { min-width: 44px; padding: 8px; }

.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { text-align: center; font-size: 12px; color: var(--gris); padding: 4px 0; }
.cal .jour {
  position: relative; aspect-ratio: 1 / 1.1; border-radius: 10px; border: 1px solid transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  cursor: pointer; padding: 2px; background: var(--card);
}
.cal .jour .num { font-weight: 600; font-size: 16px; }
.cal .jour .nb { font-size: 11px; line-height: 1; }
.cal .jour.ok { background: var(--ok-bg); color: var(--ok); }
.cal .jour.partiel { background: var(--partiel-bg); color: var(--partiel); }
.cal .jour.ko { background: var(--ko-bg); color: var(--ko); }
.cal .jour.passe { opacity: .45; }
.cal .jour.today { border-color: var(--texte); border-width: 2px; }
.cal .jour.moi::after {
  content: ""; position: absolute; top: 5px; right: 5px; width: 7px; height: 7px;
  border-radius: 50%; background: var(--rouge);
}
.cal .vide { visibility: hidden; }

.legende { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; color: var(--gris); margin-top: 12px; }
.legende span::before {
  content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 4px;
  margin-right: 5px; vertical-align: -1px;
}
.legende .l-ok::before { background: var(--ok); }
.legende .l-partiel::before { background: var(--partiel); }
.legende .l-ko::before { background: var(--ko); }
.legende .l-moi::before { background: var(--rouge); border-radius: 50%; width: 8px; height: 8px; }

/* ---------- Listes ---------- */
.liste { list-style: none; margin: 0; padding: 0; }
.liste li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--bord);
}
.liste li:last-child { border-bottom: 0; }
.liste .grow { flex: 1; min-width: 0; }
.liste .titre { font-weight: 600; }
.liste .sous { font-size: 13px; color: var(--gris); }
.badge {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px;
  background: var(--rouge-clair); color: var(--rouge); vertical-align: 1px; margin-left: 4px;
}
.badge.gris { background: var(--bord); color: var(--gris); }
.pastille { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.pastille.ok { background: var(--ok); }
.pastille.partiel { background: var(--partiel); }
.pastille.ko { background: var(--ko); }
.tel { text-decoration: none; font-size: 22px; }

/* Interrupteur "dispo" */
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute; inset: 0; border-radius: 999px; background: var(--bord); transition: .2s; cursor: pointer;
}
.switch span::before {
  content: ""; position: absolute; width: 26px; height: 26px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(20px); }

.horaires-btn {
  border: 0; background: none; padding: 0; color: var(--gris); font-size: 13px;
  text-decoration: underline dotted; cursor: pointer;
}

.semaine-sep { font-size: 12px; color: var(--gris); text-transform: uppercase; letter-spacing: .04em; padding-top: 14px !important; border-bottom: 0 !important; }

.jours-semaine { display: flex; gap: 6px; flex-wrap: wrap; }
.jours-semaine label {
  margin: 0; flex: 1; min-width: 40px; text-align: center; padding: 10px 0; border-radius: 10px;
  border: 1px solid var(--bord); color: var(--texte); cursor: pointer; font-size: 14px;
}
.jours-semaine input { display: none; }
.jours-semaine label:has(input:checked) { background: var(--rouge); color: #fff; border-color: var(--rouge); }

/* ---------- Onglets bas ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--card); border-top: 1px solid var(--bord);
  padding-bottom: var(--safe-bottom);
}
.tabs button {
  flex: 1; border: 0; background: none; padding: 8px 0 10px; font-size: 12px; color: var(--gris);
  display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
}
.tabs button .ico { font-size: 20px; filter: grayscale(1); }
.tabs button.active { color: var(--rouge); font-weight: 600; }
.tabs button.active .ico { filter: none; }

/* ---------- Feuille du bas (bottom sheet) ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow: auto;
  background: var(--card); border-radius: 18px 18px 0 0;
  padding: 8px 18px calc(20px + var(--safe-bottom));
  max-width: 760px; margin: 0 auto; animation: monte .2s ease-out;
}
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--bord); margin: 4px auto 12px; }
@keyframes monte { from { transform: translateY(40px); opacity: 0; } }

.statut-soir { padding: 10px 14px; border-radius: 10px; font-weight: 600; margin-bottom: 8px; }
.statut-soir.ok { background: var(--ok-bg); color: var(--ok); }
.statut-soir.partiel { background: var(--partiel-bg); color: var(--partiel); }
.statut-soir.ko { background: var(--ko-bg); color: var(--ko); }

.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 60;
  bottom: calc(84px + var(--safe-bottom));
  background: #222; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25); max-width: 90vw; text-align: center;
}

/* ---------- Connexion ---------- */
.login { max-width: 380px; margin: 20px auto; }
.login .logo { display: block; margin: 0 auto 10px; border-radius: 22px; }
.login h2 { text-align: center; }
.pin { letter-spacing: .5em; text-align: center; font-size: 22px; }

.install-tip { font-size: 14px; line-height: 1.5; }
.install-tip ol { padding-left: 20px; margin: 6px 0; }
