/* SM Manager — mobile-first, toutes les vues responsive-ready (règle n°5).
   SOCLE DE DESIGN (règle n°9) : les valeurs ci-dessous sont les DÉFAUTS des
   tokens ; /theme.css (généré depuis la table design_tokens) les surcharge.
   Tout nouveau style DOIT consommer var(--sm-…) — jamais de couleur/arrondi/
   police en dur ailleurs que dans ce bloc :root. */
:root {
  --sm-primaire: #0C1F40;
  --sm-action: #2e7d32;
  --sm-danger: #b00020;
  --sm-fond: #f4f6f9;
  --sm-surface: #ffffff;
  --sm-texte: #333333;
  --sm-muted: #777777;
  --sm-bord: #d9dee6;
  --sm-radius: 10px;
  --sm-btn-radius: 6px;
  --sm-font: 'Open Sans', system-ui, -apple-system, sans-serif;
  /* Dérivés non surchargables */
  --sm-contraste: #ffffff;      /* texte sur fonds foncés */
  --sm-nav-lien: #cfd8e6;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* l'attribut hidden gagne sur display:grid/flex */
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sm-font);
  color: var(--sm-texte);
  background: var(--sm-fond);
  min-height: 100dvh; /* jamais 100vh : barre navigateur mobile */
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── Navigation : sidebar (desktop) / off-canvas + barre burger (mobile) ── */
.brand { color: var(--sm-contraste); font-weight: 700; font-size: 1.1rem; text-decoration: none; }

.mobilebar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--sm-primaire);
  color: var(--sm-contraste);
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  position: sticky;
  top: 0;
  z-index: 30;
}
.btn-burger {
  background: none;
  border: none;
  color: var(--sm-contraste);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 2px 8px;
}

.layout { display: flex; min-height: 100dvh; }

.sidebar {
  background: var(--sm-primaire);
  color: var(--sm-contraste);
  width: 230px;
  flex-shrink: 0;
  padding: 16px 0;
  padding-top: max(16px, env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  gap: 18px;
  /* Mobile : off-canvas */
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 40;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
}
.sidebar.ouverte { transform: translateX(0); }
.sidebar .brand { padding: 0 18px; }
.sidebar .nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar .nav a {
  color: var(--sm-nav-lien);
  text-decoration: none;
  padding: 11px 18px;
  border-left: 3px solid transparent;
}
.sidebar .nav a:hover { color: var(--sm-contraste); background: rgba(255, 255, 255, 0.07); }
.sidebar .nav a.actif {
  color: var(--sm-contraste);
  font-weight: 700;
  border-left-color: var(--sm-contraste);
  background: rgba(255, 255, 255, 0.12);
}

.voile {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 35;
}

/* ── Page ── */
.page { padding: 16px; max-width: 1100px; margin: 0 auto; flex: 1; min-width: 0; }
h1 { font-size: 1.35rem; margin: 8px 0 16px; }
.muted { color: var(--sm-muted); }

/* ── Cartes (mobile-first : 1 colonne, puis grille) ── */
.cards { display: grid; grid-template-columns: 1fr; gap: 12px; }
.card {
  background: var(--sm-surface);
  border: 1px solid var(--sm-bord);
  border-radius: var(--sm-radius);
  padding: 16px;
}
.card h2 { margin: 0 0 8px; font-size: 1.05rem; }
.kpi-valeur { font-size: 1.5rem; font-weight: 700; margin: 4px 0; color: var(--sm-primaire); }
.card.kpi-danger .kpi-valeur { color: var(--sm-danger); }

/* ── Formulaires (mobile-first : 1 colonne) ── */
.form-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
fieldset {
  border: 1px solid var(--sm-bord);
  border-radius: var(--sm-radius);
  background: var(--sm-surface);
  padding: 12px 16px 16px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  min-width: 0;
}
legend { font-weight: 700; padding: 0 6px; }
/* Dans un fieldset en grille : tables, totaux et barres d'action = pleine largeur */
fieldset > .table-scroll, fieldset > .totaux, fieldset > .actions,
fieldset > button, fieldset > div[id] { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; min-width: 0; }
label.check { flex-direction: row; align-items: center; gap: 8px; }
input, select, textarea {
  font: inherit;
  padding: 9px 10px;
  border: 1px solid var(--sm-bord);
  border-radius: calc(var(--sm-btn-radius) / 2 + 3px);
  width: 100%;
  min-width: 0;
  background: var(--sm-surface);
  color: var(--sm-texte);
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--sm-primaire); outline-offset: 1px; }

