:root {
  --paper: #FBF7F0;
  --card: #FFFFFF;
  --ink: #2B2422;
  --muted: #8A8078;
  --line: #EBE3D7;
  --tomato: #C63A22;
  --tomato-dark: #A62D18;
  --basil: #4E7C4A;
  --shadow: 0 2px 12px rgba(43, 36, 34, 0.08);
  --radius: 16px;
  font-size: 17px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--paper);
  color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden { display: none !important; }

.brand-slice { color: var(--tomato); font-size: 0.9em; }

/* --- Connexion ------------------------------------------------------------ */
.login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.brand { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; }
.login-sub { color: var(--muted); margin: 8px 0 28px; font-size: 0.95rem; }

/* --- Barre du haut -------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 14px) 20px 14px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.brand-small { font-weight: 800; letter-spacing: -0.02em; }
.link { background: none; border: none; color: var(--tomato); font-size: 0.95rem; cursor: pointer; padding: 6px; }
.link.small { font-size: 0.85rem; padding: 4px 0; display: inline-block; }

/* --- Résumé du mois ------------------------------------------------------- */
.month-summary { padding: 24px 20px 8px; }
.month-picker {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 12px;
}
.month-picker span { font-weight: 600; min-width: 160px; text-align: center; text-transform: capitalize; }
.chev {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 36px; height: 36px;
  font-size: 1.3rem; line-height: 1;
  color: var(--ink);
  cursor: pointer;
}
.total-big { text-align: center; }
.total-big > span:first-child {
  display: block;
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ink);
}
.total-caption { color: var(--muted); font-size: 0.9rem; }

/* --- Filtre --------------------------------------------------------------- */
.filter-row { padding: 12px 20px 4px; }
select, input[type="date"], input[type="number"], input[type="password"], input[type="text"] {
  width: 100%;
  font-size: 1rem;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font-family: inherit;
}
select:focus, input:focus { outline: 2px solid var(--tomato); outline-offset: 1px; border-color: var(--tomato); }

/* --- Liste de factures ---------------------------------------------------- */
.facture-list { padding: 8px 20px 120px; display: flex; flex-direction: column; gap: 10px; }
.facture {
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.facture-thumb {
  width: 48px; height: 48px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--line);
  flex-shrink: 0;
}
.facture-thumb.placeholder { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 1.3rem; }
.facture-info { flex: 1; min-width: 0; }
.facture-fourn { font-weight: 700; }
.facture-date { color: var(--muted); font-size: 0.85rem; }
.facture-amount { font-weight: 800; font-size: 1.1rem; white-space: nowrap; }
.facture-action { background: none; border: none; color: var(--muted); font-size: 1.1rem; padding: 6px; cursor: pointer; }

.facture.is-annulee { opacity: 0.6; }
.facture.is-annulee .facture-fourn,
.facture.is-annulee .facture-amount { text-decoration: line-through; }
.badge-annulee {
  display: inline-block;
  margin-top: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--tomato);
  background: rgba(198, 58, 34, 0.1);
  padding: 2px 8px;
  border-radius: 999px;
}

.empty { text-align: center; color: var(--muted); padding: 48px 32px; line-height: 1.5; }

/* --- Bouton flottant ------------------------------------------------------ */
.fab {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  right: 24px;
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--tomato);
  color: #fff;
  border: none;
  box-shadow: 0 6px 20px rgba(198, 58, 34, 0.4);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  z-index: 10;
}
.fab:active { background: var(--tomato-dark); transform: scale(0.96); }

