/* BISPRO Central — port fidèle du dark theme ESP32 BISPRO Monitor.
   Variables reprises du baseStyles() ESP32. */

:root {
  --bg: #121212;
  --fg: #fff;
  --card: #1e1e1e;
  --h2: #90caf9;
  --input-bg: #111;
  --input-bd: #333;
  --muted: #bbb;
  --ip: #1a237e22;
  --row-bd: #333;
  --ok: #4caf50;
  --down: #f44336;
  --warn: #ff9800;
  --info: #2196f3;
  --info-dk: #1976d2;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  padding: 20px;
  line-height: 1.4;
}

h1 { margin: 0 0 10px 0; font-size: 22px; }
h2 { color: var(--h2); margin: 0 0 15px 0; font-size: 18px; }
h3 { margin: 0 0 10px 0; font-size: 15px; color: var(--h2); }
a  { color: var(--h2); }

/* -------- Layout -------- */

.topBar {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 15px;
  flex-wrap: wrap;
}
.topBar .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 240px;
}
.topBar .brand img { height: 48px; width: auto; }
.topBar h1 { margin: 0; }

.nav {
  margin-bottom: 20px;
  padding: 12px 15px;
  background: var(--card);
  border-radius: 10px;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  align-items: center;
}
.nav a {
  color: var(--h2);
  text-decoration: none;
  margin-right: 16px;
  font-weight: bold;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.nav a.active { color: #fff; border-bottom: 2px solid var(--h2); }
.nav a svg { opacity: 0.85; }
.nav a.active svg { opacity: 1; }
.navSearch { display: inline-flex; align-items: center; gap: 6px; }
.kbd { border: 1px solid #37474f; border-radius: 4px; padding: 0 5px; opacity: 0.8; }

/* Icône de marque (topBar) : pastille discrète autour du glyphe. */
.brandMark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: 9px;
  background: #1976d222;
  color: var(--h2);
  flex: 0 0 34px;
}

/* Alignement générique icône+texte dans boutons/titres/onglets. */
.btn svg, .tabs a svg, h2 svg, h3 svg, .pill svg { flex: 0 0 auto; }
.btn { align-items: center; gap: 6px; }
.btn:has(svg) { display: inline-flex; }
h2, h3 { display: flex; align-items: center; gap: 8px; }
h2 svg, h3 svg { opacity: 0.75; color: var(--h2); }
.tabs a { display: inline-flex; align-items: center; gap: 6px; }

/* ============================================================================
   Couleur des icônes SVG — accents sémantiques MUETS (dark-theme friendly).
   Chaque icône a sa teinte (via `color`, stroke=currentColor la suit) pour
   redonner de la variété façon emoji, sans être criard.
   Exceptions : dans un bouton, l'icône reprend la couleur du texte du bouton
   (contraste blanc sur fond coloré) — voir override plus bas.
   ============================================================================ */
.bi-dashboard { color: #5aa9e6; }
.bi-events    { color: #e0b15a; }
.bi-firmware  { color: #6ac77f; }
.bi-settings  { color: #9aa7b0; }
.bi-user, .bi-users { color: #4fc3c7; }
.bi-logout    { color: #e08a8a; }
.bi-search    { color: #7bb8e8; }
.bi-lock      { color: #a98fd6; }
.bi-bell      { color: #e0b15a; }
.bi-key       { color: #d6c24f; }
.bi-archive   { color: #8fc79a; }
.bi-clipboard { color: #9aa7b0; }
.bi-shield    { color: #6ac77f; }
.bi-warning   { color: #e0b15a; }
.bi-building  { color: #8b9ba6; }
.bi-pin       { color: #e08a8a; }
.bi-tag       { color: #c98fd6; }
.bi-activity  { color: #5aa9e6; }
.bi-chart     { color: #4fc3c7; }
.bi-download, .bi-upload { color: #7bb8e8; }
.bi-server    { color: #9aa7b0; }
.bi-sort      { color: #9aa7b0; }
.bi-bookmark  { color: #d6c24f; }
.bi-reboot, .bi-refresh { color: #e0b15a; }
.bi-edit      { color: #7bb8e8; }
.bi-plus      { color: #6ac77f; }
.bi-copy      { color: #9aa7b0; }
.bi-eye, .bi-eye-off { color: #9aa7b0; }
.bi-zap       { color: #d6c24f; }
.bi-trash     { color: #e08a8a; }
.bi-mail      { color: #e0b15a; }
.bi-wifi      { color: #4fc3c7; }
.bi-send      { color: #7bb8e8; }
.bi-tool      { color: #9aa7b0; }
/* Dans les boutons : l'icône reprend la couleur du texte du bouton
   (blanc sur fonds colorés, --fg sur ghost) — priorité sur les teintes ci-dessus. */
.btn .bi, button .bi, .pwToggle .bi, .copyBtn .bi, .favBtn .bi { color: inherit; }
/* Nav active : icône passe en blanc comme le libellé. */
.nav a.active .bi { color: #fff; }

/* ============================================================================
   Page de connexion — écran dédié, centré, dark avec halo discret.
   ============================================================================ */
.loginBody {
  min-height: 100vh;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1100px 500px at 50% -10%, #16324a55, transparent 70%),
    radial-gradient(800px 400px at 50% 120%, #1a237e22, transparent 70%),
    var(--bg);
}
.loginCard {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--row-bd);
  border-radius: 14px;
  padding: 28px 26px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}
.loginBrand {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 22px;
}
.loginBrand h1 { margin: 0; font-size: 20px; letter-spacing: -0.01em; }
.loginMark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px; height: 46px;
  border-radius: 12px;
  flex: 0 0 46px;
  color: var(--h2);
  background: linear-gradient(135deg, #1976d233, #1976d211);
  border: 1px solid #1976d244;
}
.loginCard label { margin-top: 12px; }
.loginCard input { font-size: 15px; }
.loginSubmit {
  width: 100%;
  margin-top: 18px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
}
.loginCard .flashErr { margin-bottom: 16px; animation: none; }

/* Section repliable (ex : "Ajouter un équipement" sur la page device) :
   summary stylé comme un bouton d'action discret. */
details.addHost > summary {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--h2);
  list-style: none;
  padding: 4px 0;
}
details.addHost > summary::-webkit-details-marker { display: none; }
details.addHost[open] > summary { margin-bottom: 12px; }
.nav .spacer { flex: 1; }
.nav .user { color: var(--muted); font-weight: normal; margin-right: 10px; }

.ipinfo {
  margin-bottom: 15px;
  padding: 10px 14px;
  background: var(--ip);
  border-radius: 8px;
  font-size: 13px;
}
.ipinfo a { color: var(--h2); }

/* -------- Cards -------- */

.card {
  background: linear-gradient(180deg, #212a32, var(--card));
  padding: 16px 18px;
  border-radius: 12px;
  margin-bottom: 18px;
  border: 1px solid #2a323b;
  box-shadow: 0 1px 0 rgba(255,255,255,0.03) inset, 0 6px 18px rgba(0,0,0,0.28);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.row { display: flex; gap: 12px; flex-wrap: wrap; }
.col { flex: 1; min-width: 220px; }

/* -------- Forms -------- */

label { font-size: 13px; color: var(--muted); display: block; margin-top: 6px; }

input, select, textarea {
  margin: 4px 0 10px 0;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--input-bd);
  width: 100%;
  background: var(--input-bg);
  color: var(--fg);
  font-size: 14px;
  font-family: inherit;
}
textarea { min-height: 80px; resize: vertical; }

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%23bbbbbb' d='M1 1l5 5 5-5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

button, .btn {
  margin-top: 10px;
  padding: 10px 14px;
  border: none;
  border-radius: 6px;
  /* Fond assombri (#1976d2) pour que le texte blanc atteigne 4.6:1 (WCAG AA).
     var(--info) #2196f3 en fond échouait (3.1:1). Le token reste #2196f3 pour
     les usages TEXTE (KPI, dots, .up/.down) où le contraste sur fond sombre est
     bon. Ne change que le fond des boutons. */
  background: var(--info-dk);
  color: white;
  cursor: pointer;
  font-size: 14px;
  text-decoration: none;
  display: inline-block;
  font-family: inherit;
}
button:hover, .btn:hover { background: #1565c0; }
.btnSm { padding: 6px 10px; margin: 2px 4px; font-size: 13px; }
/* Boutons sémantiques : fonds assombris pour texte blanc ≥ 4.5:1
   (vert 5.1:1, orange brûlé 5.6:1). */
.btnGreen { background: #2e7d32; }
.btnGreen:hover { background: #1b5e20; }
.btnOrange { background: #bf360c; }
.btnOrange:hover { background: #a62d0a; }
.dangerBtn { background: #b00020 !important; }
/* Assombrit au hover comme tous les autres boutons (cohérence de direction). */
.dangerBtn:hover { background: #8c0019 !important; }
.btnGhost { background: transparent; border: 1px solid var(--input-bd); color: var(--fg); }
.btnGhost:hover { background: #2a2a2a; }

.req { color: var(--down); font-weight: bold; margin-left: 3px; }

/* Input file : le bouton natif (« Choose File ») est le seul morceau stylable ;
   on le met aux couleurs du thème. Le libellé « no file chosen » reste natif
   (non adressable en CSS) — un wrapper custom FR serait nécessaire pour l'effacer. */
input[type="file"] { padding: 6px; cursor: pointer; }
input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 7px 12px;
  border: none;
  border-radius: 6px;
  background: var(--info-dk);
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
input[type="file"]::file-selector-button:hover { background: #1565c0; }

/* -------- Password toggle (œil) -------- */
.pwWrap { position: relative; margin: 4px 0 10px 0; }
.pwWrap input { margin: 0 !important; padding-right: 42px !important; }
.pwToggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 0;
  color: #bbb;
  cursor: pointer;
  padding: 4px 8px;
  font-size: 16px;
  margin: 0;
  line-height: 1;
  height: auto;
  width: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pwToggle:hover { color: #fff; background: #333; border-radius: 4px; }

/* -------- States -------- */
.up { color: var(--ok); font-weight: bold; }
.down { color: var(--down); font-weight: bold; }
.muted { color: var(--muted); font-size: 13px; }
.danger { color: #ff6b6b; text-decoration: none; margin-left: 10px; }

/* -------- Badges / pills -------- */
.badge {
  display: inline-block;
  background: #2a2a2a;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  margin-left: 4px;
}
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  margin: 2px;
  font-weight: 600;
}
/* Variante "état" (ONLINE/OFFLINE) : vrai dot centré, pas de glyphe Unicode ●
   qui se balade sur la baseline selon la police. */
.pill-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
  vertical-align: middle;
}
.pill-state .pill-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255,255,255,0.95);
  flex: 0 0 7px;
}
/* Badges protocole — texte couleur vive sur fond teinté sombre (même hue).
   L'ancienne version (texte blanc sur couleur pleine) échouait WCAG :
   http 2.2:1, tcp 2.3:1, https 3.3:1. Ici chaque badge est du texte clair
   color-codé sur un fond ~12% de sa propre teinte → 8-10:1, on-brand. */
.proto {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: bold;
  font-family: 'Consolas','Courier New',monospace;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-left: 4px;
  border: 1px solid transparent;
}
.proto-ping  { background: #546e7a26; color: #cfd8dc; border-color: #546e7a66; }
.proto-http  { background: #ff98001f; color: #ffb74d; border-color: #ff980059; }
.proto-https { background: #43a0471f; color: #81c784; border-color: #43a04759; }
.proto-tcp   { background: #00bcd41f; color: #4dd0e1; border-color: #00bcd459; }
.proto-rtsp  { background: #e5393521; color: #ef9a9a; border-color: #e5393559; }

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.dot-up { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.dot-down { background: var(--down); box-shadow: 0 0 6px var(--down); }
.dot-unknown { background: #888; }

/* -------- Flash messages -------- */
.flash {
  background: #263238;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 15px;
}
.flashErr {
  background: #c62828;
  color: #fff;
  padding: 14px;
  border-radius: 8px;
  margin-bottom: 15px;
  font-weight: bold;
  text-align: center;
  border: 2px solid #ff5252;
  box-shadow: 0 0 12px #ff525255;
  /* Entrée attention-getting FINIE (2 pulses) puis repos — plus de pulse infini
     anxiogène qui « nague » l'utilisateur en permanence. */
  animation: pulseErr 1.2s ease-in-out 2 alternate;
}
@keyframes pulseErr {
  from { box-shadow: 0 0 8px #ff525244; }
  to   { box-shadow: 0 0 18px #ff525288; }
}
.flashOk {
  background: #1b5e20;
  color: #fff;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 15px;
}

/* -------- Device card (dashboard) -------- */
.dev-card {
  background: linear-gradient(180deg, #212a32, var(--card));
  padding: 16px;
  border-radius: 12px;
  transition: transform .14s ease-out, box-shadow .14s ease-out, border-color .14s ease-out;
  text-decoration: none;
  color: var(--fg);
  display: block;
  border: 1px solid #2a323b;
  box-shadow: 0 1px 0 rgba(255,255,255,0.03) inset, 0 4px 14px rgba(0,0,0,0.25);
}
.dev-card:hover {
  transform: translateY(-3px);
  border-color: var(--h2);
  box-shadow: 0 1px 0 rgba(255,255,255,0.05) inset, 0 12px 28px rgba(0,0,0,0.42), 0 0 0 1px #90caf933;
}
.dev-card .dev-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 6px;
  gap: 10px;
}
.dev-card .dev-name { font-weight: bold; font-size: 16px; line-height: 1.25; }
.dev-card .dev-sub { color: var(--muted); font-size: 12px; line-height: 1.3; margin-top: 2px; }
.dev-card .dev-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  font-size: 12px;
  margin-top: 10px;
  color: var(--muted);
}
.dev-card .dev-stats b { color: var(--fg); }

/* -------- Progress bar (CPU/RAM) -------- */
.progress {
  background: #333;
  border-radius: 6px;
  overflow: hidden;
  height: 8px;
  margin: 6px 0;
}
.progress > div { height: 100%; transition: width .3s; }
.progress.cpu > div { background: var(--warn); }
.progress.ram > div { background: var(--ok); }

/* -------- KPI -------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.kpi {
  background: linear-gradient(180deg, #222b33, var(--card));
  padding: 16px 14px;
  border-radius: 12px;
  text-align: center;
  border: 1px solid #2a323b;
  box-shadow: 0 1px 0 rgba(255,255,255,0.03) inset, 0 4px 12px rgba(0,0,0,0.22);
}
.kpi .val { font-size: 28px; font-weight: bold; }
.kpi .lbl { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
.kpi.ok .val { color: var(--ok); }
.kpi.down .val { color: var(--down); }
.kpi.warn .val { color: var(--warn); }
/* Variante "Favoris" — jaune doré pour matcher l'étoile ⭐ des cards */
.kpi.fav .val { color: #ffc107; }

/* KPI cliquables (tuiles "filtre rapide" du dashboard).
   - <a> utilisé au lieu de <div> → on annule les styles de lien par défaut.
   - Hover : léger soulèvement + halo, curseur pointer.
   - Active : bordure colorée + léger halo pour indiquer le filtre courant. */
.kpi-link {
  display: block;
  color: inherit;
  text-decoration: none;
  border: 1px solid transparent;
  transition: transform .08s ease-out, box-shadow .12s ease-out, border-color .12s ease-out;
  cursor: pointer;
}
.kpi-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
  border-color: #455a64;
}
.kpi-link.kpi-active {
  border-color: #1976d2;
  box-shadow: 0 0 0 1px #1976d2 inset, 0 2px 8px rgba(25,118,210,0.35);
}
.kpi-link.ok.kpi-active      { border-color: var(--ok);   box-shadow: 0 0 0 1px var(--ok)   inset, 0 2px 8px rgba(76,175,80,0.35); }
.kpi-link.down.kpi-active    { border-color: var(--down); box-shadow: 0 0 0 1px var(--down) inset, 0 2px 8px rgba(244,67,54,0.35); }
.kpi-link.fav.kpi-active     { border-color: #ffc107;     box-shadow: 0 0 0 1px #ffc107     inset, 0 2px 10px rgba(255,193,7,0.45); }

/* -------- Tables -------- */
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--row-bd);
  font-size: 13px;
}
th { color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; font-size: 11px; }
tr:hover { background: #252525; }

/* -------- Timeline events -------- */
.timeline .event {
  padding: 10px 0;
  border-bottom: 1px solid var(--row-bd);
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.timeline .ts { color: var(--muted); font-size: 12px; min-width: 150px; }
.timeline .ev-DOWN { color: var(--down); font-weight: bold; }
.timeline .ev-RECOVERY { color: var(--ok); font-weight: bold; }
.timeline .ev-OTA { color: var(--warn); font-weight: bold; }

/* -------- Host row (device detail) -------- */
.host-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--row-bd);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Host card (device detail page — clone ESP .host) */
.host {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 14px 16px;
  margin-bottom: 10px;
  min-height: 120px;
  background: #1a1f23;
  border: 1px solid var(--row-bd);
  border-radius: 8px;
  flex-wrap: wrap;
  line-height: 1.55;
}
.host .badge { margin: 2px 2px 2px 0; }
.host strong { font-size: 15px; }
.host .proto { margin-left: 6px; }

/* -------- Tabs -------- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--row-bd);
  margin-bottom: 15px;
}
.tabs a {
  padding: 10px 16px;
  text-decoration: none;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs a.active { color: var(--fg); border-bottom-color: var(--h2); }

/* -------- Filters bar -------- */
.filterBar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 15px;
  padding: 10px 12px;
  background: var(--card);
  border-radius: 8px;
}
.filterBar input, .filterBar select {
  margin: 0;
  width: auto;
  min-width: 140px;
  padding: 6px 10px;
  font-size: 13px;
}

/* -------- Utils -------- */
.hidden { display: none !important; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 12px; }
.small { font-size: 12px; }
.right { text-align: right; }
.spacer { flex: 1; }
hr { border: 0; border-top: 1px solid var(--row-bd); margin: 15px 0; }

/* -------- Phase 8 : favoris / copy / deep-link highlight -------- */
.dev-card-fav {
  box-shadow: 0 0 0 2px rgba(255,193,7,0.45);
}
/* Étoile favoris — bouton compact, discret, sans bordure.
   Transition douce de la couleur entre l'état "on" (or) et "off" (gris). */
.favBtn {
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0 6px 0 0;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  vertical-align: middle;
  transition: transform 0.1s, color 0.15s;
  font-family: inherit;
}
.favBtn[data-fav="1"] { color: #ffc107; text-shadow: 0 0 6px rgba(255,193,7,0.5); }
.favBtn[data-fav="0"] { color: #546e7a; }
.favBtn:hover         { transform: scale(1.2); color: #ffc107; }
.favBtn:disabled      { opacity: 0.5; cursor: wait; }

.copyBtn {
  background: transparent;
  border: 0;
  color: #78909c;
  padding: 0 2px;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  margin: 0 0 0 2px;
  opacity: 0.55;
  transition: opacity 0.15s, color 0.15s;
  vertical-align: baseline;
  font-family: inherit;
}
.copyBtn:hover    { opacity: 1; color: #fff; }
.copyBtn.copied   { opacity: 1; color: #4caf50; }
.copyBtn:disabled { opacity: 0.3; cursor: default; }

@keyframes anchorPulse {
  0%   { box-shadow: 0 0 0 0 rgba(255,193,7,0.6); }
  50%  { box-shadow: 0 0 0 12px rgba(255,193,7,0.05); }
  100% { box-shadow: 0 0 0 0 rgba(255,193,7,0); }
}
.anchor-highlight {
  animation: anchorPulse 1.4s ease-out 2;
  outline: 2px solid #ffc107;
  outline-offset: 2px;
  border-radius: 6px;
}

/* -------- Phase 7 : barre bulk commands -------- */
#bulkBar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #263238;
  border: 1px solid #455a64;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
/* Checkbox bulk : on masque la native (sans la retirer du flow, pour rester
   cliquable) et on dessine un carré custom via le <label> wrapper. */
.bulkCheckWrap {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
  position: relative;
}
.bulkCheckWrap input.bulkCheck {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.bulkCheckWrap .bulkCheckBox {
  width: 18px;
  height: 18px;
  border: 2px solid #546e7a;
  border-radius: 4px;
  background: rgba(0,0,0,0.25);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  flex: 0 0 18px;
}
.bulkCheckWrap .bulkCheckBox::after {
  content: '✓';
  color: #fff;
  font-size: 14px;
  font-weight: bold;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.1s;
}
.bulkCheckWrap input.bulkCheck:checked ~ .bulkCheckBox {
  background: #1976d2;
  border-color: #1976d2;
}
.bulkCheckWrap input.bulkCheck:checked ~ .bulkCheckBox::after {
  opacity: 1;
}
.bulkCheckWrap:hover .bulkCheckBox { border-color: #90caf9; }

/* ============================================================================
   T8-11 — Undo toast (en bas à droite, empilable, barre de progression)
   ============================================================================ */
.bispro-toast-wrap {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  z-index: 9999;
  pointer-events: none; /* clics traversent sauf sur les toasts eux-mêmes */
}
.bispro-toast {
  pointer-events: auto;
  background: #263238;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.45);
  border: 1px solid #37474f;
  min-width: 280px;
  max-width: 420px;
  position: relative;
  display: flex;
  align-items: center;
  font-size: 14px;
  animation: bisproToastIn 0.2s ease-out;
}
.bispro-toast-bar {
  position: absolute;
  left: 0; bottom: 0;
  height: 3px;
  width: 100%;
  background: #4caf50;
  border-radius: 0 0 8px 8px;
}
/* Variantes sémantiques du toast générique (bisproToast). */
.bispro-toast-error   { border-color: #b00020; box-shadow: 0 6px 20px rgba(0,0,0,0.45), 0 0 0 1px #b0002055; }
.bispro-toast-success { border-color: #2e7d32; }
.bispro-toast-info    { border-color: #1976d2; }
.bispro-toast-cancelled {
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.25s ease-in;
}
@keyframes bisproToastIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================================
   T8-12 — Mobile-first : adaptations < 640px (astreinte mobile)
   ============================================================================ */
@media (max-width: 640px) {
  body { font-size: 14px; }

  /* Top bar empilée */
  .topBar { flex-direction: column; align-items: flex-start; gap: 6px; padding: 10px 12px; }
  .topBar h1 { font-size: 18px; }

  /* Nav en scroll horizontal si trop large (évite de casser le layout) */
  .nav {
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 10px;
  }
  .nav a, .nav button { font-size: 13px; padding: 6px 10px; }
  .nav .spacer { flex-basis: 100%; height: 0; }

  /* KPIs : 2 colonnes au lieu de auto-fill (sinon trop étroits sur mobile) */
  .kpis {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .kpi { padding: 10px 8px; }
  .kpi .val { font-size: 22px; }
  .kpi .lbl { font-size: 10px; letter-spacing: 0.5px; }

  /* Grid devices : une colonne en mobile */
  .grid { grid-template-columns: 1fr !important; }

  /* Cards : padding réduit */
  .card { padding: 12px; margin-bottom: 12px; }

  /* FilterBar stackée
     IMPORTANT : le wrapper inline a `align-items:flex-end` qui gagnait sur
     `stretch` (inline > CSS externe sans !important) → tous les filtres se
     collaient à droite avec leur largeur naturelle. !important est nécessaire
     ici parce qu'on lutte contre du style inline. */
  #filterForm > div[style*="flex-wrap"] {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }
  /* Chaque filtre (Recherche/Client/Site/...) est un <div flex-column> :
     il faut qu'il prenne toute la largeur du parent stretchable. */
  #filterForm > div[style*="flex-wrap"] > div { width: 100%; margin-left: 0 !important; }
  #filterForm details { width: 100%; }
  #filterForm summary { width: 100%; justify-content: flex-start; box-sizing: border-box; }
  #filterForm input[type="search"],
  #filterForm input[type="text"],
  #filterForm #f-search { width: 100%; min-width: 0 !important; }
  /* Les <select> de tri (Client/Asc) sont dans un sous-div flex row → gardent
     leur largeur partagée mais on évite le débord. */
  #filterForm select.filterCtrl { min-width: 0; flex: 1; }

  /* Events / timeline : plus compact */
  .event { flex-direction: column !important; align-items: stretch !important; gap: 4px !important; }
  .event .ts { font-size: 11px; }

  /* Tables scrollables horizontalement (fallback) */
  table { display: block; overflow-x: auto; }

  /* Toast : pleine largeur */
  .bispro-toast-wrap { left: 8px; right: 8px; bottom: 8px; }
  .bispro-toast { min-width: 0; width: 100%; }

  /* Host cards (device.html) empilés proprement */
  .host { flex-direction: column !important; align-items: stretch !important; }

  /* Dropdowns filtres dashboard (Client/Site/Hosts/OTA/Vues) :
     les panneaux <details><div position:absolute> ont un min-width qui les
     fait déborder du viewport sur petit écran. On force un cap viewport. */
  details > div[style*="position:absolute"] {
    min-width: 0 !important;
    max-width: calc(100vw - 24px);
    max-height: 70vh;
    overflow: auto;
  }

  /* Boutons dans une rangée : empile pour éviter les chevauchements. */
  .card .row { gap: 8px; }

  /* Inputs filtres events (q/tag) : full width au lieu de min-width:240px. */
  #filterForm input[style*="min-width"] { min-width: 0 !important; }

  /* Audit log + tables larges : déjà passées en display:block + overflow-x.
     On élargit la zone tap des liens pour éviter le mistap mobile. */
  table a { padding: 2px 0; display: inline-block; }

  /* Boutons dans les cellules de tableau (settings users / firmwares / etc.) :
     sans nowrap, le texte ("Désactiver", "Déconnecter tout") wrap verticalement
     dans la cellule étroite → boutons géants empilés (cf. screenshot mobile).
     On force one-line + on regroupe les forms côte-à-côte. */
  table td .btn,
  table td button {
    white-space: nowrap;
    margin: 2px 4px 2px 0;
  }
  /* Cellule d'actions : <form style="display:inline"> doit pouvoir wrapper en
     plusieurs lignes proprement (au lieu de tout sur une seule ligne tronquée). */
  table td form[style*="display:inline"] { display: inline-block !important; }
}

/* Tablettes (640–960) : KPIs en 3 colonnes */
@media (min-width: 641px) and (max-width: 960px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
}

/* ============================================================================
   T9-2/9-3 — Panneau patterns (petites pills plus lisibles)
   ============================================================================ */
#patternsPanel[open] > summary { margin-bottom: 8px; }
#patternsPanel h4 { color: #b0bec5; font-size: 13px; font-weight: 600; }
#patternsBody .pill { font-size: 12px; padding: 2px 10px; border-radius: 99px; }

/* ============================================================================
   T7-7 — Badge "out-of-sync"
   ----------------------------------------------------------------------------
   Orange vif (contraste sur fond sombre), indique qu'une commande pending n'a
   pas été ack depuis > 5 min. N'implique pas que le device soit offline —
   c'est une info de désynchronisation config.
   ============================================================================ */
.badge-oos {
  background: #ff9800;
  color: #212121;
  font-weight: bold;
  border: 1px solid #f57c00;
  animation: oos-pulse 2s ease-in-out infinite;
}
@keyframes oos-pulse {
  0%, 100% { opacity: 1;   }
  50%      { opacity: 0.55;}
}


/* ============================================================================
   Placeholder pour <input type="date">
   ----------------------------------------------------------------------------
   <input type=date> n'affiche pas l'attribut placeholder. On l'expose via
   data-placeholder + ::before, masqué dès que la valeur n'est pas vide
   (sélecteur :not([value=""]) tient à jour parce que value est attribut DOM).
   On masque aussi quand le champ a le focus pour éviter de superposer le
   widget calendrier natif.
   ============================================================================ */
input.dateField {
  position: relative;
}
input.dateField:not([value=""]) {
  color: var(--fg);
}
input.dateField[value=""]:not(:focus)::-webkit-datetime-edit {
  color: transparent;
}
input.dateField[value=""]:not(:focus)::before {
  content: attr(data-placeholder);
  color: var(--muted, #9e9e9e);
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

/* ============================================================================
   Accessibilité — états focus clavier, placeholder, disabled
   ----------------------------------------------------------------------------
   Le CSS n'avait aucun état :focus : navigation clavier aveugle (astreinte de
   nuit, a11y). On pose un anneau cohérent via :focus-visible (souris intacte,
   ring seulement au clavier). Couleur = --h2 (#90caf9, ~10:1 sur fond sombre).
   ============================================================================ */
a:focus-visible,
button:focus-visible,
.btn:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible,
.kpi-link:focus-visible,
.favBtn:focus-visible,
.copyBtn:focus-visible {
  outline: 2px solid var(--h2);
  outline-offset: 2px;
  border-radius: 6px;
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--h2);
  outline-offset: 1px;
  border-color: var(--h2);
}
/* Case à cocher custom (bulk) : l'input natif est masqué, on porte le ring
   sur le carré dessiné. */
.bulkCheckWrap input.bulkCheck:focus-visible ~ .bulkCheckBox {
  outline: 2px solid var(--h2);
  outline-offset: 2px;
}

/* Placeholder : jamais défini → rendu variable par navigateur. On fige un gris
   à 7.5:1 sur les inputs sombres. */
::placeholder { color: #9e9e9e; opacity: 1; }

/* Disabled générique : les composants qui gèrent déjà leur état (.favBtn,
   .copyBtn) gardent leur règle (spécificité supérieure). */
button:disabled,
.btn:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================================================
   prefers-reduced-motion — obligatoire.
   Neutralise les animations infinies (flashErr pulseErr, badge-oos oos-pulse,
   anchorPulse) et raccourcit les transitions pour les utilisateurs sensibles
   au mouvement, sans supprimer le feedback d'état (crossfade quasi-instantané).
   ============================================================================ */
/* ============================================================================
   Modal de confirmation unifié (remplace confirm()/prompt() natifs).
   ============================================================================ */
.bispro-confirm {
  border: 1px solid var(--row-bd);
  border-radius: 12px;
  background: var(--card);
  color: var(--fg);
  padding: 0;
  max-width: 440px;
  width: calc(100vw - 32px);
  box-shadow: 0 20px 60px rgba(0,0,0,0.55);
}
.bispro-confirm::backdrop { background: rgba(0,0,0,0.6); backdrop-filter: blur(2px); }
.bispro-confirm .bc-form { padding: 20px; margin: 0; }
.bispro-confirm .bc-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bispro-confirm .bc-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px; flex: 0 0 34px;
  background: #1976d222; color: var(--h2);
}
.bispro-confirm.is-danger .bc-icon { background: rgba(176,0,32,0.18); color: #ff6b6b; }
.bispro-confirm .bc-title { margin: 0; font-size: 16px; color: var(--fg); }
.bispro-confirm .bc-msg { margin: 0 0 14px 0; color: var(--muted); font-size: 14px; line-height: 1.5; white-space: pre-line; }
.bispro-confirm .bc-typewrap { margin: 0 0 14px 0; }
.bispro-confirm .bc-typelabel { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.bispro-confirm .bc-typein { margin: 0; width: 100%; }
.bispro-confirm .bc-actions { display: flex; justify-content: flex-end; gap: 8px; margin: 0; }
.bispro-confirm .bc-actions .btn { margin: 0; }
.bispro-confirm .bc-ok:disabled { opacity: 0.45; cursor: not-allowed; }

/* ============================================================================
   Barre de progression globale HTMX (feedback de chargement).
   Pilotée par bispro.js sur htmx:beforeRequest / afterRequest.
   ============================================================================ */
#htmxProgress {
  position: fixed;
  top: 0; left: 0;
  height: 2px;
  width: 100%;
  background: var(--h2);
  transform: scaleX(0);
  transform-origin: left;
  opacity: 0;
  z-index: 10000;           /* au-dessus de #bulkBar (100) et des toasts */
  pointer-events: none;
  transition: transform 0.2s ease-out, opacity 0.2s ease-out;
  box-shadow: 0 0 8px var(--h2);
}
#htmxProgress.loading { opacity: 1; transform: scaleX(0.85); }
#htmxProgress.done    { opacity: 0; transform: scaleX(1); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
