:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --texte: #14181f;
  --texte-doux: #5b6673;
  --bord: #e2e6eb;
  --accent: #2563eb;
  --accent-doux: #dbe6ff;
  --ok: #16a34a;
  --alerte: #dc2626;
  --ombre: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --rayon: 16px;
  --safe-bas: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f16;
    --surface: #151b24;
    --surface-2: #1e2733;
    --texte: #e8ecf2;
    --texte-doux: #93a0b0;
    --bord: #263141;
    --accent: #5b8cff;
    --accent-doux: #1c2c4d;
    --ok: #3ec77a;
    --alerte: #f2685f;
    --ombre: none;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--texte);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.05rem; font-weight: 650; letter-spacing: -0.01em; }
a { color: var(--accent); }

/* --- Chargement --- */
.chargement { display: grid; place-items: center; height: 100dvh; }
.spin {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--bord); border-top-color: var(--accent);
  animation: tourne 0.7s linear infinite;
}
@keyframes tourne { to { transform: rotate(360deg); } }

/* --- Écran centré (login / setup) --- */
.centre {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
}
.carte-auth {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--bord); border-radius: var(--rayon);
  box-shadow: var(--ombre); padding: 28px 24px;
}
.marque { text-align: center; margin-bottom: 22px; }
.marque .logo { font-size: 2rem; }
.marque h1 { margin-top: 6px; }
.marque p { color: var(--texte-doux); font-size: 0.9rem; margin-top: 4px; }

label { display: block; font-size: 0.85rem; color: var(--texte-doux); margin: 14px 0 6px; font-weight: 550; }
input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; background: var(--surface-2); border: 1px solid var(--bord);
  border-radius: 12px; padding: 12px 14px; outline: none; transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.bouton {
  width: 100%; background: var(--accent); color: #fff; font-weight: 600;
  padding: 13px; border-radius: 12px; margin-top: 20px; transition: opacity 0.15s;
}
.bouton:active { opacity: 0.85; }
.bouton:disabled { opacity: 0.5; }
.bouton-doux { background: var(--surface-2); color: var(--texte); }
.erreur { color: var(--alerte); font-size: 0.85rem; margin-top: 12px; min-height: 1.2em; text-align: center; }
.aide { color: var(--texte-doux); font-size: 0.8rem; margin-top: 8px; }
.code-otp { text-align: center; letter-spacing: 0.4em; font-size: 1.4rem; font-variant-numeric: tabular-nums; }

/* --- Coquille appli --- */
.appli { min-height: 100dvh; padding-bottom: calc(68px + var(--safe-bas)); }
.entete {
  position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  padding: 14px 18px calc(14px + env(safe-area-inset-top, 0px)); padding-top: max(14px, env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--bord); display: flex; align-items: baseline; justify-content: space-between;
}
.entete .date { color: var(--texte-doux); font-size: 0.82rem; }
.vue { padding: 16px 16px 24px; max-width: 640px; margin: 0 auto; }

.carte {
  background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon);
  box-shadow: var(--ombre); padding: 16px; margin-bottom: 14px;
}
.carte h2 { margin-bottom: 12px; }
.carte h2 + .sous { margin-top: -8px; }
.sous { color: var(--texte-doux); font-size: 0.82rem; margin-bottom: 12px; }

