/* ============================================================
   Inventaire Croix-Rouge — Styles
   Polices système uniquement (aucun appel externe : RGPD-friendly)
   ============================================================ */
:root {
  --crf-red:      #e2001a;
  --crf-red-dark: #b4001533;
  --sidebar:      #111418;
  --sidebar-2:    #191d24;
  --sidebar-line: #2a2f37;
  --bg:           #f4f6f8;
  --card:         #ffffff;
  --text:         #1f2933;
  --muted:        #6b7280;
  --border:       #e6e8ec;
  --ok:           #16a34a;
  --soon:         #f59e0b;
  --expired:      #dc2626;
  --radius:       10px;
  --shadow:       0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.45;
}
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); font-weight: 400; }

/* ===================== MISE EN PAGE ===================== */
.layout { display: flex; min-height: 100vh; }

/* ----- Menu gauche ----- */
.sidebar {
  width: 250px;
  flex: 0 0 250px;
  background: var(--sidebar);
  color: #cdd2da;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--sidebar-line);
}
.brand .cross,
.login-logo .cross {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  background: var(--crf-red);
  color: #fff; font-size: 22px; font-weight: 700;
  border-radius: 8px;
}
.brand-text strong { color: #fff; display: block; font-size: 16px; letter-spacing: .2px; }
.brand-text small { color: #8b929d; font-size: 12px; }

.nav { padding: 12px 10px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; margin: 2px 0;
  border-radius: 8px;
  color: #c2c8d1; font-size: 14.5px;
  border-left: 3px solid transparent;
  cursor: pointer; transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--sidebar-2); color: #fff; }
.nav-item.active {
  background: var(--sidebar-2);
  color: #fff;
  border-left-color: var(--crf-red);
}
.nav-ico { width: 18px; text-align: center; opacity: .85; }

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--sidebar-line);
  font-size: 13px;
}
.operator { display: flex; align-items: center; gap: 8px; color: #cdd2da; margin-bottom: 8px; }
.op-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; }
.logout { color: #8b929d; }
.logout:hover { color: var(--crf-red); }

/* ----- Contenu ----- */
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 28px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 650; }
.burger { display: none; background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--text); }
.view { padding: 26px 28px; }
.loader { color: var(--muted); padding: 40px; text-align: center; }

/* ===================== COMPOSANTS ===================== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; gap: 12px; flex-wrap: wrap;
}
.card-head h2 { margin: 0; font-size: 16px; font-weight: 650; }
.section-title { margin: 0 0 18px; font-size: 14px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }

/* Cartes statistiques du tableau de bord */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow);
}
.stat .num { font-size: 30px; font-weight: 700; line-height: 1; }
.stat .lbl { color: var(--muted); font-size: 13px; margin-top: 6px; }
.stat.alert .num { color: var(--expired); }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px; border-radius: 8px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
  font-size: 14px; font-family: inherit; cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: #f7f8fa; }
