/* ───────── Thème (clair / sombre / auto) ───────── */
:root {
  --bg:#f3f5f8; --surface:#ffffff; --surface-2:#eef1f5; --text:#15181e; --muted:#5a6272; --border:#e1e5ec;
  --accent:#0a8f95; --accent-soft:#d8f1f2;
  --c-steps:#0a8f95; --c-heart:#e0455f; --c-sleep:#6a5cd6; --c-azm:#e58a12; --c-dist:#2f7de1; --c-spo2:#1f9d6b;
  --st-awake:#e58a12; --st-rem:#8f6cf0; --st-light:#6aa5ff; --st-deep:#3a4fb8;
  --dur-fast:120ms; --dur-base:200ms; --dur-slow:320ms;
  --ease-out:cubic-bezier(.22,1,.36,1); --ease-in:cubic-bezier(.64,0,.78,0);
  --ease-in-out:cubic-bezier(.65,0,.35,1); --ease-spring:cubic-bezier(.34,1.56,.64,1);
  --shadow:0 1px 2px rgb(20 30 50 / .06), 0 6px 18px rgb(20 30 50 / .06);
  --border-glass: rgba(60, 60, 67, .10);
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --border-glass: rgba(255, 255, 255, .08); } }
:root[data-theme="dark"] { --border-glass: rgba(255, 255, 255, .08); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:#101216; --surface:#181b21; --surface-2:#20242c; --text:#eceef2; --muted:#9aa2b1; --border:#272b33;
    --accent:#4cc9cf; --accent-soft:#16363a;
    --c-steps:#4cc9cf; --c-heart:#ff7088; --c-sleep:#9a8cff; --c-azm:#f2a33c; --c-dist:#6aa5ff; --c-spo2:#4fd1a0;
    --shadow:0 1px 2px rgb(0 0 0 / .4), 0 8px 22px rgb(0 0 0 / .35);
  }
}
:root[data-theme="dark"] {
  --bg:#101216; --surface:#181b21; --surface-2:#20242c; --text:#eceef2; --muted:#9aa2b1; --border:#272b33;
  --accent:#4cc9cf; --accent-soft:#16363a;
  --c-steps:#4cc9cf; --c-heart:#ff7088; --c-sleep:#9a8cff; --c-azm:#f2a33c; --c-dist:#6aa5ff; --c-spo2:#4fd1a0;
  --shadow:0 1px 2px rgb(0 0 0 / .4), 0 8px 22px rgb(0 0 0 / .35);
}
html { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

/* ───────── Base ───────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; touch-action: pan-x pan-y; }
/* Le glissement de page ne doit jamais élargir la page (sinon le téléphone dézoome et la barre sort de l'écran). */
html, body { max-width: 100%; overflow-x: hidden; }
#views { max-width: min(640px, 100vw); overflow-x: clip; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  padding: 0 16px calc(96px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: contain;
}
main, .top { max-width: 640px; margin-inline: auto; }
button { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
.num { font-variant-numeric: tabular-nums; }

.top {
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 18px) 0 12px;
}
.top h1 { font-size: 30px; font-weight: 750; letter-spacing: -.02em; }
.eyebrow { font-size: 13px; color: var(--muted); text-transform: capitalize; }
.icon-btn {
  position: relative; width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 50%; border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow);
  cursor: pointer; transition: transform var(--dur-fast) var(--ease-out);
}
.icon-btn::after { content: ""; position: absolute; inset: -6px; }
.icon-btn:active { transform: scale(.92); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────── Vues ───────── */
.view { display: grid; gap: 14px; }
.view[hidden] { display: none; }
.view.enter-right { animation: in-right var(--dur-slow) var(--ease-out); }
.view.enter-left { animation: in-left var(--dur-slow) var(--ease-out); }
@keyframes in-right { from { opacity: 0; transform: translateX(28px); } }
@keyframes in-left { from { opacity: 0; transform: translateX(-28px); } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 22px;
  padding: 18px; box-shadow: var(--shadow);
  animation: rise var(--dur-slow) var(--ease-out) both; animation-delay: calc(var(--i, 0) * 45ms);
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.card h2 { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--accent)); display: inline-block; }
.big { font-size: 40px; font-weight: 760; letter-spacing: -.03em; line-height: 1.05; }
.big small { font-size: 16px; font-weight: 600; color: var(--muted); letter-spacing: 0; margin-left: 4px; }
.sub { color: var(--muted); font-size: 14px; margin-top: 4px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.stat .big { font-size: 30px; }
.stat h2 { margin-bottom: 8px; }

/* Anneaux */
.rings { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; }
.ring-wrap { position: relative; width: 150px; height: 150px; }
.ring-wrap svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-wrap .track { stroke: var(--surface-2); }
.ring-wrap .bar { transition: stroke-dashoffset 900ms var(--ease-out); stroke-linecap: round; }
.ring-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-center b { font-size: 20px; letter-spacing: -.02em; line-height: 1.1; }
.ring-center span { font-size: 10.5px; color: var(--muted); }
.legend { display: grid; gap: 10px; }
.legend div { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.legend b { margin-left: auto; font-size: 16px; }

/* Graphiques */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; align-items: end; height: 150px; }
.bar-col { display: grid; grid-template-rows: 1fr auto auto; height: 100%; gap: 4px; text-align: center; font-size: 11px; color: var(--muted); }
.bar-col .track { display: flex; align-items: end; }
.bar-col i { display: block; width: 100%; min-height: 3px; border-radius: 8px 8px 4px 4px; background: color-mix(in srgb, var(--c, var(--accent)) 45%, transparent);
  transform-origin: bottom; animation: grow 700ms var(--ease-out) both; animation-delay: calc(var(--k, 0) * 40ms); height: var(--h); }
.bar-col.today i { background: var(--c, var(--accent)); }
.bar-col b { font-size: 11px; color: var(--text); font-weight: 650; }
@keyframes grow { from { transform: scaleY(.05); } }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; background: var(--surface-2); font-size: 12px; color: var(--muted); }
.chip i { width: 8px; height: 8px; border-radius: 3px; background: var(--c); }

