/*
 * Systeme de themes : trois palettes commutables (Bleu & Blanc par defaut,
 * Terracotta & Blanc, Orange & Noir), chacune redefinissant les memes
 * variables. Aucun composant plus bas ne connait les couleurs par leur nom :
 * il ne lit que ces jetons, donc ajouter un quatrieme theme un jour ne
 * touchera qu'a ce bloc.
 */

:root,
[data-theme="bleu"] {
  --bg: #f4f6fb;
  --bg-degrade-a: #ffffff;
  --bg-degrade-b: #e8edfb;
  --carte-bg: #ffffff;
  --carte-bordure: #e2e8f0;
  --texte: #0f172a;
  --texte-attenue: #64748b;
  --accent: #1e40af;
  --accent-fort: #173bab;
  --accent-doux: rgba(30, 64, 175, 0.08);
  --positif: #0d9488;
  --positif-bg: #f0fdfa;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --compte-1: #1e40af;
  --compte-2: #0d9488;
  --compte-3: #2563eb;
  --compte-4: #0369a1;
  --ombre-carte: 0 1px 3px rgba(15, 23, 42, 0.07), 0 1px 2px rgba(15, 23, 42, 0.04);
}

[data-theme="terracotta"] {
  --bg: #fdfaf7;
  --bg-degrade-a: #fffdfa;
  --bg-degrade-b: #eddcd2;
  --carte-bg: #ffffff;
  --carte-bordure: #eaded6;
  --texte: #2b1810;
  --texte-attenue: #6b5d54;
  --accent: #c85a32;
  --accent-fort: #b84a28;
  --accent-doux: rgba(200, 90, 50, 0.1);
  --positif: #00554e;
  --positif-bg: #e6f7f5;
  --danger: #b91c1c;
  --danger-bg: #fdecea;
  --compte-1: #c85a32;
  --compte-2: #b84a28;
  --compte-3: #d97757;
  --compte-4: #a34424;
  --ombre-carte: 0 1px 3px rgba(43, 24, 16, 0.07), 0 1px 2px rgba(43, 24, 16, 0.04);
}

[data-theme="orange"] {
  --bg: #0b0b0d;
  --bg-degrade-a: #1a130c;
  --bg-degrade-b: #0b0b0d;
  --carte-bg: #18181b;
  --carte-bordure: #2a2a2e;
  --texte: #f5f5f4;
  --texte-attenue: #a1a1aa;
  --accent: #ff6b00;
  --accent-fort: #e05e00;
  --accent-doux: rgba(255, 107, 0, 0.14);
  --positif: #22c55e;
  --positif-bg: rgba(34, 197, 94, 0.12);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.14);
  --compte-1: #ff6b00;
  --compte-2: #f59e0b;
  --compte-3: #fb923c;
  --compte-4: #ea580c;
  --ombre-carte: 0 1px 3px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.35);
}

:root {
  --font-affichage: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-texte: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --rayon-sm: 0.5rem;
  --rayon-md: 1rem;
  --rayon-lg: 1.5rem;
}

* { box-sizing: border-box; }

/* Regle defensive : sans ca, `.panneau { display: flex }` plus bas ecrase
   silencieusement l'attribut `hidden` (meme specificite, l'origine auteur
   gagne toujours sur la feuille par defaut du navigateur). */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--texte);
  font-family: var(--font-texte);
  transition: background-color 0.2s ease, color 0.2s ease;
  padding-bottom: calc(2rem + env(safe-area-inset-bottom));
}

/* -------------------------------------------------------------------- */
/* Entete + selecteur de theme                                          */
/* -------------------------------------------------------------------- */

.entete {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: calc(0.85rem + env(safe-area-inset-top)) 1.25rem 0.85rem;
  position: sticky;
  top: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--carte-bordure);
  z-index: 10;
}

