:root {
  color-scheme: dark;
  --fond: #0f1220;
  --fond-haut: #181c33;
  --surface: rgba(255, 255, 255, 0.07);
  --bordure: rgba(255, 255, 255, 0.13);
  --texte: #f3f4fb;
  --texte-att: rgba(243, 244, 251, 0.68);
  --accent: #818cf8;
  --accent-texte: #0f1220;
  --dialogue: #1b2040;
  --rouge: #ff6b6b;
  --or: #ffc857;
  --rayon: 20px;
}

:root[data-theme="clair"] {
  color-scheme: light;
  --fond: #e9ecf8;
  --fond-haut: #f8f9fe;
  --surface: rgba(15, 18, 32, 0.05);
  --bordure: rgba(15, 18, 32, 0.15);
  --texte: #151a2e;
  --texte-att: rgba(21, 26, 46, 0.68);
  --accent: #5058e0;
  --accent-texte: #fff;
  --dialogue: #fff;
  --rouge: #d6323d;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--texte);
  background: linear-gradient(180deg, var(--fond-haut), var(--fond));
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }
option { color: var(--texte); background: var(--dialogue); }

.v-app {
  max-width: 900px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 14px calc(env(safe-area-inset-bottom) + 100px);
}

/* ── En-tête ── */
.v-entete { display: flex; gap: 8px; align-items: center; }
.v-entete h1 { margin: 0; flex: 1; font-size: 1.6rem; letter-spacing: 0.5px; }
.v-outils { display: flex; gap: 8px; margin-top: 12px; }
.v-outils input { flex: 1; min-width: 0; }
.v-outils select { width: auto; max-width: 48%; }

input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--bordure);
  border-radius: 12px;
  padding: 10px 12px;
  width: 100%;
}
input[type="checkbox"] { width: auto; }

.v-icone-btn {
  background: var(--surface);
  border: 1px solid var(--bordure);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 1.05rem;
  cursor: pointer;
}

.v-rappel { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; padding: 10px 12px; border-radius: 14px; background: rgba(255, 200, 87, 0.14); border: 1px solid rgba(255, 200, 87, 0.4); font-size: 0.88rem; }
.v-rappel[hidden] { display: none; }
.v-rappel span { flex: 1 1 200px; }
.v-rappel button { background: var(--surface); border: 1px solid var(--bordure); border-radius: 10px; padding: 6px 12px; cursor: pointer; }

/* ── Filtres ── */
.v-filtres { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0 6px; scrollbar-width: none; }
.v-filtres::-webkit-scrollbar { display: none; }
.v-puce {
  flex: none;
  background: var(--surface);
  border: 1px solid var(--bordure);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.v-puce.actif { background: var(--accent); border-color: var(--accent); color: var(--accent-texte); font-weight: 600; }

/* ── Grille de cartes ── */
.v-grille { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 14px; margin-top: 8px; }
.v-grille.liste { grid-template-columns: 1fr; gap: 10px; }

@keyframes apparition { from { opacity: 0; transform: translateY(14px) scale(0.97); } }

.v-tuile {
  position: relative;
  aspect-ratio: 1.586;                 /* format carte bancaire, pour le coup d'œil */
  border-radius: 22px;
  padding: 11px 12px;
  color: #fff;
  cursor: pointer;
  overflow: hidden;
  background: linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 52%, #000));
  box-shadow: 0 16px 30px -16px rgba(0, 0, 0, 0.75), inset 0 0 0 1px rgba(255, 255, 255, 0.18);
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "badge droite" "bas bas";
  align-items: start;
  animation: apparition 0.4s ease backwards;
  animation-delay: calc(var(--i, 0) * 35ms);
  transition: transform 0.15s ease;
}
.v-tuile:active { transform: scale(0.96); }
.v-tuile::before {                      /* reflet de carte */
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, rgba(255, 255, 255, 0.34) 0%, rgba(255, 255, 255, 0.06) 38%, rgba(255, 255, 255, 0) 55%);
  pointer-events: none;
}
.v-tuile.photo { background: #000 center / cover no-repeat; }
.v-tuile.photo::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0, 0, 0, 0.35), transparent 40%, rgba(0, 0, 0, 0.7)); pointer-events: none; }
.v-tuile > * { position: relative; z-index: 1; }

.v-badge {
  grid-area: badge;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.24);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.v-badge.logo { background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35); padding: 4px; }
