/* =============================================================================
   LifeZen — feuille de style. Mobile d'abord, mode clair et sombre (automatique ou choisi),
   aucune ressource externe (CSP stricte : pas de style en ligne, pas de police distante).
   ============================================================================= */
:root {
  color-scheme: light;
  --bg: #f3f7f5; --bg-accent: #dcefe9; --surface: #ffffff; --surface-2: #eef4f1;
  --text: #17201e; --muted: #53625e; --border: #d3ded9; --input-border: #788782;
  --primary: #1f7a68; --primary-strong: #17604f; --on-primary: #ffffff; --tint: #e8f5f1;
  --danger: #b3261e; --danger-bg: #fdecea; --danger-border: #f2b8b5;
  --success: #17653a; --success-bg: #e4f5ea; --success-border: #b4dfc3;
  --warning: #7a4f00; --warning-bg: #fff3d6; --warning-border: #f0d48a;
  --info: #1b5a85; --info-bg: #e6f0f8; --info-border: #b5d2e8;
  --ring: rgba(31, 122, 104, 0.45);
  --shadow: 0 1px 2px rgba(23, 32, 30, 0.06), 0 10px 30px rgba(23, 32, 30, 0.08);
  --radius: 16px; --radius-sm: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d1412; --bg-accent: #14312a; --surface: #15201d; --surface-2: #1c2a26;
    --text: #e8f0ed; --muted: #a0b3ad; --border: #2a3a35; --input-border: #6f847d;
    --primary: #4fc3a8; --primary-strong: #6fd3bb; --on-primary: #062219; --tint: #1b3a33;
    --danger: #ff9b92; --danger-bg: #3a1f1d; --danger-border: #6e3732;
    --success: #7fdca0; --success-bg: #173325; --success-border: #2f6a48;
    --warning: #f3c969; --warning-bg: #38300f; --warning-border: #6b5a1d;
    --info: #8cc4ef; --info-bg: #172a3a; --info-border: #2f5675;
    --ring: rgba(79, 195, 168, 0.5);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1412; --bg-accent: #14312a; --surface: #15201d; --surface-2: #1c2a26;
  --text: #e8f0ed; --muted: #a0b3ad; --border: #2a3a35; --input-border: #6f847d;
  --primary: #4fc3a8; --primary-strong: #6fd3bb; --on-primary: #062219; --tint: #1b3a33;
  --danger: #ff9b92; --danger-bg: #3a1f1d; --danger-border: #6e3732;
  --success: #7fdca0; --success-bg: #173325; --success-border: #2f6a48;
  --warning: #f3c969; --warning-bg: #38300f; --warning-border: #6b5a1d;
  --info: #8cc4ef; --info-bg: #172a3a; --info-border: #2f5675;
  --ring: rgba(79, 195, 168, 0.5);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
}