.entete-marque {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.entete-logo {
  color: var(--accent);
  font-size: 1.1rem;
}

.entete-titre {
  font-family: var(--font-affichage);
  font-weight: 700;
  font-size: 1.05rem;
}

.selecteur-theme {
  display: flex;
  gap: 0.2rem;
  background: var(--carte-bg);
  border: 1px solid var(--carte-bordure);
  border-radius: 999px;
  padding: 0.2rem;
  margin-left: auto;
  overflow-x: auto;
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: none;
  border: none;
  border-radius: 999px;
  padding: 0.35rem 0.6rem;
  font-family: var(--font-texte);
  font-size: 0.72rem;
  color: var(--texte-attenue);
  white-space: nowrap;
}

.theme-option[aria-checked="true"] {
  background: var(--accent-doux);
  color: var(--texte);
  font-weight: 600;
}

.theme-pastille {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 999px;
  flex-shrink: 0;
}

.theme-pastille-bleu { background: #1e40af; }
.theme-pastille-terracotta { background: #c85a32; }
.theme-pastille-orange { background: #ff6b00; }

.bouton-icone {
  background: none;
  border: 1px solid var(--carte-bordure);
  color: var(--texte);
  border-radius: 999px;
  width: 2.25rem;
  height: 2.25rem;
  font-size: 1.1rem;
  line-height: 1;
  flex-shrink: 0;
}

.bouton-icone.en-cours { animation: tourner 0.8s linear infinite; }

@keyframes tourner {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* -------------------------------------------------------------------- */
/* Onglets                                                                */
/* -------------------------------------------------------------------- */

.onglets {
  display: flex;
  gap: 0.4rem;
  padding: 0.75rem 1.25rem 0;
  max-width: 960px;
  margin: 0 auto;
}

.onglet-bouton {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--texte-attenue);
  font-family: var(--font-texte);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 0.2rem;
  cursor: pointer;
}

.onglet-bouton[aria-selected="true"] {
  color: var(--texte);
  border-bottom-color: var(--accent);
}

.section-entete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 1.25rem 0 0.85rem;
}

.section-titre {
  font-family: var(--font-affichage);
  font-size: 1.1rem;
  margin: 0;
}

.bouton-compact { flex: none; padding: 0.45rem 0.8rem; font-weight: 600; }

/* -------------------------------------------------------------------- */
/* Bandeaux d'etat                                                       */
/* -------------------------------------------------------------------- */

.bandeau {
  margin: 0.75rem 1.25rem;
  padding: 0.6rem 0.9rem;
  border-radius: var(--rayon-sm);
  background: var(--accent-doux);
  color: var(--accent-fort);
  font-size: 0.85rem;
}

.bandeau-erreur {
  background: var(--danger-bg);
  color: var(--danger);
}

main { padding: 0 1.25rem; max-width: 960px; margin: 0 auto; }

/* -------------------------------------------------------------------- */
/* Bandeau hero                                                          */
/* -------------------------------------------------------------------- */

.hero {
  position: relative;
  overflow: hidden;
  border-radius: var(--rayon-lg);
  background: linear-gradient(135deg, var(--bg-degrade-a), var(--bg-degrade-b));
  box-shadow: var(--ombre-carte);
  padding: 1.5rem;
  margin: 1.25rem 0;
  border: 1px solid var(--carte-bordure);
}

.hero-fond {
  position: absolute;
  right: -4rem;
  bottom: -4rem;
  width: 14rem;
  height: 14rem;
  border-radius: 999px;
  background: var(--accent);
  opacity: 0.08;
  filter: blur(30px);
  pointer-events: none;
}

.hero-contenu { position: relative; z-index: 1; }

.hero-badge {
  display: inline-block;
  font-family: var(--font-texte);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent-fort);
  background: var(--accent-doux);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  margin-bottom: 0.6rem;
}

.hero-montant {
  display: block;
  font-family: var(--font-affichage);
  font-size: clamp(1.85rem, 7vw, 2.4rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.hero-tuiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-top: 1.1rem;
}

.hero-tuile {
  background: color-mix(in srgb, var(--carte-bg) 80%, transparent);
  backdrop-filter: blur(6px);
  border-radius: var(--rayon-md);
  padding: 0.75rem 0.9rem;
  box-shadow: var(--ombre-carte);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.hero-tuile-libelle {
  font-size: 0.72rem;
  color: var(--texte-attenue);
}

.hero-tuile-montant {
  font-family: var(--font-affichage);
  font-size: 1.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* -------------------------------------------------------------------- */
/* Cartes comptes                                                        */
/* -------------------------------------------------------------------- */

.comptes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.85rem;
}

.compte {
  position: relative;
  background: var(--carte-bg);
  border: 1px solid var(--carte-bordure);
  border-radius: var(--rayon-lg);
  box-shadow: var(--ombre-carte);
  overflow: hidden;
}

.compte-bande { height: 0.35rem; background: var(--compte-1); }
.comptes .compte:nth-of-type(4n+2) .compte-bande { background: var(--compte-2); }
.comptes .compte:nth-of-type(4n+3) .compte-bande { background: var(--compte-3); }
.comptes .compte:nth-of-type(4n+4) .compte-bande { background: var(--compte-4); }

.compte-corps { padding: 1.1rem; display: flex; flex-direction: column; gap: 0.9rem; }

.compte-entete { display: flex; align-items: flex-start; justify-content: space-between; }

.compte-identite { display: flex; align-items: center; gap: 0.65rem; }

.compte-monogramme {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: var(--rayon-sm);
  background: var(--accent-doux);
  color: var(--accent-fort);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-affichage);
  font-weight: 700;
  font-size: 0.75rem;
  flex-shrink: 0;
}

.compte-nom { margin: 0; font-family: var(--font-texte); font-size: 0.95rem; font-weight: 600; }

.compte-sous-titre { font-size: 0.75rem; color: var(--texte-attenue); }

.compte-pastille {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 999px;
  background: var(--positif);
  margin-top: 0.3rem;
  flex-shrink: 0;
}

.compte-dispo-libelle { display: block; font-size: 0.78rem; color: var(--texte-attenue); }

.compte-dispo {
  font-family: var(--font-affichage);
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 0.15rem;
}

.montant-positif { color: var(--positif); }
.montant-negatif { color: var(--accent-fort); }
.montant-danger { color: var(--danger); font-weight: 700; }

.compte-detail {
  background: var(--bg);
  border-radius: var(--rayon-md);
  padding: 0.65rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.compte-detail-ligne {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--texte-attenue);
}

.compte-detail-ligne .compte-solde-actuel { color: var(--texte); font-weight: 600; }

.compte-barre {
  width: 100%;
  height: 0.35rem;
  border-radius: 999px;
  background: var(--carte-bordure);
  overflow: hidden;
}

.compte-barre-remplie { height: 100%; background: var(--compte-1); border-radius: 999px; }

.compte-lien {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent-fort);
  font-size: 0.82rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

/* -------------------------------------------------------------------- */
/* Actions                                                                */
/* -------------------------------------------------------------------- */

.actions { display: flex; gap: 0.6rem; margin-top: 1.5rem; }

.bouton-secondaire {
  flex: 1;
  background: var(--carte-bg);
  border: 1px solid var(--carte-bordure);
  color: var(--texte);
  border-radius: var(--rayon-sm);
  padding: 0.7rem;
  font-size: 0.85rem;
  font-family: var(--font-texte);
}

.bouton-lien {
  display: block;
  text-align: center;
  text-decoration: none;
}

/* -------------------------------------------------------------------- */
/* Budgets par categorie                                                 */
/* -------------------------------------------------------------------- */

.formulaire-budget {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.formulaire-budget select,
.formulaire-budget input {
  flex: 1;
  min-width: 8rem;
  border: 1px solid var(--carte-bordure);
  border-radius: var(--rayon-sm);
  background: var(--carte-bg);
  color: var(--texte);
  padding: 0.5rem 0.6rem;
  font-family: var(--font-texte);
  font-size: 0.85rem;
}

.bouton-primaire {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--rayon-sm);
  padding: 0.5rem 1rem;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

.budgets-liste {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.budget {
  background: var(--carte-bg);
  border: 1px solid var(--carte-bordure);
  border-radius: var(--rayon-md);
  box-shadow: var(--ombre-carte);
  padding: 1rem 1.1rem;
}

.budget-entete { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }

.budget-categorie { font-family: var(--font-texte); font-weight: 600; font-size: 0.9rem; }

.budget-montants { font-family: var(--font-affichage); font-size: 0.95rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

.budget-montants .budget-limite { color: var(--texte-attenue); font-weight: 400; }

.budget-barre {
  width: 100%;
  height: 0.5rem;
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
  margin-top: 0.6rem;
}

.budget-barre-remplie { height: 100%; border-radius: 999px; background: var(--accent); }

.budget.depasse .budget-barre-remplie { background: var(--danger); }
.budget.depasse .budget-montants { color: var(--danger); }

.objectif.atteint .budget-barre-remplie { background: var(--positif); }
.objectif.atteint .budget-montants { color: var(--positif); }

.objectif-modifier,
.objectif-atteint {
  background: none;
  border: none;
  color: var(--texte-attenue);
  font-size: 0.72rem;
}

.objectif-modifier { text-decoration: underline; cursor: pointer; }
.objectif-atteint { color: var(--positif); font-weight: 600; }

.budget-pied {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--texte-attenue);
}

.budget-supprimer {
  background: none;
  border: none;
  color: var(--texte-attenue);
  font-size: 0.72rem;
  text-decoration: underline;
  cursor: pointer;
}

.derniere-maj {
  text-align: center;
  color: var(--texte-attenue);
  font-size: 0.75rem;
  margin-top: 1.5rem;
}

/* -------------------------------------------------------------------- */
/* Panneau des mouvements (modal)                                        */
/* -------------------------------------------------------------------- */

.panneau { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; }

.panneau-fond { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.5); }

.panneau-contenu {
  position: relative;
  z-index: 1;
  width: 100%;
  max-height: 82vh;
  margin: 0 auto;
  background: var(--carte-bg);
  color: var(--texte);
  border-radius: var(--rayon-lg) var(--rayon-lg) 0 0;
  padding: 1.25rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panneau-entete { display: flex; align-items: flex-start; justify-content: space-between; }

.panneau-titre { margin: 0; font-family: var(--font-affichage); font-size: 1.15rem; }

.panneau-solde { font-size: 0.85rem; color: var(--texte-attenue); }

.panneau-section-titre {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--texte-attenue);
  margin: 0 0 0.5rem;
}

.panneau-liste { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }

.panneau-ligne {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0.6rem;
  border-radius: var(--rayon-sm);
  background: var(--bg);
}

.panneau-ligne.en-retard { outline: 1px solid var(--danger); }

.panneau-ligne-libelle { font-size: 0.85rem; font-weight: 600; }

.panneau-ligne-meta { font-size: 0.72rem; color: var(--texte-attenue); }

.panneau-ligne-montant { font-family: var(--font-affichage); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.categorie-badge {
  display: inline-flex;
  align-items: center;
  background: var(--accent-doux);
  color: var(--accent-fort);
  border: none;
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  font-family: var(--font-texte);
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
}

.categorie-select {
  font-family: var(--font-texte);
  font-size: 0.72rem;
  border: 1px solid var(--carte-bordure);
  border-radius: var(--rayon-sm);
  background: var(--carte-bg);
  color: var(--texte);
  padding: 0.1rem 0.3rem;
  max-width: 11rem;
}

/* -------------------------------------------------------------------- */
/* Petit ecran (telephone) : cible tactile plus large, en-tete compact   */
/* -------------------------------------------------------------------- */

@media (max-width: 600px) {
  .entete { padding-left: 1rem; padding-right: 1rem; gap: 0.5rem; }
  .entete-titre { font-size: 0.95rem; }

  .selecteur-theme { overflow: visible; }
  .theme-nom { display: none; }
  .theme-option { padding: 0.5rem; }
  .theme-pastille { width: 0.85rem; height: 0.85rem; }

  .bouton-icone { width: 2.75rem; height: 2.75rem; font-size: 1.3rem; }

  main { padding: 0 1rem; }
  .hero { padding: 1.25rem 1rem; margin: 1rem 0; }
  .hero-tuiles { grid-template-columns: 1fr; }

  .comptes { grid-template-columns: 1fr; }

  .compte-lien { padding: 0.5rem 0; font-size: 0.88rem; }

  .actions { flex-direction: column; }
  .bouton-secondaire { padding: 0.9rem; font-size: 0.9rem; }
}

@media (min-width: 640px) {
  .panneau { align-items: center; }
  .panneau-contenu { max-width: 480px; border-radius: var(--rayon-lg); max-height: 80vh; }
}
