/* ================================================================
   TB DISTRIBUTION – Design System
   Mobile-first · iPhone X optimisé · Compatible PC
   ================================================================ */

/* ── Variables ───────────────────────────────────────────────── */
:root {
  --purple:        rgb(140, 83, 255);   /* couleur d'origine du projet */
  --purple-dark:   #5b21b6;
  --purple-light:  #ede9fe;
  --blue:          rgb(0, 123, 255);    /* couleur config du projet */
  --blue-light:    #dbeafe;
  --green:         #059669;
  --green-light:   #d1fae5;
  --red:           #dc2626;
  --red-light:     #fee2e2;
  --bg:            #f1f5f9;
  --card:          #ffffff;
  --border:        #e2e8f0;
  --text:          #0f172a;
  --text-2:        #475569;
  --text-3:        #94a3b8;
  --radius:        14px;
  --shadow:        0 1px 3px rgba(0,0,0,.07), 0 4px 14px rgba(0,0,0,.05);
  --shadow-sm:     0 1px 2px rgba(0,0,0,.06);
}

/* ── Reset minimal ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

/* ── Base body ───────────────────────────────────────────────── */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  /* Réserve pour header fixe + encoche iPhone X */
  padding-top: calc(62px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  padding-left:  env(safe-area-inset-left,  0px);
  padding-right: env(safe-area-inset-right, 0px);
  min-height: 100dvh;
}

/* ── Header fixe ─────────────────────────────────────────────── */
.header {
  position: fixed !important;
  top: 0; left: 0; right: 0;
  z-index: 200;
  /* On conserve la couleur originale pour le toggle JS */
  background-color: rgb(140, 83, 255) !important;
  color: white !important;
  text-align: center !important;
  font-size: 17px !important;
  font-weight: 700;
  letter-spacing: .4px;
  /* Padding top = safe area encoche + padding normal */
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 20px 16px !important;
  min-height: calc(62px + env(safe-area-inset-top, 0px));
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 2px 16px rgba(0,0,0,.18);
  transition: background-color .25s ease;
  display: flex !important;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.header::before { content: '📦'; font-size: 16px; }
.header::after  { content: '⚙️'; font-size: 14px; opacity: .7; }
.header:active  { filter: brightness(.92); }

/* ── Containers principaux ───────────────────────────────────── */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 18px 14px;
  transition: opacity .3s ease;
}
.container_edit,
.container_selection_edit { transition: opacity .3s ease; }