/* --- Boutons -------------------------------------------------------------- */
.btn {
  font-size: 1rem;
  font-weight: 700;
  padding: 14px 20px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  width: 100%;
  font-family: inherit;
}
.btn-primary { background: var(--tomato); color: #fff; }
.btn-primary:active { background: var(--tomato-dark); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }

/* --- Modale (bottom sheet) ------------------------------------------------ */
.modal, .viewer {
  position: fixed; inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  background: rgba(43, 36, 34, 0.5);
}
.sheet {
  background: var(--paper);
  width: 100%;
  border-radius: 24px 24px 0 0;
  padding: 12px 20px calc(env(safe-area-inset-bottom) + 24px);
  max-height: 92dvh;
  overflow-y: auto;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle { width: 40px; height: 4px; background: var(--line); border-radius: 2px; margin: 4px auto 12px; }
.sheet h2 { margin: 0 0 16px; font-size: 1.3rem; }
.sheet label { display: block; font-weight: 600; font-size: 0.9rem; margin: 16px 0 6px; }
.sheet label .opt { color: var(--muted); font-weight: 400; }
.money-input { position: relative; }
.money-input .euro { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.money-input input { padding-right: 32px; }
.sheet-actions { display: flex; gap: 12px; margin-top: 24px; }

.photo-preview { text-align: center; margin-bottom: 12px; }
.photo-preview img { max-height: 180px; border-radius: 12px; box-shadow: var(--shadow); }
.ocr-status { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.9rem; margin-bottom: 8px; }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--tomato);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Visionneuse ---------------------------------------------------------- */
.viewer { background: rgba(0,0,0,0.9); align-items: center; justify-content: center; }
.viewer img { max-width: 94vw; max-height: 88vh; border-radius: 8px; }
.viewer-close { position: absolute; top: calc(env(safe-area-inset-top) + 16px); right: 20px; background: rgba(255,255,255,0.15); color: #fff; border: none; width: 40px; height: 40px; border-radius: 50%; font-size: 1.2rem; cursor: pointer; }

.error { color: var(--tomato); font-size: 0.9rem; margin-top: 12px; }

/* --- Barre d'onglets ------------------------------------------------------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 15;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 12px rgba(43, 36, 34, 0.05);
}
.tab {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
}
.tab-icon { font-size: 1.3rem; line-height: 1; filter: grayscale(1); opacity: 0.55; }
.tab-label { font-size: 0.72rem; font-weight: 600; }
.tab.is-active { color: var(--tomato); }
.tab.is-active .tab-icon { filter: none; opacity: 1; }

/* Laisse la place à la tabbar en bas de chaque vue */
.facture-list { padding-bottom: 150px; }

/* Le bouton photo remonte au-dessus de la tabbar */
.fab {
  bottom: calc(env(safe-area-inset-bottom) + 80px);
}

/* --- Écrans "à venir" ------------------------------------------------------ */
.coming-soon {
  text-align: center;
  padding: 80px 32px 120px;
  color: var(--muted);
}
.cs-icon { font-size: 3rem; margin-bottom: 12px; }
.coming-soon h2 { color: var(--ink); margin: 0 0 6px; font-size: 1.5rem; }
.coming-soon p { margin: 4px 0; }
.cs-detail { font-size: 0.9rem; margin-top: 16px; line-height: 1.5; }

/* --- Recettes : ligne de synchro ------------------------------------------ */
.sync-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 20px 8px;
}
.sync-info { font-size: 0.8rem; color: var(--muted); }
.btn-sync {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--tomato);
  font-weight: 600;
  font-size: 0.82rem;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
}
.btn-sync:disabled { opacity: 0.6; }

/* --- Répartition par moyen de paiement ------------------------------------ */
.breakdown {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 20px 12px;
  -webkit-overflow-scrolling: touch;
}
.bd-chip {
  flex-shrink: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.bd-label { font-size: 0.72rem; color: var(--muted); }
.bd-val { font-weight: 700; }

/* --- Badges source (SumUp / Manuel) --------------------------------------- */
.src-badge {
  font-size: 0.62rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  vertical-align: middle;
  margin-left: 4px;
}
.src-badge.sumup { background: rgba(78, 124, 74, 0.12); color: var(--basil); }
.src-badge.manuel { background: rgba(198, 58, 34, 0.1); color: var(--tomato); }

/* --- Bénéfices ------------------------------------------------------------- */
.benef-lines {
  margin: 8px 20px;
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 4px 16px;
}
.benef-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.benef-line:last-child { border-bottom: none; }
.benef-line span:first-child { color: var(--muted); }
.benef-line span:last-child { font-weight: 700; font-size: 1.05rem; }
.benef-line .pos { color: var(--basil); }
.benef-line .neg { color: var(--tomato); }
.benef-line.total span { font-weight: 800; }
.benef-line.total span:first-child { color: var(--ink); }
.neg-total { color: var(--tomato) !important; }
.benef-note {
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  padding: 8px 32px 120px;
  line-height: 1.5;
}

.sheet-hint { color: var(--muted); font-size: 0.85rem; margin: -4px 0 8px; line-height: 1.4; }
