:root {
  --bg: #0f1720;
  --surface: #ffffff;
  --ink: #1b2733;
  --ink-soft: #5a6b7b;
  --line: #e3e9ef;
  --brand: #0b7d5b;
  --brand-dark: #086047;
  --accent: #d98324;
  --danger: #c0392b;
  --warn: #b9770e;
  --ok: #1e8449;
  --radius: 14px;
  --shadow: 0 2px 14px rgba(15, 23, 32, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--ink);
  background: #f2f5f8;
  line-height: 1.5;
  overflow-x: hidden; /* aucun défilement horizontal de l'app */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
main { flex: 1 0 auto; width: 100%; }
.app-footer { flex-shrink: 0; margin-top: auto; }
a { color: var(--brand-dark); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }

/* --- Layout --- */
header.topbar {
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
  color: #fff;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 50;
}
header.topbar .brand { font-weight: 700; font-size: 1.15rem; letter-spacing: .3px; }
header.topbar .spacer { flex: 1; }
header.topbar .who { font-size: .9rem; opacity: .95; }

main { max-width: 1080px; margin: 0 auto; padding: 18px; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.tabs button {
  background: #e7edf2; color: var(--ink-soft); border: 0;
  padding: 9px 16px; border-radius: 999px; cursor: pointer; font-size: .92rem; font-weight: 600;
}
.tabs button.active { background: var(--brand); color: #fff; }
.tabs .lbl-short { display: none; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

/* --- Buttons --- */
button, .btn {
  font: inherit; cursor: pointer; border: 0; border-radius: 10px;
  padding: 10px 16px; font-weight: 600; background: var(--brand); color: #fff;
}
button.secondary, .btn.secondary { background: #e7edf2; color: var(--ink); }
button.ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.6); }
button.danger { background: var(--danger); }
button.warn { background: var(--warn); }
button.small { padding: 6px 10px; font-size: .84rem; border-radius: 8px; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px; border-radius: 10px; line-height: 0;
}
button.icon-btn.ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.55); }
button.icon-btn.ghost:hover { background: rgba(255,255,255,.14); }

.btn-google {
  background: #fff; color: #3c4043; border: 1px solid #dadce0;
  display: inline-flex; align-items: center; gap: 10px;
}
.btn-google svg { width: 18px; height: 18px; }

/* --- Forms --- */
label { display: block; font-size: .86rem; font-weight: 600; color: var(--ink-soft); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; font: inherit; background: #fbfcfd; color: var(--ink);
}
textarea { min-height: 74px; resize: vertical; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 160px; }

/* --- Badges / pills --- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: .76rem; font-weight: 700; letter-spacing: .2px;
}
.badge.brouillon { background: #eceff1; color: #607d8b; }
.badge.ouverte { background: #e3f4ec; color: var(--ok); }
.badge.en_cours { background: #e6f0fb; color: #1e5fa8; }
.badge.cloturee { background: #f0e6e6; color: #7b4b4b; }
.badge.en_attente { background: #fdf1e0; color: var(--warn); }
.badge.valide, .badge.acceptee { background: #e3f4ec; color: var(--ok); }
.badge.rejete, .badge.refusee, .badge.exclu { background: #fbe6e4; color: var(--danger); }
.badge.retard { background: var(--danger); color: #fff; }
.badge.actif { background: #e3f4ec; color: var(--ok); }
.badge.retire { background: #eceff1; color: #607d8b; }

.badge.prise-pris { background: #e3f4ec; color: var(--ok); }
.badge.prise-a_confirmer { background: #fdf1e0; color: var(--warn); }
.badge.prise-non_pris { background: #eceff1; color: #607d8b; }

.muted { color: var(--ink-soft); font-size: .88rem; }
.big { font-size: 1.5rem; font-weight: 800; }

/* --- Tables --- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--ink-soft); font-size: .8rem; text-transform: uppercase; letter-spacing: .4px; }

/* suivi matrix */
.matrix td, .matrix th { text-align: center; }
.cell { display: inline-block; width: 20px; height: 20px; border-radius: 6px; }
.cell.valide { background: var(--ok); }
.cell.en_attente { background: var(--accent); }
.cell.retard { background: var(--danger); }
.cell.du { background: #f0d264; }
.cell.a_venir { background: #dfe6ec; }

/* --- Notifications --- */
.bell { position: relative; cursor: pointer; font-size: 1.2rem; }
.bell .count {
  position: absolute; top: -6px; right: -8px; background: var(--accent); color: #fff;
  border-radius: 999px; font-size: .68rem; padding: 1px 5px; font-weight: 700;
}
.notif-panel {
  position: absolute; right: 12px; top: 56px; width: min(360px, 92vw);
  background: #fff; color: var(--ink); border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.22);
  max-height: 70vh; overflow-y: auto; z-index: 100;
}
.notif-panel .item { padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: .9rem; }
.notif-panel .item.unread { background: #f3f9f6; }

.toast-wrap { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1b2733; color: #fff; padding: 11px 16px; border-radius: 10px; font-size: .9rem; box-shadow: var(--shadow); }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }

/* --- Modal --- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15,23,32,.5);
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 150; overflow-y: auto;
}
.modal { background: #fff; border-radius: var(--radius); padding: 22px; width: min(560px, 100%); }

.app-footer {
  text-align: center;
  padding: 22px 16px 28px;
  color: var(--ink-soft);
  font-size: .82rem;
}

.hidden { display: none !important; }
.center { text-align: center; }
.stack > * + * { margin-top: 10px; }

/* drag ordre */
.ordre-list li {
  list-style: none; background: #f7f9fb; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 8px; display: flex; align-items: center; gap: 10px; cursor: grab;
}
.ordre-list li.dragging { opacity: .4; }
.ordre-list .rang { font-weight: 800; color: var(--brand); min-width: 24px; }
.ordre-list { padding: 0; margin: 0; }

/* --- Panneau latéral gestionnaire --- */
.gest-shell { display: flex; align-items: flex-start; gap: 18px; }
.gest-content { flex: 1 1 auto; min-width: 0; }

.sidenav {
  flex: 0 0 208px; display: flex; flex-direction: column; gap: 6px;
  position: sticky; top: 74px;
}
.sidenav button {
  display: flex; align-items: center; gap: 8px; width: 100%;
  text-align: left; background: #e7edf2; color: var(--ink-soft); border: 0;
  padding: 11px 14px; border-radius: 10px; cursor: pointer;
  font-weight: 600; font-size: .92rem;
}
.sidenav button.active { background: var(--brand); color: #fff; }
.sidenav button .badge { margin-left: auto; }
.sidenav-close { display: none; }

.content-head {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  gap: 12px; margin-bottom: 14px;
}
.content-head .nav-toggle { justify-self: start; }
.content-head #btnNewTontine { grid-column: 2; }

.nav-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  background: #e7edf2; color: var(--ink);
}
#appView.nav-collapsed .sidenav { display: none; }

.nav-scrim { position: fixed; inset: 0; background: rgba(15,23,32,.45); z-index: 90; }

@media (max-width: 860px) {
  .gest-shell { display: block; }
  .nav-scrim.hidden { display: none; }
  .sidenav {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
    width: 264px; max-width: 82vw; padding: 16px; overflow-y: auto;
    background: #fff; box-shadow: 0 10px 40px rgba(0,0,0,.25);
    transform: translateX(-100%); transition: transform .22s ease;
  }
  #appView.nav-open .sidenav { transform: none; }
  .sidenav button { font-size: 1rem; padding: 13px 14px; }
  .sidenav-close {
    display: block; align-self: flex-end; width: auto;
    background: transparent; color: var(--ink-soft); font-size: 1.1rem; padding: 4px 8px;
  }
}

/* --- Tables en cartes sur mobile : aucun défilement horizontal --- */
@media (max-width: 640px) {
  .table-wrap { overflow-x: visible; }
  .table-wrap table,
  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap td { display: block; width: auto; }
  .table-wrap thead { display: none; }
  .table-wrap tr {
    border: 1px solid var(--line); border-radius: 10px;
    margin-bottom: 10px; padding: 4px 12px; background: var(--surface);
  }
  .table-wrap td {
    border: 0; border-bottom: 1px solid var(--line); padding: 8px 0; min-width: 0;
    display: flex; gap: 12px; align-items: baseline; justify-content: space-between;
    text-align: right; white-space: normal; overflow-wrap: anywhere;
  }
  .table-wrap tr td:last-child { border-bottom: 0; }
  .table-wrap td:empty { display: none; }
  .table-wrap td[data-label]::before {
    content: attr(data-label);
    font-weight: 600; color: var(--ink-soft); text-align: left;
    flex: 0 0 40%; white-space: nowrap;
  }
  .table-wrap td:not([data-label]) { justify-content: flex-end; }
  .table-wrap td[colspan] { display: block; text-align: center; }
  .table-wrap td[colspan]::before { display: none; }
  .table-wrap td input,
  .table-wrap td select { width: auto; flex: 1 1 55%; min-width: 0; }
  .matrix .cell { width: 16px; height: 16px; }
  .big { font-size: 1.1rem; overflow-wrap: anywhere; }
}

@media (max-width: 560px) {
  main { padding: 12px; }
  .card { padding: 14px; }

  /* Onglets participant : tous sur une seule ligne */
  .tabs { flex-wrap: nowrap; gap: 5px; }
  .tabs button {
    flex: 1 1 0; min-width: 0; padding: 9px 6px; font-size: .8rem;
    text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .tabs .lbl-full { display: none; }
  .tabs .lbl-short { display: inline; }

  /* En-tête : ne jamais déborder */
  header.topbar { gap: 8px; padding: 12px 14px; }
  header.topbar .brand { font-size: 1rem; }
  header.topbar .who { max-width: 32vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .btn-google { font-size: .82rem; padding: 8px 10px; }

  /* Groupes de boutons : ne pas forcer 160px, laisser 2 boutons par ligne */
  .row > button,
  .row > .btn { flex: 1 1 130px; min-width: 0; }
  .row > button.small { flex: 1 1 auto; }

  /* Boutons d'action des tableaux : autoriser le retour à la ligne (dernière colonne) */
  td:last-child { white-space: normal; }
  td:last-child button { margin: 2px 3px 2px 0; }

  /* Barre d'actions d'une tontine : boutons pleine largeur, empilés proprement */
  .actions-bar button.small { flex: 1 1 100%; padding: 11px 14px; font-size: .9rem; }

  /* Liste ordre de prise : passer les boutons sous le nom */
  .ordre-list li { flex-wrap: wrap; }
  .ordre-list li > span[style*="flex:2"] { flex: 1 1 100%; }
  .ordre-list li button.small { flex: 1 1 auto; }

  /* Modales : boutons Enregistrer / Annuler bien visibles */
  .modal .row button { flex: 1 1 120px; padding: 12px 14px; }
}

/* --- Inscription participant (statut compte) --- */
.badge.refuse { background: #fbe6e4; color: var(--danger); }
.badge.incomplet { background: #eceff1; color: #607d8b; }

.gest-line {
  max-width: 1080px;
  margin: 10px auto 0;
  padding: 8px 18px;
  font-size: .9rem;
  color: var(--ink-soft);
}
.gest-line strong { color: var(--ink); }

.acct-banner {
  max-width: 1080px;
  margin: 12px auto 0;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: .95rem;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.acct-banner.wait { background: #fdf1e0; color: var(--warn); }
.acct-banner.todo { background: #e6f0fb; color: #1e5fa8; }