/* ── Boutons ── */
.actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.btn-save {
  background: var(--sm-action);
  color: var(--sm-contraste);
  border: 2px solid var(--sm-action);
  border-radius: var(--sm-btn-radius);
  padding: 11px 20px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.btn-save:hover { filter: brightness(1.08); }
.btn-emettre {
  background: var(--sm-primaire);
  color: var(--sm-contraste);
  border: 2px solid var(--sm-primaire);
  border-radius: var(--sm-btn-radius);
  padding: 11px 20px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.btn-secondaire {
  background: var(--sm-surface);
  color: var(--sm-texte);
  border: 1px solid var(--sm-bord);
  border-radius: var(--sm-btn-radius);
  padding: 10px 16px;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn-suppr { background: none; border: none; color: var(--sm-danger); cursor: pointer; font-size: 1rem; }

/* ── Page de connexion ── */
.login-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--sm-primaire);
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.login-carte {
  background: var(--sm-surface);
  border-radius: var(--sm-radius);
  padding: 28px 26px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-carte h1 { margin: 0; color: var(--sm-primaire); font-size: 1.4rem; }
.login-erreur {
  background: color-mix(in srgb, var(--sm-danger) 12%, var(--sm-surface));
  color: var(--sm-danger);
  border-radius: 6px;
  padding: 9px 12px;
  margin: 0;
  font-size: 0.9rem;
}

/* ── Pied de sidebar (utilisateur) ── */
.sidebar .pied {
  margin-top: auto;
  padding: 12px 18px 4px;
  font-size: 0.82rem;
  color: var(--sm-nav-lien);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar .pied button {
  background: none;
  border: 1px solid var(--sm-nav-lien);
  color: var(--sm-nav-lien);
  border-radius: var(--sm-btn-radius);
  padding: 6px 10px;
  cursor: pointer;
  font: inherit;
}
.sidebar .pied button:hover { color: var(--sm-contraste); border-color: var(--sm-contraste); }

/* ── Options d'affichage (ligne de checkboxes) ── */
.options-affichage { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 0.9rem; }
.options-affichage label.check { flex-direction: row; }

/* ── Toolbar ── */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }

/* ── Tables (wrapper scrollable : jamais de scroll horizontal de page) ── */
.table-scroll { overflow-x: auto; background: var(--sm-surface); border: 1px solid var(--sm-bord); border-radius: var(--sm-radius); }
table.liste { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.liste th, table.liste td { padding: 10px 12px; text-align: left; white-space: nowrap; }
table.liste th { background: var(--sm-fond); font-size: 0.8rem; text-transform: uppercase; color: var(--sm-muted); }
table.liste tbody tr { border-top: 1px solid var(--sm-bord); cursor: pointer; }
table.liste tbody tr:hover { background: color-mix(in srgb, var(--sm-primaire) 6%, var(--sm-surface)); }
table.liste .num { text-align: right; }
table.liste input { padding: 6px 8px; min-width: 70px; }
table.liste td:first-child input { min-width: 180px; }

/* ── Badges de statut (sémantiques, non thémables) ── */
.badge { padding: 3px 10px; border-radius: 12px; font-size: 0.78rem; font-weight: 700; }
.badge-gris   { background: #F5F5F5; color: #666; }
.badge-orange { background: #FFF3E0; color: #E65100; }
.badge-violet { background: #f3e5f5; color: #7b1fa2; }
.badge-vert   { background: #E8F5E9; color: #2E7D32; }

/* ── Graphe CA (barres CSS pures) ── */
.graphe-ca {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 160px;
  padding-top: 8px;
}
.ca-colonne { flex: 1; display: flex; flex-direction: column; height: 100%; min-width: 0; }
.ca-barres { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.ca-barre { width: 40%; max-width: 22px; border-radius: 2px 2px 0 0; }
.ca-barre.facture { background: var(--sm-primaire); }
.ca-barre.encaisse { background: color-mix(in srgb, var(--sm-action) 55%, var(--sm-surface)); }
.ca-label { text-align: center; font-size: 0.7rem; color: var(--sm-muted); padding-top: 4px; }

/* ── Totaux facture ── */
.totaux { margin-top: 12px; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.totaux .grand-total { font-size: 1.1rem; color: var(--sm-primaire); }

/* ── ≥768px : sidebar fixe + grilles multi-colonnes ── */
@media (min-width: 768px) {
  .mobilebar { display: none; }
  .sidebar { position: sticky; top: 0; height: 100dvh; transform: none; transition: none; }
  .voile { display: none; }
  .page { padding: 24px 32px; }
  .cards { grid-template-columns: repeat(3, 1fr); }
  fieldset { grid-template-columns: 1fr 1fr; }
  label.wide { grid-column: 1 / -1; }
}
