/* ===== Tokens de design ===== */
:root {
  --bg: #14171C;
  --surface: #1C2028;
  --surface-2: #242933;
  --border: rgba(255, 255, 255, 0.08);
  --text: #EDEFF3;
  --text-muted: #8A93A3;

  --eur: #E8A33D;       /* Prêt étudiant */
  --eur-soft: rgba(232, 163, 61, 0.14);
  --cad: #3DBFA8;       /* Compte canadien */
  --cad-soft: rgba(61, 191, 168, 0.14);

  --accent: #6C8CFF;
  --accent-soft: rgba(108, 140, 255, 0.14);
  --danger: #E8574D;
  --danger-soft: rgba(232, 87, 77, 0.14);
  --success: #4ECB8D;

  --radius-s: 8px;
  --radius-m: 14px;
  --radius-l: 20px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

[data-theme="light"] {
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --surface-2: #F0F1F4;
  --border: rgba(20, 23, 28, 0.08);
  --text: #1A1D23;
  --text-muted: #6B7280;

  --eur-soft: rgba(197, 130, 20, 0.12);
  --eur: #B87A17;
  --cad-soft: rgba(19, 140, 120, 0.12);
  --cad: #158E79;
  --accent-soft: rgba(74, 102, 224, 0.10);
  --accent: #4A66E0;
  --danger-soft: rgba(214, 69, 60, 0.10);
  --danger: #D6453C;
  --shadow: 0 8px 24px rgba(20, 23, 28, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Lexend', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
}

body {
  min-height: 100vh;
  padding-bottom: 90px; /* place pour le bouton flottant sur mobile */
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }

/* ===== Focus visible (accessibilité) ===== */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ===== Layout général ===== */
.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 20px;
}

.topbar-title {
  font-size: 20px;
  font-weight: 700;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-s);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 17px;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn:active { transform: scale(0.95); }

/* ===== Cartes de solde ===== */
.balances {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.balance-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: 18px;
  position: relative;
  overflow: hidden;
}

.balance-card.loan { border-top: 3px solid var(--eur); }
.balance-card.cad { border-top: 3px solid var(--cad); }

.balance-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.balance-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.balance-dot.loan { background: var(--eur); }
.balance-dot.cad { background: var(--cad); }

.balance-amount {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.balance-amount .currency {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 4px;
}

/* Barre de progression double (prêt) */
.loan-progress {
  margin-top: 14px;
}

.loan-progress-track {
  position: relative;
  height: 6px;
  border-radius: 4px;
  background: var(--surface-2);
  overflow: visible;
  margin-bottom: 8px;
}

.loan-progress-fill {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  border-radius: 4px;
  background: var(--eur);
  transition: width 0.4s ease;
}

.loan-progress-marker {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 12px;
  background: var(--text);
  opacity: 0.5;
  border-radius: 2px;
  transition: left 0.4s ease;
}

.loan-progress-legend {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

.loan-progress-legend strong {
  color: var(--text);
  font-weight: 600;
}

/* ===== Liste de transactions ===== */
.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 8px 0 12px;
}

.tx-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.tx-day-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tx-day-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 4px 0;
  z-index: 1;
}

.tx-day-total {
  font-weight: 400;
  color: var(--text-muted);
}

.tx-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 12px 14px;
}

.tx-icon {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.tx-icon.EUR { background: var(--eur-soft); color: var(--eur); }
.tx-icon.CAD { background: var(--cad-soft); color: var(--cad); }

.tx-info {
  flex: 1;
  min-width: 0;
}

.tx-reason {
  font-weight: 500;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-category {
  font-size: 12.5px;
  color: var(--text-muted);
}

.tx-amount {
  font-weight: 600;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tx-amount.entree { color: var(--success); }
.tx-amount.depense { color: var(--text); }

.tx-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  font-size: 15px;
  opacity: 0.6;
}
.tx-delete:hover { opacity: 1; color: var(--danger); }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ===== Bouton flottant d'ajout ===== */
.fab {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 14px 22px;
  font-size: 15px;
  font-weight: 600;
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 20;
}
.fab:active { transform: translateX(-50%) scale(0.97); }

/* ===== Feuille modale (formulaire) ===== */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 30;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.sheet-backdrop.open { display: flex; }

.sheet {
  background: var(--surface);
  width: 100%;
  max-width: 480px;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  max-height: 88vh;
  overflow-y: auto;
  animation: slideUp 0.22s ease;
}

@media (min-width: 640px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 20px; }
}

@keyframes slideUp {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 11px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
}

/* Segmented control (type / devise) */
.segmented {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-s);
  padding: 3px;
  gap: 3px;
}

.segmented button {
  flex: 1;
  padding: 9px 10px;
  border: none;
  background: transparent;
  border-radius: 6px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 13.5px;
  cursor: pointer;
}

.segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

/* Sélecteur de catégories en grille d'icônes */
.category-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.category-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 6px;
  border-radius: var(--radius-s);
  background: var(--surface-2);
  border: 1px solid transparent;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 11.5px;
  text-align: center;
}

.category-option i { font-size: 17px; }

.category-option.selected {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-soft);
}

.btn-primary {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: var(--radius-s);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  margin-top: 6px;
}
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  width: 100%;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text);
  font-weight: 500;
  font-size: 14.5px;
  cursor: pointer;
}

/* ===== Pages d'authentification ===== */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: 28px 24px;
}

.auth-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin-bottom: 16px;
}

.auth-title {
  font-size: 20px;
  margin-bottom: 4px;
}

.auth-subtitle {
  color: var(--text-muted);
  font-size: 13.5px;
  margin-bottom: 22px;
}

.auth-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius-s);
  padding: 10px 12px;
  font-size: 13.5px;
  margin-bottom: 16px;
}

/* ===== Page appareils ===== */
.device-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 14px;
  margin-bottom: 10px;
}

.device-icon {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.device-info { flex: 1; min-width: 0; }

.device-name {
  font-weight: 500;
  font-size: 14.5px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.device-badge {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.device-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.device-revoke {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  font-size: 16px;
}
.device-revoke:hover { color: var(--danger); }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 13.5px;
  margin-bottom: 16px;
}

@media (max-width: 380px) {
  .balances { grid-template-columns: 1fr; }
}
