/* Comptes — thème sombre mobile-first, inspiré de Settle Up */
:root {
  --bg: #101014;
  --surface: #1a1a20;
  --surface-2: #24242c;
  --surface-3: #2e2e38;
  --border: #33333e;
  --text: #eceae7;
  --muted: #9c99a6;
  --accent: #f4845f;
  --accent-strong: #ef6c3b;
  --accent-soft: rgba(244, 132, 95, 0.14);
  --green: #7ac07e;
  --red: #e57373;
  --radius: 14px;
  --nav-h: 62px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 600; }
a { color: var(--accent); text-decoration: none; }

#app { max-width: 640px; margin: 0 auto; padding-bottom: calc(var(--nav-h) + 24px); }

/* ---------- En-tête ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 8px;
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(var(--bg) 75%, transparent);
}
.topbar .brand { font-size: 1.15rem; font-weight: 700; letter-spacing: .01em; }
.topbar .space-switch {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: none; cursor: pointer; padding: 2px 2px;
  font-size: 1.15rem; font-weight: 700; letter-spacing: .01em; color: var(--text);
}
.topbar .space-switch .chev { font-size: .75rem; color: var(--muted); }
.topbar .space-switch:active { opacity: .7; }
.space-opt { display: flex; align-items: center; gap: 10px; }
.space-opt.on { border-color: var(--accent); }
.space-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.topbar .balance-chip {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 12px; font-size: .85rem; color: var(--muted);
  cursor: pointer; white-space: nowrap;
}
.topbar .balance-chip strong { color: var(--accent); font-variant-numeric: tabular-nums; }

/* ---------- Navigation basse ---------- */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; justify-content: space-around; align-items: stretch;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(20, 20, 26, 0.97);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.bottomnav button {
  flex: 1; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); font-size: .68rem; padding: 4px 0;
}
.bottomnav button .ico { font-size: 1.25rem; line-height: 1; }
.bottomnav button.active { color: var(--accent); }
.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 31;
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent-strong); color: #fff; border: none;
  font-size: 1.9rem; line-height: 1; cursor: pointer;
  box-shadow: 0 6px 18px rgba(239, 108, 59, .45);
  display: flex; align-items: center; justify-content: center;
}
.fab:active { transform: scale(.96); }

