:root {
  --bg: #eef1f6; --panel: #ffffff; --panel2: #f3f6fb; --line: #dde3ec;
  --txt: #1b2431; --txt2: #55606f; --txt3: #8b95a4;
  --accent: #2563eb; --accent-d: #1d4ed8;
  --green: #16a34a; --green-bg: rgba(22,163,74,.12);
  --amber: #c77d0a; --amber-bg: rgba(217,140,20,.15);
  --red: #dc2626; --red-bg: rgba(220,38,38,.11);
  --grey: #64748b; --grey-bg: rgba(100,116,139,.13);
  --radius: 14px; --shadow: 0 8px 30px rgba(30,45,80,.12);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--txt); font-size: 15px; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: none; color: inherit; }
input { font-family: inherit; }
/* barres de défilement fines et discrètes */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb { background: #cdd5e0; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #a9b4c3; }
@supports not selector(::-webkit-scrollbar) { * { scrollbar-width: thin; scrollbar-color: #cdd5e0 transparent; } }

/* Chargement vers le tableau de bord (après connexion) */
.load-overlay { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; z-index: 120; }
.load-box { display: flex; flex-direction: column; align-items: center; gap: 20px; width: 280px; text-align: center; }
.load-box p { margin: 0; color: var(--txt2); font-size: 14px; transition: opacity .2s ease; }
/* anneau de progression circulaire */
.ring { position: relative; width: 132px; height: 132px; display: grid; place-items: center; }
.ring > svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 7; stroke-linecap: round; }
.ring .ring-bg { stroke: var(--line); }
.ring .ring-fill { stroke: var(--accent); stroke-dasharray: 326.73; stroke-dashoffset: 326.73; transition: stroke-dashoffset .38s cubic-bezier(.4, 0, .2, 1); }
.ring .logo { width: 56px; height: 56px; font-size: 27px; border-radius: 16px; }
.load-overlay.out { animation: overlayOut .4s ease forwards; }
@keyframes overlayOut { to { opacity: 0; } }

/* Écran de démarrage (avant de savoir si on est connecté) */
.boot-splash { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 100; }

/* LOGIN */
.login-screen { min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1000px 500px at 50% -5%, #dbe6ff 0%, var(--bg) 55%); }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 30px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 15px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 { font-size: 20px; margin: 0; }
.brand p { margin: 3px 0 0; color: var(--txt2); font-size: 13px; }
.logo { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #8b5cf6); color: #fff; font-weight: 800; font-size: 22px; flex-shrink: 0; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--txt2); }
.login-card input { background: var(--bg); border: 1px solid var(--line); color: var(--txt); padding: 12px; border-radius: 10px; font-size: 15px; outline: none; }
.login-card input:focus { border-color: var(--accent); }
.login-card button { background: var(--accent-d); color: #fff; padding: 13px; border-radius: 10px; font-size: 15px; font-weight: 600; }
.login-card button:hover { background: var(--accent); }
.login-error { color: var(--red); font-size: 13px; min-height: 15px; margin: 0; }
.login-note { color: var(--txt3); font-size: 11px; line-height: 1.5; margin: 0; }
/* Note d'information (session fermée pour inactivité, par exemple) */
.login-info { display: flex; gap: 9px; align-items: flex-start; margin: 0; padding: 10px 12px;
  font-size: 12.5px; line-height: 1.45; color: var(--txt2); background: #f4f7fd;
  border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 9px;
  animation: infoIn .35s cubic-bezier(.4, 0, .2, 1) both; }
.login-info svg { flex: none; width: 15px; height: 15px; margin-top: 1px; color: var(--accent-d); }
.login-info b { color: var(--txt); font-weight: 600; }
@keyframes infoIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
/* Animation d'entrée après connexion */
.login-card.leaving { animation: cardOut .42s cubic-bezier(.4, 0, .2, 1) forwards; }
@keyframes cardOut { to { opacity: 0; transform: translateY(-16px) scale(.95); } }
.app.entering { animation: appIn .45s cubic-bezier(.4, 0, .2, 1); }
@keyframes appIn { from { opacity: 0; } to { opacity: 1; } }

/* TOPBAR */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding: 9px 16px; min-height: 60px; background: #f5f8fc; border-bottom: 1px solid var(--line); }
.brand.small { gap: 10px; flex-shrink: 0; }
.brand.small .logo { width: 32px; height: 32px; font-size: 16px; border-radius: 8px; }
.iconbtn { background: transparent; color: var(--txt2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; font-size: 13px; font-weight: 600; flex-shrink: 0; }
.iconbtn:hover:not(:disabled) { color: var(--txt); border-color: var(--txt3); }
.iconbtn:disabled { opacity: .4; cursor: default; }
#homeLogo { cursor: pointer; }


.subbar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--panel2); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.subbar-lbl { font-size: 12.5px; color: var(--txt2); font-weight: 600; }
.subbar select { background: var(--panel); border: 1px solid var(--line); color: var(--txt); padding: 6px 9px; border-radius: 8px; font-size: 12.5px; cursor: pointer; }
.subbar-hint { font-size: 12px; color: var(--txt3); }
.primary.sm, .ghost.sm { padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }
.ghost.sm { border: 1px solid var(--line); color: var(--txt2); background: transparent; }
.vbadge { display: inline-block; background: var(--grey-bg); color: var(--txt2); border-radius: 5px; padding: 0 5px; font-size: 10.5px; font-weight: 700; margin-left: 4px; }
/* Barre du haut, zone de droite : le compte */
.topright { display: flex; align-items: center; justify-content: flex-end; gap: 14px; min-width: 0; }
.topsearch { width: 340px; justify-self: center; } /* largeur fixe, identique avant/après recherche */
.clearsearch { position: absolute; right: 8px; width: 24px; height: 24px; border-radius: 6px; background: transparent;
  color: var(--txt2); font-size: 18px; line-height: 1; display: grid; place-items: center; z-index: 2; }
.clearsearch:hover { background: var(--panel2); color: var(--txt); }
.topsearch .ico { left: 13px; width: 18px; height: 18px; }
.topsearch #searchInput { padding: 10px 34px 10px 40px; font-size: 15px; border-radius: 10px; }
.entlink { color: var(--accent); text-decoration: none; font-weight: 600; }
.entlink:hover { text-decoration: underline; }
.account { display: flex; align-items: center; gap: 14px; flex: 0 1 auto; min-width: 0; }
.account #logoutBtn { flex-shrink: 0; }
.root-name { color: var(--txt2); font-size: 13px; min-width: 0; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ghost { background: transparent; color: var(--txt2); border: 1px solid var(--line); padding: 8px 13px; border-radius: 9px; font-size: 13px; }
.ghost:hover { color: var(--txt); border-color: var(--txt3); }

/* HERO / SEARCH */
.hero { padding: 22px 20px 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
.mode-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.mode-tabs button { display: inline-flex; align-items: center; gap: 7px; background: var(--bg); color: var(--txt2); padding: 9px 16px; border-radius: 10px; font-size: 14px; font-weight: 600; border: 1px solid var(--line); }
.mode-tabs button .mi { font-size: 15px; }
.mode-tabs button:hover { color: var(--txt); }
.mode-tabs button.active { background: var(--accent-d); color: #fff; border-color: var(--accent-d); }
.search-wrap { position: relative; display: flex; align-items: center; gap: 10px; max-width: 760px; }
.search-wrap .ico { position: absolute; left: 15px; width: 20px; height: 20px; color: var(--txt3); pointer-events: none; }
#searchInput { flex: 1; background: var(--bg); border: 1px solid var(--line); color: var(--txt); padding: 14px 15px 14px 46px; border-radius: 12px; font-size: 16px; outline: none; }
#searchInput:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,140,255,.12); }
.primary { background: var(--accent-d); color: #fff; padding: 13px 22px; border-radius: 11px; font-weight: 600; font-size: 15px; }
.primary:hover { background: var(--accent); }
.filters { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; align-items: center; max-width: 760px; }
.filters input[type=text] { background: var(--bg); border: 1px solid var(--line); color: var(--txt); padding: 10px 12px; border-radius: 9px; font-size: 13px; }
.chk { display: inline-flex; align-items: center; gap: 6px; color: var(--txt2); font-size: 13px; cursor: pointer; }
.hint { margin-top: 11px; color: var(--txt3); font-size: 12.5px; }

/* LAYOUT */
.layout { flex: 1; display: grid; grid-template-columns: 1fr 0; overflow: hidden; transition: grid-template-columns .18s ease; }
.layout.with-detail { grid-template-columns: minmax(0, 1fr) clamp(540px, 52vw, 900px); }
.leftcol { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.results { flex: 1; overflow: auto; padding: 16px 22px; }
.detail { overflow: auto; border-left: 1px solid var(--line); background: var(--panel); }

/* groupes de recherche */
.group-head { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--txt3); font-weight: 700; margin: 18px 2px 10px; display: flex; align-items: center; gap: 8px; }
.group-head:first-child { margin-top: 2px; }
.group-head .gcount { background: var(--panel2); color: var(--txt2); border-radius: 999px; padding: 1px 9px; font-size: 11px; letter-spacing: 0; }
.card.static { cursor: default; }
.card.static:hover { border-color: var(--line); background: var(--panel); }
.ghost.back { margin-bottom: 14px; }
.chk.sub { margin: 2px 2px 12px; }
.result-head.sub2 { margin: 2px 2px 8px; }
.muted { color: var(--txt3); }
.small { font-size: 12px; }
.empty.small { padding: 14px; text-align: left; }
td.wrap { white-space: normal; }
.filterbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 4px 2px 12px; }
.filt { background: var(--bg); border: 1px solid var(--line); color: var(--txt); padding: 7px 10px; border-radius: 8px; font-size: 12.5px; cursor: pointer; }
.filt:hover { border-color: var(--txt3); }
.clearfilt { background: transparent; color: var(--accent); border: 1px solid var(--line); padding: 7px 11px; border-radius: 8px; font-size: 12.5px; font-weight: 600; }
.clearfilt:hover { border-color: var(--accent); }
tr.grouprow td { background: var(--panel2); font-weight: 700; font-size: 12.5px; color: var(--txt); border-top: 2px solid var(--line); }
tr.grouprow .entlink { color: inherit; font-weight: inherit; font-size: inherit; text-decoration: none; cursor: pointer; }
tr.grouprow .entlink:hover { color: inherit; text-decoration: none; }
tr.grouprow .gcount { background: var(--bg); color: var(--txt2); border-radius: 999px; padding: 1px 8px; font-size: 11px; font-weight: 600; margin-left: 6px; }
tr.histrow td { color: var(--txt3); }
/* Mode sélection : bouton contouré bleu-vert, lignes teintées de la même couleur */
.ghost.sm.selactive { border-color: var(--green); color: #15803d; } /* actif : simple contour vert, même taille */
table.dt tbody tr.selected td { background: rgba(13,148,136,.12); }
table.dt tbody tr.selected td:first-child { box-shadow: inset 3px 0 0 #0d9488; }
.vbadge.big { font-size: 12px; padding: 2px 9px; background: var(--grey-bg); color: var(--txt); margin-left: 0; font-weight: 700; }
.vbadge.big.v2 { background: var(--green-bg); }
.seltoolbar { display: flex; align-items: center; gap: 10px; margin: 4px 2px 10px; flex-wrap: wrap; }
.danger.sm { padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }
.danger:disabled { opacity: .45; cursor: not-allowed; }
td.selcol, th.selcol { width: 34px; text-align: center; }
.selbox { cursor: pointer; width: 15px; height: 15px; }
.cact { margin-top: 12px; text-align: right; }
.cresult { font-size: 12.5px; font-weight: 600; display: inline-flex; align-items: center; gap: 7px; }
.cresult.ok { color: #15803d; }
.cresult.err { color: #b91c1c; text-align: right; }

/* RESULT: client cards */
.rlist { display: flex; flex-direction: column; gap: 9px; max-width: 900px; }
.result-head { display: flex; align-items: center; gap: 12px; margin: 0 2px 12px; color: var(--txt2); font-size: 13px; }
.result-head .count { font-weight: 600; color: var(--txt); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: flex; align-items: center; gap: 14px; cursor: pointer; transition: border-color .12s, background .12s; color: inherit; text-decoration: none; }
.card:hover { border-color: var(--accent); background: var(--panel2); }
.card .avatar.ct { background: #efe9ff; color: #7c3aed; }
.card .avatar { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex-shrink: 0; background: #e4edff; color: #2563eb; }
.card .grow { flex: 1; min-width: 0; }
.card .title { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { color: var(--txt2); font-size: 12.5px; margin-top: 3px; }
.card .chev { color: var(--txt3); font-size: 18px; }

/* TABLE (devices) */
.tablewrap { border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; max-width: 1100px; } /* défilement horizontal si le contenu dépasse */
table.dt { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.dt th { text-align: left; color: var(--txt); font-weight: 600; padding: 11px 14px; background: var(--panel2); border-bottom: 1px solid var(--line); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; white-space: nowrap; }
table.dt th.sortable { cursor: pointer; user-select: none; }
table.dt th.sortable:hover { color: var(--txt); }
table.dt th.sorted { color: var(--txt); font-weight: 700; } /* colonne de tri : juste le titre en gras */
table.dt td { padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.dt tbody tr { cursor: pointer; }
table.dt tbody tr:last-child td { border-bottom: none; }
table.dt tbody tr:hover { background: var(--panel2); }
table.dt tr.active td { background: #d6e4ff; } /* lecteur ouvert : bleu bien visible */
table.dt tr.active td.c-sn { color: var(--accent-d); }
.mono { font-family: "SF Mono", "Cascadia Mono", Consolas, monospace; }
td.cap { color: var(--txt2); transition: filter .35s ease, opacity .35s ease; }
/* Chargement progressif : flou doux + squelette tant que la ligne n'est pas chargée */
td.cap.pending { filter: blur(2.5px); opacity: .55; }
.skel { display: inline-block; width: 44px; height: 10px; border-radius: 5px; vertical-align: middle;
  background: linear-gradient(90deg, #e3e9f2 25%, #f3f6fb 50%, #e3e9f2 75%); background-size: 200% 100%;
  animation: shimmer 1.25s linear infinite; }
.skel.wide { width: 110px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* status / badges */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.s-green { background: var(--green-bg); color: #15803d; }
.s-amber { background: var(--amber-bg); color: #b45309; }
.s-red { background: var(--red-bg); color: #b91c1c; }
.s-grey { background: var(--grey-bg); color: #475569; }
.recency { font-size: 12px; }
table.dt td.conn { font-size: 13.5px; font-weight: 600; }  /* dernière connexion : même taille que le reste */
.r-recent { color: #15803d; } .r-old { color: #b91c1c; } .r-none { color: var(--txt3); }

/* DETAIL PANEL */
.d-head { padding: 18px 20px 0; position: sticky; top: 0; background: var(--panel); z-index: 3; }
.d-head .close { position: absolute; right: 16px; top: 14px; background: transparent; color: var(--txt2); font-size: 22px; line-height: 1; width: 30px; height: 30px; border-radius: 8px; }
.d-head .close:hover { background: var(--panel2); color: var(--txt); }
.d-title { font-size: 19px; font-weight: 700; margin: 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.d-sub { color: var(--txt2); font-size: 13px; margin: 5px 0 14px; }
.d-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.d-tabs button { background: transparent; color: var(--txt2); padding: 10px 13px; font-size: 13px; font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.d-tabs button:hover { color: var(--txt); }
.d-tabs button.active { color: var(--txt); border-bottom-color: var(--accent); }
.d-body { padding: 18px 22px 44px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 9px 18px; font-size: 13.5px; align-items: baseline; }
.kv .k { color: var(--txt2); white-space: nowrap; }
.kv .v { color: var(--txt); word-break: break-word; }
.blk { margin-bottom: 22px; }
.blk > h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--txt3); margin: 0 0 11px; }

/* contract card */
.contract { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 10px; }
.contract.revoked { opacity: .6; }
.contract .ctop { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.contract .cnum { font-family: "SF Mono", Consolas, monospace; font-weight: 700; font-size: 15px; letter-spacing: .3px; }
.contract .kv { grid-template-columns: max-content 1fr; gap: 7px 16px; font-size: 13px; }
.contract .crevoke { background: var(--red); color: #fff; border: none; padding: 8px 14px; border-radius: 8px; font-size: 12.5px; font-weight: 700; box-shadow: 0 1px 3px rgba(220,38,38,.35); }
.contract .crevoke:hover { background: #b91c1c; }
.contract .crevoke:disabled { opacity: .6; }

.empty { color: var(--txt3); font-size: 13.5px; padding: 44px 12px; text-align: center; }
.loading { color: var(--txt2); font-size: 13.5px; padding: 34px 12px; text-align: center; }
.spinner.light { border-color: rgba(255,255,255,.35); border-top-color: #fff; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -3px; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* MODAL */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 60; padding: 16px; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px; width: 100%; max-width: 400px; box-shadow: var(--shadow); }
.modal-box h3 { margin: 0 0 10px; font-size: 17px; }
.modal-box p { margin: 0 0 20px; color: var(--txt2); font-size: 14px; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.danger { background: var(--red); color: #fff; padding: 9px 16px; border-radius: 9px; font-weight: 600; font-size: 14px; }
.danger:hover { background: #e04340; }

/* TOAST */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); color: var(--txt); padding: 12px 20px; border-radius: 11px; box-shadow: var(--shadow); font-size: 13.5px; z-index: 70; max-width: 90vw; }
.toast.ok { border-color: var(--green); }
.toast.err { border-color: var(--red); }

.d-empty { min-height: 70vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 24px; text-align: center; }
.d-empty p { margin: 0; }
.d-empty-t { color: var(--txt2); font-size: 14.5px; font-weight: 600; }
.d-empty-s { color: var(--txt3); font-size: 13px; margin-top: 4px !important; max-width: 260px; line-height: 1.5; }
.empty-ill { width: 92px; height: 92px; margin-bottom: 10px; }
.empty-ill svg { width: 100%; height: 100%; }
.empty-ill .il-body { fill: none; stroke: #c9d4e4; stroke-width: 2.5; }
.empty-ill .il-slot { fill: #dfe7f3; }
.empty-ill .il-line { fill: #eaf0f8; }
.empty-ill .il-dot { fill: var(--accent); opacity: .6; }

@media (max-width: 860px) {
  .layout, .layout.with-detail { grid-template-columns: 1fr; }
  .detail { display: none; }
  .layout.device-open .results { display: none; }
  .layout.device-open .detail { display: block; }
  .root-name { display: none; }
}

/* Notification de tâche (révocation) : petite fenêtre en bas à droite */
.tasktoast { position: fixed; right: 20px; bottom: 20px; z-index: 90; width: 340px; max-width: calc(100vw - 40px);
  display: flex; align-items: flex-start; gap: 11px; padding: 12px 10px 12px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(30, 45, 80, .12); font-size: 13px; line-height: 1.35; }
.tt-ico { width: 18px; height: 18px; display: grid; place-items: center; flex-shrink: 0; margin-top: 1px; }
.tt-ico svg { width: 18px; height: 18px; }
.tasktoast.ok .tt-ico { color: var(--green); }
.tasktoast.err .tt-ico { color: var(--red); }
.tasktoast .spinner { width: 15px; height: 15px; margin: 0; vertical-align: 0; border-width: 2px; border-color: #d6dfeb; border-top-color: var(--accent); }
.tt-body { flex: 1; min-width: 0; }
.tt-title { font-weight: 600; color: var(--txt); }
.tt-sub { margin-top: 2px; font-size: 12px; color: var(--txt2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.tt-sub:empty { display: none; }
.tt-close { flex-shrink: 0; width: 22px; height: 22px; margin: -3px 0 0; border-radius: 5px; background: transparent; color: var(--txt3); font-size: 17px; line-height: 1; display: grid; place-items: center; }
.tt-close:hover { background: var(--panel2); color: var(--txt); }
.tasktoast.drop { animation: ttIn .28s ease-out; }
.tasktoast.out { animation: ttOut .2s ease-in forwards; }
@keyframes ttIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes ttOut { to { opacity: 0; transform: translateY(10px); } }

/* Boutons d'icône de la barre du haut (historique, actualiser, scanner) */
.iconbtn2 { position: relative; width: 34px; height: 34px; border-radius: 8px; background: transparent; color: var(--txt2); display: grid; place-items: center; flex-shrink: 0; transition: background .15s ease, color .15s ease; }
.iconbtn2 svg { width: 19px; height: 19px; }
.iconbtn2:hover, .iconbtn2[aria-expanded="true"] { background: var(--panel2); color: var(--txt); }
.iconbtn2:disabled { cursor: default; }
#refreshBtn.spinning svg { animation: spin .8s linear infinite; color: var(--accent); }
.histcount { position: absolute; top: 0; right: -1px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; line-height: 16px; text-align: center; box-shadow: 0 0 0 2px #f5f8fc; }
.logoutbtn svg { display: none; width: 18px; height: 18px; }
.searchrow { display: flex; align-items: center; gap: 8px; justify-self: center; min-width: 0; }
.scanbtn { display: none; } /* le scanner n'apparaît que sur téléphone / tablette */

/* Historique des révocations : panneau qui glisse depuis la droite (feuille du bas sur téléphone) */
.hbackdrop { position: fixed; inset: 0; z-index: 96; background: rgba(15, 23, 42, .22); opacity: 0; transition: opacity .25s ease; }
.hbackdrop.show { opacity: 1; }
.hdrawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 97; width: 420px; max-width: 100vw; display: flex; flex-direction: column;
  background: var(--bg); border-left: 1px solid var(--line); box-shadow: -14px 0 36px rgba(30, 45, 80, .14);
  transform: translateX(104%); transition: transform .3s cubic-bezier(.22, .8, .24, 1); }
.hdrawer.show { transform: none; }
.hd-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 18px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.hd-head h2 { margin: 0; font-size: 16px; }
.hd-head p { margin: 3px 0 0; font-size: 12.5px; color: var(--txt2); }
.hd-close { width: 32px; height: 32px; border-radius: 8px; background: transparent; color: var(--txt2); font-size: 22px; line-height: 1; display: grid; place-items: center; flex-shrink: 0; }
.hd-close:hover { background: var(--panel2); color: var(--txt); }
.hd-sum { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 18px 0; }
.hd-chip { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 6px; background: var(--panel); border: 1px solid var(--line); color: var(--txt2); }
.hd-chip.ok { color: #15803d; }
.hd-chip.bad { color: #b91c1c; }
.hd-list { flex: 1; overflow-y: auto; padding: 12px 18px 22px; display: flex; flex-direction: column; gap: 10px; }
.hd-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.hd-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.hd-ent { font-size: 13.5px; font-weight: 700; color: var(--txt); min-width: 0; overflow-wrap: anywhere; }
.hd-time { font-size: 11.5px; color: var(--txt3); white-space: nowrap; }
.hd-rows { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.hd-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--txt2); flex-wrap: wrap; }
.hd-row .ico { width: 15px; height: 15px; flex-shrink: 0; }
.hd-row .ico svg { width: 15px; height: 15px; display: block; }
.hd-row.ok .ico { color: var(--green); }
.hd-row.bad .ico { color: var(--red); }
.hd-sn { font-family: "SF Mono", "Cascadia Mono", Consolas, monospace; font-weight: 700; color: var(--txt); }
.hd-st { color: #b91c1c; font-weight: 600; }
.hd-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 40px 24px; text-align: center; color: var(--txt3); font-size: 13px; }
.hd-empty b { color: var(--txt2); font-size: 14px; }

/* Scanner (téléphone) : plein écran caméra, cadre de visée */
.scanov { position: fixed; inset: 0; z-index: 130; background: #0b1220; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.scanov video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanframe { position: relative; width: min(78vw, 340px); height: min(46vw, 200px); border-radius: 12px; box-shadow: 0 0 0 100vmax rgba(8, 14, 28, .55); border: 2px solid rgba(255, 255, 255, .9); }
.scanframe::after { content: ""; position: absolute; left: 8%; right: 8%; top: 50%; height: 2px; background: rgba(96, 165, 250, .9); box-shadow: 0 0 10px rgba(96, 165, 250, .8); }
.scanhint { position: relative; margin: 22px 24px 0; color: #fff; font-size: 15px; font-weight: 600; text-align: center; text-shadow: 0 1px 3px rgba(0, 0, 0, .5); }
.scanerr { position: relative; margin: 10px 24px 0; color: #fecaca; font-size: 14px; text-align: center; max-width: 360px; }
.scanerr:empty { display: none; }
.scanclose { position: absolute; bottom: max(28px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); padding: 13px 34px; border-radius: 10px; background: rgba(255, 255, 255, .95); color: var(--txt); font-size: 15px; font-weight: 600; }

/* Accessibilité : contour visible au clavier */
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Tablette ---------- */
@media (max-width: 860px) {
  .scanbtn { display: grid; }
}

/* ---------- Téléphone ---------- */
@media (max-width: 640px) {
  /* barre du haut sur deux lignes : logo + actions, puis la recherche (et le scanner) en pleine largeur */
  .topbar { grid-template-columns: auto 1fr; grid-template-areas: "logo right" "search search"; gap: 8px 10px; padding: 8px 12px 10px; min-height: 0; }
  #homeLogo { grid-area: logo; }
  .topright { grid-area: right; }
  .searchrow { grid-area: search; justify-self: stretch; width: 100%; }
  .topsearch { width: auto; flex: 1; max-width: none; }
  .topsearch #searchInput { font-size: 16px; padding: 11px 36px 11px 40px; } /* 16px : pas de zoom automatique sur iPhone */
  .iconbtn2.scanbtn { width: 45px; height: 45px; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; color: var(--txt); }
  .account { gap: 4px; }
  .iconbtn2 { width: 40px; height: 40px; }
  .logoutbtn { padding: 0; width: 40px; height: 40px; border: none; display: grid; place-items: center; }
  .logoutbtn svg { display: block; }
  .logoutbtn .btn-lbl { display: none; }

  .results { padding: 12px 12px 90px; }
  .result-head { flex-wrap: wrap; gap: 2px 8px; font-size: 13px; }
  .group-head { margin: 16px 2px 8px; }
  .card { padding: 13px 14px; }
  .seltoolbar { margin-bottom: 8px; }

  /* tableaux de lecteurs → cartes lisibles */
  .results .tablewrap { border: none; border-radius: 0; overflow: visible; max-width: none; }
  .results table.dt thead { display: none; }
  .results table.dt, .results table.dt tbody { display: block; }
  .results table.dt tbody tr[data-devid] { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 12px 14px; margin-bottom: 8px;
    background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
  .results table.dt tbody tr[data-devid] td { border: none; padding: 0; background: transparent !important; box-shadow: none !important; white-space: nowrap; }
  .results table.dt tbody tr[data-devid]:hover { background: var(--panel); }
  .results table.dt tbody tr.active { border-color: var(--accent); background: #d6e4ff; }
  .results table.dt tbody tr.selected { border-color: #0d9488; background: rgba(13, 148, 136, .1); }
  .results td.c-sn { order: 1; flex: 1 1 auto; font-size: 15px; font-weight: 700; }
  .results td.c-prod { order: 2; }
  .results td.c-conn { order: 3; font-size: 13px; }
  .results td.c-client { order: 4; flex: 1 1 100%; white-space: normal !important; font-size: 13px; }
  .results td.c-fw, .results td.c-com, .results td.c-proto, .results td.c-ecv { order: 5; font-size: 12.5px; color: var(--txt2); }
  .results td.c-fw::before { content: "FW "; color: var(--txt3); }
  /* ligne 1 : S/N · version · date ; ligne 2 : firmware, COM, protocole, Kap ECV */
  .results table.dt tbody tr[data-devid]:has(td.c-fw)::after { content: ""; order: 4; flex-basis: 100%; height: 0; }
  .results td.c-conn { margin-left: auto; }
  .results table.dt tr.grouprow { display: block; margin: 14px 2px 6px; }
  .results table.dt tr.grouprow td { display: block; padding: 0; background: transparent; border: none; font-size: 13px; }

  /* fiche lecteur plein écran */
  .d-head { padding: 12px 14px 0; }
  .d-head .close { top: 8px; right: 8px; width: 40px; height: 40px; }
  .d-title { font-size: 18px; padding-right: 44px; }
  .d-tabs button { padding: 11px 12px; }
  .d-body { padding: 14px 14px 40px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv .k { margin-top: 8px; font-size: 12.5px; }

  .tasktoast { left: 12px; right: 12px; bottom: 12px; width: auto; max-width: none; }
  .hdrawer { top: auto; left: 0; width: 100%; max-height: 86vh; border-left: none; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0;
    transform: translateY(104%); box-shadow: 0 -14px 36px rgba(30, 45, 80, .16); }
  .hdrawer.show { transform: none; }
  .hd-head { border-radius: 14px 14px 0 0; }
  .login-card { padding: 22px; }
  .modal-box { padding: 20px; }
  .modal-actions button { flex: 1; padding: 12px; }
}

/* S/N cliquable : même apparence, mais ouvrable dans un nouvel onglet (molette, Ctrl+clic) */
.snlink { color: inherit; text-decoration: none; }
.snlink:hover { text-decoration: underline; }

/* Nombre de clients : ouvre les 5 derniers clients enregistrés */
.clientsbtn { background: transparent; color: var(--txt2); font-size: 13px; padding: 4px 6px; border-radius: 6px; white-space: nowrap; }
.clientsbtn:hover, .clientsbtn[aria-expanded="true"] { background: var(--panel2); color: var(--txt); }
.minipanel { position: fixed; top: 58px; right: 16px; z-index: 95; width: 340px; max-width: calc(100vw - 32px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px rgba(30, 45, 80, .14);
  overflow: hidden; animation: ttIn .18s ease-out; }
.mp-head { padding: 12px 14px 10px; border-bottom: 1px solid var(--line); font-size: 13px; font-weight: 700; }
.mp-head span { font-weight: 500; color: var(--txt3); font-size: 11.5px; }
.mp-item { display: block; padding: 10px 14px; color: inherit; text-decoration: none; }
.mp-item + .mp-item { border-top: 1px solid var(--panel2); }
.mp-item:hover { background: var(--panel2); }
.mp-name { font-size: 13px; font-weight: 600; color: var(--txt); }
.mp-sub { font-size: 11.5px; color: var(--txt2); margin-top: 1px; }
.mp-empty { padding: 20px 14px; text-align: center; color: var(--txt3); font-size: 12.5px; }
@media (max-width: 860px) { .clientsbtn { display: none; } }

/* Correction de l'association contrat -> entité */
.ctfix { width: 30px; height: 30px; opacity: 0; transition: opacity .15s ease, background .15s ease, color .15s ease; }
.ctfix svg { width: 16px; height: 16px; }
.card:hover .ctfix, .ctfix:focus-visible, .ctfix.on { opacity: 1; }
.tagfix { font-size: 10.5px; color: var(--txt3); border: 1px solid var(--line); border-radius: 5px; padding: 0 4px; vertical-align: 1px; }
.assocpop { position: fixed; z-index: 110; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 12px 34px rgba(30, 45, 80, .18); overflow: hidden; animation: ttIn .16s ease-out; }
.ap-head { padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 12px; color: var(--txt2); }
.ap-head .mono { color: var(--txt); font-weight: 600; }
.ap-input { display: block; width: calc(100% - 20px); margin: 10px; padding: 8px 10px; font-size: 13px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; color: var(--txt); outline: none; }
.ap-input:focus { border-color: var(--accent); }
.ap-list { max-height: 196px; overflow: auto; border-top: 1px solid var(--panel2); }
.ap-item { display: flex; align-items: baseline; gap: 8px; width: 100%; text-align: left; padding: 8px 12px; background: transparent; }
.ap-item:hover { background: var(--panel2); }
.ap-item + .ap-item { border-top: 1px solid var(--panel2); }
.ap-name { font-size: 12.5px; color: var(--txt); }
.ap-ref { font-size: 11px; color: var(--txt3); margin-left: auto; font-variant-numeric: tabular-nums; }
.ap-empty { padding: 14px 12px; text-align: center; font-size: 12px; color: var(--txt3); }
.ap-foot { border-top: 1px solid var(--line); padding: 6px; }
.ap-act { display: block; width: 100%; text-align: left; padding: 7px 10px; border-radius: 7px; font-size: 12.5px; color: var(--txt2); background: transparent; }
.ap-act:hover { background: var(--panel2); color: var(--txt); }
.ap-note { margin: 4px 10px 6px; font-size: 10.5px; line-height: 1.4; color: var(--txt3); }
@media (max-width: 860px) { .ctfix { opacity: 1; } }
