/* ==========================================================================
   Courses — style inspiré d'Apple (sombre par défaut)
   ========================================================================== */
:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --card-2: #f0f0f3;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, 0.08);
  --accent: #0071e3;
  --accent-soft: rgba(0, 113, 227, 0.12);
  --green: #1f9d45;
  --green-soft: rgba(52, 199, 89, 0.14);
  --red: #d70015;
  --red-soft: rgba(255, 59, 48, 0.12);
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --radius: 22px;
  --blur-bg: rgba(245, 245, 247, 0.78);
}
:root[data-theme="dark"] {
  --bg: #000000;
  --card: #1c1c1e;
  --card-2: #2c2c2e;
  --text: #f5f5f7;
  --muted: #98989d;
  --line: rgba(255, 255, 255, 0.08);
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.18);
  --green: #30d158;
  --green-soft: rgba(48, 209, 88, 0.16);
  --red: #ff453a;
  --red-soft: rgba(255, 69, 58, 0.16);
  --shadow: none;
  --blur-bg: rgba(0, 0, 0, 0.72);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { color-scheme: light dark; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  transition: background .3s ease, color .3s ease;
  padding-bottom: calc(110px + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 20px 12px;
  background: var(--blur-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 32px; font-weight: 700; letter-spacing: -0.02em; }
.hello { font-size: 13px; color: var(--muted); font-weight: 500; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.topbar-actions form { margin: 0; }

.icon-btn, .theme-toggle {
  width: 40px; height: 40px; border-radius: 50%;
  border: none; background: var(--card-2); cursor: pointer;
  display: grid; place-items: center;
  transition: transform .15s ease, background .2s;
}
.icon-btn:active, .theme-toggle:active { transform: scale(.92); }
.icon-btn svg, .theme-toggle svg { width: 20px; height: 20px; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
.theme-toggle.floating { position: fixed; top: calc(16px + env(safe-area-inset-top)); right: 16px; }

/* ---------- Contenu ---------- */
.container { max-width: 560px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 14px; font-size: 19px; font-weight: 650; letter-spacing: -0.01em; }
.label { font-size: 13px; color: var(--muted); font-weight: 500; }
.muted { color: var(--muted); }

/* Mois */
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.month-label {
  flex: 1; border: none; background: none; cursor: pointer;
  font-size: 17px; font-weight: 600; text-transform: capitalize; padding: 8px;
}

/* Carte principale */
.hero { text-align: center; padding: 26px 20px 22px; }
.big {
  font-size: 46px; font-weight: 700; letter-spacing: -0.03em;
  margin: 4px 0 12px; font-variant-numeric: tabular-nums;
}
.delta {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 999px;
  font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums;
  background: var(--card-2); color: var(--muted);
}
.delta.up { background: var(--red-soft); color: var(--red); }
.delta.down { background: var(--green-soft); color: var(--green); }
.delta svg { width: 16px; height: 16px; stroke-width: 2.5; }
.sub { margin-top: 12px; font-size: 13px; color: var(--muted); }
.sub strong { color: var(--text); font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.stat { padding: 16px 18px; }
.mid { font-size: 22px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* Semaines */
.weeks { display: flex; flex-direction: column; gap: 14px; }
.week-row { display: grid; grid-template-columns: 92px 1fr auto; align-items: center; gap: 12px; }
.week-name { font-size: 14px; color: var(--muted); }
.week-row.current .week-name { color: var(--accent); font-weight: 600; }
.bar-track { height: 10px; background: var(--card-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; width: 0; transition: width .5s cubic-bezier(.2,.8,.2,1); }
.week-row:not(.current) .bar-fill { opacity: .55; }
.week-amount { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 78px; text-align: right; }

/* 6 derniers mois */
.months-chart { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; align-items: end; height: 170px; }
.mcol { border: none; background: none; padding: 0; cursor: pointer; font: inherit; color: inherit; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; }
.mval { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.mbar { width: 100%; max-width: 36px; border-radius: 8px 8px 4px 4px; background: var(--card-2); min-height: 4px; transition: height .5s cubic-bezier(.2,.8,.2,1); }
.mcol.sel .mbar { background: var(--accent); }
.mcol.sel .mval { color: var(--text); font-weight: 600; }
.mname { font-size: 12px; color: var(--muted); text-transform: capitalize; }
.mcol.sel .mname { color: var(--text); font-weight: 600; }

/* Liste */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 4px; border-bottom: 1px solid var(--line); cursor: pointer;
  border-radius: 10px; transition: background .15s;
}
.list li:last-child { border-bottom: none; }
.list li:active { background: var(--card-2); }
.list .d { font-size: 15px; }
.list .a { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 6px; }
.list .a svg { width: 16px; height: 16px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); margin: 8px 0; }

/* Bouton + */
.fab {
  position: fixed; right: 20px; bottom: calc(24px + env(safe-area-inset-bottom));
  width: 62px; height: 62px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--accent); color: #fff; display: grid; place-items: center;
  box-shadow: 0 8px 24px rgba(0, 113, 227, .45);
  transition: transform .15s ease;
  z-index: 20;
}
.fab:active { transform: scale(.92); }
.fab svg { width: 28px; height: 28px; stroke-width: 2.6; }

/* Fenêtre du bas */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 30; animation: fade .2s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  max-width: 560px; margin: 0 auto;
  background: var(--card); border-radius: 26px 26px 0 0;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom));
  animation: up .28s cubic-bezier(.2,.8,.2,1);
}
.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--card-2); margin: 0 auto 14px; }
.sheet h2 { margin: 0 0 18px; font-size: 20px; text-align: center; }
.sheet form { display: flex; flex-direction: column; gap: 12px; }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* Champs */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; padding-left: 4px; }
.field input {
  width: 100%; font: inherit; font-size: 17px; color: var(--text);
  background: var(--card-2); border: 2px solid transparent; border-radius: 14px;
  padding: 14px 16px; outline: none; transition: border-color .2s;
}
.field input:focus { border-color: var(--accent); }
.amount-wrap { position: relative; }
.amount-wrap input { font-size: 34px; font-weight: 700; text-align: center; padding: 14px 44px; font-variant-numeric: tabular-nums; }
.euro { position: absolute; right: 20px; top: 50%; transform: translateY(-50%); font-size: 26px; font-weight: 600; color: var(--muted); }
.form-error { color: var(--red); font-size: 14px; min-height: 18px; text-align: center; }

