/* ============================================================
   Budget — design tokens
   Palette "grand livre" : papier sauge frais, encre pin profonde,
   chiffres en tabulaire mono façon relevé bancaire.
   ============================================================ */
:root {
  --bg: #EEF2EC;
  --surface: #FFFFFF;
  --surface-alt: #F6F9F4;
  --surface-sunken: #E4EAE1;
  --ink: #1B2E27;
  --ink-soft: #44554D;
  --muted: #6C7B72;
  --muted-2: #8A968E;
  --border: #DDE5DA;
  --border-strong: #C7D2C3;

  --primary: #1E5C46;
  --primary-dark: #143D2F;
  --primary-soft: #E1ECE5;

  --income: #2C8C5B;
  --income-soft: #E3F2E9;
  --expense: #A6402C;
  --expense-soft: #F6E6E1;
  --pending: #B8842A;
  --pending-soft: #F6EEDB;

  --tag-pine: #1E5C46;   --tag-pine-soft: #E1ECE5;
  --tag-slate: #54636B;  --tag-slate-soft: #E7ECEC;
  --tag-blue: #2E6B8C;   --tag-blue-soft: #E3EEF3;
  --tag-amber: #B8842A;  --tag-amber-soft: #F6EEDB;
  --tag-purple: #6A4E8C; --tag-purple-soft: #EDE6F3;
  --tag-rose: #A6425F;   --tag-rose-soft: #F6E3E9;
  --tag-income: #2C8C5B; --tag-income-soft: #E3F2E9;

  --font-display: 'Fraunces', 'Iowan Old Style', serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SF Mono', monospace;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(20,35,29,0.07);
  --shadow-md: 0 6px 20px rgba(20,35,29,0.10);
  --shadow-lg: 0 20px 48px rgba(20,35,29,0.18);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--font-display); margin: 0; font-weight: 600; }
p { margin: 0; }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }

.icon { width: 1.1em; height: 1.1em; display: inline-block; vertical-align: -0.15em; flex-shrink: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ---------- Layout général de l'appli ---------- */
.app-shell {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 96px;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--primary-dark);
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
}
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.icon-btn:hover { background: var(--surface-alt); color: var(--primary-dark); }

