/* ==========================================================================
   Composants — cartes, boutons, champs, listes, progression, modales, toasts
   ========================================================================== */

/* ---------- Cartes ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-md);
  border: 0.5px solid var(--separator);
}

.card--tight {
  padding: var(--space-md);
}

.card__label {
  font-size: var(--text-footnote);
  color: var(--text-secondary);
  font-weight: var(--weight-medium);
}

/* ---------- Carte HERO : Reste à vivre ---------- */
.hero {
  position: relative;
  overflow: hidden;
  background: var(--hero-gradient);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: var(--space-xl) var(--space-lg);
  box-shadow: var(--shadow-lg);
  border: none;
}

.hero::after {
  /* halo lumineux discret */
  content: "";
  position: absolute;
  top: -40%;
  right: -20%;
  width: 220px;
  height: 220px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.28), transparent 70%);
  pointer-events: none;
}

.hero__eyebrow {
  font-size: var(--text-footnote);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.85;
}

.hero__amount {
  font-size: var(--text-hero);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
  font-variant-numeric: tabular-nums;
  margin-top: var(--space-xs);
  line-height: 1.05;
}

.hero__meta {
  margin-top: var(--space-sm);
  font-size: var(--text-footnote);
  opacity: 0.9;
}

.hero.is-negative {
  --hero-gradient: linear-gradient(135deg, #FF453A 0%, #C4122F 100%);
  background: var(--hero-gradient);
  box-shadow: 0 12px 40px rgba(196, 18, 47, 0.4);
}

/* ---------- Statistiques rapides (grille) ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}

.stat {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  box-shadow: var(--shadow-sm);
  border: 0.5px solid var(--separator);
}

.stat__label {
  font-size: var(--text-footnote);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}

.stat__value {
  font-size: var(--text-large);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}

.stat__value--income { color: var(--accent); }
.stat__value--fixed  { color: var(--text-primary); }

/* ---------- Barre de progression (ratio charges / revenus) ---------- */
.progress {
  margin-top: var(--space-md);
}

.progress__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--space-sm);
}

.progress__pct {
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
}

.progress__track {
  height: 14px;
  border-radius: var(--radius-full);
  background: var(--fill-quaternary);
  overflow: hidden;
  display: flex;
}

.progress__fill {
  height: 100%;
  border-radius: var(--radius-full);
  width: 0;
  transition: width var(--dur-slow) var(--ease-ios),
              background-color var(--dur-base) var(--ease-ios);
}

.progress__legend {
  display: flex;
  gap: var(--space-lg);
  margin-top: var(--space-sm);
  font-size: var(--text-footnote);
  color: var(--text-secondary);
  flex-wrap: wrap;
}

.progress__legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 14px var(--space-lg);
  border-radius: var(--radius-md);
  font-size: var(--text-body);
  font-weight: var(--weight-semibold);
  transition: transform var(--dur-fast) var(--ease-spring),
              background-color var(--dur-fast) var(--ease-ios),
              opacity var(--dur-fast) var(--ease-ios);
}

.btn:active {
  transform: scale(0.96);
}

.btn--primary {
  background: var(--accent);
  color: #fff;
}
.btn--primary:hover { background: var(--accent-strong); }

.btn--secondary {
  background: var(--fill-quaternary);
  color: var(--accent);
}

.btn--danger {
  background: var(--fill-quaternary);
  color: var(--accent-red);
}

.btn--ghost {
  background: transparent;
  color: var(--accent);
  padding: 8px 12px;
}

.btn--block { width: 100%; }

.btn:disabled {
  opacity: 0.45;
  pointer-events: none;
}

.btn-row {
  display: flex;
  gap: var(--space-md);
}

/* Bouton icône rond */
.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  display: grid;
  place-items: center;
  background: var(--fill-quaternary);
  color: var(--text-primary);
  transition: transform var(--dur-fast) var(--ease-spring),
              background-color var(--dur-fast) var(--ease-ios);
}
.icon-btn:active { transform: scale(0.9); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- Champs de formulaire ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.field__label {
  font-size: var(--text-footnote);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  padding-left: var(--space-xs);
}

.input,
.select {
  width: 100%;
  padding: 14px var(--space-md);
  background: var(--surface-2);
  border: 0.5px solid var(--separator);
  border-radius: var(--radius-md);
  font-size: var(--text-body);
  color: var(--text-primary);
  transition: border-color var(--dur-fast) var(--ease-ios),
              background-color var(--dur-fast) var(--ease-ios),
              box-shadow var(--dur-fast) var(--ease-ios);
  appearance: none;
  -webkit-appearance: none;
}

.input::placeholder { color: var(--text-tertiary); }

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(10, 132, 255, 0.15);
}

.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238A8A8E' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-md) center;
  padding-right: 44px;
}

.input-amount {
  position: relative;
}
.input-amount .input { padding-right: 40px; }
.input-amount__suffix {
  position: absolute;
  right: var(--space-md);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  font-weight: var(--weight-semibold);
  pointer-events: none;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}

/* ---------- Listes (charges / dépenses) ---------- */
.list {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 0.5px solid var(--separator);
  overflow: hidden;
}

.list__item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  border-bottom: 0.5px solid var(--separator);
  animation: item-in var(--dur-base) var(--ease-ios) both;
}

.list__item:last-child { border-bottom: none; }