.list { display: grid; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 0; min-height: 48px; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }
.row span:first-child { color: var(--muted); font-size: 14px; }
.row b { font-variant-numeric: tabular-nums; }

/* Squelettes + états */
.skeleton { background: linear-gradient(100deg, var(--surface-2) 30%, color-mix(in srgb, var(--surface-2) 40%, var(--surface)) 50%, var(--surface-2) 70%); background-size: 200% 100%; animation: shimmer 1.3s linear infinite; border-radius: 12px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.empty { text-align: center; padding: 28px 18px; }
.empty h3 { font-size: 20px; margin-bottom: 6px; }
.empty p { color: var(--muted); margin-bottom: 16px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px;
  border-radius: 16px; border: 0; background: var(--accent); color: #fff; font-weight: 650; cursor: pointer; text-decoration: none;
  transition: transform var(--dur-fast) var(--ease-out), opacity var(--dur-fast);
}
:root[data-theme="dark"] .btn { color: #07282a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn { color: #07282a; } }
.btn:active { transform: scale(.96); }
:root .btn.ghost { background: var(--surface-2); color: var(--text); }
:root .btn.danger { background: transparent; color: var(--c-heart); border: 1px solid var(--border); }
:root .banner .btn.ghost { background: var(--surface); }
.btn-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.note { font-size: 13px; color: var(--muted); }
.banner { background: var(--accent-soft); border-radius: 16px; padding: 12px 14px; font-size: 14px; display: flex; gap: 10px; align-items: center; justify-content: space-between; }

/* Réglages */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border-radius: 14px; padding: 3px; gap: 3px; }
.seg button { min-height: 44px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); cursor: pointer; transition: background var(--dur-base), color var(--dur-base); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 650; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; min-height: 52px; border-top: 1px solid var(--border); }
.field:first-of-type { border-top: 0; }
.field input { width: 110px; min-height: 44px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); padding: 0 12px; font: inherit; text-align: right; }
details pre { max-height: 260px; overflow: auto; font-size: 11px; background: var(--surface-2); padding: 10px; border-radius: 12px; white-space: pre-wrap; word-break: break-all; }
details summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--muted); }

/* Tirer pour actualiser (gestures.js) */
.ptr { position: fixed; top: calc(env(safe-area-inset-top, 0px) - 30px); left: 50%; z-index: 60; width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; opacity: 0; transform: translate(-50%, 0); pointer-events: none;
  background: var(--surface); border: 1px solid var(--border); box-shadow: 0 4px 14px -4px rgba(0, 0, 0, .35); }
.ptr svg { width: 18px; height: 18px; fill: var(--muted); }
.ptr.ready svg, .ptr.spin svg { fill: var(--accent); }
.ptr:not(.spin) { transition: opacity .15s; }
.ptr.spin svg { animation: spin .8s linear infinite; }