.v-badge img { width: 100%; height: 100%; object-fit: contain; }
.v-droite { grid-area: droite; justify-self: end; display: flex; gap: 4px; align-items: center; }
.v-tuile-star { font-size: 1.15rem; color: var(--or); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55); }
.v-fleche { border: 0; border-radius: 8px; width: 28px; height: 28px; background: rgba(0, 0, 0, 0.4); color: #fff; cursor: pointer; }
.v-bas { grid-area: bas; align-self: end; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.v-tuile-nom { font-weight: 700; font-size: 1rem; line-height: 1.15; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.55); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.v-tuile-meta { font-size: 0.74rem; opacity: 0.92; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); }
.v-pastille { align-self: flex-start; font-size: 0.7rem; font-weight: 700; border-radius: 999px; padding: 1px 8px; background: rgba(0, 0, 0, 0.5); }
.v-pastille.bientot { background: #f59e0b; color: #1a1200; }
.v-pastille.expiree { background: #dc2626; color: #fff; }

/* Vue liste : une ligne par carte */
.liste .v-tuile {
  aspect-ratio: auto;
  min-height: 64px;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto;
  grid-template-areas: "badge bas droite";
  align-items: center;
  column-gap: 12px;
  border-radius: 18px;
}
.liste .v-bas { align-self: center; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 2px 8px; }
.liste .v-tuile-nom { flex: 1 1 100%; }

.v-vide { grid-column: 1 / -1; white-space: pre-line; text-align: center; color: var(--texte-att); padding: 60px 20px; line-height: 1.6; }

.v-ajout {
  position: fixed;
  right: calc(env(safe-area-inset-right) + 20px);
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 0;
  font-size: 2rem;
  line-height: 1;
  background: var(--accent);
  color: var(--accent-texte);
  box-shadow: 0 14px 30px -10px rgba(99, 102, 241, 0.85);
  cursor: pointer;
}

/* ── Plein écran (caisse) : toujours fond blanc, code noir très grand ── */
@keyframes ouvrir { from { opacity: 0; transform: scale(0.94); } }
.v-plein {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #fff;
  color: #111;
  border: 12px solid var(--c, #818cf8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 14px) 14px calc(env(safe-area-inset-bottom) + 14px);
  animation: ouvrir 0.22s ease;
}
.v-plein[hidden] { display: none; }
.v-plein-fermer { position: absolute; top: calc(env(safe-area-inset-top) + 8px); right: 8px; width: 44px; height: 44px; border-radius: 50%; border: 0; background: #eee; color: #111; font-size: 1.2rem; cursor: pointer; }
.v-plein-logo { width: 56px; height: 56px; object-fit: contain; border-radius: 12px; background: #fff; box-shadow: 0 1px 6px rgba(0, 0, 0, 0.25); padding: 4px; }
.v-plein-logo[hidden] { display: none; }
.v-plein-nom { font-size: 1.5rem; font-weight: 700; text-align: center; padding: 0 46px; }
.v-plein-corps { width: min(100%, 520px); display: flex; justify-content: center; transition: width 0.2s ease; }
.v-plein.zoom .v-plein-corps { width: min(100%, 900px); }
.v-plein-corps svg { width: 100%; height: auto; max-height: 56vh; }
.v-plein.zoom .v-plein-corps svg { max-height: 74vh; }
.v-plein-corps img { max-width: 100%; max-height: 66vh; border-radius: 14px; }
.v-plein-valeur { font-family: ui-monospace, Consolas, monospace; font-size: 1.05rem; letter-spacing: 1px; color: #444; overflow-wrap: anywhere; text-align: center; }
.v-plein-info { color: #555; font-size: 0.95rem; text-align: center; }
.v-plein-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.v-plein-actions button { background: #eee; border: 0; color: #111; border-radius: 12px; padding: 9px 13px; cursor: pointer; font-size: 0.9rem; }
.v-plein-actions .v-plein-danger { background: #fde8e8; color: #b42318; }
.v-plein-actions button[hidden] { display: none; }

/* ── Verrou PIN ── */
.v-verrou { position: fixed; inset: 0; z-index: 100; background: linear-gradient(180deg, var(--fond-haut), var(--fond)); display: grid; place-items: center; }
.v-verrou[hidden] { display: none; }
.v-verrou-corps { text-align: center; padding: 20px; }
.v-verrou-corps img { border-radius: 18px; }
.v-verrou-points { font-size: 1.8rem; letter-spacing: 10px; margin: 8px 0 18px; }
.v-verrou-clavier { display: grid; grid-template-columns: repeat(3, 72px); gap: 12px; justify-content: center; }
.v-verrou-clavier button { height: 72px; border-radius: 50%; border: 1px solid var(--bordure); background: var(--surface); font-size: 1.5rem; cursor: pointer; }
.v-verrou-clavier button:disabled { visibility: hidden; }
.v-lien { margin-top: 20px; background: none; border: 0; color: var(--texte-att); text-decoration: underline; cursor: pointer; }
@keyframes secoue { 25% { transform: translateX(-10px); } 75% { transform: translateX(10px); } }
.v-verrou-corps.secoue { animation: secoue 0.35s; }

/* ── Splash ── */
.v-splash { position: fixed; inset: 0; z-index: 200; background: var(--fond); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; font-size: 1.6rem; font-weight: 800; letter-spacing: 1px; transition: opacity 0.4s ease; }
.v-splash img { width: 96px; height: 96px; border-radius: 24px; animation: ouvrir 0.5s ease; }
.v-splash.fini { opacity: 0; pointer-events: none; }

/* ── Dialogues ── */
.v-dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  background: var(--dialogue);
  color: var(--texte);
  border: 1px solid var(--bordure);
  border-radius: 24px;
  padding: 18px;
}
.v-dialog[open] { animation: ouvrir 0.2s ease; }
.v-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.v-dialog h2 { margin: 0 0 10px; }
.v-dialog h3 { margin: 18px 0 6px; font-size: 1rem; }
.v-dialog label, .v-champ { display: block; margin-top: 12px; font-size: 0.88rem; color: var(--texte-att); }
.v-dialog label input, .v-dialog label select, .v-dialog label textarea { margin-top: 5px; color: var(--texte); }
.v-case { display: flex !important; gap: 8px; align-items: center; }

.v-avertissement { background: rgba(255, 200, 87, 0.14); border: 1px solid rgba(255, 200, 87, 0.4); border-radius: 12px; padding: 8px 10px; font-size: 0.85rem; margin: 0; }
.v-hint { font-size: 0.85rem; color: var(--texte-att); line-height: 1.5; margin: 6px 0; overflow-wrap: anywhere; }
.v-erreur { color: var(--rouge); font-size: 0.88rem; margin: 10px 0 0; }
.v-deux { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
progress { width: 100%; height: 10px; accent-color: var(--accent); }

.v-couleurs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.v-couleurs button { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; background: var(--c); cursor: pointer; }
.v-couleurs button.actif { border-color: var(--texte); }

.v-bascule { display: flex; gap: 6px; margin-top: 16px; background: var(--surface); border-radius: 14px; padding: 4px; }
.v-bascule button { flex: 1; border: 0; background: transparent; border-radius: 10px; padding: 9px; cursor: pointer; }
.v-bascule button.actif { background: var(--accent); color: var(--accent-texte); font-weight: 600; }

.v-scan-gros { display: block; width: 100%; margin-top: 14px; padding: 14px; border: 0; border-radius: 14px; background: var(--accent); color: var(--accent-texte); font-weight: 700; font-size: 1rem; cursor: pointer; }
#v-f-video { width: 100%; border-radius: 14px; margin-top: 10px; background: #000; }
.v-apercu-code { background: #fff; border-radius: 14px; margin-top: 12px; padding: 6px; }
.v-apercu-code:empty { display: none; }
.v-apercu-code svg { width: 100%; max-height: 180px; }

.v-logo-ligne { display: flex; gap: 10px; align-items: center; margin-top: 6px; }
.v-logo-apercu { flex: none; width: 48px; height: 48px; border-radius: 12px; background: #fff; color: #888; display: grid; place-items: center; font-weight: 800; overflow: hidden; border: 1px solid var(--bordure); }
.v-logo-apercu img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }
.v-photo-slot { margin-top: 14px; }
.v-photo-boutons { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.v-photo-boutons button { flex: 1; min-width: 100px; padding: 12px; border-radius: 12px; border: 1px solid var(--bordure); background: var(--surface); cursor: pointer; }
.v-photo-boutons button[hidden] { display: none; }
.v-apercu-photo { width: 100%; border-radius: 14px; margin-top: 10px; }
.v-apercu-photo[hidden] { display: none; }
.v-cache { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }

.v-boutons { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.v-boutons-gauche { justify-content: flex-start; margin-top: 8px; }
.v-boutons .v-danger { margin-right: auto; }
.v-boutons-gauche .v-danger { margin-right: 0; }
.v-primaire, .v-secondaire, .v-danger {
  border-radius: 12px;
  padding: 10px 16px;
  border: 1px solid var(--bordure);
  background: var(--surface);
  cursor: pointer;
}
.v-secondaire { color: var(--texte); }
#v-sauvegarde-btn { display: block; width: 100%; }
.v-boutons .v-secondaire { width: auto; }
.v-primaire { background: var(--accent); border-color: var(--accent); color: var(--accent-texte); font-weight: 700; }
.v-danger { color: var(--rouge); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
