/* Design system Matteo Martocchia : couleurs, typographies, rayons et ombres repris tels quels. */
@font-face { font-family: 'Satoshi'; src: url('/fonts/Satoshi-400.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Satoshi'; src: url('/fonts/Satoshi-500.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Satoshi'; src: url('/fonts/Satoshi-700.woff2') format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Cabinet Grotesk'; src: url('/fonts/CabinetGrotesk-500.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Cabinet Grotesk'; src: url('/fonts/CabinetGrotesk-700.woff2') format('woff2'); font-weight: 700; font-display: swap; }

:root {
  --ivoire-paradiso: #F5EBDD;
  --ombre-parrain: #2B211C;
  --rouille-dune: #B04A2C;
  --rouille-dune-hover: oklch(0.50 0.13 40);
  --rouille-dune-press: oklch(0.44 0.13 40);
  --rouille-dune-soft: oklch(0.94 0.04 45);
  --ete-cmbyn: #D98B5F;
  --sarcelle-itmfl: #2C5A54;
  --sarcelle-soft: oklch(0.93 0.03 185);
  --blanc: #FFFFFF;
  --gris-100: #F7F7F7;
  --gris-500: #808080;
  --ligne-douce: rgba(43, 33, 28, 0.14);
  --ligne-subtile: rgba(43, 33, 28, 0.08);

  --font-display: "Cabinet Grotesk", "Satoshi", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-body: "Satoshi", "Cabinet Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(43, 33, 28, 0.06);
  --shadow-md: 0 6px 20px rgba(43, 33, 28, 0.10);
  --shadow-lg: 0 18px 48px rgba(43, 33, 28, 0.16);
  --space-1: 6px;
  --space-2: 12px;
  --space-3: 20px;
  --space-4: 24px;
  --space-5: 32px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --dur: 180ms;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  background: var(--ivoire-paradiso);
  color: var(--ombre-parrain);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  font-variant-numeric: tabular-nums;
}

[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--font-display); margin: 0; line-height: 1.3; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg.dots circle { fill: currentColor; stroke: none; }
:focus-visible { outline: 3px solid var(--sarcelle-itmfl); outline-offset: 2px; }
.muted { color: var(--gris-500); margin: 0; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Surfaces ---------- */
.card {
  background: var(--blanc);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--ligne-subtile);
  padding: var(--space-3);
  margin-bottom: var(--space-2);
}
.card-title { font-size: 16px; font-weight: 700; margin-bottom: var(--space-2); }
.card-note { font-size: 12px; line-height: 1.5; color: var(--gris-500); margin: var(--space-2) 0 0; }

/* ---------- Connexion ---------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
}
.login-card { width: min(380px, 100%); padding: var(--space-5) var(--space-4); }
.login-title { font-size: 32px; font-weight: 700; letter-spacing: -0.5px; }
.login-card .muted { margin-bottom: var(--space-4); }

/* ---------- Structure ---------- */
.app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(4px + var(--safe-top)) 16px calc(116px + var(--safe-bottom));
}

.topbar { display: flex; align-items: center; gap: 2px; padding: 8px 0; }
.month-label {
  flex: 1;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
}
.month-label::first-letter { text-transform: uppercase; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px;
  border: 0; border-radius: var(--radius-pill);
  background: transparent; color: inherit; cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--ligne-subtile); }
.icon-btn:disabled { opacity: 0.3; cursor: default; background: none; }

.tabs, .segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--ligne-subtile);
  border-radius: var(--radius-pill);
  margin: 4px 0 var(--space-3);
}
.tab, .segmented button {
  min-height: 40px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ombre-parrain);
  font: 500 15px var(--font-body);
  cursor: pointer;
  transition: background var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.tab[aria-selected="true"], .segmented button[aria-checked="true"] {
  background: var(--blanc);
  box-shadow: var(--shadow-sm);
  font-weight: 700;
}

