/* Portail d'accès — thème sombre « nuit ardoise » par défaut, clair en option. Couleur par protocole = repère principal. */
[data-theme="sombre"] { color-scheme: dark; }
[data-theme="clair"] { color-scheme: light; }
:root, [data-theme="sombre"] {
  --fond: #141a22; --panneau: #1b2330; --panneau-2: #222c3b; --trait: #2c3848;
  --texte: #e4e8ee; --texte-2: #8b95a7; --survol: #253041; --actif: #2b3950;
  --rdp: #5b8def; --ssh: #e0a546; --vnc: #a07be0;
  --ok: #4cb37a; --ko: #d65a4e; --inconnu: #6b7486;
  --focus: #9cc1ff; --ombre: 0 12px 32px rgba(0, 0, 0, .45);
}
[data-theme="clair"] {
  --fond: #eef1f5; --panneau: #ffffff; --panneau-2: #f5f7fa; --trait: #d8dee8;
  --texte: #1c2330; --texte-2: #5d6778; --survol: #e9eef6; --actif: #dde7f7;
  --rdp: #2f67d8; --ssh: #b67a12; --vnc: #7a52c4;
  --ok: #2f8f5b; --ko: #bf3e33; --inconnu: #8d95a3;
  --focus: #2f67d8; --ombre: 0 12px 32px rgba(20, 30, 50, .18);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  background: var(--fond); color: var(--texte);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.aide { color: var(--texte-2); margin: .2rem 0 1rem; }
.erreur { color: var(--ko); min-height: 1.3em; margin: .2rem 0; }

/* ---------- Connexion */
.connexion { min-height: 100%; display: grid; place-items: center; padding: 1.5rem; }
.carte-connexion {
  width: min(380px, 100%); background: var(--panneau); border: 1px solid var(--trait);
  border-radius: 10px; padding: 2rem 1.8rem; box-shadow: var(--ombre);
}
.carte-connexion label { display: block; margin: .8rem 0; color: var(--texte-2); font-size: 13px; }
.carte-connexion input {
  display: block; width: 100%; margin-top: .3rem; padding: .6rem .7rem; background: var(--panneau-2);
  border: 1px solid var(--trait); border-radius: 6px;
}
.carte-connexion button { width: 100%; margin-top: .6rem; }
.marque { font-size: 28px; font-weight: 650; letter-spacing: -.02em; margin: 0; }
.marque::before {
  content: ""; display: inline-block; width: .55em; height: .55em; margin-right: .35em; border-radius: 2px;
  background: linear-gradient(90deg, var(--rdp) 0 33%, var(--ssh) 33% 66%, var(--vnc) 66%);
}
.marque.petite { font-size: 17px; }
button {
  background: var(--rdp); color: #fff; border: 0; border-radius: 6px; padding: .55rem .9rem; cursor: pointer;
  font-weight: 550;
}
button.discret, .lien-discret { background: none; color: var(--texte-2); padding: .3rem .4rem; font-weight: 450; }
button.discret:hover, .lien-discret:hover { color: var(--texte); }
.lien-discret { text-decoration: none; font-size: 13px; }
button.icone { background: none; color: var(--texte-2); padding: .2rem .45rem; font-size: 16px; }

/* ---------- Structure */
.portail { display: grid; grid-template-columns: 280px 1fr; height: 100vh; }
.barre { background: var(--panneau); border-right: 1px solid var(--trait); display: flex; flex-direction: column; min-height: 0; }
.barre-haut { display: flex; align-items: center; justify-content: space-between; padding: .9rem .9rem .5rem; }
.recherche {
  margin: 0 .9rem .6rem; padding: .5rem .65rem; background: var(--panneau-2); border: 1px solid var(--trait);
  border-radius: 6px;
}
.arbre { flex: 1; overflow: auto; padding: 0 .4rem .8rem; }
.barre-bas {
  border-top: 1px solid var(--trait); padding: .6rem .9rem; display: flex; gap: .4rem; align-items: center;
  flex-wrap: wrap; font-size: 13px;
}
.utilisateur { flex: 1 0 100%; color: var(--texte-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Arbre */
.groupe-titre {
  display: flex; align-items: center; gap: .35rem; width: 100%; background: none; color: var(--texte-2);
  padding: .55rem .5rem .3rem; font-size: 12.5px; font-weight: 600; border-radius: 5px; text-align: left;
}
.groupe-titre:hover { color: var(--texte); }
.groupe-titre .chevron { width: 1em; transition: transform .15s; }
.groupe[data-replie="1"] .chevron { transform: rotate(-90deg); }
.groupe[data-replie="1"] .entrees { display: none; }
.groupe .compte { margin-left: auto; font-weight: 450; }
.entree {
  display: grid; grid-template-columns: 8px 1fr auto; align-items: center; gap: .55rem;
  padding: .38rem .5rem .38rem .6rem; border-radius: 6px; cursor: pointer; position: relative;
  border-left: 3px solid transparent;
}
.entree:hover { background: var(--survol); }
.entree[aria-current="true"] { background: var(--actif); }
.entree.rdp { border-left-color: var(--rdp); } .entree.ssh { border-left-color: var(--ssh); } .entree.vnc { border-left-color: var(--vnc); }
.pastille { width: 8px; height: 8px; border-radius: 50%; background: var(--inconnu); }
.pastille.en_ligne { background: var(--ok); } .pastille.hors_ligne { background: var(--ko); }
.entree .nom { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entree .proto { font-size: 11px; color: var(--texte-2); }
.entree .actions-entree {
  display: flex; gap: .1rem; align-items: center; opacity: 0; position: absolute; right: .3rem; top: 50%;
  transform: translateY(-50%); background: var(--survol); border-radius: 5px; padding: 0 .15rem;
}
.entree:has(.favori-actif) .actions-entree { opacity: 1; background: none; }
.entree:has(.favori-actif):hover .actions-entree { background: var(--survol); }
.entree:hover .actions-entree, .entree:focus-within .actions-entree { opacity: 1; }
.entree .actions-entree button { background: none; color: var(--texte-2); padding: .1rem .3rem; font-size: 13px; }
.entree .actions-entree button:hover { color: var(--texte); }
.entree .actions-entree button.favori-actif { color: var(--ssh); }
.entree:has(.favori-actif):not(:hover) .actions-entree > :not(.favori-actif) { display: none; }
.gere { font-size: 11px; color: var(--texte-2); }

/* ---------- Onglets */
.zone { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.onglets-barre {
  display: flex; align-items: flex-end; gap: .5rem; background: var(--panneau); border-bottom: 1px solid var(--trait);
  padding: .45rem .6rem 0; min-height: 44px;
}
.onglets { display: flex; gap: 2px; overflow-x: auto; flex: 1; }
.onglet {
  display: flex; align-items: center; gap: .5rem; padding: .45rem .5rem .5rem .75rem; background: var(--panneau-2);
  color: var(--texte-2); border-radius: 7px 7px 0 0; border-top: 3px solid transparent; white-space: nowrap;
  cursor: pointer; max-width: 240px;
}
.onglet.rdp { border-top-color: var(--rdp); } .onglet.ssh { border-top-color: var(--ssh); } .onglet.vnc { border-top-color: var(--vnc); }
.onglet[aria-selected="true"] { background: var(--fond); color: var(--texte); }
.onglet .titre { overflow: hidden; text-overflow: ellipsis; }
.onglet .etat { width: 7px; height: 7px; border-radius: 50%; background: var(--inconnu); flex: none; }
.onglet .etat.connecte { background: var(--ok); } .onglet .etat.erreur { background: var(--ko); }
.onglet .fermer { background: none; color: var(--texte-2); padding: 0 .3rem; font-size: 15px; line-height: 1; }
.onglet .fermer:hover { color: var(--texte); }
.outils { display: flex; gap: .25rem; padding-bottom: .4rem; }
.outil { background: none; color: var(--texte-2); padding: .3rem .55rem; font-size: 13px; font-weight: 500; border-radius: 5px; }
.outil:hover { background: var(--survol); color: var(--texte); }

/* ---------- Scène des sessions */
.scene { flex: 1; position: relative; min-height: 0; background: #000; overflow: hidden; }
.session { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.session[hidden] { display: none !important; }
.session .affichage { outline: none; }
.session .message {
  position: absolute; inset: auto 1rem 1rem auto; background: var(--panneau); color: var(--texte);
  padding: .6rem .8rem; border-radius: 6px; box-shadow: var(--ombre); max-width: 360px;
}
.session .message button { margin-left: .6rem; }
.vide { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; background: var(--fond); padding: 2rem; }
.vide-titre { font-size: 18px; font-weight: 600; margin: 0 0 .3rem; }
.vide .aide { max-width: 44ch; }

/* ---------- Menus, panneaux, modale */
.menu {
  position: fixed; z-index: 20; background: var(--panneau); border: 1px solid var(--trait); border-radius: 8px;
  box-shadow: var(--ombre); padding: .3rem; display: flex; flex-direction: column; min-width: 190px;
}
.menu button { background: none; color: var(--texte); text-align: left; padding: .45rem .6rem; font-weight: 450; border-radius: 5px; }
.menu button:hover, .menu button:focus-visible { background: var(--survol); }
.menu-contextuel { max-width: 300px; }
.menu button.danger { color: var(--ko); }
.menu-sep { border: none; border-top: 1px solid var(--trait); margin: .25rem .3rem; }
.panneau {
  position: fixed; z-index: 20; right: 1rem; top: 3.4rem; width: min(420px, calc(100vw - 2rem));
  background: var(--panneau); border: 1px solid var(--trait); border-radius: 10px; box-shadow: var(--ombre); padding: 1rem 1.1rem;
}
.panneau.large { width: min(560px, calc(100vw - 2rem)); }
.panneau h2 { font-size: 15px; margin: 0 0 .3rem; }
.panneau textarea {
  width: 100%; background: var(--panneau-2); border: 1px solid var(--trait); border-radius: 6px; padding: .5rem;
  font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; font-size: 13px;
}
.actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .8rem; align-items: center; }
.actions button[data-fermer] { background: var(--panneau-2); color: var(--texte); }
label.bouton { background: var(--rdp); color: #fff; border-radius: 6px; padding: .55rem .9rem; cursor: pointer; font-weight: 550; }
.chemin { font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; font-size: 12.5px; color: var(--texte-2); margin: .2rem 0 .5rem; }
.liste-fichiers { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow: auto; border: 1px solid var(--trait); border-radius: 6px; }
.liste-fichiers li { display: flex; gap: .5rem; align-items: center; padding: .4rem .6rem; border-bottom: 1px solid var(--trait); cursor: pointer; }
.liste-fichiers li:last-child { border-bottom: 0; }
.liste-fichiers li:hover { background: var(--survol); }
.liste-fichiers .type { width: 1.2em; color: var(--texte-2); }
.transferts { margin-top: .7rem; }
.transferts h3 { font-size: 13px; margin: 0 0 .3rem; }
.liste-fichiers li progress { width: 7rem; max-width: 32%; }
.liste-fichiers li:has(progress) { cursor: default; }
.modale { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .55); display: grid; place-items: center; }
.modale .panneau { position: static; }
#form-modification label { display: block; margin: .6rem 0; color: var(--texte-2); font-size: 13px; }
#form-modification input {
  display: block; width: 100%; margin-top: .3rem; padding: .55rem .65rem; background: var(--panneau-2);
  border: 1px solid var(--trait); border-radius: 6px;
}
.annonce { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* Fenêtre détachée : pas de barre latérale */
body.detache .portail { grid-template-columns: 1fr; }
body.detache .barre { display: none; }

@media (max-width: 760px) {
  .portail { grid-template-columns: 1fr; }
  .barre { position: fixed; inset: 0 auto 0 0; width: 86vw; z-index: 10; }
  .portail.session-ouverte .barre { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Demande d'identifiants */
#champs-identifiants label { display: block; margin: .6rem 0; color: var(--texte-2); font-size: 13px; }
#champs-identifiants input {
  display: block; width: 100%; margin-top: .3rem; padding: .55rem .65rem; background: var(--panneau-2);
  border: 1px solid var(--trait); border-radius: 6px;
}