@keyframes item-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.list__item.is-leaving {
  animation: item-out var(--dur-base) var(--ease-ios) forwards;
}

@keyframes item-out {
  to {
    opacity: 0;
    transform: translateX(40px);
    height: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin: 0;
  }
}

.item__icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  flex: none;
  font-size: 20px;
}

.item__body { flex: 1; min-width: 0; }

.item__name {
  font-weight: var(--weight-semibold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item__meta {
  font-size: var(--text-footnote);
  color: var(--text-secondary);
  margin-top: 2px;
}

.item__amount {
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.item__actions {
  display: flex;
  gap: var(--space-xs);
}

/* ---------- État vide ---------- */
.empty {
  text-align: center;
  padding: var(--space-2xl) var(--space-lg);
  color: var(--text-secondary);
}
.empty__emoji { font-size: 40px; margin-bottom: var(--space-sm); }
.empty__title { font-weight: var(--weight-semibold); color: var(--text-primary); }
.empty__text { font-size: var(--text-footnote); margin-top: 4px; }

/* ---------- Modale / Sheet iOS ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.4);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-ios);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-backdrop.is-open { opacity: 1; }

.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--space-md) var(--space-lg)
           calc(env(safe-area-inset-bottom) + var(--space-lg));
  box-shadow: var(--shadow-lg);
  transform: translateY(100%);
  transition: transform var(--dur-base) var(--ease-ios);
  max-height: 92vh;
  overflow-y: auto;
}

.sheet-backdrop.is-open .sheet { transform: translateY(0); }

.sheet__grabber {
  width: 40px;
  height: 5px;
  border-radius: var(--radius-full);
  background: var(--separator);
  margin: 0 auto var(--space-md);
}

.sheet__title {
  font-size: var(--text-title);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
  margin-bottom: var(--space-lg);
}

.sheet__form { display: flex; flex-direction: column; gap: var(--space-md); }

/* ---------- Toast ---------- */
.toast-wrap {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 96px);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: calc(100% - var(--space-xl));
}

.toast {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  border: 0.5px solid var(--glass-brdr);
  color: var(--text-primary);
  padding: 12px var(--space-lg);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-footnote);
  font-weight: var(--weight-medium);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  animation: toast-in var(--dur-base) var(--ease-spring) both;
}

.toast.is-leaving { animation: toast-out var(--dur-base) var(--ease-ios) forwards; }
.toast__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-green); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(20px) scale(0.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(20px) scale(0.9); }
}

/* ---------- Segmented control (thème) ---------- */
.segmented {
  display: inline-flex;
  background: var(--fill-quaternary);
  border-radius: var(--radius-full);
  padding: 3px;
  gap: 2px;
}

.segmented__btn {
  padding: 7px 16px;
  border-radius: var(--radius-full);
  font-size: var(--text-footnote);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  transition: color var(--dur-fast) var(--ease-ios),
              background-color var(--dur-fast) var(--ease-ios);
}

.segmented__btn.is-active {
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* ---------- Count-up (montant animé) ---------- */
.count-pop { animation: count-pop var(--dur-base) var(--ease-spring); }
@keyframes count-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.06); }
  100% { transform: scale(1); }
}

/* ---------- Bannière d'installation PWA ---------- */
.install-banner {
  position: fixed;
  left: 50%;
  transform: translateX(-50%) translateY(140%);
  bottom: calc(env(safe-area-inset-bottom) + 92px);
  z-index: 60;
  width: min(440px, calc(100% - var(--space-xl)));
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 12px var(--space-md);
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  border: 0.5px solid var(--glass-brdr);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  transition: transform var(--dur-base) var(--ease-spring), opacity var(--dur-base) var(--ease-ios);
  opacity: 0;
}

.install-banner.is-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.install-banner__icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  flex: none;
  box-shadow: var(--shadow-sm);
}

.install-banner__text { flex: 1; min-width: 0; line-height: 1.25; }
.install-banner__text strong { font-size: var(--text-body); font-weight: var(--weight-semibold); }
.install-banner__text span { display: block; font-size: var(--text-caption); color: var(--text-secondary); }

.install-banner__cta {
  flex: none;
  padding: 9px 16px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: #fff;
  font-size: var(--text-footnote);
  font-weight: var(--weight-semibold);
  transition: transform var(--dur-fast) var(--ease-spring);
}
.install-banner__cta:active { transform: scale(0.94); }

.install-banner__close {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-full);
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  background: var(--fill-quaternary);
  font-size: 16px;
  line-height: 1;
}

/* Étapes d'installation iOS (dans une sheet) */
.ios-steps { display: flex; flex-direction: column; gap: var(--space-md); margin-bottom: var(--space-lg); }
.ios-step { display: flex; align-items: center; gap: var(--space-md); }
.ios-step__num {
  width: 28px; height: 28px; border-radius: var(--radius-full);
  background: var(--accent); color: #fff; flex: none;
  display: grid; place-items: center; font-weight: var(--weight-bold); font-size: var(--text-footnote);
}
.ios-step__ico { width: 24px; height: 24px; color: var(--accent); flex: none; }

/* Ligne label/valeur */
.kv {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 0.5px solid var(--separator);
}
.kv:last-child { border-bottom: none; }
.kv__label { color: var(--text-secondary); font-size: var(--text-footnote); }
.kv__value { font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; }
