/* ====== Thèmes ====== */
:root {
  --bg: #12141a;
  --bg-elev: #1a1d24;
  --bg-card: #22262f;
  --text: #eef0f4;
  --text-dim: #9aa1ad;
  --border: #2e333e;
  --accent: #4f8cff;
  --green: #34c77b;
  --red: #ff5d5d;
  --orange: #ff9f43;
  --yellow: #ffd54a;
  --tab-h: 64px;
  --header-h: 56px;
}

html[data-theme="light"] {
  --bg: #f4f5f8;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --text: #1b1e26;
  --text-dim: #5d6470;
  --border: #dde0e6;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

/* ====== Bannière hors ligne ====== */
.offline-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 60;
  background: var(--yellow);
  color: #1b1e26;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 12px;
  padding-top: calc(6px + env(safe-area-inset-top));
}

/* ====== En-tête ====== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pb-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-dim);
  display: inline-block;
}
.pb-dot--ok { background: var(--green); }
.pb-dot--ko { background: var(--red); }

.header-actions { display: flex; gap: 8px; align-items: center; }

.icon-btn {
  min-width: 48px;
  min-height: 48px;
  font-size: 1.3rem;
  border-radius: 12px;
}
.icon-btn:active { background: var(--bg-card); }

.user-badge {
  min-width: 48px;
  min-height: 48px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
}

/* ====== Contenu ====== */
.app-main {
  padding: 16px;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 88px);
  min-height: calc(100vh - var(--header-h));
}

.view[hidden] { display: none; }

.placeholder-note {
  color: var(--text-dim);
  text-align: center;
  padding: 32px 16px;
  font-size: 0.95rem;
}

/* ====== Dashboard ====== */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.dashboard-grid .stat-card:first-child { grid-column: 1 / -1; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}

.stat-card { display: flex; flex-direction: column; gap: 6px; }
.stat-label { color: var(--text-dim); font-size: 0.85rem; }
.stat-value { font-size: 1.6rem; font-weight: 700; }
.stat-detail { color: var(--text-dim); font-size: 0.78rem; }
.stat-card--alert .stat-value { color: var(--yellow); }

.bloc-titre { margin: 20px 0 10px; font-size: 1.05rem; color: var(--yellow); }

.mvt-signe--alerte { color: var(--yellow); background: rgba(255, 213, 74, 0.12); }

.tab-icon { position: relative; }
.tab-alerte {
  position: absolute;
  top: -2px;
  right: -8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--yellow);
  border: 2px solid var(--bg-elev);
}

/* ====== Bouton flottant ====== */
.fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 55;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 2rem;
  font-weight: 700;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}
.fab:active { transform: scale(0.94); }

/* ====== Navigation onglets ====== */
.tab-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 50;
  display: flex;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 48px;
  color: var(--text-dim);
}
.tab.is-active { color: var(--accent); }
.tab-icon { font-size: 1.3rem; }
.tab-label { font-size: 0.68rem; font-weight: 600; }

/* ====== Formulaires ====== */
.input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 1rem;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.input--search { margin-bottom: 12px; }

.btn {
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn--primary { background: var(--accent); color: #fff; }
.btn--secondary { background: var(--bg-card); border: 1px solid var(--border); }
.btn--block { width: 100%; margin-top: 12px; }
.btn:disabled { opacity: 0.5; }
.btn:active { transform: scale(0.98); }

.form { display: flex; flex-direction: column; gap: 14px; }
.form-label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--text-dim); font-weight: 600; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-hint { color: var(--text-dim); font-size: 0.85rem; }

.form-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  font-weight: 600;
}
.form-switch input { width: 22px; height: 22px; accent-color: var(--accent); }

/* ====== Liste produits ====== */
.liste { display: flex; flex-direction: column; gap: 10px; }

.produit-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 10px 12px;
  text-align: left;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.produit-card:active { border-color: var(--accent); }
.produit-card--inactif { opacity: 0.55; }

.produit-photo {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  border-radius: 10px;
  background: var(--bg-elev);
  overflow: hidden;
}
.produit-photo img { width: 100%; height: 100%; object-fit: cover; }