/* ---------- Hero solde ---------- */
.solde-hero {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 22px 22px 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}
.solde-hero-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.solde-label {
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
}
.solde-montant {
  font-family: var(--font-mono);
  font-size: 38px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.solde-maj {
  font-size: 12.5px;
  color: var(--muted-2);
  margin-top: 4px;
}
.btn-maj-solde {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  border: none;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}
.btn-maj-solde:hover { background: #D3E4DA; }

.solde-edit-form { display: flex; gap: 8px; margin-top: 4px; }
.solde-edit-form input {
  font-family: var(--font-mono);
  font-size: 22px;
  width: 160px;
  padding: 8px 10px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--ink);
}
.solde-edit-form input:focus { border-color: var(--primary); background: var(--surface); }

.sparkline { margin-top: 14px; width: 100%; height: 44px; display: block; }
.sparkline-empty { color: var(--muted-2); font-size: 12.5px; margin-top: 14px; }

/* ---------- Navigation mensuelle (onglets "carnet de compte") ---------- */
.mois-nav {
  display: flex;
  align-items: stretch;
  gap: 4px;
  margin-bottom: 0;
}
.mois-nav-fleche {
  flex-shrink: 0;
  width: 34px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.mois-nav-fleche:hover { background: var(--surface-alt); color: var(--primary-dark); }
.mois-nav-tabs {
  flex: 1;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
}
.mois-tab {
  position: relative;
  border: none;
  background: var(--surface-sunken);
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 600;
  text-transform: capitalize;
  padding: 10px 4px 12px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mois-tab:hover { background: var(--border); color: var(--ink-soft); }
.mois-tab.actif {
  background: var(--surface);
  color: var(--primary-dark);
  box-shadow: 0 -2px 8px rgba(20,35,29,0.06);
}
.mois-tab .point-attente {
  position: absolute;
  top: 6px;
  right: 50%;
  transform: translateX(13px);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--pending);
}

/* ---------- Panneau du mois ---------- */
.mois-panel {
  background: var(--surface);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 18px 18px 8px;
  margin-bottom: 20px;
}

.mois-resume {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}
.resume-carte {
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: left;
}
.resume-carte .r-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 5px;
}
.resume-carte .r-label .icon { width: 12px; height: 12px; }
.resume-carte .r-valeur {
  font-family: var(--font-mono);
  font-size: 14.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.resume-carte.revenus .r-valeur { color: var(--income); }
.resume-carte.depenses .r-valeur { color: var(--expense); }

/* ---------- Liste de transactions ---------- */
.transactions-liste { list-style: none; margin: 0; padding: 0; }
.transaction {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 2px;
  border-top: 1px solid var(--border);
}
.transaction:first-child { border-top: none; }
.transaction.est-passe { opacity: 0.62; }

.t-check {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--muted-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}
.t-check .icon { width: 15px; height: 15px; }
.transaction.est-passe .t-check {
  background: var(--income-soft);
  border-color: var(--income-soft);
  color: var(--income);
}
.transaction:not(.est-passe) .t-check { color: var(--pending); border-color: var(--pending-soft); background: var(--pending-soft); }

.t-icone {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.t-icone .icon { width: 16px; height: 16px; }

.t-info { flex: 1; min-width: 0; }
.t-libelle {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.t-meta { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.t-meta .icon { width: 11px; height: 11px; }

.t-chiffres { text-align: right; flex-shrink: 0; }
.t-montant {
  display: block;
  font-family: var(--font-mono);
  font-size: 14.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.t-montant.positif { color: var(--income); }
.t-montant.negatif { color: var(--expense); }
.t-solde-apres {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted-2);
  margin-top: 1px;
  font-variant-numeric: tabular-nums;
}

.t-actions { display: flex; gap: 2px; flex-shrink: 0; margin-left: 2px; }
.t-actions .icon-btn { width: 30px; height: 30px; opacity: 0; transition: opacity 0.15s ease, background 0.15s ease; }
.transaction:hover .t-actions .icon-btn,
.transaction:focus-within .t-actions .icon-btn { opacity: 1; }
.t-actions .icon-btn.confirme-suppr { opacity: 1; color: var(--expense); background: var(--expense-soft); }

.mois-vide {
  text-align: center;
  padding: 36px 16px 30px;
  color: var(--muted);
}
.mois-vide .icon { width: 26px; height: 26px; color: var(--muted-2); margin-bottom: 8px; }
.mois-vide p { font-size: 13.5px; }

/* ---------- Jetons de catégorie ---------- */
.tag-pine   { background: var(--tag-pine-soft);   color: var(--tag-pine); }
.tag-slate  { background: var(--tag-slate-soft);  color: var(--tag-slate); }
.tag-blue   { background: var(--tag-blue-soft);   color: var(--tag-blue); }
.tag-amber  { background: var(--tag-amber-soft);  color: var(--tag-amber); }
.tag-purple { background: var(--tag-purple-soft); color: var(--tag-purple); }
.tag-rose   { background: var(--tag-rose-soft);   color: var(--tag-rose); }
.tag-income { background: var(--tag-income-soft); color: var(--tag-income); }

/* ---------- Bouton flottant d'ajout ---------- */
.fab-ajout {
  position: fixed;
  right: 20px;
  bottom: 24px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  z-index: 20;
}
.fab-ajout:hover { background: var(--primary-dark); transform: translateY(-1px); }
.fab-ajout .icon { width: 24px; height: 24px; }

/* ---------- Boutons génériques ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 999px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.btn-primaire { background: var(--primary); color: #fff; }
.btn-primaire:hover { background: var(--primary-dark); }
.btn-discret { background: var(--surface-alt); color: var(--ink-soft); }
.btn-discret:hover { background: var(--border); }
.btn-texte { background: transparent; color: var(--muted); padding: 8px 10px; }
.btn-texte:hover { color: var(--ink); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-large { width: 100%; padding: 12px 16px; font-size: 15px; }

/* ---------- Panneau latéral (récurrences) ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(20,35,29,0.32);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 30;
}
.overlay.ouvert { opacity: 1; pointer-events: auto; }

.panneau {
  position: fixed;
  top: 0; right: 0;
  height: 100%;
  width: min(420px, 92vw);
  background: var(--bg);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 31;
  display: flex;
  flex-direction: column;
}
.panneau.ouvert { transform: translateX(0); }
.panneau-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.panneau-header h2 { font-size: 18px; color: var(--primary-dark); }
.panneau-corps { flex: 1; overflow-y: auto; padding: 16px 18px 100px; }

.recurrence-ligne {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
}
.recurrence-ligne.inactive { opacity: 0.55; }
.recurrence-ligne .t-icone { width: 30px; height: 30px; }
.recurrence-ligne .r-info { flex: 1; min-width: 0; }
.recurrence-ligne .r-libelle { font-size: 13.5px; font-weight: 500; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recurrence-ligne .r-detail { font-size: 11.5px; color: var(--muted); }
.recurrence-ligne .r-montant { font-family: var(--font-mono); font-size: 13.5px; font-variant-numeric: tabular-nums; flex-shrink: 0; }

.section-titre {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); font-weight: 700; margin: 18px 0 10px;
}
.section-titre:first-child { margin-top: 0; }

/* ---------- Formulaires (modale + panneau) ---------- */
.champ { margin-bottom: 14px; }
.champ label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 5px;
}
.champ input, .champ select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: inherit;
  font-size: 14.5px;
  color: var(--ink);
}
.champ input:focus, .champ select:focus { border-color: var(--primary); }
.champ-ligne { display: flex; gap: 10px; }
.champ-ligne .champ { flex: 1; }

.toggle-type {
  display: flex;
  border-radius: 999px;
  background: var(--surface-alt);
  padding: 3px;
  margin-bottom: 14px;
}
.toggle-type button {
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 0;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s ease;
}
.toggle-type button.actif.depense { background: var(--expense-soft); color: var(--expense); }
.toggle-type button.actif.revenu { background: var(--income-soft); color: var(--income); }

/* ---------- Modale ---------- */
.modale-fond {
  position: fixed; inset: 0;
  background: rgba(20,35,29,0.32);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 40;
  padding: 0;
}
.modale-fond.ouvert { opacity: 1; pointer-events: auto; }
.modale {
  background: var(--bg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 20px 20px 24px;
  transform: translateY(24px);
  transition: transform 0.22s ease;
}
.modale-fond.ouvert .modale { transform: translateY(0); }
.modale-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modale-header h2 { font-size: 17px; color: var(--primary-dark); }
.modale-actions { display: flex; gap: 8px; margin-top: 18px; }
.modale-actions .btn { flex: 1; }
.modale-erreur { color: var(--expense); font-size: 13px; margin-bottom: 10px; }

@media (min-width: 640px) {
  .modale-fond { align-items: center; }
  .modale { border-radius: var(--radius-lg); transform: translateY(8px); }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translate(-50%, 12px);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  z-index: 50;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Page de connexion ---------- */
.page-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}
.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 32px 28px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.login-mark {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: 14px;
}
.login-card h1 { font-size: 22px; color: var(--primary-dark); margin-bottom: 6px; }
.login-sub { font-size: 13px; color: var(--muted); margin-bottom: 20px; }
.login-erreur { color: var(--expense); font-size: 13px; margin-bottom: 12px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; }
.login-card label { text-align: left; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
.login-card input {
  padding: 11px 12px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 15px;
  background: var(--surface-alt);
}
.login-card input:focus { border-color: var(--primary); background: var(--surface); }
.login-card button {
  margin-top: 6px;
  padding: 11px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
}
.login-card button:hover { background: var(--primary-dark); }

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .solde-montant { font-size: 32px; }
  .mois-resume { grid-template-columns: repeat(2, 1fr); }
  .t-actions { display: none; }
}
