/* =============================================================================
   Nasty Follow — styles.css
   Mobile-first. Priorité : lisibilité et vitesse de saisie sur téléphone.
   ========================================================================== */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --texte: #171a1f;
  --muet: #6b7280;
  --bord: #e2e6ea;
  --primaire: #3b6fe0;
  --primaire-fonce: #2c57bd;
  --ok: #12a150;
  --danger: #e5484d;
  --nav: #141821;
  --nav-texte: #e7eaf0;
  --rayon: 12px;
  --rayon-sm: 8px;
  --ombre: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--texte);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

h1 { font-size: 1.45rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 0.75rem; }

/* ------------------------------ Navigation ------------------------------ */
.nav {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.9rem;
  background: var(--nav);
  color: var(--nav-texte);
  flex-wrap: wrap;
}
.nav-marque { font-weight: 700; letter-spacing: 0.2px; margin-right: auto; }
.nav-liens { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.nav-liens a {
  color: var(--nav-texte);
  text-decoration: none;
  padding: 0.4rem 0.7rem;
  border-radius: var(--rayon-sm);
  font-size: 0.95rem;
  opacity: 0.85;
}
.nav-liens a:hover { opacity: 1; background: rgba(255, 255, 255, 0.08); }
.nav-liens a[aria-current="page"] { opacity: 1; background: rgba(255, 255, 255, 0.16); font-weight: 600; }
.nav-deco {
  background: transparent;
  color: var(--nav-texte);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--rayon-sm);
  padding: 0.4rem 0.7rem;
  font-size: 0.9rem;
  cursor: pointer;
}
.nav-deco:hover { background: rgba(255, 255, 255, 0.1); }

/* ------------------------------- Contenu -------------------------------- */
.contenu { max-width: 760px; margin: 0 auto; padding: 1rem 0.9rem 4rem; }

.carte {
  background: var(--surface);
  border: 1px solid var(--bord);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  padding: 1rem;
  margin-bottom: 1rem;
}

/* -------------------------------- Champs -------------------------------- */
.champ { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.85rem; }
.champ label { font-size: 0.85rem; font-weight: 600; color: var(--muet); }
.ligne-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

input, select, textarea {
  width: 100%;
  font-size: 1.05rem;      /* >=16px : évite le zoom auto iOS */
  padding: 0.7rem 0.75rem;
  min-height: 48px;
  border: 1px solid var(--bord);
  border-radius: var(--rayon-sm);
  background: var(--surface);
  color: var(--texte);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primaire);
  box-shadow: 0 0 0 3px rgba(59, 111, 224, 0.15);
}

.total-ligne {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.6rem 0.2rem;
  border-top: 1px dashed var(--bord);
  margin: 0.4rem 0 0.8rem;
}
.total-ligne strong { font-size: 1.5rem; color: var(--primaire-fonce); }

details.details-optionnels { margin-bottom: 0.9rem; }
details.details-optionnels > summary {
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--muet);
  padding: 0.4rem 0;
  user-select: none;
}

/* -------------------------------- Boutons ------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.7rem 1rem;
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: var(--rayon-sm);
  cursor: pointer;
  background: var(--surface-2);
  color: var(--texte);
}
.btn:hover { filter: brightness(0.98); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primaire { background: var(--primaire); color: #fff; }
.btn-primaire:hover { background: var(--primaire-fonce); }
.btn-bloc { width: 100%; font-size: 1.1rem; padding: 0.9rem; }
.btn-petit { min-height: 38px; padding: 0.4rem 0.7rem; font-size: 0.88rem; }
.btn-danger { color: var(--danger); border-color: var(--bord); background: var(--surface); }
.btn-danger:hover { background: #fdecec; }

/* --------------------------------- Chips -------------------------------- */
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface);
  border: 1px solid var(--bord);
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  font-size: 0.9rem;
  box-shadow: var(--ombre);
}
.chip .qte { font-weight: 700; }
.chip.bas { border-color: var(--danger); }
.chip.bas .qte { color: var(--danger); }
.chip.rupture { background: #fdecec; border-color: var(--danger); }

/* -------------------------------- Listes -------------------------------- */
.liste-ventes { list-style: none; padding: 0; margin: 0; }
.liste-ventes li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--bord);
  border-radius: var(--rayon-sm);
  padding: 0.6rem 0.8rem;
  margin-bottom: 0.5rem;
}
.liste-ventes .desc { display: flex; flex-direction: column; }
.liste-ventes .desc .titre { font-weight: 600; }
.liste-ventes .desc .sous { font-size: 0.82rem; color: var(--muet); }