.produit-infos { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.produit-nom { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.produit-sous { color: var(--text-dim); font-size: 0.82rem; }

.produit-badges { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.badge { font-size: 0.7rem; font-weight: 700; padding: 3px 8px; border-radius: 99px; }
.badge--alerte { background: var(--yellow); color: #1b1e26; }
.badge--off { background: var(--border); color: var(--text-dim); }

/* ====== Panneau coulissant ====== */
.modal-overlay--sheet { align-items: flex-end; padding: 0; }

.sheet {
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border);
  padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.sheet-head h2 { font-size: 1.2rem; }

.photo-bloc { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.photo-preview {
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  border-radius: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  overflow: hidden;
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }

.variantes-bloc { margin-top: 24px; }
.variantes-bloc h3 { margin-bottom: 10px; font-size: 1.05rem; }

.variante-ligne {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 52px;
  padding: 10px 14px;
  margin-bottom: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.95rem;
}
.variante-ligne:active { border-color: var(--accent); }
.variante-stock { font-weight: 700; }
.variante-stock--alerte { color: var(--yellow); }

/* ====== Mouvements ====== */
.filtres-chips { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }

.chip {
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 0.9rem;
  font-weight: 600;
}
.chip.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }

.type-toggle { display: flex; gap: 10px; margin-bottom: 14px; }

.type-btn {
  flex: 1;
  min-height: 56px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--bg-card);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-dim);
}
.type-btn--entree.is-active { border-color: var(--green); color: var(--green); background: rgba(52, 199, 123, 0.12); }
.type-btn--sortie.is-active { border-color: var(--red); color: var(--red); background: rgba(255, 93, 93, 0.12); }

.titre--entree { color: var(--green); }
.titre--sortie { color: var(--red); }

.quantite-bloc {
  display: flex;
  align-items: center;
  gap: 14px;
  justify-content: center;
  margin: 18px 0;
}

.quantite-btn {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 2rem;
  font-weight: 700;
}
.quantite-btn:active { border-color: var(--accent); }

.quantite-input {
  width: 110px;
  height: 64px;
  text-align: center;
  font-size: 1.8rem;
  font-weight: 700;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--text);
}

.canal-bloc { margin-bottom: 14px; }
.canal-bloc .form-label { margin-bottom: 8px; }
#canal-champs { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }

.btn--vert { background: var(--green); color: #fff; }
.btn--danger { background: var(--red); color: #fff; }

.badge--recent { background: var(--accent); color: #fff; font-size: 0.7rem; font-weight: 700; padding: 3px 8px; border-radius: 99px; }

.mvt-ligne {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.mvt-signe {
  min-width: 56px;
  font-size: 1.2rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}
.mvt-signe--entree { color: var(--green); background: rgba(52, 199, 123, 0.12); }
.mvt-signe--sortie { color: var(--red); background: rgba(255, 93, 93, 0.12); }

.mvt-infos { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }

.btn-mini {
  min-height: 40px;
  padding: 6px 12px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  align-self: center;
  white-space: nowrap;
}
.btn-mini--discret { background: var(--bg-elev); color: var(--text-dim); border: 1px solid var(--border); }

.reappro-actions { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.mvt-produit { font-weight: 700; }
.mvt-meta { color: var(--text-dim); font-size: 0.8rem; }

/* ====== Devis ====== */
.profil-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  padding: 12px 14px;
  text-align: left;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 14px;
}
.profil-card.is-active { border-color: var(--accent); }
.profil-nom { font-weight: 700; }
.profil-nom small { color: var(--text-dim); font-weight: 600; }
.profil-prix { font-size: 1.25rem; font-weight: 800; color: var(--accent); }
.profil-marge { font-size: 0.8rem; color: var(--text-dim); }
.profil-marge--alerte { color: var(--red); font-weight: 700; }

.devis-detail {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.88rem;
  color: var(--text-dim);
  padding: 3px 0;
  flex-wrap: wrap;
}
.devis-detail strong { color: var(--text); }

.devis-total-ligne {
  display: flex;
  justify-content: space-between;
  font-size: 1.2rem;
  font-weight: 800;
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding-top: 8px;
}

/* ====== Agenda & casier ====== */
.matrice-grille {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.matrice-case {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 6px;
  border-radius: 12px;
  border: 2px solid transparent;
  font-weight: 600;
}
.matrice-case.is-active { border-color: var(--text); }
.matrice-nb { font-size: 1.4rem; font-weight: 800; }
.matrice-nom { font-size: 0.68rem; text-align: center; }

.q-rouge { background: rgba(255, 93, 93, 0.18); color: var(--red); }
.q-bleu { background: rgba(79, 140, 255, 0.18); color: var(--accent); }
.q-orange { background: rgba(255, 159, 67, 0.18); color: var(--orange); }
.q-gris { background: rgba(154, 161, 173, 0.18); color: var(--text-dim); }

.tache-check {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  border: 2px solid currentColor;
  font-size: 1.2rem;
  font-weight: 800;
  align-self: center;
}

.tache--faite { text-decoration: line-through; opacity: 0.6; }

.quadrant-choix { border-width: 2px; }
.quadrant-choix.is-active { border-color: currentColor; }

.casier-badge {
  position: absolute;
  top: 4px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  border-radius: 99px;
  background: var(--red);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}
#btn-casier { position: relative; }

.note--nonlue { border-color: var(--accent); }

.avatar {
  border-radius: 50%;
  object-fit: cover;
  vertical-align: middle;
}
.avatar--initiale {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}
.user-badge { overflow: hidden; padding: 0; }

/* ====== Modale ====== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  padding: 24px;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.modal h2 { font-size: 1.3rem; margin-bottom: 8px; }
.modal-sub { color: var(--text-dim); font-size: 0.9rem; margin-bottom: 20px; }

.user-choices { display: flex; gap: 12px; }

.user-choice {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px 12px;
  min-height: 48px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  font-size: 1.05rem;
  font-weight: 600;
}
.user-choice:active { border-color: var(--accent); }

.user-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-size: 1.4rem;
  font-weight: 700;
}
