:root{
  --bg:#EEF1F6;
  --card:#FFFFFF;
  --text:#1C2333;
  --muted:#7A8194;
  --navy:#16213E;
  --line:#E3E7EF;
  --red:#E5484D;
  --shadow:0 1px 3px rgba(20,30,60,.10);
}
@media (prefers-color-scheme: dark){
  :root{
    --bg:#12141A;
    --card:#1E212B;
    --text:#ECEEF4;
    --muted:#9AA3B5;
    --navy:#0F1830;
    --line:#2A2F3D;
    --shadow:0 1px 3px rgba(0,0,0,.45);
  }
}
:root[data-theme="dark"]{
  --bg:#12141A;
  --card:#1E212B;
  --text:#ECEEF4;
  --muted:#9AA3B5;
  --navy:#0F1830;
  --line:#2A2F3D;
  --shadow:0 1px 3px rgba(0,0,0,.45);
}
:root[data-theme="light"]{
  --bg:#EEF1F6;
  --card:#FFFFFF;
  --text:#1C2333;
  --muted:#7A8194;
  --navy:#16213E;
  --line:#E3E7EF;
  --red:#E5484D;
  --shadow:0 1px 3px rgba(20,30,60,.10);
}
*{box-sizing:border-box}
html,body{margin:0;padding:0}
body{
  font-family:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;
  background:var(--bg);
  color:var(--text);
  -webkit-tap-highlight-color:transparent;
}
.app{max-width:520px;margin:0 auto;min-height:100vh;display:flex;flex-direction:column}
button{font-family:inherit;cursor:pointer}