/* -------------------------------- Tables -------------------------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.table th, table.table td {
  text-align: left;
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--bord);
  white-space: nowrap;
}
table.table th { color: var(--muet); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
table.table td.num, table.table th.num { text-align: right; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }

/* --------------------------------- KPIs --------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; margin-bottom: 1rem; }
.kpi {
  background: var(--surface);
  border: 1px solid var(--bord);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  padding: 0.9rem;
}
.kpi .valeur { font-size: 1.5rem; font-weight: 700; }
.kpi .etiquette { font-size: 0.8rem; color: var(--muet); }

/* ------------------------------ Filtres période ------------------------- */
.segments { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; margin-bottom: 1rem; }
.segments button {
  border: none;
  background: transparent;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--muet);
}
.segments button.actif { background: var(--surface); color: var(--texte); font-weight: 600; box-shadow: var(--ombre); }

/* -------------------------------- Graphe -------------------------------- */
.graphe { width: 100%; height: auto; display: block; }
.graphe-axe { fill: var(--muet); font-size: 12px; }
.graphe-zero { stroke: var(--bord); stroke-width: 1; }
.graphe-vide { color: var(--muet); text-align: center; padding: 2rem 0; }

/* --------------------------------- Toast -------------------------------- */
.zone-toast {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(92vw, 420px);
}
.toast {
  padding: 0.75rem 1rem;
  border-radius: var(--rayon-sm);
  color: #fff;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  font-size: 0.95rem;
  transition: opacity 0.3s, transform 0.3s;
}
.toast-info { background: #334155; }
.toast-ok { background: var(--ok); }
.toast-erreur { background: var(--danger); }
.toast.sortie { opacity: 0; transform: translateY(8px); }

/* --------------------------------- Login -------------------------------- */
.login-page { min-height: 100dvh; display: grid; place-items: center; padding: 1.2rem; }
.login-carte { width: min(94vw, 380px); }
.login-carte h1 { text-align: center; }
.login-erreur { color: var(--danger); font-size: 0.9rem; min-height: 1.2em; margin-bottom: 0.5rem; }

/* --------------------------------- Divers ------------------------------- */
.muet { color: var(--muet); }
.actions-ligne { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.entete-section { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; }
.actions-cellule { display: flex; gap: 0.4rem; justify-content: flex-end; white-space: nowrap; }

/* Badges (journal) */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-ok { background: #e6f5ec; color: #0d7a3c; }
.badge-info { background: #e7eefc; color: #2c57bd; }
.badge-danger { background: #fdecec; color: #c02a2f; }

/* Modale native <dialog> — centrée, focus piégé nativement, arrière-plan inerte */
dialog.modal {
  border: none;
  padding: 1.1rem;
  width: min(94vw, 560px);
  max-height: 88vh;
  overflow-y: auto;
  overscroll-behavior: contain; /* coupe le scroll-chaining vers la page */
  border-radius: var(--rayon);
  background: var(--surface);
  color: var(--texte);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}
dialog.modal::backdrop { background: rgba(16, 20, 28, 0.5); }

/* Interrupteur (payé / à payer plus tard) */
.switch { display: inline-flex; align-items: center; gap: 0.6rem; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-piste {
  width: 46px; height: 28px; border-radius: 999px; background: var(--bord);
  position: relative; transition: background 0.15s; flex: none;
}
.switch-bouton {
  position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.15s;
}
.switch input:checked + .switch-piste { background: var(--ok); }
.switch input:checked + .switch-piste .switch-bouton { transform: translateX(18px); }
.switch input:focus-visible + .switch-piste { box-shadow: 0 0 0 3px rgba(59, 111, 224, 0.25); }
.switch-txt { font-weight: 600; }

@media (max-width: 420px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .ligne-2 { grid-template-columns: 1fr 1fr; }
}
