@font-face { font-family: 'Plex'; src: url(/fonts/plex-400.woff2) format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Plex'; src: url(/fonts/plex-500.woff2) format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Plex'; src: url(/fonts/plex-600.woff2) format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'PlexMono'; src: url(/fonts/plexmono-400.woff2) format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'PlexMono'; src: url(/fonts/plexmono-500.woff2) format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Barlow'; src: url(/fonts/barlow-600.woff2) format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Barlow'; src: url(/fonts/barlow-700.woff2) format('woff2'); font-weight: 700; font-display: swap; }

:root {
  --slate: #1C3436;       /* ardoise : panneaux, en-têtes */
  --slate-2: #27474A;
  --copper: #B4562A;      /* cuivre : accent, actions */
  --copper-d: #8F3F1B;
  --malachite: #2C7A64;   /* malachite : conforme / OK */
  --bg: #E9EDEB;          /* gris béton clair */
  --card: #FFFFFF;
  --ink: #142426;
  --mute: #5A6A6B;
  --line: #CDD6D3;
  --line-2: #E2E8E5;
  --warn: #A3610A; --warn-bg: #FCF1DC;
  --bad: #A3271B; --bad-bg: #FBE4E0;
  --ok-bg: #E0F0EA;
  --info-bg: #E6EEF0;
  --radius: 6px;
  --display: 'Barlow', 'Arial Narrow', sans-serif;
  --body: 'Plex', 'Segoe UI', system-ui, sans-serif;
  --mono: 'PlexMono', ui-monospace, Consolas, monospace;
  --side: 268px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--body); font-size: 14.5px; color: var(--ink); background: var(--bg); line-height: 1.45; -webkit-text-size-adjust: 100%; }
a { color: var(--copper-d); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--copper); outline-offset: 2px; }
.num, td.n, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: .01em; margin: 0; }
h1 { font-size: 30px; line-height: 1.05; }
h2 { font-size: 21px; }
h3 { font-size: 16.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--slate-2); }
.hidden { display: none !important; }

/* ---------- Structure ---------- */
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side {
  background: linear-gradient(180deg, #132426 0%, #172C2E 60%, #101E20 100%);
  color: #DCE6E3;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.07);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.16);
  user-select: none;
  z-index: 20;
}

/* Brand header */
.brand {
  padding: 16px 16px 14px;
  background: rgba(0, 0, 0, 0.18);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  gap: 12px;
  align-items: center;
}
.brand-mark { width: 38px; height: 38px; flex: none; filter: drop-shadow(0 2px 8px rgba(180, 86, 42, 0.35)); }
.brand-text { flex: 1; min-width: 0; }
.brand-title { display: flex; align-items: center; gap: 6px; }
.brand b { font-family: var(--display); font-size: 19px; font-weight: 700; letter-spacing: .08em; color: #FFFFFF; line-height: 1.1; }
.brand .plant-live { display: inline-flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 11px; color: #9EC0BA; letter-spacing: 0.02em; }
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #34D399;
  box-shadow: 0 0 8px #34D399;
  display: inline-block;
  animation: pulseDot 2.2s infinite ease-in-out;
}
@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.85); }
}

/* Quick search / filter in sidebar */
.side-search { padding: 10px 14px 4px; position: relative; }
.side-search input {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 7px;
  padding: 7px 10px 7px 32px;
  color: #fff;
  font-size: 12.5px;
  outline: none;
  transition: all 0.2s ease;
}
.side-search input::placeholder { color: rgba(220, 230, 227, 0.45); }
.side-search input:focus {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--copper);
  box-shadow: 0 0 0 2px rgba(180, 86, 42, 0.25);
}
.side-search svg {
  position: absolute;
  left: 23px;
  top: 18px;
  width: 14px;
  height: 14px;
  color: rgba(220, 230, 227, 0.45);
  pointer-events: none;
}

/* Scrollable nav items */
.side-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 10px 16px;
}
.side-scroll::-webkit-scrollbar { width: 4px; }
.side-scroll::-webkit-scrollbar-track { background: transparent; }
.side-scroll::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 4px; }
.side-scroll::-webkit-scrollbar-thumb:hover { background: rgba(180, 86, 42, 0.5); }