/* ---------- Barre du haut ---------- */
.topbar{
  margin:10px 10px 6px;
  padding:10px 10px;
  border-radius:22px;
  background:linear-gradient(120deg,#152238,#2A4A8B);
  color:#fff;
  display:flex;
  align-items:center;
  gap:6px;
}
.iconbtn{
  width:38px;height:38px;flex:0 0 auto;
  border:0;border-radius:50%;
  background:rgba(255,255,255,.14);
  color:#fff;font-size:19px;line-height:1;
  display:flex;align-items:center;justify-content:center;
}
.iconbtn.dark{background:var(--bg);color:var(--text)}
.monthwrap{flex:1;display:flex;flex-direction:column;align-items:center;gap:3px;min-width:0}
.monthlabel{font-size:17px;font-weight:700;text-transform:capitalize}
.todaybtn{
  border:0;border-radius:999px;
  background:rgba(255,255,255,.16);color:#fff;
  font-size:11px;font-weight:600;padding:3px 10px;
}

/* ---------- Calendrier ---------- */
main{flex:1;padding-bottom:8px}
.weekdays{
  display:grid;grid-template-columns:repeat(7,1fr);gap:5px;
  margin:6px 12px 4px;
  font-size:11px;font-weight:600;color:var(--muted);text-align:center;
}
.grid{display:grid;grid-template-columns:repeat(7,1fr);gap:5px;padding:0 12px}
.cell{
  position:relative;
  border:0;border-radius:12px;
  background:var(--card);
  box-shadow:var(--shadow);
  min-height:66px;
  padding:4px 3px 4px;
  display:flex;flex-direction:column;align-items:center;gap:2px;
  color:var(--text);
}
.cell.out{opacity:.42}
.cell .num{
  font-size:12px;font-weight:700;
  min-width:19px;height:19px;line-height:19px;
  border-radius:50%;
}
.cell.today .num{background:var(--red);color:#fff}
.cell .lbl{
  font-size:9px;font-weight:700;
  max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
}
.badges{display:flex;gap:2px;margin-top:auto;flex-wrap:wrap;justify-content:center}
.b{
  font-size:8px;line-height:1;font-weight:700;
  padding:2px 4px;border-radius:6px;
  background:rgba(127,127,127,.22);color:inherit;
}
.b-rdv{background:#274B8A;color:#fff}
.b-task.alldone{background:#2E9E5B;color:#fff}

/* ---------- Statistiques ---------- */
.card{
  background:var(--card);border-radius:16px;box-shadow:var(--shadow);
  margin:12px;padding:14px;
}

/* ---------- Aide-mémoire des rendez-vous ---------- */
.agenda h3{margin:0 0 4px;font-size:14px}
.agrow{
  display:flex;align-items:center;gap:8px;width:100%;
  border:0;background:none;color:var(--text);text-align:left;
  padding:8px 0;border-bottom:1px solid var(--line);
  font-size:13px;
}
.agrow:last-child{border-bottom:0}
.agrow.past{opacity:.45}
.agdate{flex:0 0 50px;font-size:12px;font-weight:700;color:var(--muted)}
.agtime{flex:0 0 42px;font-weight:800}
.agrow .grow{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}

.stats h3{margin:0 0 10px;font-size:14px}
.stat-cards{display:flex;gap:8px;margin-bottom:12px}
.stat-card{
  flex:1;border:1px solid var(--line);border-radius:12px;padding:8px 10px;
}
.stat-card .k{font-size:11px;color:var(--muted)}
.stat-card .v{font-size:19px;font-weight:800}
.strow{margin:9px 0}
.strow .l1{display:flex;align-items:center;gap:7px;font-size:13px;font-weight:600}
.strow .dot{width:10px;height:10px;border-radius:50%;flex:0 0 auto}
.strow .spacer{flex:1}
.strow .hrs{font-weight:800}
.strow .l2{display:flex;align-items:center;gap:8px;margin-top:4px}
.strow .bar{flex:1;height:6px;border-radius:3px;background:var(--line);overflow:hidden}
.strow .bar i{display:block;height:100%;border-radius:3px}
.strow .pct{font-size:11px;color:var(--muted);min-width:56px;text-align:right}
.stats .empty{color:var(--muted);font-size:13px;margin:0}

/* ---------- Palette (bas d'écran) ---------- */
.palette-bar{
  position:sticky;bottom:0;z-index:10;
  padding:6px 10px calc(10px + env(safe-area-inset-bottom));
  background:linear-gradient(to top, var(--bg) 75%, transparent);
}
.palette-hint{font-size:11px;color:var(--muted);text-align:center;margin-bottom:6px}
.palette{display:flex;gap:6px;overflow-x:auto;scrollbar-width:none;padding-bottom:2px}
.palette::-webkit-scrollbar{display:none}
.chip{
  flex:0 0 auto;
  display:flex;align-items:center;gap:6px;
  padding:8px 13px;border-radius:999px;
  border:2px solid transparent;
  background:var(--card);box-shadow:var(--shadow);
  font-size:13px;font-weight:600;color:var(--text);
}
.chip::before{content:"";width:12px;height:12px;border-radius:50%;background:var(--c,transparent)}
.chip-erase::before,.chip-add::before{display:none}
.chip.sel{border-color:var(--text)}

/* ---------- Feuilles (modales) ---------- */
.overlay{
  position:fixed;inset:0;z-index:50;
  background:rgba(10,15,30,.45);
  display:flex;align-items:flex-end;justify-content:center;
}
.overlay[hidden]{display:none}
.sheet{
  background:var(--card);color:var(--text);
  width:100%;max-width:520px;max-height:88vh;overflow-y:auto;
  border-radius:20px 20px 0 0;
  padding:14px 16px calc(18px + env(safe-area-inset-bottom));
}
.sheet-head{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:4px}
.sheet h2{margin:0;font-size:17px;text-transform:capitalize}
.sheet h3{
  margin:14px 0 6px;font-size:11px;font-weight:700;
  text-transform:uppercase;letter-spacing:.4px;color:var(--muted);
}
.sheet p{font-size:13px;line-height:1.45;margin:4px 0 10px}
.sheet input[type=text],.sheet input[type=time],.sheet textarea{
  width:100%;border:1px solid var(--line);border-radius:10px;
  background:var(--bg);color:var(--text);
  font-family:inherit;font-size:14px;padding:9px 10px;
}
.sheet textarea{resize:vertical}
.addrow{display:flex;gap:6px}
.addrow input[type=time]{width:96px;flex:0 0 auto}
.addrow input[type=text]{flex:1;min-width:0}
.addbtn{
  flex:0 0 auto;width:40px;border:0;border-radius:10px;
  background:var(--navy);color:#fff;font-size:20px;font-weight:700;
}
.itemlist:empty::after{content:"Rien pour ce jour.";font-size:12px;color:var(--muted)}
.itemrow{
  display:flex;align-items:center;gap:8px;
  padding:7px 2px;border-bottom:1px solid var(--line);
  font-size:14px;
}
.itemrow:last-child{border-bottom:0}
.itemrow .time{font-weight:800;font-size:13px;min-width:44px}
.itemrow .grow{flex:1;min-width:0;overflow-wrap:anywhere}
.itemrow input[type=checkbox]{width:19px;height:19px;accent-color:#2E9E5B;flex:0 0 auto}
.itemrow.done .grow{text-decoration:line-through;color:var(--muted)}
.delbtn{
  flex:0 0 auto;width:28px;height:28px;border:0;border-radius:50%;
  background:transparent;color:var(--muted);font-size:16px;
}
.bellbtn{
  flex:0 0 auto;width:28px;height:28px;border:0;border-radius:50%;
  background:transparent;font-size:15px;
}
.daytype-chips{display:flex;gap:6px;flex-wrap:wrap}
.primary{
  display:block;width:100%;margin-top:16px;
  border:0;border-radius:12px;padding:12px;
  background:var(--navy);color:#fff;font-size:15px;font-weight:700;
}
.danger{
  display:block;width:100%;margin-top:8px;
  border:0;border-radius:12px;padding:11px;
  background:transparent;color:var(--red);font-size:14px;font-weight:700;
}
.hint{font-size:11.5px;color:var(--muted);text-align:center;margin:12px 0 0}

/* Types de journées (liste) */
.typerow{
  display:flex;align-items:center;gap:10px;width:100%;
  border:0;background:transparent;color:var(--text);
  padding:11px 2px;border-bottom:1px solid var(--line);
  font-size:15px;font-weight:600;text-align:left;
}
.typerow .dot{width:16px;height:16px;border-radius:50%;flex:0 0 auto}
.typerow .grow{flex:1}
.typerow .hours{font-size:13px;color:var(--muted);font-weight:700}
.typerow .chev{color:var(--muted)}

/* Couleurs */
.swatches{display:grid;grid-template-columns:repeat(6,1fr);gap:8px}
.swatch{
  aspect-ratio:1/1;border-radius:50%;border:3px solid transparent;
  background:var(--c);
}
.swatch.sel{border-color:var(--text)}
.customcolor{display:flex;align-items:center;gap:10px;margin-top:12px;font-size:13px;color:var(--muted)}
.customcolor input{width:44px;height:32px;border:1px solid var(--line);border-radius:8px;background:var(--bg);padding:2px}

/* Menu */
.menurow{
  display:block;width:100%;text-align:left;
  border:0;background:transparent;color:var(--text);
  font-size:15px;font-weight:600;
  padding:13px 2px;border-bottom:1px solid var(--line);
}
.menurow:last-of-type{border-bottom:0}

/* Toast */
.toast{
  position:fixed;left:50%;bottom:90px;transform:translateX(-50%);
  z-index:100;
  background:var(--navy);color:#fff;
  font-size:13px;font-weight:600;
  padding:10px 16px;border-radius:999px;
  box-shadow:0 4px 14px rgba(0,0,0,.3);
  max-width:85vw;text-align:center;
}
.toast[hidden]{display:none}
