:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #1e293b;
  --muted: #64748b;
  --faint: #94a3b8;
  --line: #e2e8f0;
  --accent: #4f46e5;
  --good: #22c55e;
  --bad: #ef4444;
  --shadow: 0 1px 4px rgba(0,0,0,.06);
  --tabbar-h: 64px;
  --header-h: 56px;
  /* couleurs par groupe */
  --g-bonheur: #eab308;
  --g-sommeil: #6366f1;
  --g-travail: #3b82f6;
  --g-temps: #ef4444;
  --g-lecture: #f59e0b;
  --g-sante: #ec4899;
  --g-activites: #8b5cf6;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, sans-serif;
  background: var(--bg); color: var(--ink);
  overscroll-behavior-y: none;
  overflow-x: hidden;
}
body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }

/* ── Header ─────────────────────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(135deg, #1e293b, #334155);
  color: #fff; padding: env(safe-area-inset-top) 12px 0;
  box-shadow: var(--shadow);
}
.period-nav {
  height: var(--header-h);
  display: flex; align-items: center; justify-content: center; gap: 18px;
}
.nav-arrow {
  background: rgba(255,255,255,.12); color: #fff; border: 0;
  width: 36px; height: 36px; border-radius: 10px;
  font-size: 22px; line-height: 1; cursor: pointer;
}
.nav-arrow:disabled { opacity: .3; }
.period-label { font-size: 17px; font-weight: 700; min-width: 150px; text-align: center; text-transform: capitalize; }

/* ── Vue / contenu ──────────────────────────────────── */
.view { padding: 12px; max-width: 720px; margin: 0 auto; }
.loading { text-align: center; color: var(--muted); padding: 40px 0; }
.section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); margin: 18px 4px 8px;
}
.section-title:first-child { margin-top: 4px; }

/* ── Cartes métriques (grille) ──────────────────────── */
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.card {
  background: var(--card); border-radius: 14px; padding: 14px;
  box-shadow: var(--shadow); border-left: 4px solid var(--accent);
  display: flex; flex-direction: column; gap: 2px;
  min-width: 0; overflow: hidden;
}
.card .c-label { font-size: 12px; color: var(--muted); }
.card .c-value { font-size: 24px; font-weight: 800; letter-spacing: -.5px; }
.card .c-sub { font-size: 11px; color: var(--faint); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.delta { font-weight: 700; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.delta.flat { color: var(--faint); }

/* ── Bloc graphe ────────────────────────────────────── */
.panel {
  background: var(--card); border-radius: 14px; padding: 14px;
  box-shadow: var(--shadow); margin-bottom: 12px;
}
.panel h2 { font-size: 14px; margin-bottom: 4px; }
.panel .hint { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.chart-wrap { position: relative; width: 100%; }
.chart-wrap.tall { height: 240px; }
.chart-wrap.pie { height: 260px; }

/* ── Sélecteurs ─────────────────────────────────────── */
.select-row { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
select, .seg button {
  font-size: 14px; font-family: inherit;
}
select {
  flex: 1; min-width: 140px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  -webkit-appearance: none; appearance: none;
}
.seg { display: inline-flex; background: var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; color: var(--muted); cursor: pointer; }
.seg button.active { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

/* ── Stat résumé ────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-bottom: 12px; }
.stat-box { background: var(--card); border-radius: 12px; padding: 10px; text-align: center; box-shadow: var(--shadow); }
.stat-box .v { font-size: 18px; font-weight: 800; }
.stat-box .l { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }

/* ── Liste projets / légende ────────────────────────── */
.legend { margin-top: 10px; }
.legend-item { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 13px; border-bottom: 1px solid var(--line); }
.legend-item:last-child { border-bottom: 0; }
.legend-dot { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.legend-name { flex: 1; }
.legend-val { font-weight: 700; }
.legend-pct { color: var(--faint); min-width: 48px; text-align: right; }

/* ── Comparaison Thomas ─────────────────────────────── */
.vs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.vs-card { background: var(--card); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); }
.vs-card h3 { font-size: 13px; margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.vs-card .big { font-size: 26px; font-weight: 800; }
.vs-card .unit { font-size: 13px; color: var(--muted); font-weight: 600; }
.vs-card ul { list-style: none; margin-top: 8px; font-size: 12px; }
.vs-card li { display: flex; justify-content: space-between; padding: 3px 0; color: var(--muted); }

.empty { text-align: center; color: var(--faint); padding: 30px 0; font-size: 13px; }

/* ── Tabbar ─────────────────────────────────────────── */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
  display: flex;
}
.tab {
  flex: 1; border: 0; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--faint); font-size: 11px; font-family: inherit;
}
.tab .ico { font-size: 20px; filter: grayscale(1) opacity(.6); }
.tab.active { color: var(--accent); }
.tab.active .ico { filter: none; }
