:root {
  --bg: #ffffff;
  --bg-soft: #faf7f4;
  --card: #ffffff;
  --border: #ece6e0;
  --text: #2d2a28;
  --text-soft: #857b73;
  --primary: #e07a5f;        /* terracotta */
  --primary-dark: #c85f45;
  --secondary: #81a26c;      /* vert herbe */
  --secondary-dark: #688a54;
  --accent-bg: #fbeee9;
  --danger: #c0564b;
  --ok: #4f8a5b;
  --shadow: 0 2px 10px rgba(45, 42, 40, 0.06);
  --radius: 14px;
  --nav-h: 64px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

.hidden { display: none !important; }

/* ---------------------------- Connexion ---------------------------- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #fbeee9 0%, #ffffff 60%);
}
.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: var(--shadow);
}
.auth-logo { font-size: 48px; }
.auth-title { margin: 8px 0 2px; font-size: 24px; }
.auth-subtitle { color: var(--text-soft); margin: 0 0 20px; font-size: 14px; }
.auth-error { color: var(--danger); font-size: 14px; min-height: 18px; margin: 10px 0 0; }

.password-field { position: relative; margin-bottom: 12px; }
.password-field input { padding-right: 44px; }
.toggle-password {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: none; font-size: 18px; cursor: pointer; padding: 4px;
}

/* ---------------------------- Formulaires -------------------------- */
input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 16px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
textarea { resize: vertical; min-height: 70px; }
label { display: block; font-size: 13px; color: var(--text-soft); margin: 10px 0 4px; }

/* ----------------------------- Boutons ----------------------------- */
.btn-primary, .btn-secondary, .btn-ghost {
  border: none; border-radius: 12px; padding: 12px 16px;
  font-size: 15px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:active { background: var(--secondary-dark); }
.btn-ghost { background: var(--bg-soft); color: var(--text); border: 1px solid var(--border); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 14px; }
.icon-btn {
  background: none; border: none; font-size: 22px; cursor: pointer;
  padding: 4px 10px; border-radius: 10px; color: var(--text);
}
.icon-btn:active { background: var(--bg-soft); }

/* ------------------------------ Layout ----------------------------- */
.app { min-height: 100vh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px calc(14px);
  padding-top: calc(14px + env(safe-area-inset-top));
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.brand { font-size: 19px; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 2px; }
#btn-refresh.spinning { animation: spin .6s linear; }
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
.content { padding: 16px; max-width: 640px; margin: 0 auto; }
.view-head { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 10px; }
.view-head h2 { font-size: 17px; margin: 0; }
.hint { color: var(--text-soft); font-size: 12.5px; margin: 8px 2px 0; }

/* -------------------------- Nav bas d'écran ------------------------ */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--bg); border-top: 1px solid var(--border);
}
.nav-btn {
  flex: 1; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; color: var(--text-soft); font-family: inherit;
}
.nav-btn span { font-size: 22px; }
.nav-btn.active { color: var(--primary); font-weight: 600; }

/* --------------------------- Semaine ------------------------------- */
.week-switch, .month-switch {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 8px; margin-bottom: 14px;
}
.week-label { font-weight: 600; font-size: 15px; text-align: center; flex: 1; }
.plan-days { display: flex; flex-direction: column; gap: 10px; }
.plan-day {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
}
.plan-day-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.plan-day-name { font-weight: 700; text-transform: capitalize; }
.plan-day-date { color: var(--text-soft); font-size: 12px; }
.plan-day-recipe {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 6px;
}
.plan-recipe-name { font-size: 15px; }
.plan-recipe-empty { color: var(--text-soft); font-style: italic; }
.plan-day-cook {
  display: flex; align-items: center; gap: 10px;
  margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border);
}
.cook-label { font-size: 13px; color: var(--text-soft); white-space: nowrap; }
.cook-select { flex: 1; padding: 8px 10px; font-size: 14px; }

/* --------------------------- Recettes ------------------------------ */
.search-input { margin-bottom: 12px; }
.recipes-list { display: flex; flex-direction: column; gap: 10px; }
.recipe-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
}
.recipe-card-head { display: flex; justify-content: space-between; align-items: center; }
.recipe-name { font-weight: 700; font-size: 16px; }
.recipe-meta { color: var(--text-soft); font-size: 13px; margin-top: 2px; }
.ing-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.ing-chip {
  background: var(--accent-bg); color: var(--primary-dark);
  border-radius: 20px; padding: 3px 10px; font-size: 12.5px;
}