/* Nav items & groups */
.nav { padding: 4px 0; }
.nav-group {
  font-family: var(--display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: #6C8783;
  padding: 14px 10px 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.nav-group::after { content: ''; flex: 1; height: 1px; background: rgba(255, 255, 255, 0.06); }
.nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 12px;
  margin: 2px 0;
  border-radius: 7px;
  color: #BFCEC9;
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.16s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
}
.nav a:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #FFFFFF;
  transform: translateX(3px);
}
.nav a.active {
  background: linear-gradient(90deg, rgba(180, 86, 42, 0.26) 0%, rgba(180, 86, 42, 0.08) 100%);
  color: #FFFFFF;
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(180, 86, 42, 0.4);
}
.nav a.active::before {
  content: '';
  position: absolute;
  left: -2px;
  top: 6px;
  bottom: 6px;
  width: 3.5px;
  background: var(--copper);
  border-radius: 2px;
  box-shadow: 0 0 10px rgba(180, 86, 42, 0.6);
}
.nav a svg {
  width: 17px;
  height: 17px;
  flex: none;
  opacity: .75;
  transition: opacity 0.16s ease, transform 0.16s ease;
}
.nav a:hover svg,
.nav a.active svg {
  opacity: 1;
  color: #EFA682;
}
.nav .badge {
  margin-left: auto;
  font-size: 10.5px;
  padding: 1px 7px;
  border-radius: 12px;
  background: rgba(180, 86, 42, 0.28);
  color: #F8C3AC;
  border: 1px solid rgba(180, 86, 42, 0.45);
}