/* ---------- Vues ---------- */
.view { padding: 4px 14px 20px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px;
}
.card h2 { font-size: 1rem; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
.tnum { font-variant-numeric: tabular-nums; }

/* ---------- Solde ---------- */
.balance-hero {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 26px 0 18px;
}
.balance-circle {
  width: 180px; height: 180px; border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #a07160, #7c5648);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.balance-circle .who { font-size: 1.25rem; font-weight: 600; }
.balance-circle .amount { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.balance-circle .label { font-size: .8rem; opacity: .85; }
.balance-circle.even { background: radial-gradient(circle at 32% 28%, #5b8a5e, #43684a); }
.balance-people { display: flex; flex-direction: column; }
.person-line { padding: 10px 0; border-bottom: 1px solid var(--border); }
.person-line:last-child { border-bottom: none; }
.person-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.person-name { font-weight: 600; }
.person-net { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.person-detail { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 3px; }

/* ---------- Listes de dépenses ---------- */
.month-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 18px 2px 6px; font-size: .82rem; color: var(--muted);
  text-transform: capitalize;
}
.expense-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 6px;
  cursor: pointer;
}
.expense-row:active { background: var(--surface-2); }
.expense-row.highlight { outline: 2px solid var(--accent); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .82rem; color: #fff;
}
.avatar.u1 { background: #6d5ac2; }
.avatar.u2 { background: #b45a7d; }
.avatar.sys { background: #4d6a58; }
.expense-main { flex: 1; min-width: 0; }
.expense-main .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.expense-main .sub { font-size: .78rem; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; }
.expense-amt { text-align: right; flex: none; }
.expense-amt .amt { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.expense-amt .badges { font-size: .75rem; }
.catchip {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 0 6px; border-radius: 6px; background: var(--surface-3);
  font-size: .74rem;
}

/* ---------- Formulaires ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field > span, .field-label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], input[type=date],
input[type=datetime-local], select, textarea {
  width: 100%; padding: 10px 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; outline: none; color: var(--text);
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.amount-input {
  font-size: 2rem; font-weight: 700; text-align: center;
  background: transparent; border: none; border-radius: 0;
  flex: 1; width: 100%; min-width: 0; padding: 6px 4px; color: var(--text);
}
.amount-wrap { display: flex; align-items: stretch; gap: 8px; justify-content: flex-start; margin: 6px 0 14px; }
/* Le montant et le symbole € partagent un même champ (sans soulignement). */
.amount-field { display: flex; align-items: center; flex: 1; min-width: 0; }
.amount-field .cur { color: var(--muted); font-size: 1.5rem; font-weight: 700; padding: 0 6px; }
/* Enregistrement rapide : bouton icône à droite du montant (même hauteur que le
   champ) pour valider sans dérouler tout le formulaire. */
.amount-save {
  align-self: stretch; width: 52px; border-radius: 12px;
  background: var(--accent-strong); color: #fff; border: none;
  font-size: 1.4rem; line-height: 1; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.amount-save:active { transform: scale(0.94); }
.amount-save:disabled { opacity: 0.5; cursor: default; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 16px; cursor: pointer;
}
.btn:active { background: var(--surface-3); }
.btn.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; font-weight: 600; }
.btn.danger { color: var(--red); border-color: rgba(229, 115, 115, .4); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 10px; font-size: .84rem; border-radius: 8px; }
.btn[disabled] { opacity: .5; cursor: default; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
/* Sur PC (souris), une rangée à défilement horizontal ne peut pas se faire
   glisser au doigt et la molette défile verticalement : les puces hors écran
   deviennent inatteignables. Sur ces appareils, on les laisse passer à la
   ligne pour que toutes les catégories/favoris restent visibles et cliquables. */
@media (hover: hover) and (pointer: fine) {
  .chips.scroll { flex-wrap: wrap; overflow-x: visible; }
}
.chip {
  flex: none; padding: 6px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: .84rem; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.seg { display: flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: none; background: none; padding: 9px 6px; cursor: pointer; color: var(--muted); font-size: .9rem; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.suggestions {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; margin-top: 4px; overflow: hidden;
}
.suggestions div { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.suggestions div:last-child { border-bottom: none; }
.suggestions div:active { background: var(--surface-3); }

.collapse-toggle { background: none; border: none; color: var(--accent); cursor: pointer; padding: 4px 0; font-size: .88rem; }
/* Rangée de sections repliables du formulaire : les boutons se suivent sur une
   ou deux lignes, la section dépliée prend toute la largeur juste en dessous. */
.collapse-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0 18px; }
.collapse-row > :not(.collapse-toggle) { flex: 0 0 100%; margin-top: 4px; }

/* ---------- Panneau (sheet) et modales ---------- */
.sheet-backdrop, .modal-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, .55);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-backdrop { align-items: center; padding: 18px; z-index: 50; }
.sheet {
  background: var(--surface); width: 100%; max-width: 640px;
  border-radius: 18px 18px 0 0; border: 1px solid var(--border);
  max-height: 92dvh; overflow-y: auto; padding: 16px 16px 26px;
}
.modal {
  background: var(--surface); width: 100%; max-width: 420px;
  border-radius: var(--radius); border: 1px solid var(--border);
  max-height: 86dvh; overflow-y: auto; padding: 18px;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sheet-head h2 { margin: 0; font-size: 1.05rem; }
.sheet-close { background: none; border: none; color: var(--muted); font-size: 1.4rem; cursor: pointer; padding: 4px 8px; }

.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.cat-grid button {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 6px; cursor: pointer; text-align: center; font-size: .8rem;
  display: flex; flex-direction: column; gap: 4px; align-items: center;
}
.cat-grid button .ico { font-size: 1.3rem; }
.cat-grid button.on { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- Tableaux de stats ---------- */
table.stats { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.stats td, table.stats th { padding: 7px 6px; text-align: left; border-bottom: 1px solid var(--border); }
table.stats td.num, table.stats th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar { height: 5px; border-radius: 3px; background: var(--accent); margin-top: 4px; min-width: 2px; }
tr.cat-clickable { cursor: pointer; }
tr.cat-clickable:active td { background: var(--surface-2); }

/* ---------- Divers ---------- */
.banner {
  display: flex; gap: 10px; align-items: flex-start;
  background: rgba(244, 132, 95, .12); border: 1px solid rgba(244, 132, 95, .5);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; font-size: .9rem;
}
.banner.info { background: rgba(100, 181, 246, .1); border-color: rgba(100, 181, 246, .4); }
.banner .x { margin-left: auto; background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1.1rem; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 20px); z-index: 60;
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 10px 18px; font-size: .9rem;
  box-shadow: 0 6px 18px rgba(0,0,0,.4);
  animation: toast-in .2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(8px); } }
.toast.error { border-color: var(--red); color: var(--red); }

.activity-row { display: flex; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--border); font-size: .92rem; }
.activity-row .when { color: var(--muted); font-size: .78rem; }

.login-wrap { min-height: 88dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-box { width: 100%; max-width: 360px; }
.login-box .logo { text-align: center; font-size: 2.4rem; margin-bottom: 6px; }

.row { display: flex; gap: 10px; align-items: center; }
.row .grow { flex: 1; }
.split-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.list-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

@media (min-width: 700px) {
  body { font-size: 15.5px; }
  .sheet { border-radius: 18px; margin-bottom: 5dvh; }
  .sheet-backdrop { align-items: center; }
}

/* ---------- Hors ligne : badge réseau et file d'attente ---------- */
/* Icône compacte : ne doit pas pousser le sélecteur de compte ni le solde. */
.net-badge {
  flex: none; margin-left: 8px; margin-right: 2px;
  position: relative; display: inline-flex; align-items: center;
  background: none; border: none; padding: 2px 4px;
  font-size: 1.1rem; line-height: 1; cursor: pointer;
}
.net-badge .net-count {
  position: absolute; top: -3px; right: -4px;
  min-width: 15px; height: 15px; padding: 0 3px; box-sizing: border-box;
  background: var(--accent-strong); color: #fff;
  border-radius: 999px; font-size: .62rem; font-weight: 700; line-height: 15px;
  text-align: center;
}
.net-badge[hidden] { display: none; }
.topbar .balance-chip { margin-left: 0; }
.pending-card { border-color: rgba(244, 132, 95, .45); }
.pending-row { padding: 7px 0; border-bottom: 1px solid var(--border); }

/* ---------- Voyages ---------- */
.voyage-card { cursor: pointer; }
.voyage-card:active { opacity: .8; }
.voyage-title { font-weight: 700; font-size: 1.05rem; }
.voyage-total { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.voyage-phases { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 4px; }
/* Cas rare d'une dépense après le séjour : 4 cartes → 2×2, illisible sur 4 colonnes. */
.voyage-phases.four { grid-template-columns: repeat(2, 1fr); }
.voyage-phase {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 8px; text-align: center;
}
.vdetach {
  align-self: center; padding: 4px 9px; color: var(--muted);
  border-color: var(--border); flex: none;
}
.vdetach:active { color: var(--red); border-color: var(--red); }
