/* =====================================================================
   Planning des enfants — Mini App Telegram
   Meme langage visuel que le brief familial : fond clair FIXE (on n'herite
   PAS du theme Telegram), en-tete degrade colore par enfant, onglets.
   Ajout specifique : grille hebdo 7 colonnes (lun -> dim).
   ===================================================================== */

:root {
  --bg:     #eef2f6;
  --card:   #ffffff;
  --text:   #0f172a;
  --hint:   #64748b;
  --sep:    color-mix(in srgb, var(--text) 12%, transparent);
  --tab-bg: #ffffff;
  --accent: #2563eb;

  --radius: 16px;
  --pad: 14px;
  --maxw: 920px;          /* + large que le brief : grille 7 jours */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  overflow-x: hidden;            /* securite : jamais de scroll horizontal */
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.app {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------- Loader ---------- */
.loader {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--hint); background: var(--bg);
  font-size: 15px; z-index: 50;
  transition: opacity .25s ease;
}
.loader.hidden { opacity: 0; pointer-events: none; }

/* ---------- En-tete (titre + semaine), degrade colore par enfant ---------- */
.head {
  padding: calc(var(--pad) + env(safe-area-inset-top, 0px)) var(--pad) 16px;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #1e3a8a);
  transition: background .25s ease;
}
.head-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.head-row.r1 { align-items: flex-start; }
.head .p-title {
  font-size: clamp(22px, 6vw, 30px);
  font-weight: 800;
  letter-spacing: -.5px;
  margin: 0;
}
.head-row.r2 { margin-top: 6px; flex-wrap: wrap; row-gap: 2px; }
.head .p-week { font-size: 15px; opacity: .97; font-weight: 600; }
.head .p-updated {
  font-size: 12px; opacity: .8; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---------- Onglets (membres de la famille) ---------- */
.tabs {
  position: sticky; top: 0; z-index: 20;
  display: flex; gap: 6px;
  padding: 8px 10px;
  background: var(--tab-bg);
  border-bottom: 1px solid var(--sep);
  overflow-x: auto; scrollbar-width: none;          /* securite si tres petit ecran */
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  --accent: #2563eb;
  flex: 1 1 0; min-width: 0;
  appearance: none; border: 1.5px solid var(--sep);
  background: var(--card); color: var(--hint);
  font: inherit; font-weight: 700; font-size: 15px;
  padding: 9px 8px; border-radius: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  transition: color .15s, background .15s, border-color .15s;
}
.tab .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab .tab-dot {
  flex: 0 0 auto; width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
}
/* Petits ecrans : 4 onglets doivent tenir sans rogner */
@media (max-width: 480px) {
  .tabs { gap: 4px; padding: 7px 7px; }
  .tab { font-size: 13px; padding: 8px 5px; gap: 5px; }
  .tab .tab-dot { width: 8px; height: 8px; }
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] {
  color: #fff; background: var(--accent); border-color: var(--accent);
}
.tab[aria-selected="true"] .tab-dot { background: #fff; }

/* ---------- Contenu ---------- */
.content {
  flex: 1;
  padding: var(--pad);
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}
.p-note {
  background: color-mix(in srgb, var(--accent) 10%, var(--card));
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 12px 14px; margin-bottom: 12px;
  font-size: 14px; color: var(--text);
}


/* =====================================================================
   GRILLE HORAIRE (vrai planning) : axe des heures a gauche + 7 colonnes.
   Les blocs cours/activites sont positionnes en absolu dans leur creneau.
   ===================================================================== */
.p-cal { position: relative; }

/* --- En-tete des jours (colle sous la barre d'onglets) --- */
.p-cal-head {
  position: sticky;
  top: var(--tabs-h, 0px);
  z-index: 8;
  display: grid;
  grid-template-columns: var(--axis) repeat(7, minmax(0, 1fr));
  background: var(--bg);
  border-bottom: 1px solid var(--sep);
  padding-bottom: 2px;
}
.p-corner { }
.p-dhead {
  text-align: center;
  padding: 5px 1px 4px;
  border-left: 1px solid var(--sep);
}
.p-dhead.weekend { background: color-mix(in srgb, var(--text) 4%, transparent); }
.p-dhead.today { background: color-mix(in srgb, var(--accent) 16%, transparent); border-radius: 8px 8px 0 0; }
.p-dow {
  display: block;
  font-size: 9.5px; font-weight: 800; letter-spacing: .3px;
  text-transform: uppercase; color: var(--hint);
}
.p-dom { display: block; font-size: 15px; font-weight: 800; color: var(--text); line-height: 1.15; }
.p-dhead.today .p-dow { color: var(--accent); }
.p-dhead.today .p-dom { color: var(--accent); }
.p-allday {
  margin-top: 2px; font-size: 8.5px; font-weight: 700; line-height: 1.1;
  color: #0d9488; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* --- Corps : axe + zone colonnes --- */
.p-cal-body {
  display: grid;
  grid-template-columns: var(--axis) 1fr;
  position: relative;
}
.p-axis { position: relative; }
.p-hour {
  position: absolute; right: 5px; transform: translateY(-50%);
  font-size: 10px; font-weight: 700; color: var(--hint);
  font-variant-numeric: tabular-nums;
}
.p-colswrap { position: relative; }
.p-hline {
  position: absolute; left: 0; right: 0; height: 0;
  border-top: 1px solid var(--sep);
}
.p-cols {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}
.p-col {
  position: relative;
  border-left: 1px solid var(--sep);
}
.p-col:last-child { border-right: 1px solid var(--sep); }
.p-col.weekend { background: color-mix(in srgb, var(--text) 3.5%, transparent); }
.p-col.today { background: color-mix(in srgb, var(--accent) 7%, transparent); }

/* --- Bloc d'evenement (cours / activite) --- */
.p-ev {
  position: absolute;
  overflow: hidden;
  border-radius: 5px;
  padding: 1px 3px 2px;
  box-sizing: border-box;
}
.p-ev.cours {
  --c: var(--accent);
  background: color-mix(in srgb, var(--c) 16%, var(--card));
  border-left: 3px solid var(--c);
}
.p-ev.act {
  --c: #0d9488;
  background: color-mix(in srgb, var(--c) 13%, var(--card));
  border: 1.5px dashed var(--c);
}
.p-ev-main {
  font-size: 10.5px; font-weight: 700; color: var(--text);
  line-height: 1.1; overflow: hidden;
}
.p-ev.act .p-ev-main { color: color-mix(in srgb, var(--c) 82%, var(--text)); }
.p-ev-star { color: var(--c); }
.p-ev-meta {
  font-size: 9px; color: var(--hint); line-height: 1.1; margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.p-ev.changed { box-shadow: inset 0 0 0 1.5px #d97706; }
.p-ev.canceled { box-shadow: inset 0 0 0 1.5px #dc2626; border-left-color: #dc2626; }
.p-ev.canceled .p-ev-main { color: var(--hint); text-decoration: line-through; }

/* --- Ligne "maintenant" (heure courante) --- */
.p-now {
  position: absolute; left: 0; right: 0; height: 0;
  border-top: 2px solid var(--NOW, #ef4444);
  z-index: 6; pointer-events: none;
}
.p-now-dot {
  position: absolute; top: -4px;
  width: 7px; height: 7px; border-radius: 50%;
  background: #ef4444;
  margin-left: -3px;
}

/* --- Ecran etroit (telephone) : on resserre encore --- */
@media (max-width: 560px) {
  :root { --pad: 8px; }
  .p-ev { padding: 1px 2px; border-radius: 4px; }
  .p-ev-main { font-size: 9.5px; }
  .p-ev-meta { font-size: 8px; }
  .p-hour { font-size: 9px; right: 4px; }
  .p-dom { font-size: 13px; }
  .p-dow { font-size: 8.5px; }
}

/* En-tete de jour cliquable (ouvre la vue jour) */
.p-dhead.clickable { cursor: pointer; transition: background .12s; }
.p-dhead.clickable:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* =====================================================================
   VUE "JOUR" : un seul jour en plein ecran, gros texte (lisibilite mobile).
   ===================================================================== */
.p-daybar {
  position: sticky; top: var(--tabs-h, 0px); z-index: 9;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--bg); padding: 6px 2px 10px;
}
.p-daynav { display: flex; align-items: center; gap: 6px; }
.p-navbtn {
  appearance: none; border: 1.5px solid var(--sep); background: var(--card);
  color: var(--accent); font: inherit; font-weight: 800; font-size: 20px; line-height: 1;
  width: 34px; height: 34px; border-radius: 10px; cursor: pointer;
}
.p-navbtn:disabled { color: var(--hint); opacity: .4; cursor: default; }
.p-daylbl {
  font-size: 17px; font-weight: 800; color: var(--text);
  min-width: 9.5em; text-align: center;
}
.p-daylbl.today { color: var(--accent); }
.p-back {
  appearance: none; border: 1.5px solid var(--accent); background: var(--accent);
  color: #fff; font: inherit; font-weight: 700; font-size: 14px;
  padding: 8px 12px; border-radius: 10px; cursor: pointer; white-space: nowrap;
}

/* Liste agenda du jour : cartes a HAUTEUR DYNAMIQUE (jamais coupees) */
.p-daylist { display: flex; flex-direction: column; gap: 8px; padding-top: 2px; }
.p-daycard {
  --c: var(--accent);
  background: var(--card);
  border-radius: 12px;
  padding: 10px 13px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.p-daycard.cours { border-left: 5px solid var(--c); background: color-mix(in srgb, var(--c) 8%, var(--card)); }
.p-daycard.act {
  --c: #0d9488;
  border: 1.5px dashed var(--c);
  background: color-mix(in srgb, var(--c) 9%, var(--card));
}
.p-dc-time {
  font-size: 12.5px; font-weight: 800; font-variant-numeric: tabular-nums;
  color: color-mix(in srgb, var(--c) 62%, var(--text));
}
.p-dc-title { font-size: 16px; font-weight: 700; color: var(--text); line-height: 1.25; margin-top: 1px; }
.p-daycard.act .p-dc-title { color: color-mix(in srgb, var(--c) 82%, var(--text)); }
.p-dc-meta { font-size: 13px; color: var(--hint); margin-top: 3px; line-height: 1.3; }
.p-daycard.changed { box-shadow: inset 0 0 0 2px #d97706; }
.p-daycard.canceled { box-shadow: inset 0 0 0 2px #dc2626; border-left-color: #dc2626; }
.p-daycard.canceled .p-dc-title { color: var(--hint); text-decoration: line-through; }
.p-day-empty { text-align: center; color: var(--hint); padding: 36px 12px; font-size: 15px; }

/* Repere "maintenant" intercale dans la liste du jour */
.p-nowmark {
  display: flex; align-items: center; gap: 8px;
  margin: 2px 0; color: #ef4444;
}
.p-nowmark::before { content: ""; flex: 0 0 7px; width: 7px; height: 7px; border-radius: 50%; background: #ef4444; }
.p-nowmark::after { content: ""; flex: 1; height: 0; border-top: 2px solid #ef4444; }
.p-nowmark-lbl { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }

/* Petite animation d'entree */
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.content > * { animation: fade .22s ease both; }
@media (prefers-reduced-motion: reduce) { .content > * { animation: none; } }
