:root {
  --bg: #0f1420;
  --bg-2: #171d2b;
  --card: #1c2434;
  --card-2: #232c3f;
  --line: #2b3446;
  --text: #f2f5fb;
  --muted: #97a1b6;
  --faint: #6c768c;
  --accent: #378add;

  /* Catégories */
  --c-rdv: #4b93e6;      --c-rdv-bg: #17304f;
  --c-tache: #e0a13a;    --c-tache-bg: #3a2e12;
  --c-sortie: #38b98a;   --c-sortie-bg: #123a2d;
  --c-rappel: #a98cf0;   --c-rappel-bg: #2a2247;
  --c-sport: #38b98a;    --c-sport-bg: #123a2d;
  --c-repas: #e8746b;    --c-repas-bg: #3d1f1c;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; overscroll-behavior: none; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
}

/* ---------- En-tête ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 18px) 12px 12px;
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-bottom: 0.5px solid var(--line);
}
.menu-btn {
  width: 40px; height: 40px; font-size: 22px; line-height: 1;
  color: var(--text); border-radius: 12px; flex-shrink: 0;
}
.menu-btn:active { background: var(--card); }
.nav-btn {
  width: 40px; height: 40px;
  font-size: 26px; line-height: 1;
  color: var(--muted);
  border-radius: 12px;
}

/* ---------- Menu latéral ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 60; }
.drawer-backdrop[hidden] { display: none; }
.drawer {
  position: absolute; top: 0; left: 0; bottom: 0;
  width: 78%; max-width: 300px;
  background: var(--bg-2); border-right: 0.5px solid var(--line);
  padding: calc(var(--safe-top) + 22px) 14px calc(var(--safe-bottom) + 18px);
  display: flex; flex-direction: column;
  animation: slideIn .22s ease;
}
@keyframes slideIn { from { transform: translateX(-100%); } to { transform: translateX(0); } }
.drawer-head { font-size: 13px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .5px; margin: 0 8px 12px; }
.drawer a, .drawer .app-soon {
  display: flex; align-items: center; gap: 14px;
  padding: 14px; border-radius: 12px; text-decoration: none;
  color: var(--text); font-size: 16px; font-weight: 500; margin-bottom: 4px;
}
.drawer a:active { background: var(--card); }
.drawer a.current { background: var(--card); }
.drawer a.current .app-ico { color: var(--accent); }
.drawer .app-ico { font-size: 22px; width: 26px; text-align: center; }
.drawer .app-soon { color: var(--faint); }
.drawer .app-soon .soon-tag { font-size: 11px; margin-left: auto; background: var(--card); padding: 3px 8px; border-radius: 999px; }
.drawer-foot { margin-top: auto; font-size: 12px; color: var(--faint); text-align: center; padding-top: 12px; }
.nav-btn:active { background: var(--card); }
.date-block { text-align: center; padding: 4px 16px; border-radius: 12px; }
.date-block:active { background: var(--card); }
.date-weekday { display: block; font-size: 20px; font-weight: 600; text-transform: capitalize; }
.date-full { display: block; font-size: 13px; color: var(--muted); margin-top: 1px; }

/* ---------- Bascule Jour / Semaine ---------- */
.segmented {
  display: flex; gap: 4px;
  margin: 10px 16px 0; padding: 4px;
  background: var(--card); border: 0.5px solid var(--line);
  border-radius: 12px;
}
.seg {
  flex: 1; padding: 8px; border-radius: 9px;
  font-size: 14px; font-weight: 600; color: var(--muted);
}
.seg.active { background: var(--accent); color: #fff; }

/* ---------- Vue Semaine ---------- */
.wk-day {
  border: 0.5px solid var(--line); border-radius: 14px;
  background: var(--card); margin-top: 12px; overflow: hidden;
}
.wk-day.today { border-color: var(--accent); }
.wk-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
}
.wk-day.today .wk-head { background: rgba(55,138,221,.12); }
.wk-dname { font-size: 15px; font-weight: 600; text-transform: capitalize; }
.wk-dname .wk-today-tag { color: var(--accent); font-size: 12px; margin-left: 6px; }
.wk-count { font-size: 12px; color: var(--muted); }
.wk-list { padding: 0 14px 10px; display: flex; flex-direction: column; gap: 7px; }
.wk-empty { padding: 0 14px 12px; font-size: 13px; color: var(--faint); }
.wk-item { display: flex; align-items: center; gap: 9px; }
.wk-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--cat, var(--accent)); flex-shrink: 0; }
.wk-time { font-size: 13px; color: var(--muted); width: 42px; flex-shrink: 0; }
.wk-title { font-size: 14px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wk-title.done { text-decoration: line-through; color: var(--faint); }

/* ---------- Réglages ---------- */
.set-section { border: 0.5px solid var(--line); border-radius: 14px; padding: 14px; background: var(--card); display: flex; flex-direction: column; gap: 12px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.set-label { font-size: 15px; font-weight: 600; margin: 0; }
.set-hint { font-size: 13px; color: var(--muted); margin: 2px 0 0; }
.set-btn { padding: 9px 16px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 14px; font-weight: 600; flex-shrink: 0; }
.set-btn.wide { width: 100%; background: var(--card-2); color: var(--text); border: 0.5px solid var(--line); }
.set-btn.done { background: var(--c-sortie); }
.set-note { font-size: 12.5px; color: var(--muted); line-height: 1.5; margin: 0; }
.set-about { font-size: 12.5px; color: var(--faint); text-align: center; margin: 0; }

/* ---------- Zone défilante ---------- */
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 16px; }
.scroll-pad { height: 24px; }

/* ---------- Résumé ---------- */
.summary { display: flex; gap: 10px; margin: 16px 0 8px; }
.stat { flex: 1; background: var(--card); border: 0.5px solid var(--line); border-radius: 16px; padding: 12px 10px; }
.stat-num { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- Frise ---------- */
.timeline { padding: 8px 0; }
.tl-item { display: flex; gap: 12px; margin-bottom: 14px; }
.tl-time { width: 46px; flex-shrink: 0; padding-top: 12px; text-align: right; }
.tl-time .h { font-size: 15px; font-weight: 600; }
.tl-time .now { color: var(--accent); }
.tl-time .past { color: var(--faint); }
.tl-card {
  flex: 1;
  background: var(--card);
  border: 0.5px solid var(--line);
  border-left: 4px solid var(--cat, var(--accent));
  border-radius: 4px 16px 16px 4px;
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  transition: opacity .2s;
}
.tl-card.done { opacity: .5; }
.tl-check {
  width: 26px; height: 26px; flex-shrink: 0; margin-top: 1px;
  border-radius: 50%;
  border: 2px solid var(--cat, var(--muted));
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; color: #fff;
}
.tl-check.on { background: var(--cat, var(--accent)); }
.tl-body { flex: 1; min-width: 0; }
.tl-cat { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; color: var(--cat); }
.tl-title { font-size: 16px; font-weight: 600; margin: 1px 0 0; }
.tl-card.done .tl-title { text-decoration: line-through; }
.tl-meta { font-size: 13px; color: var(--muted); margin-top: 3px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.tl-repeat { color: var(--cat); }
.tl-emoji { font-size: 18px; }

/* ---------- État vide ---------- */
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-emoji { font-size: 44px; }
.empty-title { font-size: 18px; font-weight: 600; color: var(--text); margin: 12px 0 4px; }
.empty-sub { font-size: 14px; margin: 0; }

/* ---------- Barre d'onglets ---------- */
.tabbar {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 8px 8px calc(var(--safe-bottom) + 8px);
  background: var(--bg-2);
  border-top: 0.5px solid var(--line);
}
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 10px; color: var(--faint);
  padding: 4px 0;
}
.tab .tab-ico { font-size: 20px; filter: grayscale(1) opacity(.7); }
.tab.active { color: var(--accent); }
.tab.active .tab-ico { filter: none; }
.tab-add {
  flex: 0 0 auto;
  width: 52px; height: 52px;
  background: var(--accent);
  border-radius: 50%;
  font-size: 30px; color: #fff; font-weight: 300;
  margin-top: -18px;
  box-shadow: 0 6px 16px rgba(55,138,221,.45);
}
.tab-add:active { transform: scale(.94); }

/* ---------- Fiche (sheet) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: flex-end;
  z-index: 50;
}
.sheet-backdrop[hidden] { display: none; }
.sheet {
  width: 100%;
  max-width: 480px; margin: 0 auto;
  background: var(--bg-2);
  border-radius: 22px 22px 0 0;
  padding: 8px 18px calc(var(--safe-bottom) + 18px);
  animation: slideUp .25s ease;
  max-height: 92vh; overflow-y: auto;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle { width: 40px; height: 5px; background: var(--line); border-radius: 3px; margin: 6px auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { font-size: 17px; font-weight: 600; margin: 0; }
.sheet-cancel { color: var(--muted); font-size: 16px; }
.sheet-save { color: var(--accent); font-size: 16px; font-weight: 600; }
.sheet-body { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; }
.field input, .field select {
  width: 100%;
  background: var(--card); border: 0.5px solid var(--line);
  border-radius: 12px; padding: 13px 14px;
  color: var(--text); font-size: 16px;
  -webkit-appearance: none; appearance: none;
}
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2397a1b6' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
  padding-right: 38px;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.row2 { display: flex; gap: 12px; }
.row2 .field { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 14px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line);
  font-size: 14px; color: var(--muted);
  display: flex; align-items: center; gap: 6px;
}
.chip.on { color: var(--text); border-color: var(--cat); background: var(--cat-bg); }
.delete-btn {
  margin-top: 4px; padding: 13px;
  background: var(--c-repas-bg); color: var(--c-repas);
  border-radius: 12px; font-size: 15px; font-weight: 600;
}

/* ---------- Affichage bureau (grand écran) ---------- */
@media (min-width: 768px) {
  #app { max-width: 760px; }
  .scroll { padding: 0 32px; }
  .summary { gap: 14px; }
  .tl-card { padding: 14px 18px; }
  .tabbar { border-radius: 0; }
}
