:root {
  --primary: #2563eb;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.5;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

/* ── Layout ── */
#app { display: flex; flex-direction: column; min-height: 100vh; }
.page { display: none; flex: 1; padding: 0 0 80px; }
.page.active { display: block; }

/* ── Login ── */
#login-page {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: white;
}
#login-page.active { display: flex; }
.login-card { width: 100%; max-width: 360px; }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo h1 { font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.login-logo p { color: var(--gray-500); margin-top: 4px; font-size: .9rem; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: 6px; color: var(--gray-700); }
.form-group input, .form-group select {
  width: 100%; padding: 12px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: 10px;
  font-size: 1rem;
  outline: none;
  transition: border-color .15s;
  background: white;
  color: var(--gray-800);
}
.form-group input:focus, .form-group select:focus { border-color: var(--primary); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 20px;
  border: none; border-radius: 10px; cursor: pointer;
  font-size: .95rem; font-weight: 600; transition: all .15s;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: white; width: 100%; }
.btn-primary:active { background: #1d4ed8; }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); }
.btn-secondary:active { background: var(--gray-200); }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-sm { padding: 8px 14px; font-size: .85rem; border-radius: 8px; }
.btn-icon { padding: 8px; border-radius: 8px; background: none; border: none; cursor: pointer; color: var(--gray-500); }
.btn-icon:active { background: var(--gray-100); }

/* ── Header ── */
.page-header {
  background: white;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--gray-100);
  position: sticky; top: 0; z-index: 10;
}
.page-header h2 { font-size: 1.1rem; font-weight: 700; }
.page-header-row { display: flex; align-items: center; justify-content: space-between; }

/* ── Cards ── */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 0;
}
.section { padding: 16px; }
.section + .section { padding-top: 0; }
.section-title {
  font-size: .75rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--gray-400);
  margin-bottom: 10px;
}

/* ── Dashboard Hero ── */
.hero-card {
  background: var(--primary);
  color: white;
  border-radius: var(--radius);
  padding: 24px 20px 20px;
  margin: 16px;
  position: relative;
  overflow: hidden;
}
.hero-card::before {
  content: ''; position: absolute;
  top: -40px; right: -40px;
  width: 160px; height: 160px;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
}
.hero-label { font-size: .8rem; font-weight: 500; opacity: .8; margin-bottom: 4px; }
.hero-amount {
  font-size: 3rem; font-weight: 800;
  line-height: 1; letter-spacing: -.02em;
}
.hero-amount.negative { color: #fca5a5; }
.hero-period { font-size: .78rem; opacity: .7; margin-top: 4px; }
.hero-stats {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px; margin-top: 16px;
}
.hero-stat {
  background: rgba(255,255,255,.15);
  border-radius: 10px;
  padding: 10px 12px;
}
.hero-stat-label { font-size: .72rem; opacity: .8; }
.hero-stat-value { font-size: 1.05rem; font-weight: 700; margin-top: 2px; }

/* ── Progress bar ── */
.progress-bar {
  height: 6px; background: rgba(255,255,255,.25);
  border-radius: 99px; margin-top: 12px; overflow: hidden;
}
.progress-fill {
  height: 100%; border-radius: 99px;
  background: white;
  transition: width .4s ease;
}
.progress-fill.over { background: #fca5a5; }

/* ── Reminder banner ── */
.reminder-banner {
  margin: 0 16px 8px;
  background: var(--warning-light);
  border: 1.5px solid #fcd34d;
  border-radius: 12px;
  padding: 12px 16px;
  display: flex; align-items: center; gap: 10px;
}
.reminder-banner .icon { font-size: 1.4rem; flex-shrink: 0; }
.reminder-banner .text { flex: 1; }
.reminder-banner strong { display: block; font-size: .9rem; color: var(--warning); }
.reminder-banner small { font-size: .78rem; color: var(--gray-600); }
.reminder-banner button { flex-shrink: 0; }

/* ── Expense list ── */
.expense-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0;
}
.expense-item + .expense-item { border-top: 1px solid var(--gray-100); }
.expense-icon {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem; flex-shrink: 0;
  background: var(--gray-100);
}
.expense-info { flex: 1; min-width: 0; }
.expense-desc { font-weight: 500; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.expense-meta { font-size: .78rem; color: var(--gray-400); margin-top: 1px; }
.expense-amount { font-weight: 700; font-size: 1rem; color: var(--danger); white-space: nowrap; }
.expense-amount.income { color: var(--success); }
.expense-actions { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.expense-item:hover .expense-actions { opacity: 1; }
@media (pointer: coarse) {
  .expense-actions { opacity: 1; }
}

/* ── Category chips ── */
.category-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  padding: 5px 12px; border-radius: 99px; font-size: .8rem; font-weight: 500;
  border: 1.5px solid var(--gray-200); background: white; cursor: pointer;
  transition: all .15s; color: var(--gray-600);
}
.chip.active { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }

/* ── Category breakdown ── */
.cat-bar-item { margin-bottom: 10px; }
.cat-bar-header { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: 4px; }
.cat-bar-name { font-weight: 500; }
.cat-bar-amount { color: var(--gray-500); }
.cat-bar-track { height: 6px; background: var(--gray-100); border-radius: 99px; overflow: hidden; }
.cat-bar-fill { height: 100%; border-radius: 99px; }

/* ── FAB ── */
.fab {
  position: fixed; bottom: 90px; right: 20px;
  width: 56px; height: 56px;
  background: var(--primary); color: white;
  border-radius: 50%; border: none; cursor: pointer;
  font-size: 1.6rem; line-height: 1;
  box-shadow: 0 4px 16px rgba(37,99,235,.4);
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s, box-shadow .15s;
  z-index: 20;
}
.fab:active { transform: scale(.93); box-shadow: 0 2px 8px rgba(37,99,235,.3); }

/* ── Bottom Nav ── */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  background: white;
  border-top: 1px solid var(--gray-100);
  display: flex;
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 10px 4px 8px;
  border: none; background: none; cursor: pointer;
  color: var(--gray-400); font-size: .68rem; font-weight: 500;
  transition: color .15s; gap: 3px;
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--primary); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 100; display: none; align-items: flex-end;
}
.modal-overlay.open { display: flex; }
.modal {
  background: white; width: 100%; max-width: 480px; margin: 0 auto;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px 32px;
  max-height: 90vh; overflow-y: auto;
  animation: slideUp .25s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-handle {
  width: 36px; height: 4px; border-radius: 99px;
  background: var(--gray-200); margin: 0 auto 20px;
}
.modal-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 20px; }