/* --------------------------- Courses ------------------------------- */
.progress-pill {
  background: var(--secondary); color: #fff; border-radius: 20px;
  padding: 4px 12px; font-size: 13px; font-weight: 600;
}
.extra-form { display: flex; gap: 8px; margin-bottom: 14px; }
.extra-form .qty-input { max-width: 64px; }
.shopping-list { display: flex; flex-direction: column; gap: 16px; }
.aisle-group h3 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--secondary-dark); margin: 0 0 8px; padding-left: 4px;
}
.shop-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 14px; margin-bottom: 8px;
}
.shop-item.checked { opacity: .5; }
.shop-item.checked .shop-name { text-decoration: line-through; }
.shop-check {
  width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--border);
  flex: 0 0 auto; display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 15px; color: #fff; background: var(--bg);
}
.shop-item.checked .shop-check { background: var(--secondary); border-color: var(--secondary); }
.shop-body { flex: 1; min-width: 0; }
.shop-name { font-size: 15px; }
.shop-qty { color: var(--text-soft); font-size: 13px; }
.shop-del { color: var(--text-soft); background: none; border: none; font-size: 18px; cursor: pointer; }
.courses-actions { display: flex; gap: 10px; margin-top: 18px; }
.courses-actions button { flex: 1; }
.empty-note { color: var(--text-soft); text-align: center; padding: 30px 10px; font-style: italic; }

/* --------------------------- Budget -------------------------------- */
.balance-card {
  background: linear-gradient(140deg, #fbeee9, #ffffff);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 8px;
}
.balance-totals { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.balance-stat { text-align: center; flex: 1; }
.balance-stat .num { font-size: 20px; font-weight: 700; }
.balance-stat .lbl { font-size: 11px; color: var(--text-soft); text-transform: uppercase; letter-spacing: .03em; }
.balance-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.member-dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; }
.balance-name { flex: 1; font-weight: 600; }
.balance-net.pos { color: var(--ok); font-weight: 700; }
.balance-net.neg { color: var(--danger); font-weight: 700; }
.balance-subhead {
  font-size: 11px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--text-soft); margin: 10px 0 2px;
}
.settle {
  margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border);
  font-size: 14px;
}
.settle-line { padding: 3px 0; }
.settle-line strong { color: var(--primary-dark); }

/* Suivi par catégorie */
.cat-track { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
.cat-track-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; font-weight: 600; color: var(--text);
}
.link-btn {
  background: none; border: none; color: var(--primary-dark); font-weight: 600;
  font-size: 13px; cursor: pointer; font-family: inherit; padding: 2px 4px;
}
.cat-bar-row { margin-top: 10px; }
.cat-bar-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 3px; }
.cat-bar { height: 8px; background: var(--bg-soft); border-radius: 6px; overflow: hidden; }
.cat-bar-fill { height: 100%; border-radius: 6px; transition: width .3s; }

.expenses-list, .recurring-list { display: flex; flex-direction: column; gap: 8px; }
.expense-card {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 14px;
}
.expense-card.paye { background: #f4f8f2; }
.exp-status {
  width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--border);
  flex: 0 0 auto; cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 15px; color: #fff; background: var(--bg);
}
.expense-card.paye .exp-status { background: var(--ok); border-color: var(--ok); }
.exp-body { flex: 1; min-width: 0; }
.exp-label { font-weight: 600; }
.exp-sub { font-size: 12.5px; color: var(--text-soft); display: flex; gap: 8px; align-items: center; }
.exp-amount { font-weight: 700; white-space: nowrap; }
.exp-del { background: none; border: none; color: var(--text-soft); font-size: 17px; cursor: pointer; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 12px; background: var(--bg-soft); color: var(--text-soft); }
.pill.recurring { background: var(--accent-bg); color: var(--primary-dark); }
.pill.share { background: #eef3ea; color: var(--secondary-dark); }

/* Cases "Partagé entre" */
.share-picker { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.share-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 12px; font-size: 14px; cursor: pointer;
  margin: 0;
}
.share-chip input { width: auto; margin: 0; }
.share-chip .member-dot { width: 10px; height: 10px; }

/* --------------------------- Modales ------------------------------- */
.modal-root {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(45, 42, 40, .4);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
.modal {
  background: var(--card); width: 100%; max-width: 560px;
  border-radius: 20px 20px 0 0; padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow-y: auto;
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: .5; } to { transform: translateY(0); opacity: 1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h2 { font-size: 18px; margin: 0; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions button { flex: 1; }

.ing-row { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
.ing-row input { padding: 10px; }
.ing-row .ing-qty { max-width: 64px; }
.ing-row .ing-unit { max-width: 72px; }
.ing-row .ing-del { flex: 0 0 auto; }
.row-2 { display: flex; gap: 10px; }
.row-2 > * { flex: 1; }

.member-line {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.member-line .member-dot { width: 16px; height: 16px; }
.member-line .m-name { flex: 1; font-weight: 600; }
.member-line .m-payer { font-size: 12px; color: var(--text-soft); }

.toggle-row {
  display: flex; align-items: center; gap: 14px; justify-content: space-between;
  margin: 8px 0 0; font-size: 14px; font-weight: 600; cursor: pointer;
}
.toggle-row input { width: 44px; height: 26px; flex: 0 0 auto; accent-color: var(--secondary); }

@media (min-width: 560px) {
  .modal-root { align-items: center; }
  .modal { border-radius: 20px; }
}

/* ----------------------------- Toast ------------------------------- */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 16px); left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 20px;
  font-size: 14px; z-index: 100; box-shadow: var(--shadow); max-width: 90%;
}
