/* =========================================================
   Styles communs : tokens, fond d'écran, barre d'état, grille.
   Les valeurs viennent de docs/DESIGN.md (ne pas mettre de
   couleur ou de taille « en dur » ailleurs que dans les tokens).
   ========================================================= */
:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
          "Helvetica Neue", "Inter", Roboto, "Segoe UI", system-ui, sans-serif;

  /* Accents (vive / encre) */
  --red: #ff3b30;    --red-ink: #d70015;
  --orange: #ff9500; --orange-ink: #c93400;
  --yellow: #ffcc00;
  --green: #34c759;  --green-ink: #248a3d;
  --blue: #0a84ff;   --blue-ink: #0055d4;
  --indigo: #5e5ce6; --indigo-ink: #3634a3;
  --teal: #30b0c7;   --teal-ink: #00748f;   /* widget Activités */

  /* Personnes : C = orange, F = violet (choix de Chico) */
  --p-c: #ff9500; --p-c-ink: #c96a00; --p-c-on: #1d1d1f;
  --p-f: #5e5ce6; --p-f-ink: #5e5ce6; --p-f-on: #fff;
  --p-deux: #636366; --p-deux-on: #fff;

  /* Surfaces */
  --w-bg: #fff; --w-ink: #1d1d1f; --w-muted: #6e6e73; --w-line: #e5e5ea; --w-field: #f2f2f7;
  --w-group: #f2f2f7;
  /* Alerte et panneaux */
  --sheet-bg: rgba(242,242,247,.97); --sheet-bg-plein: #f2f2f7;
  --sheet-ink: #1d1d1f; --sheet-muted: #3c3c43; --sheet-line: #c6c6c8;
  --scrim: rgba(0,0,0,.35);

  /* Formes */
  --r-widget: 30px; --r-sheet: 24px; --r-field: 14px; --r-pill: 999px;
  --sh-widget: 0 8px 24px -10px rgba(0,0,0,.35);
  --sh-float: 0 20px 50px rgba(0,0,0,.4);
  --sh-badge: 0 2px 6px rgba(0,0,0,.3);

  /* Mise en page tablette */
  --colonnes: 8;
  --ecart: 24px;
  --marge-widget: 20px;

  /* Fond d'écran de jour (maquette) : 3 halos + voile noir de 18 % */
  --fond:
    linear-gradient(rgba(0,0,0,.18), rgba(0,0,0,.18)),
    radial-gradient(120% 90% at 10% 0%, #ffb37a 0%, transparent 55%),
    radial-gradient(90% 80% at 100% 20%, #7f7cf0 0%, transparent 60%),
    radial-gradient(120% 100% at 50% 110%, #2f6fd6 0%, transparent 60%),
    #3b2a6b;
}

/* Nuit (22 h → 7 h) : thème sombre, fond éteint, accents sombres */
body.nuit {
  --red-ink: #ff6961; --orange-ink: #ff9f0a; --green-ink: #30d158; --blue-ink: #409cff; --indigo-ink: #7d7aff;
  --teal: #40c8e0; --teal-ink: #5ac8e0;
  --p-c: #ff9f0a; --p-c-ink: #ff9f0a; --p-f-ink: #7d7aff; --p-deux: #8e8e93; --p-deux-on: #1d1d1f;
  --w-bg: #1c1c1e; --w-ink: #ebebf0; --w-muted: #98989d; --w-line: #38383a; --w-field: #2c2c2e;
  --w-group: #000;
  --sheet-bg: rgba(44,44,46,.97); --sheet-bg-plein: #2c2c2e;
  --sheet-ink: #f2f2f7; --sheet-muted: #c7c7cc; --sheet-line: #48484a;
  --scrim: rgba(0,0,0,.55);
  --fond:
    linear-gradient(rgba(0,0,0,.18), rgba(0,0,0,.18)),
    radial-gradient(120% 90% at 10% 0%, #5a3a3a 0%, transparent 55%),
    radial-gradient(90% 80% at 100% 20%, #2b2a5e 0%, transparent 60%),
    radial-gradient(120% 100% at 50% 110%, #14284f 0%, transparent 60%),
    #0b0b14;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--fond);
  background-attachment: fixed;
  color: #fff;
  font-family: var(--font);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;           /* tablette : une seule page, pas de défilement */
}
@media (prefers-reduced-motion: no-preference) {
  body { transition: background 1.2s; }
}
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.ic { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2;
      stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Voile de nuit : simule la luminosité baissée tant que Fully Kiosk n'est pas là */
.voile { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; z-index: 7; }
body.nuit .voile { opacity: .28; }
@media (prefers-reduced-motion: no-preference) { .voile { transition: opacity 1.2s; } }

/* Bande sous la barre d'état de l'iPhone (heure, batterie) quand l'appli est installée :
   les widgets qui défilent passent dessous, floutés, sans se mélanger au texte blanc.
   Hauteur 0 ailleurs (navigateur, tablette sans encoche). */
body::before {
  content: ""; position: fixed; top: 0; left: 0; right: 0; z-index: 5; pointer-events: none;
  height: env(safe-area-inset-top, 0px);
  background: rgba(20,14,40,.55); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}

/* ---------- Barre d'état ----------
   Masquée à la demande de Chico (28/11/2026) : l'heure et la date sont déjà dans les widgets
   Horloge et Calendrier. Le code reste en place (main.js la remplit toujours, les tests s'en
   servent pour vérifier que l'appli a démarré) : retirer « display: none » pour la remettre. */
.etat {
  height: 60px; flex: none;
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 32px 0;
  font: 600 20px var(--font);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.etat .date { font-weight: 500; }
.etat .date::first-letter { text-transform: uppercase; }
.etat { display: none; } /* placé après la règle .etat pour l'emporter */

/* ---------- Grille 8 colonnes x 4 rangées (tablette) ---------- */
.grille {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: repeat(var(--colonnes), minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  grid-auto-rows: 160px;
  grid-auto-flow: dense;      /* comble les trous comme sur iPhone */
  gap: var(--ecart);
  padding: 28px 32px 28px; /* 28 px en haut : plus de barre d'état au-dessus */
  /* Appli installée en plein écran : jamais sous une encoche ou la barre des gestes */
  padding: max(28px, env(safe-area-inset-top)) max(32px, env(safe-area-inset-right))
           max(28px, env(safe-area-inset-bottom)) max(32px, env(safe-area-inset-left));
  overflow-y: auto;
}
.case { position: relative; display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; }
.case.petit { grid-column: span 2; grid-row: span 2; }
.case.moyen { grid-column: span 4; grid-row: span 2; }
.case.grand { grid-column: span 4; grid-row: span 4; }

/* La carte du widget */
.w {
  flex: 1; min-height: 0; position: relative;
  border-radius: var(--r-widget);
  padding: var(--marge-widget);
  display: flex; flex-direction: column; gap: 8px;
  overflow: hidden;
  background: var(--w-bg); color: var(--w-ink);
  box-shadow: var(--sh-widget);
}
/* Nom sous le widget, centré, blanc avec ombre */
.nom {
  font: 600 15px/20px var(--font);
  text-align: center; color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.55), 0 0 8px rgba(0,0,0,.25);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.vide-tout {
  grid-column: 1 / -1; grid-row: 2 / span 2; align-self: center; text-align: center;
  font: 600 24px var(--font); text-shadow: 0 1px 3px rgba(0,0,0,.4);
}

/* ---------- Éléments partagés par plusieurs widgets ---------- */
.lh { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.lh .tt { font: 700 22px var(--font); color: var(--acc); }
.lh .ct { font: 700 34px/1 var(--font); font-variant-numeric: tabular-nums; }
.meta { font: 500 16px var(--font); color: var(--w-muted); }
.err { display: grid; gap: 10px; margin: auto 0; justify-items: start; }
.err .ic { color: var(--red-ink); width: 30px; height: 30px; }
.err b { font: 600 20px var(--font); }

/* Listes des widgets : on n'affiche que les lignes entières (bug B4).
   La liste prend la place restante ; les lignes qui ne tiennent pas en hauteur passent,
   grâce au retour à la ligne en colonne, dans une 2e colonne cachée à droite (overflow).
   Le trait de séparation est porté par le HAUT de la ligne suivante : une ligne cachée
   emporte son trait avec elle, il ne reste jamais de trait seul en bas. */
ul.l {
  list-style: none; margin: 0; padding: 0; min-height: 0;
  flex: 1 1 0; overflow: hidden;
  display: flex; flex-direction: column; flex-wrap: wrap; align-content: flex-start;
}
ul.l > li { width: 100%; flex: none; }
ul.l > li + li { border-top: 1px solid var(--w-line); }
.tx { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rad { width: 28px; height: 28px; border-radius: 50%; border: 2.5px solid var(--c, var(--green-ink));
       flex: none; display: grid; place-items: center; color: #fff; }
.rad .ic { width: 18px; height: 18px; stroke-width: 3; opacity: 0; }
.fait .rad { background: var(--c, var(--green-ink)); }
.fait .rad .ic { opacity: 1; }
.fait .tx { color: var(--w-muted); text-decoration: line-through; }

/* Pastille personne : toujours couleur + initiale */
.qui { width: 28px; height: 28px; border-radius: 50%; flex: none; display: grid; place-items: center;
       font: 700 13px var(--font); background: var(--pc); color: var(--pon); }
.qui.deux { width: 50px; background: none; position: relative; }
.qui.deux i { position: absolute; top: 0; width: 28px; height: 28px; border-radius: 50%; display: grid;
              place-items: center; font: 700 11px var(--font); font-style: normal; box-shadow: 0 0 0 2px var(--w-bg); }
/* C passe devant F : les deux initiales restent lisibles */
.qui.deux i:first-child { left: 0; z-index: 1; background: var(--p-c); color: var(--p-c-on); }
.qui.deux i:last-child { right: 0; background: var(--p-f); color: var(--p-f-on); }

/* ---------- iPhone : 4 colonnes, rangées de 74 px, défilement ---------- */
@media (max-width: 700px) {
  :root {
    --colonnes: 4;
    --r-widget: 22px;
    --marge-widget: 14px;
  }
  body { overflow: auto; }
  .etat { padding: 8px 22px 0; font-size: 17px; }
  .grille {
    grid-template-rows: none;
    grid-auto-rows: 74px;
    gap: 26px 18px;
    padding: 18px 22px 24px;
    /* iPhone installé : la barre d'état est posée sur l'appli (black-translucent), on descend dessous */
    padding: calc(18px + env(safe-area-inset-top)) max(22px, env(safe-area-inset-right))
             calc(24px + env(safe-area-inset-bottom)) max(22px, env(safe-area-inset-left));
    overflow: visible;
  }
  .nom { font: 500 12px/16px var(--font); }
  .lh .tt { font-size: 17px; }
  .lh .ct { font-size: 26px; }
  .meta { font-size: 13px; }
  .rad { width: 22px; height: 22px; border-width: 2px; }
  .rad .ic { width: 14px; height: 14px; }
  .qui { width: 22px; height: 22px; font-size: 11px; }
  .qui.deux { width: 38px; }
  .qui.deux i { width: 22px; height: 22px; font-size: 9px; }
}
