@import url('https://fonts.googleapis.com/css2?family=Public+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500&display=swap');

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Public Sans', system-ui, sans-serif;
  background: #F5F6F8;
  color: #12151B;
  font-size: 14px;
}
.num { font-family: 'IBM Plex Mono', monospace; font-variant-numeric: tabular-nums; }
a { color: inherit; }
button { font-family: inherit; cursor: pointer; }

/* --- Layout --- */
#app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: #1B2430; box-sizing: border-box;
  padding: 20px 14px; display: flex; flex-direction: column; gap: 24px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: #5B8DEF; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 13px; }
.brand-name { color: #fff; font-weight: 700; font-size: 15px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.navlink { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 8px; color: #AEB6C4; font-size: 14px; font-weight: 500; text-decoration: none; border: none; background: none; text-align: left; width: 100%; }
.navlink:hover { background: #232B38; color: #F5F6F8; }
.navlink.active { background: #2B3648; color: #fff; }
.navlink .dot { width: 6px; height: 6px; border-radius: 50%; background: transparent; flex-shrink: 0; }
.navlink.active .dot { background: #5B8DEF; }
#app.nav-masquee .sidebar { display: none; }
.nav-toggle { width: 34px; height: 34px; border-radius: 8px; border: 1px solid #E4E7EC; background: #fff; color: #4B5563; font-size: 16px; line-height: 1; display: flex; align-items: center; justify-content: center; }
.nav-toggle:hover { background: #F5F6F8; }
.sidebar-user { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px; border-top: 1px solid #2B3648; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #3A4658; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px; font-weight: 600; flex-shrink: 0; }
.sidebar-user-name { color: #fff; font-size: 13px; font-weight: 600; }
.sidebar-user-role { color: #8A93A3; font-size: 11px; }
.logout-btn { background: none; border: none; color: #8A93A3; font-size: 11px; cursor: pointer; padding: 0; text-align: left; }
.logout-btn:hover { color: #fff; text-decoration: underline; }
.phase-badge { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: #232B38; border: 1px solid #2B3648; border-radius: 8px; padding: 9px 12px; text-decoration: none; }
.phase-badge:hover { background: #2B3648; }
.phase-badge-label { color: #fff; font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.region-badge { margin-top: -6px; }
.phase-cible { margin: 14px 0 6px; padding: 12px 14px; border: 2px solid #2563EB; border-radius: 8px; background: #EFF6FF; display: flex; flex-direction: column; gap: 4px; }
.phase-cible-titre { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: #1D4ED8; }
.phase-cible-valeur { font-size: 20px; font-weight: 800; color: #0F172A; display: flex; align-items: center; gap: 10px; }
.region-badge select { width: 100%; background: transparent; color: #fff; border: 0; font-size: 13px; font-weight: 700; cursor: pointer; }
.region-badge select option { color: #111; }

.main { flex-grow: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 64px; flex-shrink: 0; background: #fff; border-bottom: 1px solid #E4E7EC; display: flex; align-items: center; justify-content: space-between; padding: 0 28px; box-sizing: border-box; gap: 16px; }
.topbar-title { font-size: 16px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.selector { display: flex; align-items: center; gap: 8px; background: #F5F6F8; border: 1px solid #E4E7EC; border-radius: 8px; padding: 8px 12px; font-size: 13px; font-weight: 600; }
.selector select { border: none; background: none; font: inherit; font-weight: 600; color: #5B8DEF; }
.body-scroll { flex-grow: 1; overflow: auto; padding: 24px 28px; box-sizing: border-box; display: flex; flex-direction: column; gap: 20px; }

/* --- Components --- */
.card { background: #fff; border: 1px solid #E4E7EC; border-radius: 12px; }
.kpi { background: #fff; border: 1px solid #E4E7EC; border-radius: 12px; padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.kpi-label { font-size: 12px; font-weight: 600; color: #6B7280; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 26px; font-weight: 700; }
.kpi-lien { text-decoration: none; color: inherit; cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.kpi-lien:hover { border-color: #5B8DEF; box-shadow: 0 1px 4px rgba(91,141,239,.25); }
.delta-up { color: #DC2626; font-size: 12px; font-weight: 600; }
.delta-down { color: #15803D; font-size: 12px; font-weight: 600; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; font-weight: 700; color: #6B7280; text-transform: uppercase; letter-spacing: .03em; padding: 10px; border-bottom: 1px solid #E4E7EC; background: #FAFBFC; position: sticky; top: 0; }
td { padding: 10px; font-size: 13px; border-bottom: 1px solid #F0F1F3; }
tr.row:hover td { background: #F7F9FE; }

.pill { display: inline-flex; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.pill-run { background: #E8F0FE; color: #1D4ED8; }
.pill-build { background: #FDF2E9; color: #C2410C; }
.pill-auto { background: #F0F1F3; color: #4B5563; }
.pill-active { background: #E7F6EC; color: #15803D; }
.pill-inactive { background: #F0F1F3; color: #6B7280; }
.pill-todo { background: #FEF3E8; color: #C2410C; border: 1px dashed #F0B27A; }
.pill-motif { background: #EEF2FF; color: #4338CA; }

input[type=text], input[type=number], input[type=password], select, textarea {
  font-family: inherit; font-size: 13px; border: 1px solid #E4E7EC; border-radius: 7px; padding: 7px 10px; background: #fff; color: #12151B;
}
label { font-size: 11px; color: #6B7280; display: block; margin-bottom: 4px; }
.field { display: flex; flex-direction: column; gap: 4px; }

.combobox { position: relative; }
.combobox-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 60;
  background: #fff; border: 1px solid #E4E7EC; border-radius: 8px; box-shadow: 0 8px 24px rgba(15,20,30,.12);
  max-height: 220px; overflow-y: auto; padding: 4px;
}
.combobox-option { padding: 7px 10px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.combobox-option:hover, .combobox-option.highlighted { background: #EEF2FF; color: #1D4ED8; }
.combobox-empty { padding: 8px 10px; font-size: 12px; color: #9AA3B2; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; font-size: 13px; font-weight: 600; border: 1px solid transparent; }
.btn-primary { background: #5B8DEF; color: #fff; }
.btn-primary:hover { background: #4676DD; }
.btn-primary:disabled { background: #A9BFEF; cursor: not-allowed; }
.btn-ghost { background: #fff; color: #12151B; border-color: #E4E7EC; }
.btn-ghost:hover { background: #F5F6F8; }
.btn-danger { background: #fff; color: #DC2626; border-color: #F4A6A6; }
.btn-danger:hover { background: #FEF2F2; }
.icon-btn { width: 26px; height: 26px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; color: #6B7280; border: none; background: none; }
.icon-btn:hover { background: #F0F1F3; }

.subnav-item { display: flex; align-items: center; justify-content: space-between; padding: 9px 12px; border-radius: 8px; font-size: 13px; font-weight: 500; color: #374151; cursor: pointer; border: none; background: none; width: 100%; text-align: left; }
.subnav-item:hover { background: #F5F6F8; }
.subnav-item.active { background: #EEF2FF; color: #1D4ED8; font-weight: 600; }
.subnav-count { font-size: 11px; color: #9AA3B2; font-family: 'IBM Plex Mono', monospace; }
.subnav-item.active .subnav-count { color: #1D4ED8; }
.subnav-group-label { font-size: 11px; font-weight: 700; color: #9AA3B2; text-transform: uppercase; letter-spacing: .04em; padding: 0 12px 6px; }

.switch { width: 34px; height: 20px; border-radius: 999px; background: #D1D5DB; position: relative; display: inline-block; border: none; padding: 0; cursor: pointer; flex-shrink: 0; }
.switch.on { background: #5B8DEF; }
.switch .knob { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .12s; }
.switch.on .knob { left: 16px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 20, 30, .45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: 560px; max-width: 92vw; max-height: 86vh; overflow: auto; padding: 22px 24px; }
.modal h3 { margin: 0 0 4px; font-size: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* z-index au-dessus de .loading-overlay (500) : un enchaînement action + rafraîchissement
   (ex. import puis rechargement de la liste) peut réafficher la mire juste après l'action ;
   le résultat (succès/erreur) doit rester visible par-dessus, jamais caché derrière le voile. */
.toast { position: fixed; bottom: 22px; right: 22px; background: #12151B; color: #fff; padding: 12px 16px; border-radius: 10px; font-size: 13px; z-index: 600; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.error { background: #DC2626; }
.toast.success { background: #15803D; }

.empty { color: #9AA3B2; font-size: 13px; padding: 24px; text-align: center; }
.hint { font-size: 12px; color: #6B7280; }
.locked-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: #9AA3B2; }

/* --- Mire de traitement (jauge de progression estimée) --- */
/* Bloque tous les clics dès qu'une requête est en cours (import, enregistrement,
   recalcul...), pour éviter un double-clic pendant le traitement ; la jauge
   n'apparaît qu'après un court délai, pour ne pas clignoter sur les actions
   quasi instantanées, mais le blocage des clics est lui immédiat dès le
   lancement de la requête. La progression est estimée (pas de mesure réelle
   côté serveur) : elle avance vite puis ralentit en s'approchant de 92%,
   pour ne jamais donner l'impression d'être terminée avant de l'être.  */
.loading-overlay { position: fixed; inset: 0; z-index: 500; cursor: wait; opacity: 0; transition: opacity .15s ease; }
.loading-overlay.visible { opacity: 1; background: rgba(255,255,255,.55); backdrop-filter: blur(1px); }
.loading-progress { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 240px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.loading-progress-track { width: 100%; height: 8px; border-radius: 999px; background: #D7DEEA; overflow: hidden; box-shadow: 0 1px 2px rgba(15,20,30,.08) inset; }
.loading-progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #5B8DEF, #7BA6FF); border-radius: 999px; transition: width .2s ease-out; }
.loading-progress-label { font-family: 'IBM Plex Mono', monospace; font-size: 12px; font-weight: 600; color: #4676DD; font-variant-numeric: tabular-nums; }

/* --- Login --- */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #F5F6F8; }
.login-card { background: #fff; border: 1px solid #E4E7EC; border-radius: 14px; padding: 40px; width: 380px; display: flex; flex-direction: column; gap: 18px; }
.login-card h1 { font-size: 20px; margin: 0; }
.login-card p.hint { margin: -12px 0 0; }

/* --- Bandeau d'environnement local (v63) --- */
.env-banner {
  position: fixed; top: 0; left: 0; right: 0; height: 28px; z-index: 2000;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: repeating-linear-gradient(-45deg, #F59E0B 0 14px, #FBBF24 14px 28px);
  color: #1B1300; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
body.env-local { padding-top: 28px; }
body.env-local #app, body.env-local .login-screen { min-height: calc(100vh - 28px); }
body.env-local .sidebar { top: 28px; height: calc(100vh - 28px); }