/* Page voisine collée pendant le glissement */
#views.swiping { will-change: transform; }
.peek { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1; padding: 0 16px; overflow: hidden; pointer-events: none; background: var(--bg); will-change: transform; }
.peek > .view { max-width: 640px; margin-inline: auto; }
.peek .card, .peek .view, .peek i, .peek .bar { animation: none !important; transition: none !important; }

.toast { position: fixed; left: 50%; bottom: calc(84px + max(8px, calc(env(safe-area-inset-bottom) - 16px))); transform: translate(-50%, 20px); opacity: 0; z-index: 30; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; max-width: 90vw; transition: opacity var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ───────── Barre du bas : reprise exacte de l'app Patrimoine ─────────
   Capsule flottante près du bord du téléphone, juste au-dessus de la barre d'accueil de l'iPhone,
   icône + petit nom, bulle à ressort autour de l'onglet actif (navpill.js). */
.mbar {
  position: fixed; left: 12px; right: 12px; bottom: max(8px, calc(env(safe-area-inset-bottom) - 16px)); z-index: 40;
  max-width: 560px; margin-inline: auto;
  display: flex; padding: 5px; overflow: visible;
  border: 1px solid var(--border-glass); border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  -webkit-backdrop-filter: blur(24px) saturate(180%); backdrop-filter: blur(24px) saturate(180%);
  box-shadow: 0 12px 32px -12px rgba(0, 0, 0, .55);
}
.nav { position: relative; display: flex; flex-direction: row; justify-content: space-around; gap: 2px; align-items: stretch; width: 100%; touch-action: none; }
.nav a {
  flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 3px;
  height: 54px; padding: 0; border-radius: 999px; color: var(--muted); text-decoration: none;
  transition: background .25s ease, color .25s ease, transform .15s ease;
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
}
.nav a svg { width: 21px; height: 21px; fill: currentColor; flex-shrink: 0; }
.nav a span { font-size: 10px; font-weight: 600; line-height: 1; letter-spacing: .01em; white-space: nowrap; }
.nav a.active { background: var(--surface-2); color: var(--accent); box-shadow: inset 0 0 0 1px var(--border-glass), 0 2px 8px -3px rgba(0, 0, 0, .35); }

.nav-pill {
  display: block; position: absolute; left: 0; top: 0; z-index: 0; pointer-events: none; opacity: 0; overflow: hidden;
  border-radius: 999px; background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border-glass), 0 2px 8px -3px rgba(0, 0, 0, .35);
  transform-origin: center; will-change: transform;
}
.nav.pill-on .nav-pill { opacity: 1; }
.nav.pill-ready .nav-pill { transition: opacity .2s; }
.nav.pill-lens .nav-pill, .nav.pill-drag .nav-pill { z-index: 2; box-shadow: inset 0 0 0 1px var(--border-glass), 0 6px 18px -6px rgba(0, 0, 0, .5); }
.nav-pill .nav-lens { position: absolute !important; left: 0; top: 0; margin: 0 !important; padding: 0 !important; background: none !important; border: 0 !important; box-shadow: none !important; pointer-events: none; will-change: transform; visibility: hidden; }
.nav.pill-lens .nav-pill .nav-lens { visibility: visible; }
.nav-pill .nav-lens > a { position: static !important; background: transparent !important; box-shadow: none !important; transition: none !important; }
.nav-pill::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background:
    radial-gradient(52% 34% at calc(36% + var(--pill-dir, 0) * 26%) 10%, rgba(255, 255, 255, .22), rgba(255, 255, 255, 0) 62%),
    radial-gradient(70% 30% at calc(62% - var(--pill-dir, 0) * 20%) 100%, rgba(255, 255, 255, .08), rgba(255, 255, 255, 0) 65%);
  opacity: calc(.65 + .35 * var(--pill-v, 0));
}
.nav > a { position: relative; z-index: 1; }
.nav.pill-on > a.active { background: transparent; box-shadow: none; }
/* Pendant un glissement, chaque icône s'allume selon sa distance à la bulle. */
.nav:is(.pill-drag, .pill-follow) > a,
.nav:is(.pill-drag, .pill-follow) .nav-lens > a { color: color-mix(in srgb, var(--accent), var(--muted) calc(var(--pill-d, 1) * 100%)) !important; transition: none !important; }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) { .mbar { background: var(--surface); } }
@media (prefers-reduced-transparency: reduce) { .mbar { background: var(--surface); backdrop-filter: none; -webkit-backdrop-filter: none; } }
@media (prefers-reduced-motion: reduce) { .nav .nav-pill { transition: none !important; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