/* ---------- Bloc principal du mois (surface sombre) ---------- */
.hero {
  background: var(--ombre-parrain);
  color: var(--ivoire-paradiso);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-3) var(--space-3);
  margin-bottom: var(--space-2);
  box-shadow: var(--shadow-md);
}
.hero-label { font-size: 14px; opacity: 0.75; margin: 0; }
.hero-amount {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(40px, 13vw, 52px);
  letter-spacing: -1.5px;
  line-height: 1.1;
  margin: 2px 0 var(--space-3);
}
.hero-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.hero-stat span { display: block; font-size: 12px; opacity: 0.7; }
.hero-stat strong { font-family: var(--font-display); font-size: 20px; font-weight: 700; }
.hero-stat .pos { color: #9FD1C8; }
.hero-stat .neg { color: #F0A585; }

.budget { margin-top: var(--space-3); }
.budget-track { height: 8px; border-radius: var(--radius-pill); background: rgba(245, 235, 221, 0.16); overflow: hidden; }
.budget-fill { height: 100%; border-radius: var(--radius-pill); background: var(--ete-cmbyn); }
.budget-fill.over { background: var(--rouille-dune); }
.budget-text { font-size: 13px; margin: 8px 0 0; opacity: 0.85; }

/* ---------- Barres de répartition ---------- */
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: baseline; }
.bar-row .name { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .val { font-weight: 700; }
.bar-row .sub { font-size: 12px; color: var(--gris-500); font-weight: 400; margin-left: 6px; }
.bar-track { grid-column: 1 / -1; height: 6px; border-radius: var(--radius-pill); background: var(--gris-100); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: var(--radius-pill); background: var(--ete-cmbyn); }
.bar-fill.top { background: var(--rouille-dune); }
.bar-fill.teal { background: var(--sarcelle-itmfl); }

/* ---------- Liste des opérations ---------- */
.op-list { list-style: none; margin: 0 -8px; padding: 0; }
.day-head { font-size: 13px; color: var(--gris-500); padding: 14px 8px 4px; }
.day-head:first-child { padding-top: 0; }
.day-head::first-letter { text-transform: uppercase; }
.op {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 12px;
  width: 100%;
  padding: 10px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.op:hover { background: var(--gris-100); }
.op .merchant { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.op .meta { grid-column: 1; font-size: 13px; color: var(--gris-500); }
.op .amount { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-weight: 700; }
.op .amount.income { color: var(--sarcelle-itmfl); }
.empty { color: var(--gris-500); margin: 0; }

/* ---------- Analyse ---------- */
.watch {
  background: var(--rouille-dune-soft);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  margin-bottom: var(--space-2);
}
.watch-kicker { font-size: 13px; color: var(--rouille-dune-press); font-weight: 700; margin: 0; }
.watch-cat { font-size: 32px; font-weight: 700; letter-spacing: -0.5px; margin: 2px 0 6px; line-height: 1.15; }
.watch p { margin: 0; }

.chart svg { width: 100%; height: auto; display: block; overflow: visible; stroke: none; }
.chart .legend { display: flex; gap: var(--space-3); font-size: 12px; color: var(--gris-500); margin-top: 8px; }
.chart .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.rows { list-style: none; margin: 0; padding: 0; }
.rows li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 12px;
  padding: 10px 0;
  border-top: 1px solid var(--ligne-subtile);
}
.rows li:first-child { border-top: 0; padding-top: 0; }
.rows .name { font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .detail { grid-column: 1; font-size: 13px; color: var(--gris-500); }
.rows .right { grid-row: 1 / span 2; grid-column: 2; align-self: center; text-align: right; font-weight: 700; }
.pill {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  margin-top: 2px;
}
.pill.up { background: var(--rouille-dune-soft); color: var(--rouille-dune-press); }
.pill.down { background: var(--sarcelle-soft); color: var(--sarcelle-itmfl); }
.pill.flat { background: var(--gris-100); color: var(--gris-500); }

.insights-card { border-left: 4px solid var(--sarcelle-itmfl); }
.insights-summary { font-family: var(--font-display); font-size: 20px; font-weight: 500; line-height: 1.4; margin: 0 0 var(--space-2); }
.insights-list { list-style: none; margin: 0 0 var(--space-2); padding: 0; display: grid; gap: var(--space-2); }
.insights-list h3 { font-family: var(--font-body); font-size: 15px; font-weight: 700; }
.insights-list p { margin: 2px 0 0; font-size: 15px; }
.insights-sub { font-size: 13px; font-weight: 700; color: var(--sarcelle-itmfl); margin: var(--space-3) 0 var(--space-2); }
.saving { display: inline-block; margin-top: 4px; font-size: 13px; font-weight: 700; color: var(--sarcelle-itmfl); }

/* ---------- Barre d'action ---------- */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; gap: 10px; justify-content: center;
  padding: 14px 16px calc(14px + var(--safe-bottom));
  background: linear-gradient(to top, var(--ivoire-paradiso) 72%, rgba(245, 235, 221, 0));
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 22px;
  border: 0; border-radius: var(--radius-md);
  font: 700 16px var(--font-body);
  cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--rouille-dune); color: var(--blanc); }
.btn-primary:hover { background: var(--rouille-dune-hover); }
.btn-primary:active { background: var(--rouille-dune-press); }
.btn-secondary { background: var(--blanc); color: var(--ombre-parrain); box-shadow: inset 0 0 0 1px var(--ligne-douce); }
.btn-accent { background: var(--sarcelle-itmfl); color: var(--blanc); min-height: 46px; }
.btn-accent:hover { background: var(--sarcelle-hover, #244a45); }
.btn-danger { background: transparent; color: var(--rouille-dune); box-shadow: inset 0 0 0 1.5px currentColor; }
.btn-block { width: 100%; }
.btn-scan { flex: 1; max-width: 360px; box-shadow: var(--shadow-md); }

/* ---------- Fiches ---------- */
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh;
  margin: auto auto 0; padding: 0; border: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--blanc); color: var(--ombre-parrain);
  box-shadow: var(--shadow-lg);
  overflow: auto;
}
.sheet::backdrop { background: rgba(43, 33, 28, 0.45); }
.sheet[open] { animation: rise 220ms var(--ease); }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 640px) { .sheet { margin: auto; border-radius: var(--radius-lg); } }

.sheet-body { padding: 16px 20px calc(20px + var(--safe-bottom)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.sheet-head h2 { font-size: 24px; font-weight: 700; }
.sheet .segmented { margin: 4px 0 var(--space-3); }

.receipt-preview { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.receipt-preview img { width: 64px; height: 88px; object-fit: cover; border-radius: var(--radius-sm); box-shadow: inset 0 0 0 1px var(--ligne-douce); background: var(--gris-100); }
.reading { margin: 0; color: var(--gris-500); font-size: 14px; }
.reading.busy::after {
  content: ""; display: inline-block; width: 10px; height: 10px; margin-left: 8px;
  border: 2px solid var(--gris-500); border-right-color: transparent; border-radius: 50%;
  animation: spin 0.8s linear infinite; vertical-align: -1px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.notice { margin: 0 0 12px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--rouille-dune-soft); font-size: 14px; }

.field { display: block; margin-bottom: 12px; flex: 1; min-width: 0; }
.field > span { display: block; font-size: 13px; font-weight: 500; color: var(--gris-500); margin-bottom: 4px; }
.field input, .field select, .items select {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 0; border-radius: var(--radius-sm);
  box-shadow: inset 0 0 0 1px var(--ligne-douce);
  background: var(--blanc); color: var(--ombre-parrain);
  font: 400 16px var(--font-body); /* 16px évite le zoom automatique sur iPhone */
  -webkit-appearance: none; appearance: none;
}
.field input:focus, .field select:focus, .items select:focus { outline: none; box-shadow: inset 0 0 0 2px var(--sarcelle-itmfl); }
.field select, .items select {
  background-image: linear-gradient(45deg, transparent 50%, var(--gris-500) 50%), linear-gradient(135deg, var(--gris-500) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px;
}
.field-row { display: flex; gap: 10px; }
.field-narrow { flex: 0 0 90px; }

.items { margin: 4px 0 14px; }
.items summary { cursor: pointer; color: var(--gris-500); font-weight: 500; padding: 6px 0; }
.items ul { list-style: none; margin: 6px 0 0; padding: 0; }
.items li { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 8px 0; border-top: 1px solid var(--ligne-subtile); font-size: 14px; }
.items li .amt { font-weight: 700; }
.items select { grid-column: 1 / -1; min-height: 36px; padding: 6px 30px 6px 10px; font-size: 16px; }

.form-error { color: var(--rouille-dune); margin: 4px 0 10px; font-size: 14px; }
.form-error:empty { margin: 0; }
.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn-primary { flex: 1; }

.settings-links { display: grid; gap: 2px; margin-top: 20px; padding-top: 12px; border-top: 1px solid var(--ligne-subtile); }
.link { color: var(--ombre-parrain); padding: 10px 0; font: inherit; text-align: left; }
.link-danger { background: none; border: 0; text-decoration: underline; cursor: pointer; color: var(--rouille-dune); }

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

/* Couleurs du graphique d'évolution */
.chart .c-bar { fill: var(--ete-cmbyn); }
.chart .c-bar-cur { fill: var(--rouille-dune); }
.chart .c-inc { stroke: var(--sarcelle-itmfl); }
.chart .c-val { fill: var(--ombre-parrain); font-family: var(--font-body); }
.chart .c-lab { fill: var(--gris-500); font-family: var(--font-body); }