/* ── Grid d'accueil ──────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-top: 16px;
}
@media (min-width: 600px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(3, 1fr); } }

/* ── Cartes génériques ───────────────────────────────────────── */
.card {
  background: var(--card);
  padding: 18px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card.selected {
  background: #eff6ff;
  border: 2px solid var(--blue);
  box-shadow: 0 0 0 4px rgba(0,123,255,.1);
}

/* ── Stats (accueil) ─────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 0;
}
@media (min-width: 600px) { .stats { grid-template-columns: repeat(4, 1fr); } }

.stat-card {
  background: var(--card);
  padding: 16px 12px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  text-align: center;
}
.stat-number {
  font-size: 30px;
  font-weight: 800;
  color: var(--purple);
  line-height: 1;
  margin-bottom: 5px;
}
.stat-label {
  color: var(--text-2);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ── Liste machines ──────────────────────────────────────────── */
.machine-list { display: grid; gap: 10px; }

.machine-item {
  background: var(--card);
  padding: 14px 16px;
  border-radius: 12px;
  border-left: 4px solid var(--green);
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
  gap: 10px;
}
.machine-item.offline { border-left-color: var(--red); }

.machine-info { flex: 1; min-width: 0; }
.machine-info h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.machine-info p {
  color: var(--text-2);
  font-size: 11px;
  line-height: 1.4;
}

.status-badge {
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}
.status-online  { background: var(--green); color: white; }
.status-offline { background: var(--red);   color: white; }

/* ── Titres de section cliquables ────────────────────────────── */
.titre {
  background-color: rgb(140, 83, 255);  /* couleur d'origine conservée pour le JS */
  color: white;
  padding: 14px 20px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .3px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .2s;
  display: flex;
  align-items: center;
  gap: 8px;
}
.titre:active { filter: brightness(.9); }

/* ── Container des spirales ──────────────────────────────────── */
#selections-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 14px;
}
@media (min-width: 640px)  { #selections-container { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { #selections-container { grid-template-columns: repeat(3, 1fr); } }

/* Bouton "Saisie rapide" — pleine largeur, déjà stylé inline, juste grid-span */
#selections-container > button {
  grid-column: 1 / -1;
  min-height: 48px;
  border-radius: 10px !important;
  font-size: 15px !important;
  font-weight: 700 !important;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
#selections-container > button:active { opacity: .82; transform: scale(.98); }

/* Toggle "Afficher uniquement les spirales à remplir" — pleine largeur */
#selections-container > div:first-of-type {
  grid-column: 1 / -1;
  background: var(--card);
  border-radius: 10px;
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

#cb-partiel {
  width: 18px;
  height: 18px;
  accent-color: var(--purple);
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Carte spirale ───────────────────────────────────────────── */
/* Annule le grid interne que .grid appliquerait */
.selection.grid {
  display: block !important;
  grid-template-columns: unset !important;
}

.selection {
  position: relative;
  padding: 14px 14px 0 !important;
  border-radius: var(--radius) !important;
  overflow: hidden;
  border: 1.5px solid var(--border) !important;
  box-shadow: var(--shadow) !important;
  background: var(--card) !important;
  transition: box-shadow .15s;
}

/* Bande de couleur en bas = indicateur visuel */
.selection::after {
  content: '';
  display: block;
  height: 3px;
  margin: 0 -14px;
  background: linear-gradient(90deg, var(--green), #34d399);
  opacity: .6;
}
.selection.selection-pleine::after {
  background: var(--border);
  opacity: 1;
}

/* ── Nom du produit ──────────────────────────────────────────── */
.nom {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  padding-right: 68px;   /* espace pour le badge */
  margin-bottom: 10px;
  line-height: 1.35;
}

/* ── Zone stock + boutons ────────────────────────────────────── */
.stock {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding-bottom: 12px;
  font-size: 13px;
  color: var(--text-2);
  font-weight: 500;
}

/* Input numérique du stock courant */
.stock-input {
  width: 58px;
  padding: 6px 4px;
  font-size: 20px;      /* >= 16px pour éviter le zoom iOS */
  font-weight: 800;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: 9px;
  color: var(--purple);
  background: #faf5ff;
  -moz-appearance: textfield;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color .15s, box-shadow .15s;
}
.stock-input::-webkit-outer-spin-button,
.stock-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stock-input:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(140,83,255,.15);
}

/* Boutons action dans la carte spirale */
.stock button {
  flex: 1 1 auto;
  min-height: 40px;
  min-width: 60px;
  padding: 8px 10px;
  border: none;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: opacity .12s, transform .1s;
  white-space: nowrap;
}
.stock button:active { opacity: .72; transform: scale(.95); }

/* Uniter Max */
.stock button:nth-of-type(1) { background: var(--purple-light); color: var(--purple); }
/* Editer */
.stock button:nth-of-type(2) { background: #f1f5f9; color: var(--text-2); }
/* 📅 Dates */
.stock button:nth-of-type(3) { background: var(--blue-light); color: var(--blue); }

/* ── Badge "Stock bas" ───────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--red-light);
  color: var(--red);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 700;
  position: absolute;
  top: 12px;
  right: 12px;
  white-space: nowrap;
}

/* ── Panel de dates (lot-panel) ──────────────────────────────── */
.lot-panel {
  border-top: 1px solid var(--border) !important;
  padding: 12px 0 8px !important;
  margin: 0 -14px;
  padding-left:  14px !important;
  padding-right: 14px !important;
}

/* ── Utilitaires ─────────────────────────────────────────────── */
.hidden {
  opacity: 0 !important;
  visibility: hidden !important;
  height: 0 !important;
  overflow: hidden !important;
}

.form-group { margin-bottom: 15px; }

.log-entry {
  font-size: 13px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
}

/* ── Misc ────────────────────────────────────────────────────── */
ul { padding-left: 18px; }
li { margin-bottom: 4px; font-size: 14px; color: var(--text-2); }
