:root {
  --bg: #f5f3ee;
  --card: #ffffff;
  --ink: #1c1c1e;
  --muted: #6e6e73;
  --line: #e7e3da;
  --chip: #f0ede6;
  --on: #1e8a5a;
  --on-soft: #e1f2e9;
  --del: #c43d32;
  --del-soft: #fbe8e5;
  --warn: #b97800;
  --warn-soft: #fcf0d6;
  --papa: #2d6cdf;
  --papa-soft: #e5eeff;
  --maman: #a042b3;
  --maman-soft: #f5e7f8;
  --radius: 18px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 6px 20px rgb(0 0 0 / 0.04);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111114;
    --card: #1c1c21;
    --ink: #f2f2f5;
    --muted: #9b9ba3;
    --line: #2d2d34;
    --chip: #28282e;
    --on: #2ea36c;
    --on-soft: #183324;
    --del: #ff6b5e;
    --del-soft: #3a1e1b;
    --warn: #f0b53c;
    --warn-soft: #382c13;
    --papa: #74a1ff;
    --papa-soft: #1b2641;
    --maman: #d98ae6;
    --maman-soft: #33203a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { letter-spacing: -0.01em; }

/* Connexion */
.login { max-width: 360px; margin: 12vh auto 0; display: grid; gap: 4px; text-align: center; }
.login .big { font-size: 40px; }
.login h1 { margin: 4px 0 0; font-size: 26px; }
.login p { margin: 0 0 6px; }
.login .field { text-align: left; }
.login input { font-size: 16px; padding: 12px; }
.login button { margin-top: 18px; padding: 13px; font-size: 16px; }
.login-error { color: var(--del); margin: 12px 0 0 !important; }
.logout { font-size: 13px; color: var(--muted); text-decoration: none; padding: 8px 4px; white-space: nowrap; }
.logout:hover { color: var(--del); }

#app { max-width: 720px; margin: 0 auto; padding: 0 16px calc(120px + env(safe-area-inset-bottom)); }
.splash, .locked { min-height: 70vh; display: grid; place-content: center; text-align: center; gap: 6px; color: var(--muted); padding: 0 16px; }
.locked h1 { color: var(--ink); margin: 0; }
.locked .big { font-size: 40px; }

/* En-tête */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 0 12px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.who { display: flex; align-items: center; gap: 10px; }
.who h1 { margin: 0; font-size: 26px; }
.role { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 99px; }
.role.papa { background: var(--papa-soft); color: var(--papa); }
.role.maman { background: var(--maman-soft); color: var(--maman); }
.tools { display: flex; align-items: center; gap: 8px; }
.credit { font-size: 13px; color: var(--muted); white-space: nowrap; }
.icon { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 18px; line-height: 1; }
.icon:disabled { opacity: 0.6; cursor: default; }
.icon.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main { display: grid; gap: 14px; }

/* Bandeaux */
.alert { background: var(--warn-soft); border-radius: var(--radius); padding: 12px 14px; }
.alert.urgent { background: var(--del-soft); }
.alert strong { display: block; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.alert p { margin: 0; }
.note { border: 1px dashed var(--line); border-radius: var(--radius); padding: 10px 14px; color: var(--muted); font-size: 14px; }

/* Panneaux de demandes */
.panel { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.maman-panel { box-shadow: inset 0 0 0 1.5px var(--maman), var(--shadow); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.panel-head h2, .week-head h2 { margin: 0; font-size: 17px; }
.quote { margin: 8px 0 0; font-style: italic; color: var(--maman); }
.req-list { list-style: none; margin: 8px 0 0; padding: 0; }
.req-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.req-list li:first-child { border-top: 0; }
.req-text small { display: block; color: var(--muted); }
.plus b { color: var(--on); }
.minus b { color: var(--del); }
.req-actions { display: flex; gap: 6px; flex-shrink: 0; }
.small-text { font-size: 13px; margin: 8px 0 0; }
.muted { color: var(--muted); }
.tag { font-size: 12px; padding: 2px 9px; border-radius: 99px; white-space: nowrap; }
.tag.wait { background: var(--warn-soft); color: var(--warn); }
.tag.ok { background: var(--on-soft); color: var(--on); }
.tag.ko { background: var(--del-soft); color: var(--del); }

.legend { display: flex; flex-wrap: wrap; gap: 6px; }

/* Semaines */
.week { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 14px 4px; border-left: 5px solid var(--papa); }
.week.maman { border-left-color: var(--maman); }
.week.current h2::after { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--del); margin-left: 8px; vertical-align: middle; }
.week-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 4px; }
.dls { display: flex; flex-wrap: wrap; gap: 2px 10px; margin-top: 3px; }
.dl { font-size: 13px; color: var(--muted); }
.dl.soon { color: var(--del); font-weight: 600; }
.parent { border: 0; border-radius: 99px; padding: 6px 12px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.parent.papa { background: var(--papa-soft); color: var(--papa); }
.parent.maman { background: var(--maman-soft); color: var(--maman); }
.parent:disabled { cursor: default; }
.empty { color: var(--muted); margin: 6px 0 10px; font-size: 14px; }

.day { display: grid; grid-template-columns: 46px 1fr; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.day-label { border: 0; background: none; padding: 0; display: grid; justify-items: center; line-height: 1.15; color: var(--muted); }
.day-label span { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.day-label strong { font-size: 19px; color: var(--ink); width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; }
.day.today .day-label strong { color: #fff; background: var(--del); font-size: 16px; }
.day.past { opacity: 0.5; }

/* Pastilles de créneaux */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  position: relative; display: inline-flex; align-items: center;
  min-height: 38px; padding: 6px 13px; border-radius: 99px;
  border: 1.5px solid transparent; background: var(--chip);
  font-size: 14px; font-weight: 500; white-space: nowrap;
  transition: transform 0.08s ease; user-select: none; -webkit-tap-highlight-color: transparent;
}
button.chip:active { transform: scale(0.95); }
.chip.on { background: var(--on); color: #fff; }
.chip.wait { background: var(--warn); color: #fff; }
.chip.refused { background: var(--del-soft); color: var(--del); text-decoration: line-through; }
.chip.req-on { background: var(--maman-soft); color: var(--maman); border-color: var(--maman); border-style: dashed; }
.chip.req-off { background: transparent; color: var(--maman); border-color: var(--maman); border-style: dashed; text-decoration: line-through; }
.chip.adding { background: var(--on-soft); color: var(--on); border-color: var(--on); border-style: dashed; }
.chip.adding::before { content: '＋'; margin-right: 3px; font-weight: 700; }
.chip.removing { background: var(--del-soft); color: var(--del); border-color: var(--del); border-style: dashed; text-decoration: line-through; }
.chip.locked { opacity: 0.5; }
.chip.locked::after { content: '🔒'; font-size: 10px; margin-left: 4px; }
.chip.sm { min-height: 26px; padding: 2px 10px; font-size: 12px; }
.badge {
  position: absolute; top: -6px; right: -6px; width: 19px; height: 19px; border-radius: 50%;
  background: var(--maman); color: #fff; font-size: 13px; font-weight: 700; line-height: 1;
  display: grid; place-items: center; box-shadow: 0 0 0 2px var(--card);
}
.chip.sm .badge { position: static; margin-left: 5px; width: 15px; height: 15px; font-size: 10px; box-shadow: none; }

.foot { text-align: center; color: var(--muted); font-size: 12px; margin: 4px 0 0; }

/* Barre d'action */
.actionbar {
  position: fixed; z-index: 10; left: 50%; transform: translateX(-50%);
  bottom: calc(12px + env(safe-area-inset-bottom)); width: min(688px, calc(100% - 24px));
  display: flex; align-items: center; gap: 8px;
  background: var(--ink); color: var(--bg); border-radius: 20px; padding: 10px 10px 10px 16px;
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.25);
}
.actionbar div { flex: 1; display: grid; line-height: 1.2; min-width: 0; }
.actionbar strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actionbar span { font-size: 13px; opacity: 0.7; }
.actionbar button { white-space: nowrap; flex-shrink: 0; }
.actionbar .ghost { border-color: color-mix(in srgb, var(--bg) 35%, transparent); }

/* Boutons */
button.primary, button.ghost, button.ok, a.btn { border: 0; border-radius: 12px; padding: 10px 16px; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
button.primary { background: var(--on); color: #fff; }
button.ghost, a.btn { background: transparent; color: inherit; box-shadow: inset 0 0 0 1px var(--line); }
.actionbar button.ghost { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--bg) 35%, transparent); }
button.ok { background: var(--on-soft); color: var(--on); }
button.small { padding: 6px 11px; font-size: 13px; border-radius: 10px; }
button:disabled { opacity: 0.6; cursor: default; }

/* Fenêtres */
dialog {
  border: 0; padding: 0; background: var(--card); color: var(--ink);
  border-radius: 22px; width: min(520px, calc(100% - 24px)); max-height: 85vh;
  box-shadow: 0 24px 60px rgb(0 0 0 / 0.3);
}
dialog::backdrop { background: rgb(0 0 0 / 0.35); }
#sheet { padding: 20px; overflow: auto; max-height: 85vh; }
#sheet h2 { margin: 0 0 10px; font-size: 20px; }
#sheet h3 { margin: 20px 0 6px; font-size: 15px; }
.changes, .detail, .history { list-style: none; margin: 0; padding: 0; }
.changes li { padding: 9px 0; border-top: 1px solid var(--line); }
.changes li:first-child { border-top: 0; }
.changes li small { display: block; color: var(--muted); margin-left: 22px; }
.changes li b { display: inline-block; width: 16px; }
.changes li:has(b:first-child) b { color: var(--on); }
.detail li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.detail li:first-child { border-top: 0; }
.detail small { display: block; color: var(--muted); }
.detail .right { text-align: right; }
.detail .maman-text { color: var(--maman); }
.history li { font-size: 13px; padding: 7px 0; border-top: 1px solid var(--line); }
.history time { color: var(--muted); }
.row { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.field { display: grid; gap: 6px; margin-top: 14px; }
.field span { font-size: 13px; color: var(--muted); }
input, textarea { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; width: 100%; }
.copy { display: flex; gap: 8px; }
.copy input { flex: 1; min-width: 0; font-size: 13px; }

#toast {
  position: fixed; z-index: 20; left: 50%; transform: translateX(-50%);
  top: calc(14px + env(safe-area-inset-top)); max-width: calc(100% - 32px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.2);
}

/* Places : complet et liste d'attente */
.chip.full {
  background: repeating-linear-gradient(135deg, var(--chip) 0 6px, transparent 6px 12px);
  color: var(--muted); box-shadow: inset 0 0 0 1px var(--line);
}
.chip.waitonly:not(.on) { border-color: var(--warn); color: var(--warn); }
.chip.adding.waitonly { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.dot.full { color: var(--muted); border-color: var(--line); text-decoration: line-through; }
.dot.waitonly { color: var(--warn); border-style: dashed; border-color: var(--warn); }
.alert.waitlist { background: var(--warn-soft); }
.changes em.warn { color: var(--warn); font-style: normal; font-weight: 600; }

/* Bascule semaine / mois */
.switch { display: inline-flex; justify-self: start; background: var(--chip); border-radius: 12px; padding: 3px; }
.switch button { border: 0; background: transparent; padding: 7px 18px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); }
.switch button.active { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / 0.12); }

/* Ouverture des réservations du centre de loisirs */
.opening { background: var(--papa-soft); border-radius: var(--radius); padding: 12px 14px; }
.opening.hot { background: var(--warn-soft); }
.opening strong { display: block; }
.opening p { margin: 4px 0 0; font-size: 14px; }
.opening a { color: inherit; }

/* Vacances, fériés, garde */
.vac { margin: 2px 0 0; font-size: 13px; font-weight: 600; color: var(--papa); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chips .tag { align-self: center; }
.tag.holiday { background: var(--del-soft); color: var(--del); }
.tag.papa { background: var(--papa-soft); color: var(--papa); }
.tag.maman { background: var(--maman-soft); color: var(--maman); }
.tag:not(.holiday):not(.papa):not(.maman):not(.wait):not(.ok):not(.ko) { background: var(--chip); }

/* Vue mois */
.month { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; }
.month-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.month-head h2 { margin: 0; font-size: 18px; text-transform: capitalize; }
.mrow { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; margin-bottom: 4px; }
.mdays span { text-align: center; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.mcell {
  min-height: 76px; border: 0; border-radius: 10px; background: var(--chip); padding: 6px 5px 5px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px; text-align: left; overflow: hidden;
}
.mcell.papa { box-shadow: inset 0 3px 0 var(--papa); }
.mcell.maman { box-shadow: inset 0 3px 0 var(--maman); }
.mcell.changed { outline: 1.5px dashed var(--on); outline-offset: -1.5px; }
.mcell.out { background: transparent; box-shadow: none; }
.mcell:disabled { cursor: default; }
.mcell.past { opacity: 0.5; }
.mnum { font-weight: 700; font-size: 14px; line-height: 22px; min-width: 22px; text-align: center; }
.mcell.today .mnum { background: var(--del); color: #fff; border-radius: 50%; }
.mlabel { font-size: 10px; color: var(--muted); line-height: 1; }
.mlabel.holiday { color: var(--del); font-weight: 600; }
.marks { display: flex; flex-wrap: wrap; gap: 2px; }
.dot { font-size: 10px; font-weight: 700; font-style: normal; line-height: 1; padding: 3px 4px; border-radius: 5px; border: 1px solid transparent; }
.dot.on { background: var(--on); color: #fff; }
.dot.wait { background: var(--warn); color: #fff; }
.dot.adding { background: var(--on-soft); color: var(--on); border-style: dashed; border-color: var(--on); }
.dot.removing { background: var(--del-soft); color: var(--del); border-style: dashed; border-color: var(--del); text-decoration: line-through; }
.dot.req-on { background: var(--maman-soft); color: var(--maman); border-style: dashed; border-color: var(--maman); }
.dot.req-off { color: var(--maman); border-style: dashed; border-color: var(--maman); text-decoration: line-through; }
.mlegend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin: 8px 2px 0; font-size: 12px; color: var(--muted); }
.swatch { display: inline-block; width: 14px; height: 4px; border-radius: 2px; vertical-align: middle; }
.swatch.papa { background: var(--papa); }
.swatch.maman { background: var(--maman); }

/* Détail du jour */
.detail li { flex-direction: column; align-items: stretch; gap: 4px; }
.slot-line { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

@media (max-width: 420px) {
  .mcell { min-height: 64px; padding: 5px 3px 4px; }
  .dot { padding: 2px 3px; font-size: 9px; }
  .chip { padding: 6px 10px; font-size: 13px; }
  .day { grid-template-columns: 38px 1fr; gap: 8px; }
  .credit { display: none; }
  .actionbar { padding-left: 14px; gap: 6px; }
  .actionbar button { padding: 10px 11px; font-size: 14px; }
}