.btn-primary { background: var(--crf-red); border-color: var(--crf-red); color: #fff; }
.btn-primary:hover { background: #c50017; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-danger { color: var(--expired); border-color: #f1c7c7; }
.btn-danger:hover { background: #fdecec; }
.btn-block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* Tableaux */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .3px; }
tbody tr:hover { background: #fafbfc; }
td.actions { text-align: right; white-space: nowrap; }
.clickable { cursor: pointer; }
.clickable:hover { background: #f4f7ff !important; }

/* Badges de statut péremption */
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-ok      { background: #e8f6ec; color: var(--ok); }
.badge-soon    { background: #fef4e3; color: #b45309; }
.badge-expired { background: #fde6e6; color: var(--expired); }
.badge-type    { background: #eef1f5; color: #475569; font-weight: 500; }
.badge-opt     { background: #e7f0fe; color: #1d4ed8; }

/* Tableau des normes — mise en forme dédiée */
.norm-wrap {
  border: 1px solid var(--border); border-radius: 12px; overflow-x: auto;
  box-shadow: 0 1px 3px rgba(16, 20, 24, .05);
  -webkit-overflow-scrolling: touch;
}
.norm-wrap table { width: 100%; border-collapse: collapse; min-width: 600px; }
.norm-wrap thead th {
  background: var(--crf-red); color: #fff; border: 0;
  padding: 13px 14px; font-size: 12px; letter-spacing: .4px; text-transform: uppercase;
  white-space: nowrap; text-align: left; vertical-align: middle;
}
.norm-wrap tbody td {
  padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 14px;
  white-space: nowrap; vertical-align: middle;
}
/* Seules les colonnes "texte long" passent à la ligne ; les autres restent sur une ligne */
.norm-wrap thead th:first-child, .norm-wrap tbody td:first-child { white-space: normal; min-width: 220px; }
.norm-wrap tbody tr:last-child td { border-bottom: 0; }
.norm-wrap tbody tr:nth-child(even) { background: #fafbfc; }
.norm-wrap tbody tr:hover { background: #fff5f5; }
.norm-wrap tbody tr.norm-short { background: #fdecec; }
.norm-wrap tbody tr.norm-short:hover { background: #fbe0e0; }
.norm-wrap td.num { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.norm-wrap td.norm-actions { white-space: nowrap; text-align: right; }
.norm-wrap td.norm-actions .btn { margin-left: 6px; }
.norm-wrap td.norm-note { color: var(--muted); font-size: 13px; max-width: 280px; white-space: normal; }
.norm-wrap { margin-bottom: 22px; }
.norm-section-title {
  margin: 22px 0 9px; font-size: 13px; font-weight: 700; color: var(--crf-red);
  text-transform: uppercase; letter-spacing: .5px;
}
.norm-section-title:first-of-type { margin-top: 4px; }

/* Champ de recherche au-dessus d'une liste / d'un tableau */
.list-search { max-width: 380px; margin: 0 0 16px; }

/* Formulaires */
label { display: block; margin-bottom: 14px; font-size: 13.5px; font-weight: 600; }
input, select, textarea {
  width: 100%; padding: 9px 11px; margin-top: 5px;
  border: 1px solid var(--border); border-radius: 8px;
  font-family: inherit; font-size: 14px; background: #fff; color: var(--text);
  font-weight: 400;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--crf-red-dark); border-color: var(--crf-red); }
textarea { resize: vertical; min-height: 70px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* Champ « recherche + liste déroulante » (combo) */
.combo { position: relative; }
.combo-input { padding-right: 30px; }
.combo-caret { position: absolute; right: 12px; top: 50%; transform: translateY(-30%); color: var(--muted); pointer-events: none; font-size: 11px; }
.combo-list {
  position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(16,24,40,.14);
  max-height: 220px; overflow-y: auto; list-style: none; padding: 4px; margin-bottom: 0;
  z-index: 70;
}
.combo-list li { padding: 8px 11px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.combo-list li:hover, .combo-list li.active { background: #f4f7ff; }
.combo-list li.is-hidden { display: none; }
.combo-list li.none { color: var(--muted); font-style: italic; }
.combo-list .combo-empty { padding: 8px 11px; color: var(--muted); font-style: italic; }

/* ===================== CARTES (listes) ===================== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 16px;
}
.item-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.item-card.clickable { cursor: pointer; transition: box-shadow .12s, transform .12s, border-color .12s; }
.item-card.clickable:hover { box-shadow: 0 6px 20px rgba(16,24,40,.10); border-color: #d3d8df; transform: translateY(-1px); }
.ic-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.ic-title { font-weight: 650; font-size: 15.5px; line-height: 1.3; }
.ic-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.ic-meta { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.ic-meta .row { display: flex; gap: 6px; }
.ic-meta .row .k { min-width: 92px; color: var(--muted); }
.ic-meta .row .v { color: var(--text); }
.ic-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 4px; flex-wrap: wrap; }
.ic-qty { font-size: 22px; font-weight: 700; line-height: 1; }
.ic-qty small { font-size: 13px; font-weight: 500; color: var(--muted); }

/* Pastilles (listes courtes : unités, catégories, marques, fournisseurs) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: #eef1f5; color: var(--text);
  border-radius: 20px; padding: 6px 8px 6px 14px; font-size: 13.5px;
}
.chip button {
  border: 0; background: #dfe4ea; color: #475569; cursor: pointer;
  width: 20px; height: 20px; border-radius: 50%; line-height: 1; font-size: 13px; padding: 0;
}
.chip button:hover { background: var(--expired); color: #fff; }

/* Journal (liste) */
.log-list { display: flex; flex-direction: column; gap: 8px; }
.log-item { border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; background: var(--card); }
.log-item .log-top { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.log-item .log-act { font-weight: 600; font-size: 14px; }
.log-item .log-detail { color: var(--muted); font-size: 13px; }

/* Onglets de l'administration */
.admin-tabs { display: flex; align-items: center; gap: 4px; margin-bottom: 22px; border-bottom: 1px solid var(--border); }
.atab {
  background: none; border: 0; padding: 11px 16px; cursor: pointer;
  color: var(--muted); border-bottom: 2px solid transparent;
  font-size: 14.5px; font-family: inherit; margin-bottom: -1px;
}
.atab:hover { color: var(--text); }
.atab.active { color: var(--crf-red); border-bottom-color: var(--crf-red); font-weight: 600; }

/* Alertes */
.alert { padding: 11px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 16px; }
.alert-error { background: #fde6e6; color: var(--expired); }
.alert-info  { background: #eaf2ff; color: #1d4ed8; }
.empty { color: var(--muted); padding: 30px; text-align: center; font-style: italic; }

/* Sous-titre / fil d'Ariane détail contenant */
.crumb { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.crumb a { color: var(--crf-red); }
.pill-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }

/* ===================== PAGE DE CONNEXION ===================== */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--sidebar); }
.login-card {
  background: var(--card); border-radius: 14px; padding: 30px;
  width: 100%; max-width: 360px; box-shadow: 0 12px 40px rgba(0,0,0,.35);
}
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-logo strong { display: block; font-size: 18px; }
.login-logo small { color: var(--muted); }

/* ===================== MODALE ===================== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(17,20,24,.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px; z-index: 50; overflow-y: auto;
}
.modal {
  background: var(--card); border-radius: 12px; width: 100%; max-width: 520px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3); animation: pop .14s ease;
}
@keyframes pop { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-close { background: none; border: 0; font-size: 18px; cursor: pointer; color: var(--muted); }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 22px; }

/* ===================== TOAST ===================== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #111418; color: #fff; padding: 12px 20px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.3); z-index: 60;
}
.toast.err { background: var(--expired); }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 820px) {
  .sidebar {
    position: fixed; z-index: 40; left: -260px; transition: left .2s;
    box-shadow: 4px 0 24px rgba(0,0,0,.3);
  }
  .sidebar.open { left: 0; }
  .burger { display: inline-block; }
  .form-row { grid-template-columns: 1fr; }
  .view { padding: 18px 16px; }
}