/* --- Base ------------------------------------------------------------------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 5rem; }
body {
  margin: 0; min-height: 100vh; color: var(--text); background: var(--bg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem; line-height: 1.55; -webkit-font-smoothing: antialiased;
}
/* Sans cette règle, tout style qui fixe « display » ANNULE l'attribut hidden (bug du bouton Administration). */
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--primary); text-underline-offset: 0.2em; }
a:hover { color: var(--primary-strong); }
img { max-width: 100%; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); }
.icon { width: 1.25rem; height: 1.25rem; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-xl { width: 3.75rem; height: 3.75rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

/* --- Marque ------------------------------------------------------------------ */
.brand { display: inline-flex; flex: none; align-items: center; gap: 0.6rem; color: var(--text); font-weight: 700; font-size: 1.2rem; text-decoration: none; }
.brand:hover { color: var(--text); }
.brand-center { align-self: center; }

/* --- Pages d'accès (connexion, inscription...) ------------------------------------ */
body.auth {
  display: flex; align-items: center; justify-content: center;
  padding: max(1.25rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) max(1.25rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
  background: radial-gradient(900px 480px at 12% -10%, var(--bg-accent), transparent 65%), radial-gradient(700px 420px at 100% 110%, var(--bg-accent), transparent 60%), var(--bg);
}
.auth-card { width: 100%; max-width: 26rem; padding: 2rem 1.75rem 1.5rem; display: flex; flex-direction: column; gap: 1.1rem; }
.title { font-size: 1.65rem; text-align: center; }
.lead { text-align: center; color: var(--muted); }
.foot { text-align: center; color: var(--muted); font-size: 0.9rem; }
.done-icon { align-self: center; color: var(--success); }

/* --- Formulaires ---------------------------------------------------------------- */
.stack { display: flex; flex-direction: column; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: 0.4rem; }
.field label { font-weight: 600; font-size: 0.95rem; }
.field-help { font-size: 0.9rem; color: var(--muted); }
.input {
  width: 100%; min-height: 3rem; padding: 0.7rem 0.9rem; font: inherit; font-size: 1rem; color: var(--text);
  background: var(--surface); border: 1.5px solid var(--input-border); border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--ring); }
.input[readonly] { background: var(--surface-2); }
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 3.25rem; }
.reveal {
  position: absolute; top: 50%; right: 0.25rem; transform: translateY(-50%); width: 2.75rem; height: 2.75rem;
  display: inline-flex; align-items: center; justify-content: center; padding: 0; color: var(--muted);
  background: transparent; border: 0; border-radius: 10px; cursor: pointer;
}
.reveal:hover { color: var(--text); background: var(--surface-2); }

/* --- Boutons ---------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; min-height: 2.75rem; padding: 0.6rem 1.15rem;
  font: inherit; font-weight: 600; line-height: 1.2; text-decoration: none; color: var(--text); background: var(--surface);
  border: 1.5px solid var(--input-border); border-radius: var(--radius-sm); cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { color: var(--text); background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { color: var(--on-primary); background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { color: var(--on-primary); background: var(--primary-strong); border-color: var(--primary-strong); }
.btn-ghost { color: var(--muted); background: transparent; border-color: transparent; }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { color: var(--danger); background: var(--danger-bg); }
.btn-block { width: 100%; }
.btn-sm { min-height: 2.25rem; padding: 0.35rem 0.8rem; font-size: 0.9rem; }
.icon-btn {
  display: inline-flex; flex: none; align-items: center; justify-content: center; width: 2.75rem; height: 2.75rem; padding: 0; color: var(--muted);
  background: transparent; border: 0; border-radius: 12px; cursor: pointer;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }

/* --- Messages ------------------------------------------------------------------------ */
.alert { padding: 0.75rem 1rem; font-size: 0.95rem; border: 1px solid; border-left-width: 4px; border-radius: var(--radius-sm); }
ul.alert { padding-left: 2rem; margin: 0; }
.alert-error { color: var(--danger); background: var(--danger-bg); border-color: var(--danger-border); border-left-color: var(--danger); }
.alert-success { color: var(--success); background: var(--success-bg); border-color: var(--success-border); border-left-color: var(--success); }
.alert-info { color: var(--info); background: var(--info-bg); border-color: var(--info-border); border-left-color: var(--info); }
.status { text-align: center; color: var(--muted); }

/* --- Pastilles ------------------------------------------------------------------------ */
.badge { display: inline-flex; align-items: center; padding: 0.15rem 0.65rem; font-size: 0.8rem; font-weight: 600; white-space: nowrap; border: 1px solid; border-radius: 999px; }
.badge-success { color: var(--success); background: var(--success-bg); border-color: var(--success-border); }
.badge-warning { color: var(--warning); background: var(--warning-bg); border-color: var(--warning-border); }
.badge-danger { color: var(--danger); background: var(--danger-bg); border-color: var(--danger-border); }
.badge-info { color: var(--info); background: var(--info-bg); border-color: var(--info-border); }
.badge-neutral { color: var(--muted); background: var(--surface-2); border-color: var(--border); }

/* --- Barre du haut (pages connectées) ----------------------------------------------------- */
.topbar { position: sticky; top: 0; z-index: 10; padding-top: env(safe-area-inset-top); background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; gap: 1rem; max-width: 72rem; margin: 0 auto; padding: 0.6rem max(1rem, env(safe-area-inset-right)) 0.6rem max(1rem, env(safe-area-inset-left)); }
.nav { display: flex; flex: 1; gap: 0.25rem; }
.nav-link { display: inline-flex; align-items: center; gap: 0.45rem; padding: 0.5rem 0.8rem; color: var(--muted); font-weight: 600; text-decoration: none; border-radius: 10px; }
.nav-link:hover { color: var(--text); background: var(--surface-2); }
.nav-link[aria-current="page"] { color: var(--primary); background: var(--tint); }
.user { display: flex; align-items: center; gap: 0.35rem; }
.avatar { display: inline-flex; flex: none; align-items: center; justify-content: center; width: 2.25rem; height: 2.25rem; color: var(--on-primary); font-weight: 700; background: var(--primary); border-radius: 50%; }
.user-name { max-width: 10rem; overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }

/* --- Pages connectées ---------------------------------------------------------------------- */
.page { display: flex; flex-direction: column; gap: 1.5rem; max-width: 72rem; margin: 0 auto; padding: 1.5rem max(1rem, env(safe-area-inset-right)) max(3rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)); }
.page-head { display: flex; flex-direction: column; gap: 0.35rem; }
.page-head h1 { font-size: 2rem; font-size: clamp(1.6rem, 4vw, 2.2rem); }
.section-title { font-size: 1.15rem; }
.section-card { display: flex; flex-direction: column; gap: 0.9rem; padding: 1.25rem 1.4rem; }
.section-card h2 { font-size: 1.15rem; }
.callout { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.25rem 1.4rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 1rem; }
.tile { display: flex; flex-direction: column; gap: 0.6rem; padding: 1.25rem; }
.tile h3 { font-size: 1.05rem; }
.tile p { color: var(--muted); font-size: 0.95rem; }
.tile-icon { display: inline-flex; align-items: center; justify-content: center; width: 3rem; height: 3rem; color: var(--primary); background: var(--tint); border-radius: 14px; }
.tile-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 1rem; }
.stat { display: flex; flex-direction: column; gap: 0.3rem; padding: 1rem 1.25rem; }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-label { color: var(--muted); font-size: 0.9rem; }
.invite-row { display: flex; align-items: flex-end; gap: 0.75rem; }
.invite-row .grow { flex: 1; }
.linkbox { display: flex; flex-direction: column; gap: 0.6rem; padding: 1rem; background: var(--tint); border: 1.5px dashed var(--primary); border-radius: var(--radius-sm); }

