/* ============================================================
   DCRD — Design system (cards KPI, tableaux, badges sémantiques)
   Réutilise les variables de main.css (--primary-color, etc.)
   Code couleur : rouge=danger, jaune=attention, vert=bon.
   ============================================================ */

:root {
  --dcrd-bg: #f4f7fb;
  --dcrd-surface: #ffffff;
  --dcrd-border: #e6eaf0;
  --dcrd-muted: #6b7785;
  --dcrd-primary: #044B69;
  --dcrd-primary-2: #1d6fb8;
  --dcrd-shadow: 0 2px 12px rgba(16, 42, 67, .06);
  --dcrd-shadow-hov: 0 8px 28px rgba(16, 42, 67, .12);
  --dcrd-radius: 16px;

  --ok: #1aa179;       /* vert  — bon */
  --ok-bg: #e7f6f0;
  --warn: #e0a400;     /* jaune — attention */
  --warn-bg: #fdf5e0;
  --danger: #dc3545;   /* rouge — danger */
  --danger-bg: #fde8ea;
  --info: #1d6fb8;
  --info-bg: #e8f1fb;
}

/* ---------- En-tête de page ---------- */
.dcrd-page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem;
}
.dcrd-page-head h3 { font-weight: 700; color: var(--dcrd-primary); margin: 0; }
.dcrd-page-head .subtitle { color: var(--dcrd-muted); font-size: .9rem; }

/* ---------- Cards KPI ---------- */
.kpi-grid {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  margin-bottom: 1.5rem;
}
.kpi-card {
  position: relative; overflow: hidden;
  background: var(--dcrd-surface);
  border: 1px solid var(--dcrd-border);
  border-radius: var(--dcrd-radius);
  padding: 1.25rem 1.35rem;
  box-shadow: var(--dcrd-shadow);
  transition: transform .18s ease, box-shadow .18s ease;
}
.kpi-card:hover { transform: translateY(-3px); box-shadow: var(--dcrd-shadow-hov); }
.kpi-card .kpi-icon {
  position: absolute; right: 1rem; top: 1rem;
  width: 42px; height: 42px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem;
}
.kpi-card .kpi-label { color: var(--dcrd-muted); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi-card .kpi-value { font-size: 2.1rem; font-weight: 800; line-height: 1.1; margin-top: .35rem; color: var(--dcrd-primary); }
.kpi-card .kpi-sub { font-size: .8rem; color: var(--dcrd-muted); margin-top: .25rem; }
/* accent bar à gauche */
.kpi-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--dcrd-primary-2); }
.kpi-card.is-ok::before     { background: var(--ok); }
.kpi-card.is-warn::before   { background: var(--warn); }
.kpi-card.is-danger::before { background: var(--danger); }
.kpi-card.is-ok .kpi-icon     { background: var(--ok-bg); color: var(--ok); }
.kpi-card.is-warn .kpi-icon   { background: var(--warn-bg); color: var(--warn); }
.kpi-card.is-danger .kpi-icon { background: var(--danger-bg); color: var(--danger); }
.kpi-card.is-info .kpi-icon   { background: var(--info-bg); color: var(--info); }

/* ---------- Cartes / panneaux ---------- */
.dcrd-card {
  background: var(--dcrd-surface);
  border: 1px solid var(--dcrd-border);
  border-radius: var(--dcrd-radius);
  box-shadow: var(--dcrd-shadow);
  overflow: hidden;
  margin-bottom: 1.5rem;
}
.dcrd-card > .dcrd-card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--dcrd-border);
}
.dcrd-card > .dcrd-card-head h5 { margin: 0; font-weight: 700; color: var(--dcrd-primary); font-size: 1.02rem; }
.dcrd-card > .dcrd-card-body { padding: 1rem 1.25rem; }
.dcrd-card > .dcrd-card-body.p0 { padding: 0; }