/* Grille de stats */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon);
  box-shadow: var(--ombre); padding: 14px 16px;
}
.stat .val { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat .val small { font-size: 0.9rem; font-weight: 500; color: var(--texte-doux); }
.stat .lib { color: var(--texte-doux); font-size: 0.8rem; margin-top: 2px; }
.stat .obj { font-size: 0.72rem; color: var(--texte-doux); margin-top: 6px; }
.barre { height: 5px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.barre > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.barre.ok > i { background: var(--ok); }

/* Listes d'entrées */
.ligne {
  display: flex; align-items: center; gap: 12px; padding: 11px 2px; border-top: 1px solid var(--bord);
}
.ligne:first-of-type { border-top: none; }
.ligne .ico { font-size: 1.3rem; width: 30px; text-align: center; }
.ligne .txt { flex: 1; min-width: 0; }
.ligne .txt b { font-weight: 600; }
.ligne .txt span { display: block; color: var(--texte-doux); font-size: 0.8rem; }
.ligne .droite { color: var(--texte-doux); font-size: 0.85rem; text-align: right; white-space: nowrap; }
.pastille { font-size: 0.72rem; padding: 2px 8px; border-radius: 99px; font-weight: 600; }
.pastille.oui { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.pastille.non { background: color-mix(in srgb, var(--alerte) 16%, transparent); color: var(--alerte); }
.vide { color: var(--texte-doux); font-size: 0.88rem; text-align: center; padding: 18px 0; }
.supprimer { color: var(--texte-doux); font-size: 1.1rem; padding: 4px 6px; }

/* Boutons ligne + segmenté */
.champs-ligne { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin-top: 6px; }
.seg button { flex: 1; padding: 9px; border-radius: 9px; font-size: 0.85rem; font-weight: 550; color: var(--texte-doux); }
.seg button.actif { background: var(--surface); color: var(--texte); box-shadow: var(--ombre); }
.puce-jours { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.puce-jours button { padding: 7px 11px; border-radius: 99px; border: 1px solid var(--bord); font-size: 0.8rem; color: var(--texte-doux); }
.puce-jours button.actif { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Graphique */
.graph { width: 100%; height: 160px; display: block; }
.graph .zone { fill: color-mix(in srgb, var(--accent) 12%, transparent); }
.graph .courbe { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.graph .pt { fill: var(--accent); }
.graph .axe { stroke: var(--bord); stroke-width: 1; }
.graph .etq { fill: var(--texte-doux); font-size: 10px; }

/* Barre d'onglets */
.onglets {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--bord); padding-bottom: var(--safe-bas);
}
.onglets button {
  flex: 1; padding: 8px 2px 7px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--texte-doux); font-size: 0.62rem; font-weight: 550;
}
.onglets button .gl { font-size: 1.3rem; line-height: 1; }
.onglets button.actif { color: var(--accent); }

/* Modale d'ajout */
.modale-fond {
  position: fixed; inset: 0; z-index: 20; background: rgba(4, 8, 15, 0.45);
  display: grid; place-items: end center; animation: fondu 0.15s;
}
@keyframes fondu { from { opacity: 0; } }
.modale {
  width: 100%; max-width: 640px; background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(24px + var(--safe-bas)); animation: monte 0.2s ease;
  max-height: 88dvh; overflow-y: auto;
}
@keyframes monte { from { transform: translateY(100%); } }
.modale h2 { margin-bottom: 4px; }
.modale .fermer { position: absolute; }
.entete-modale { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.entete-modale button { color: var(--texte-doux); font-size: 1.4rem; padding: 2px 6px; }

.fab {
  position: fixed; right: 18px; bottom: calc(80px + var(--safe-bas)); z-index: 8;
  width: 54px; height: 54px; border-radius: 50%; background: var(--accent); color: #fff;
  font-size: 1.7rem; display: grid; place-items: center; box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
}

.rangee { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-top: 1px solid var(--bord); }
.rangee:first-child { border-top: none; }
.rangee .k { color: var(--texte-doux); }
.rangee .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9rem;
  background: var(--surface-2); padding: 12px; border-radius: 10px; word-break: break-all; text-align: center; letter-spacing: 0.05em;
}
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.codes span { font-family: ui-monospace, monospace; background: var(--surface-2); padding: 8px; border-radius: 8px; text-align: center; font-size: 0.9rem; }
.encart { background: var(--accent-doux); border-radius: 12px; padding: 12px 14px; font-size: 0.85rem; margin-top: 12px; }