/* User profile card footer */
.side-foot {
  padding: 14px 14px 16px;
  background: rgba(0, 0, 0, 0.24);
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.user-card { display: flex; align-items: center; gap: 11px; }
.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: linear-gradient(135deg, #B4562A 0%, #682E14 100%);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13.5px;
  letter-spacing: .03em;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.15);
  flex: none;
}
.user-meta { flex: 1; min-width: 0; }
.user-name {
  color: #FFFFFF;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  line-height: 1.25;
}
.user-role-badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 500;
  color: #EAA888;
  background: rgba(180, 86, 42, 0.18);
  padding: 1px 6px;
  border-radius: 4px;
  margin-top: 2px;
  letter-spacing: .02em;
}
.user-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.user-actions .btn {
  padding: 5px 8px;
  font-size: 11.5px;
  justify-content: center;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #DCE6E3;
  min-height: 30px;
  transition: all 0.16s ease;
}
.user-actions .btn:hover {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.2);
}
.user-actions .btn.logout-btn:hover {
  background: rgba(163, 39, 27, 0.25);
  color: #FFB3AA;
  border-color: rgba(163, 39, 27, 0.5);
}
.main { min-width: 0; }
.topbar { display: none; }
.page { padding: 26px 30px 60px; max-width: 1480px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .eyebrow { font-family: var(--display); font-size: 13px; letter-spacing: .16em; text-transform: uppercase; color: var(--copper); margin-bottom: 4px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.demo-ribbon { background: repeating-linear-gradient(-45deg, #F6E3C6, #F6E3C6 10px, #F2D9B4 10px, #F2D9B4 20px); color: #6B3E0A; font-size: 12.5px; padding: 6px 30px; border-bottom: 1px solid #E3C08E; }

/* ---------- Composants ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.card-pad { padding: 18px 20px; }
.card h3 { margin-bottom: 12px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 5px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 500; font-size: 14px; text-decoration: none; color: var(--ink); white-space: nowrap; min-height: 38px; }
.btn:hover { border-color: #9DAEAA; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--copper); border-color: var(--copper); color: #fff; }
.btn.primary:hover { background: var(--copper-d); }
.btn.dark { background: var(--slate); border-color: var(--slate); color: #fff; }
.btn.danger { color: var(--bad); border-color: #E6B7B0; }
.btn.ghost { background: transparent; border-color: transparent; color: inherit; }
.side .btn.ghost { color: #DCE6E3; border-color: rgba(255,255,255,.2); padding: 5px 10px; min-height: 0; font-size: 13px; }
.btn.sm { padding: 4px 9px; font-size: 13px; min-height: 30px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: 7px 14px; cursor: pointer; font-weight: 500; border-right: 1px solid var(--line); min-height: 36px; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--slate); color: #fff; }
.badge { display: inline-flex; align-items: center; font-size: 11.5px; font-weight: 600; padding: 2.5px 8px; border-radius: 12px; background: var(--info-bg); color: var(--slate-2); white-space: nowrap; letter-spacing: .02em; border: 1px solid rgba(0, 0, 0, 0.05); }
.badge.ok { background: #E1F4EC; color: #176B55; border-color: #BBE7D7; }
.badge.warn { background: #FEF4DC; color: #965406; border-color: #F8DF9E; }
.badge.bad { background: #FDE8E4; color: #A82518; border-color: #F6C1B8; }
.badge.cu { background: #F8E8DF; color: #8F3F1B; border-color: #ECC8B5; }
.nav .badge { background: var(--copper); color: #fff; border-color: transparent; }
.muted { color: var(--mute); }
.small { font-size: 12.5px; }
.flag { display: flex; gap: 9px; align-items: flex-start; padding: 7px 10px; border-radius: 5px; font-size: 13.5px; margin-bottom: 6px; }
.flag b { font-size: 10.5px; letter-spacing: .08em; font-weight: 600; padding-top: 2px; flex: none; width: 92px; }
.flag.manquant { background: var(--warn-bg); } .flag.manquant b { color: var(--warn); }
.flag.incoherent, .flag.hors_limite { background: var(--bad-bg); } .flag.incoherent b, .flag.hors_limite b { color: var(--bad); }
.flag.info { background: var(--info-bg); } .flag.info b { color: var(--slate-2); }
.empty { padding: 34px 20px; text-align: center; color: var(--mute); }

/* ---------- KPI ---------- */
.kpi { padding: 14px 16px 13px; position: relative; }
.kpi .lbl { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--mute); font-weight: 500; }
.kpi .val { font-family: var(--display); font-weight: 700; font-size: 34px; line-height: 1.05; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .val small { font-family: var(--body); font-size: 14px; font-weight: 500; color: var(--mute); margin-left: 3px; }
.kpi .sub { font-size: 12.5px; color: var(--mute); margin-top: 3px; }
.kpi.nd .val { color: var(--warn); }
.kpi .bar { height: 4px; background: var(--line-2); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.kpi .bar i { display: block; height: 100%; background: var(--malachite); }

/* ---------- Schéma de bilan (signature) ---------- */
.flowsheet { padding: 18px 20px 20px; background: var(--slate); color: #E6EEEB; border-color: var(--slate); }
.flowsheet h3 { color: #E5A07D; }
.flow { display: grid; grid-template-columns: 1fr 1.1fr 1fr; gap: 0; align-items: stretch; margin-top: 6px; }
.flow-node { border: 1px solid rgba(255,255,255,.18); border-radius: 6px; padding: 12px 14px; background: rgba(255,255,255,.03); }
.flow-node .t { font-family: var(--display); font-size: 13px; letter-spacing: .14em; text-transform: uppercase; color: #9FB3AF; }
.flow-node .big { font-family: var(--display); font-size: 30px; font-weight: 700; color: #fff; line-height: 1.1; }
.flow-node .big small { font-size: 14px; color: #9FB3AF; font-family: var(--body); font-weight: 400; }
.flow-node .grade { font-family: var(--mono); font-size: 13px; color: #F0B994; margin-top: 2px; }
.flow-mid { display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 0 12px; position: relative; }
.flow-mid::before { content: ''; position: absolute; left: 0; right: 0; top: 50%; height: 2px; background: linear-gradient(90deg, rgba(229,160,125,.2), #E5A07D, rgba(229,160,125,.2)); }
.flow-mid .rec { position: relative; background: var(--copper); color: #fff; border-radius: 50%; width: 118px; height: 118px; display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: 0 0 0 6px rgba(180,86,42,.22); }
.flow-mid .rec b { font-family: var(--display); font-size: 32px; line-height: 1; }
.flow-mid .rec span { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; opacity: .9; }
.flow-mid .rec.nd { background: #6B5A3A; }
.flow-out { display: grid; gap: 8px; }
.flow-out .flow-node { padding: 9px 14px; }
.flow-out .flow-node .big { font-size: 24px; }
.flow-foot { display: flex; gap: 22px; flex-wrap: wrap; margin-top: 14px; font-size: 13px; color: #B8C8C4; }
.flow-foot b { color: #fff; font-family: var(--mono); font-weight: 500; }

/* ---------- Tableaux universels KCM ---------- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03), 0 3px 12px rgba(28, 52, 54, 0.04);
  scrollbar-width: thin;
  scrollbar-color: #B2C2BE transparent;
  position: relative;
  max-height: calc(100vh - 280px);
}
.table-wrap::-webkit-scrollbar { height: 7px; width: 7px; }
.table-wrap::-webkit-scrollbar-track { background: transparent; }
.table-wrap::-webkit-scrollbar-thumb { background: #CBD8D5; border-radius: 4px; }
.table-wrap::-webkit-scrollbar-thumb:hover { background: #96A8A4; }

.card > .table-wrap,
.card-pad .table-wrap {
  box-shadow: none;
  border-color: var(--line-2);
}

table.t {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
  line-height: 1.42;
  color: var(--ink);
}

/* En-têtes modernes et contrastés KCM */
table.t th,
table.t thead th {
  text-align: left;
  font-family: var(--display);
  font-weight: 700;
  font-size: 11.5px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: #FFFFFF;
  background: #1C3436;
  padding: 11px 14px;
  border-bottom: 2px solid var(--copper);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 5;
  box-shadow: 0 1px 0 rgba(0,0,0,0.1);
}

table.t th:first-child { border-top-left-radius: 7px; }
table.t th:last-child { border-top-right-radius: 7px; }

table.t td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-2);
  vertical-align: middle;
  transition: background-color 0.12s ease;
}

table.t td.n, table.t th.n {
  text-align: right;
  white-space: nowrap;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* Zébrage subtil */
table.t tbody tr:nth-child(even) td {
  background-color: #FAFCFB;
}
table.t tbody tr:nth-child(odd) td {
  background-color: #FFFFFF;
}

/* Survol interactif */
table.t tbody tr {
  cursor: pointer;
}
table.t tbody tr:hover td {
  background-color: #EDF4F2 !important;
  color: #0C1A1C;
}

/* Colonnes figées (Sticky columns) */
.t th.sticky-col, .t td.sticky-col {
  position: sticky;
  left: 0;
  z-index: 4;
  background: #FFFFFF;
  box-shadow: 2px 0 6px rgba(0, 0, 0, 0.05);
}
.t thead th.sticky-col, .t th.sticky-col {
  background: #1C3436;
  color: #FFFFFF;
  z-index: 6;
}
.t th.sticky-col-second, .t td.sticky-col-second {
  position: sticky;
  left: 68px;
  z-index: 4;
  background: #FFFFFF;
  box-shadow: 2px 0 6px rgba(0, 0, 0, 0.04);
}
.t thead th.sticky-col-second, .t th.sticky-col-second {
  background: #1C3436;
  color: #FFFFFF;
  z-index: 6;
}
.t tbody tr:nth-child(even) td.sticky-col,
.t tbody tr:nth-child(even) td.sticky-col-second {
  background-color: #FAFCFB;
}
.t tbody tr:hover td.sticky-col,
.t tbody tr:hover td.sticky-col-second {
  background-color: #EDF4F2 !important;
}

/* Ligne Total / Synthèse */
table.t tr.total td {
  font-weight: 700;
  font-size: 13.5px;
  color: var(--slate);
  background: #E8F0ED !important;
  border-top: 2px solid var(--slate);
  border-bottom: none;
  padding: 12px 14px;
}
table.t tr.total td:first-child { border-bottom-left-radius: 7px; }
table.t tr.total td:last-child { border-bottom-right-radius: 7px; }

/* ========================================================
   OPTIMISATION DES LARGEURS DE COLONNES (KCM TABLE SIZING)
   Régulation stricte des min-width selon les types de données
   ======================================================== */

/* 1. Colonne ID (#1, #240) */
table.t th.col-id,
table.t td.col-id {
  width: 68px;
  min-width: 68px;
  max-width: 78px;
  text-align: center;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* 2. Colonne Code court / Référence (ex: CONC-260827, P1, LOT-04) */
table.t th.col-code,
table.t td.col-code {
  min-width: 135px;
  max-width: 185px;
  font-family: var(--mono);
  font-size: 13px;
  white-space: nowrap;
}

/* 3. Colonne Libellés, Noms, Désignations, Équipements, Articles (PRIORITAIRE) */
/* Ampleur généreuse pour ne jamais écraser les noms et intitulés */
table.t th.col-label,
table.t td.col-label {
  min-width: 220px;
  max-width: 380px;
  font-weight: 500;
  text-align: left;
  line-height: 1.4;
}

/* 4. Colonne Descriptifs longs, Causes, Opérations, Observations */
table.t th.col-desc,
table.t td.col-desc,
table.t td.wrap {
  min-width: 280px;
  max-width: 480px;
  white-space: normal;
  text-align: left;
  line-height: 1.45;
}

/* 5. Colonne Personnes / Intervenants (Responsable, Opérateur, Technicien) */
table.t th.col-person,
table.t td.col-person {
  min-width: 160px;
  max-width: 230px;
  white-space: nowrap;
  text-align: left;
}

/* 6. Colonne Poste opérationnel */
table.t th.col-shift,
table.t td.col-shift {
  min-width: 160px;
  white-space: nowrap;
  font-weight: 600;
  text-align: left;
}

/* 7. Colonne Équipe */
table.t th.col-team,
table.t td.col-team {
  min-width: 110px;
  white-space: nowrap;
  text-align: center;
}

/* 8. Colonne Catégorie, Nature, Zone, Type, Origine */
table.t th.col-cat,
table.t td.col-cat {
  min-width: 130px;
  max-width: 200px;
  white-space: nowrap;
  text-align: left;
}

/* 9. Colonne Date seule */
table.t th.col-date,
table.t td.col-date {
  min-width: 115px;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 13px;
  text-align: center;
}

/* 10. Colonne Date & Heure */
table.t th.col-datetime,
table.t td.col-datetime {
  min-width: 155px;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 13px;
  text-align: left;
}

/* 11. Colonne Heure ou créneau horaire */
table.t th.col-time,
table.t td.col-time {
  min-width: 95px;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 13px;
  text-align: center;
}

/* 12. Colonne Chiffres / Tonnages */
table.t th.col-num,
table.t td.col-num {
  min-width: 105px;
  text-align: right;
  white-space: nowrap;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

/* 13. Colonne KPI Clés / Teneurs / Rendements / Récupérations */
table.t th.col-kpi,
table.t td.col-kpi {
  min-width: 115px;
  text-align: right;
  white-space: nowrap;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* 14. Colonne Statut / Badges / Validation */
table.t th.col-status,
table.t td.col-status,
table.t th.sticky-status,
table.t td.sticky-status {
  min-width: 125px;
  text-align: center;
  white-space: nowrap;
}

/* 15. Colonne Bouton d'action */
table.t th.col-action,
table.t td.col-action {
  min-width: 110px;
  text-align: center;
  white-space: nowrap;
}

/* Règles universelles de sécurité pour tout le tableau :
   Garantit qu'aucun en-tête ni libellé ne soit étouffé */
table.t th {
  min-width: 90px;
}
table.t td:not(.n):not(.col-id) {
  min-width: 120px;
}

td .nd {
  color: #9A5808;
  font-family: var(--body);
  font-size: 12px;
  font-style: italic;
  font-weight: 500;
}

.mod-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warn);
  margin-left: 6px;
  vertical-align: middle;
  box-shadow: 0 0 0 2px rgba(163, 97, 10, 0.2);
}

/* ---------- Filtres ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 12px 14px; border-bottom: 1px solid var(--line); background: #F9FBFA; border-radius: var(--radius) var(--radius) 0 0; }
.filters label { font-size: 11.5px; color: var(--mute); font-weight: 500; display: flex; flex-direction: column; gap: 3px; }
.filters input, .filters select { min-width: 120px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; background: #fff; min-height: 36px; }
.list-foot { padding: 10px 14px; font-size: 12.5px; color: var(--mute); display: flex; gap: 12px; flex-wrap: wrap; }

/* ---------- Formulaires ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px 16px; }
.fgroup { margin-bottom: 18px; }
.fgroup > .gt { font-family: var(--display); font-size: 14px; letter-spacing: .12em; text-transform: uppercase; color: var(--copper); border-bottom: 1px solid var(--line); padding-bottom: 4px; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.wide { grid-column: 1 / -1; }
.field > span { font-size: 13px; font-weight: 500; }
.field > span em { color: var(--copper); font-style: normal; }
.field .unit-wrap { display: flex; align-items: stretch; }
.field .unit-wrap input { border-radius: 4px 0 0 4px; flex: 1; min-width: 0; }
.field .unit { background: #EEF2F0; border: 1px solid var(--line); border-left: 0; border-radius: 0 4px 4px 0; padding: 0 9px; display: flex; align-items: center; font-size: 12.5px; color: var(--mute); font-family: var(--mono); }
.field input, .field select, .field textarea { padding: 8px 10px; border: 1px solid #B9C6C2; border-radius: 4px; background: #fff; min-height: 40px; width: 100%; }
.field textarea { min-height: 76px; resize: vertical; }
.field input[readonly] { background: #F2F5F4; }
.field .hint { font-size: 12px; color: var(--mute); }
.field .err { font-size: 12.5px; color: var(--bad); font-weight: 500; }
.field.has-err input, .field.has-err select, .field.has-err textarea { border-color: var(--bad); background: #FFF8F7; }
.date-wrap { display: flex; gap: 0; }
.date-wrap input[type=text] { border-radius: 4px 0 0 4px; }
.date-wrap .pick { border: 1px solid #B9C6C2; border-left: 0; background: #F2F5F4; border-radius: 0 4px 4px 0; width: 42px; cursor: pointer; position: relative; display: flex; align-items: center; justify-content: center; }
.date-wrap .pick svg { width: 16px; height: 16px; }
.date-wrap .pick input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; padding: 0; border: 0; min-height: 0; }
.dt-pair { display: grid; grid-template-columns: 1fr 96px; gap: 6px; }
.chk { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.chk input { width: 20px; height: 20px; min-height: 0; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 14px; border-top: 1px solid var(--line); margin-top: 6px; position: sticky; bottom: 0; background: #fff; padding-bottom: 6px; }
.calc-panel { background: #F6F8F7; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.calc-steps { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.calc-steps td { padding: 5px 4px; border-bottom: 1px dashed var(--line); vertical-align: top; }
.calc-steps td.f { font-family: var(--mono); font-size: 12px; color: var(--mute); }
.calc-steps td.v { font-family: var(--mono); text-align: right; white-space: nowrap; font-weight: 500; }
.calc-head { display: flex; gap: 16px; flex-wrap: wrap; }
.calc-head .kpi { padding: 0; }
.calc-head .kpi .val { font-size: 28px; }

/* ---------- Modale / panneau ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15,30,32,.45); z-index: 50; display: flex; justify-content: flex-end; }
.drawer { background: #fff; width: min(920px, 100%); height: 100%; overflow-y: auto; box-shadow: -10px 0 30px rgba(0,0,0,.15); display: flex; flex-direction: column; }
.drawer-head { padding: 16px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; position: sticky; top: 0; background: #fff; z-index: 2; }
.drawer-head h2 { flex: 1; }
.drawer-body { padding: 18px 22px 24px; flex: 1; }
.modal-c { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: rgba(15,30,32,.5); padding: 16px; }
.modal { background: #fff; border-radius: 8px; width: min(520px, 100%); padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,.25); max-height: 92vh; overflow-y: auto; }
.modal h2 { margin-bottom: 10px; }
.modal .field { margin: 12px 0; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 9px 14px; cursor: pointer; font-weight: 500; color: var(--mute); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--copper); }
.meta-line { font-size: 12.5px; color: var(--mute); display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.hist { border-left: 2px solid var(--line); padding-left: 14px; }
.hist-item { margin-bottom: 14px; position: relative; }
.hist-item::before { content: ''; position: absolute; left: -20px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--copper); }
.hist-item .h { font-size: 13px; font-weight: 600; }
.hist-item .d { font-size: 12.5px; color: var(--mute); }
.hist-item table { font-size: 12.5px; border-collapse: collapse; margin-top: 4px; }
.hist-item td { padding: 2px 8px 2px 0; }
.hist-item td.old { color: var(--bad); text-decoration: line-through; font-family: var(--mono); }
.hist-item td.new { color: var(--malachite); font-family: var(--mono); }
dl.kv { display: grid; grid-template-columns: minmax(150px, 220px) 1fr; gap: 0; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--mute); padding: 7px 0; border-bottom: 1px solid var(--line-2); font-size: 13px; }
dl.kv dd { margin: 0; padding: 7px 0; border-bottom: 1px solid var(--line-2); white-space: pre-wrap; }
.toast-zone { position: fixed; bottom: 18px; right: 18px; z-index: 90; display: flex; flex-direction: column; gap: 8px; max-width: min(440px, calc(100vw - 36px)); }
.toast { background: var(--slate); color: #fff; padding: 11px 16px; border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.2); font-size: 14px; border-left: 4px solid var(--malachite); }
.toast.err { border-left-color: #E06A5A; }

/* ---------- Connexion ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { background: var(--slate); color: #DCE6E3; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.login-art .strata { position: absolute; inset: auto 0 0 0; height: 46%; opacity: .9; }
.login-art h1 { font-size: 54px; color: #fff; letter-spacing: .02em; max-width: 9ch; line-height: .98; }
.login-art p { max-width: 42ch; color: #B8C8C4; }
.login-art .cu { font-family: var(--display); font-size: 15px; letter-spacing: .2em; color: #E5A07D; }
.login-form { display: flex; align-items: center; justify-content: center; padding: 32px; }
.login-form form { width: min(380px, 100%); }
.login-form h2 { font-size: 28px; margin-bottom: 4px; }
.login-form .field { margin: 14px 0; }
.alert { padding: 10px 12px; border-radius: 5px; background: var(--bad-bg); color: var(--bad); font-size: 13.5px; margin: 10px 0; }
.alert.info { background: var(--info-bg); color: var(--slate-2); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.pw-rules { font-size: 12.5px; color: var(--mute); margin: 0; padding-left: 18px; }
.pw-rules li.ok { color: var(--malachite); }

.chart-box { position: relative; height: 240px; }
.guide h2 { margin: 26px 0 8px; } .guide ol, .guide ul { padding-left: 22px; } .guide li { margin: 4px 0; } .guide p { max-width: 80ch; }
.guide code { font-family: var(--mono); background: #EEF2F0; padding: 1px 5px; border-radius: 3px; font-size: 13px; }

/* ---------- Mobile / tablette ---------- */
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 280px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 10px 0 30px rgba(0,0,0,.3); }
  .topbar { display: flex; align-items: center; gap: 10px; background: var(--slate); color: #fff; padding: 8px 12px; position: sticky; top: 0; z-index: 30; }
  .topbar b { font-family: var(--display); letter-spacing: .06em; font-size: 19px; }
  .topbar button { background: none; border: 0; color: #fff; padding: 6px; min-height: 40px; min-width: 40px; }
  .page { padding: 16px 14px 60px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  h1 { font-size: 25px; }
  .flow { grid-template-columns: 1fr; gap: 10px; }
  .flow-mid { padding: 8px 0; } .flow-mid::before { left: 50%; right: auto; top: 0; bottom: 0; width: 2px; height: auto; }
  .login { grid-template-columns: 1fr; }
  .login-art { padding: 26px; min-height: 210px; } .login-art h1 { font-size: 36px; } .login-art p { display: none; }
  .drawer-body { padding: 14px; } .drawer-head { padding: 12px 14px; }
  dl.kv { grid-template-columns: 1fr; } dl.kv dt { border-bottom: 0; padding-bottom: 0; }
  .demo-ribbon { padding: 6px 14px; }
  .page-head .actions { margin-left: 0; width: 100%; }
}
@media (max-width: 520px) { .g4 { grid-template-columns: 1fr 1fr; } .kpi .val { font-size: 27px; } .filters input, .filters select { min-width: 0; width: 100%; } .filters label { flex: 1 1 45%; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media print { .side, .topbar, .page-head .actions, .filters, .btn { display: none !important; } .shell { display: block; } body { background: #fff; } .card { border-color: #999; } }
.date-wrap { min-width: 0; }
.date-wrap input[type=text] { flex: 1; min-width: 0; width: 100%; }
.page-head .actions > div[style*="width:150px"] { flex: 0 0 150px; }
@media (max-width: 520px) { .filters .date-wrap .pick { width: 36px; } table.t td { white-space: nowrap; } table.t td.wrap { white-space: normal; min-width: 180px; } }

/* ---------- Cockpits métiers ---------- */
.card-alert-bad { border-left: 4px solid var(--bad); }
.card-alert-warn { border-left: 4px solid var(--warn); }
.card-alert-ok { border-left: 4px solid var(--malachite); }
.badge.urgent { background: var(--bad); color: #fff; animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.7; } }


/* ========================================================
   MODERNISATION UI/UX KCM (Filtres, Tableaux, Tactile, Sticky)
   ======================================================== */

/* Conteneur et barre de filtres moderne */
.card-table { overflow: hidden; }
.filter-shell { background: #FAFBFB; border-bottom: 1px solid var(--line); }
.filters-bar { padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.filter-main-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 220px;
  max-width: 380px;
}
.search-wrap svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--mute);
  pointer-events: none;
}
.search-wrap input {
  width: 100%;
  padding: 8px 30px 8px 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13.5px;
  background: #fff;
  transition: all 0.16s ease;
  min-height: 38px;
}
.search-wrap input:focus {
  border-color: var(--copper);
  box-shadow: 0 0 0 3px rgba(180, 86, 42, 0.15);
  outline: none;
}
.btn-clear-q {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--mute);
  cursor: pointer;
  padding: 3px 6px;
  font-size: 13px;
  border-radius: 4px;
}
.btn-clear-q:hover { color: var(--ink); background: rgba(0,0,0,0.06); }

/* Raccourcis de dates rapides */
.date-quick-presets { display: inline-flex; gap: 4px; align-items: center; }
.preset-btn {
  padding: 4px 9px;
  font-size: 12px;
  border-radius: 5px;
  border: 1px solid var(--line-2);
  background: #fff;
  color: var(--slate-2);
  min-height: 32px;
  transition: all 0.15s ease;
}
.preset-btn:hover { background: var(--info-bg); border-color: var(--slate-2); }

.date-range-box { display: inline-flex; align-items: center; gap: 6px; }
.range-lbl { font-size: 12px; color: var(--mute); font-weight: 500; }
.date-range-box .date-wrap input { width: 115px; min-height: 36px; font-size: 13px; }

/* Filtres avancés dépliables */
.filters-adv {
  background: #FFFFFF;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 12px 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
  animation: slideDown 0.18s ease-out;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.adv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px 14px;
}
.adv-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--mute); font-weight: 500; }
.adv-field input, .adv-field select {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 13px;
  background: #fff;
  min-height: 36px;
}
.adv-field input:focus, .adv-field select:focus {
  border-color: var(--copper);
  outline: none;
}

/* Pastilles chips de filtres actifs */
.active-chips-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding-top: 6px;
  border-top: 1px dashed var(--line-2);
}
.chips-label { font-size: 12px; color: var(--mute); font-weight: 500; margin-right: 4px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 14px;
  background: var(--info-bg);
  border: 1px solid rgba(39, 71, 74, 0.15);
  color: var(--slate);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.14s ease;
}
.chip:hover { background: #D6E4E7; border-color: var(--slate); }
.btn-clear-all {
  background: none;
  border: none;
  color: var(--copper);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 6px;
  text-decoration: underline;
}

/* Groupe de boutons d'export */
.btn-group { display: inline-flex; border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.btn-group .btn { border-radius: 0; border: 0; border-right: 1px solid var(--line); }
.btn-group .btn:last-child { border-right: 0; }



/* Tiroir latéral moderne avec sticky footer */
.drawer { max-width: 800px; display: flex; flex-direction: column; }
.drawer-scroll-pane { flex: 1; overflow-y: auto; padding: 0 2px 14px; }
.drawer-footer {
  position: sticky;
  bottom: 0;
  background: #FFFFFF;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  z-index: 10;
}
.drawer-footer .btn.primary { min-width: 140px; justify-content: center; font-weight: 600; }

/* Optimisations tactiles (tablettes et smartphones) */
@media (max-width: 900px) {
  .drawer { width: 100% !important; max-width: 100% !important; }
  .table-wrap { max-height: none; }
  .filter-main-row { gap: 8px; }
  .search-wrap { max-width: 100%; min-width: 100%; }
  .date-quick-presets { overflow-x: auto; max-width: 100%; padding-bottom: 2px; }
  .btn, .field input, .field select, .field textarea { min-height: 44px; }
}

@media (max-width: 640px) {
  .page { padding: 12px 12px 60px; }
  .page-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .page-head .actions { width: 100%; justify-content: flex-start; }
  .date-range-box { flex-wrap: wrap; width: 100%; }
  .date-range-box .date-wrap { flex: 1; }
  .adv-grid { grid-template-columns: 1fr; }
  .drawer-footer { flex-direction: column; align-items: stretch; }
  .drawer-footer .btn { width: 100%; justify-content: center; min-height: 44px; }
}