/* ---------- Filtres ---------- */
.dcrd-filters {
  display: flex; gap: .75rem; flex-wrap: wrap; align-items: end;
  background: var(--dcrd-surface); border: 1px solid var(--dcrd-border);
  border-radius: 12px; padding: .85rem 1rem; box-shadow: var(--dcrd-shadow);
  margin-bottom: 1.25rem;
}
.dcrd-filters label { font-size: .75rem; font-weight: 600; color: var(--dcrd-muted); margin-bottom: .15rem; }

/* ---------- Tableaux ---------- */
.dcrd-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.dcrd-table thead th {
  background: #f3f6fb; color: var(--dcrd-muted);
  font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  padding: .7rem .9rem; border-bottom: 2px solid var(--dcrd-border);
  position: sticky; top: 0; z-index: 1;
}
.dcrd-table tbody td { padding: .7rem .9rem; border-bottom: 1px solid var(--dcrd-border); font-size: .9rem; vertical-align: middle; }
.dcrd-table tbody tr { transition: background .12s ease; }
.dcrd-table tbody tr:hover { background: #f7fafe; }
.dcrd-table tbody tr:last-child td { border-bottom: 0; }
.dcrd-table .num { font-variant-numeric: tabular-nums; text-align: right; }
.dcrd-table .ref { font-weight: 700; color: var(--dcrd-primary); }
.dcrd-empty { text-align: center; color: var(--dcrd-muted); padding: 2.5rem 1rem; }
.dcrd-empty i { font-size: 2rem; display: block; margin-bottom: .5rem; opacity: .5; }

/* ---------- Badges sémantiques ---------- */
.badge-soft { font-weight: 600; padding: .35em .65em; border-radius: 999px; font-size: .72rem; }
.badge-soft.ok     { background: var(--ok-bg); color: var(--ok); }
.badge-soft.warn   { background: var(--warn-bg); color: #9a7400; }
.badge-soft.danger { background: var(--danger-bg); color: var(--danger); }
.badge-soft.info   { background: var(--info-bg); color: var(--info); }
.badge-soft.muted  { background: #eef1f5; color: var(--dcrd-muted); }

/* ---------- Barre de progression taux ---------- */
.taux-bar { height: 22px; border-radius: 999px; background: #eef1f5; overflow: hidden; position: relative; }
.taux-bar > span {
  display: block; height: 100%; border-radius: 999px;
  color: #fff; font-size: .72rem; font-weight: 700; text-align: right;
  padding-right: .5rem; line-height: 22px; min-width: 2.2rem;
  transition: width .5s ease;
}
.taux-bar > span.ok     { background: linear-gradient(90deg, #1aa179, #34c79b); }
.taux-bar > span.warn   { background: linear-gradient(90deg, #e0a400, #f3c64b); }
.taux-bar > span.danger { background: linear-gradient(90deg, #dc3545, #f06d79); }

/* ---------- Pagination ---------- */
.dcrd-pagination { display: flex; align-items: center; justify-content: space-between; padding: .85rem 1.25rem; border-top: 1px solid var(--dcrd-border); flex-wrap: wrap; gap: .5rem; }
.dcrd-pagination .info { color: var(--dcrd-muted); font-size: .85rem; }
.dcrd-pagination .pages { display: flex; gap: .25rem; }
.dcrd-pagination .pages a, .dcrd-pagination .pages span {
  min-width: 34px; height: 34px; padding: 0 .5rem;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 9px; border: 1px solid var(--dcrd-border);
  color: var(--dcrd-primary); text-decoration: none; font-size: .85rem; background: #fff;
}
.dcrd-pagination .pages a:hover { background: var(--info-bg); }
.dcrd-pagination .pages .current { background: var(--dcrd-primary); color: #fff; border-color: var(--dcrd-primary); }
.dcrd-pagination .pages .disabled { opacity: .4; pointer-events: none; }

/* ---------- Boutons d'action compacts ---------- */
.btn-icon { padding: .3rem .55rem; line-height: 1; }

/* ---------- Graphique combiné barres + courbe cumul ---------- */
.stats-legend { display: flex; gap: 1rem; font-size: .78rem; color: var(--dcrd-muted); }
.stats-legend .lg-swatch { display: inline-block; width: 14px; height: 10px; border-radius: 2px; vertical-align: middle; margin-right: .25rem; }
.stats-legend .lg-bar { background: var(--dcrd-primary-2); }
.stats-legend .lg-line { background: var(--warn); border-radius: 999px; height: 4px; }

.combo-chart { padding-top: .5rem; }
.combo-plot { position: relative; display: flex; align-items: flex-end; gap: .5rem; height: 220px; }
.combo-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
.combo-val { font-size: .68rem; color: var(--dcrd-muted); line-height: 1; margin-bottom: 2px; }
.combo-bar { width: 70%; min-height: 2px; border-radius: 4px 4px 0 0;
  background: linear-gradient(180deg, var(--dcrd-primary-2), var(--dcrd-primary)); }
/* Courbe de ligne cumulée superposée (SVG étiré sur la zone des barres) */
.combo-line { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 2; }
.combo-line polyline { stroke: var(--warn); stroke-width: 2.5px; stroke-linejoin: round;
  stroke-linecap: round; vector-effect: non-scaling-stroke; }
.combo-dot { position: absolute; width: 8px; height: 8px; margin: -4px 0 0 -4px;
  background: var(--warn); border: 2px solid #fff; border-radius: 50%;
  box-shadow: 0 0 0 1px var(--warn); z-index: 3; }
.combo-axis { display: flex; gap: .5rem; margin-top: .25rem; }
.combo-x { flex: 1; text-align: center; font-size: .65rem; color: var(--dcrd-muted); }

/* Masquer à l'impression (bouton retour global, actions…) */
@media print { .no-print { display: none !important; } }

/* Carte de formulaire étroite, centrée horizontalement (création/édition, profil…).
   Largeur ajustable via --card-w (défaut 680px). */
.dcrd-card-narrow { max-width: var(--card-w, 680px); margin-left: auto; margin-right: auto; }

/* ============================================================
   RESPONSIVE — tablette & smartphone UNIQUEMENT.
   Rien de ce qui suit ne s'applique au desktop (>= 992px) : la version
   PC reste strictement inchangée.
   ============================================================ */
@media (max-width: 991.98px) {
  /* Tableaux scrollables horizontalement (seulement en dessous du desktop). */
  .dcrd-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .dcrd-table td, .dcrd-table th { white-space: nowrap; }

  /* Wizard : pastilles d'étapes défilables. */
  .wizard-steps { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .wizard-steps .step-pill { flex: 0 0 auto; }
}

/* Smartphone (< 768px) : empilements et paddings réduits. */
@media (max-width: 767.98px) {
  .app-container, .container-fluid { padding-left: .75rem; padding-right: .75rem; }

  /* En-tête de page : titre au-dessus, bouton d'action en dessous. */
  .dcrd-page-head { flex-direction: column; align-items: stretch; gap: .6rem; }
  .dcrd-page-head h3 { font-size: 1.25rem; }
  .dcrd-page-head > a.btn, .dcrd-page-head > .btn { width: 100%; }

  /* KPI : 1 colonne. */
  .kpi-grid { grid-template-columns: 1fr; gap: .75rem; }

  /* Cartes étroites : pleine largeur. */
  .dcrd-card-narrow { max-width: 100% !important; }

  /* Filtres : empilés verticalement. */
  .dcrd-filters { flex-direction: column; align-items: stretch; }
  .dcrd-filters > * { width: 100%; }

  /* Barre de synthèse de la fiche de contrôle : empilée. */
  .synthese-live { flex-direction: column; align-items: flex-start; gap: .35rem; }
}