/* ── Type toggle (dépense / entrée) ── */
.type-toggle { display: flex; gap: 0; margin-bottom: 4px; border-radius: 10px; overflow: hidden; border: 1.5px solid var(--gray-200); }
.type-btn {
  flex: 1; padding: 10px; font-size: .9rem; font-weight: 600;
  border: none; background: white; cursor: pointer;
  transition: all .15s; color: var(--gray-400); text-align: center;
}
.type-btn.active-expense { background: var(--danger-light); color: var(--danger); }
.type-btn.active-income  { background: var(--success-light); color: var(--success); }

/* ── Payment method tabs ── */
.method-tabs { display: flex; gap: 8px; margin-bottom: 4px; }
.method-tab {
  flex: 1; padding: 9px; border-radius: 9px; font-size: .85rem; font-weight: 500;
  border: 1.5px solid var(--gray-200); background: white; cursor: pointer;
  transition: all .15s; color: var(--gray-500); text-align: center;
}
.method-tab.active { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }

/* ── Bank badge ── */
.bank-badge {
  display: inline-block; font-size: .68rem; font-weight: 600; padding: 1px 6px;
  border-radius: 4px; background: var(--gray-100); color: var(--gray-500);
  vertical-align: middle; margin-left: 4px;
}
.bank-badge.lbp { background: #fff3cd; color: #92600a; }
.bank-badge.n26 { background: #e0f2fe; color: #0369a1; }

/* ── Recurring list ── */
.recurring-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0;
}
.recurring-item + .recurring-item { border-top: 1px solid var(--gray-100); }
.recurring-inactive { opacity: .45; }
.recurring-amount { font-weight: 700; color: var(--gray-700); white-space: nowrap; }

/* ── Settings ── */
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0;
}
.settings-row + .settings-row { border-top: 1px solid var(--gray-100); }
.settings-label { font-weight: 500; font-size: .9rem; }
.settings-value { color: var(--gray-500); font-size: .9rem; }
.settings-input {
  width: 90px; padding: 6px 10px; text-align: right;
  border: 1.5px solid var(--gray-200); border-radius: 8px; font-size: .9rem;
}
.settings-input:focus { border-color: var(--primary); outline: none; }

/* ── Payday list ── */
.payday-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; font-size: .875rem;
}
.payday-item + .payday-item { border-top: 1px solid var(--gray-100); }
.payday-date { flex: 1; font-weight: 500; }
.payday-amount { color: var(--success); font-weight: 600; }
.payday-amount.missing { color: var(--gray-300); font-style: italic; }
.payday-badge {
  font-size: .7rem; padding: 2px 8px; border-radius: 99px; font-weight: 600;
}
.payday-badge.current { background: var(--primary-light); color: var(--primary); }
.payday-badge.past { background: var(--gray-100); color: var(--gray-400); }
.payday-badge.future { background: var(--gray-50); color: var(--gray-300); }

/* ── Error / empty ── */
.error-msg { color: var(--danger); font-size: .85rem; margin-top: 8px; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--gray-400); }
.empty-state .emoji { font-size: 2.5rem; margin-bottom: 8px; }
.empty-state p { font-size: .9rem; }

/* ── Utils ── */
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-muted { color: var(--gray-400); }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-2 { margin-bottom: 8px; }
.w-full { width: 100%; }
.font-bold { font-weight: 700; }
.text-sm { font-size: .875rem; }

@media (prefers-color-scheme: dark) {
  /* Optionnel : on garde le thème clair pour la lisibilité */
}