.btn-primary, .btn-danger, .btn-ghost {
  width: 100%; border: none; border-radius: 14px; padding: 15px;
  font-size: 17px; font-weight: 600; cursor: pointer; transition: transform .12s, opacity .2s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-ghost { background: none; color: var(--accent); }
.btn-primary:active, .btn-danger:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .5; }

/* Messages */
.toast {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600; z-index: 40; animation: fade .2s ease;
}
.offline { background: var(--red-soft); color: var(--red); text-align: center; font-size: 13px; padding: 8px 16px; }
.alert { background: var(--red-soft); color: var(--red); padding: 12px 14px; border-radius: 12px; font-size: 14px; }
[hidden] { display: none !important; }

/* Page de connexion */
.login-page { padding-bottom: 0; }
.login-wrap {
  min-height: 100vh; min-height: 100dvh; max-width: 400px; margin: 0 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 16px; text-align: center;
}
.login-logo { border-radius: 20px; margin-bottom: 14px; }
.login-wrap h1 { margin: 0; font-size: 34px; letter-spacing: -0.02em; }
.login-wrap .muted { margin: 6px 0 26px; }
.login-card { width: 100%; display: flex; flex-direction: column; gap: 14px; text-align: left; }

@media (max-width: 360px) {
  .big { font-size: 38px; }
  .week-row { grid-template-columns: 78px 1fr auto; }
}