/* --- Tableaux (cartes sur mobile) ------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; font-size: 0.95rem; border-collapse: collapse; }
table.list th { color: var(--muted); font-size: 0.85rem; font-weight: 600; text-align: left; }
table.list th, table.list td { padding: 0.65rem 0.6rem; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
table.list td.actions { white-space: nowrap; }
table.list td.actions .btn { margin: 0.1rem 0.25rem 0.1rem 0; }

/* --- Page d'accueil publique ------------------------------------------------------------------ */
.landing { display: flex; flex-direction: column; min-height: 100vh; background: radial-gradient(1000px 520px at 10% -10%, var(--bg-accent), transparent 65%), var(--bg); }
.landing-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; max-width: 72rem; width: 100%; margin: 0 auto; padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 1rem max(1rem, env(safe-area-inset-left)); }
.hero { display: flex; flex-direction: column; align-items: center; gap: 1.25rem; max-width: 46rem; margin: 0 auto; padding: 3.5rem 1.25rem 2.5rem; text-align: center; }
.hero h1 { font-size: 2.6rem; font-size: clamp(2rem, 6vw, 3.25rem); }
.hero p { max-width: 36rem; color: var(--muted); font-size: 1.1rem; }
.hero-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.75rem; }
.features { max-width: 60rem; width: 100%; margin: 0 auto; padding: 0 max(1.25rem, env(safe-area-inset-right)) 3rem max(1.25rem, env(safe-area-inset-left)); }
.site-foot { margin-top: auto; padding: 1.5rem 1rem max(1.5rem, env(safe-area-inset-bottom)); color: var(--muted); font-size: 0.9rem; text-align: center; }

/* --- Petits écrans ------------------------------------------------------------------------------ */
@media (max-width: 40rem) {
  .user-name, .nav-link span, #logout span { display: none; }
  #logout { width: 2.75rem; padding: 0; }
  .nav-link { padding: 0.5rem 0.7rem; }
  .auth-card { padding: 1.75rem 1.25rem 1.25rem; }
  .invite-row { flex-direction: column; align-items: stretch; }
  .callout { flex-direction: column; align-items: stretch; }
  table.list thead { position: absolute; left: -9999px; }
  table.list, table.list tbody, table.list tr, table.list td { display: block; width: 100%; }
  table.list tr { margin-bottom: 0.75rem; padding: 0.4rem 0.9rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
  table.list td { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.4rem 0; border-bottom: 0; text-align: right; }
  table.list td::before { content: attr(data-label); color: var(--muted); font-size: 0.85rem; font-weight: 600; text-align: left; }
  table.list td.actions { flex-wrap: wrap; justify-content: flex-start; white-space: normal; }
  table.list td.actions::before { display: none; }
  table.list td.actions .btn { flex: 1 1 8rem; min-height: 2.5rem; margin: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
