/* Remote Desktop Wanaction — contrôleur 2.0.2 — tactile d'abord (iPhone, iPad), paysage privilégié */

:root {
  --fond: #101418;
  --fond-2: #1a2027;
  --fond-3: #242c35;
  --texte: #eef2f6;
  --texte-2: #aab4c0;
  --accent: #2f8fe6;
  --accent-2: #1f6fb8;
  --danger: #d64545;
  --ok: #2ecc71;
  --moyen: #f0a830;
  --mauvais: #e74c3c;
  --rayon: 12px;
  --barre: 48px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--fond);
  color: var(--texte);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  padding: var(--sat) var(--sar) 0 var(--sal);
}

[hidden] { display: none !important; }

#principal {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.ecran {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: auto;
}

.carte {
  width: 100%;
  max-width: 440px;
  background: var(--fond-2);
  border-radius: var(--rayon);
  padding: 22px 20px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

.titre { font-size: 22px; margin: 0 0 6px; font-weight: 700; }
.marque { color: var(--accent); }
.sous-titre { margin: 0 0 18px; color: var(--texte-2); line-height: 1.4; }
.message { color: var(--texte-2); line-height: 1.4; margin: 12px 0 0; }
.erreur { color: #ff8a80; margin: 8px 0 0; line-height: 1.4; }

.champ { display: block; margin-bottom: 14px; }
.champ > span { display: block; font-size: 14px; color: var(--texte-2); margin-bottom: 6px; }
.champ input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #334050;
  background: var(--fond);
  color: var(--texte);
  font-size: 17px;
}
.champ input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.champ-code input { font-size: 30px; letter-spacing: 6px; text-align: center; font-variant-numeric: tabular-nums; }

.bouton {
  min-height: 44px;
  min-width: 44px;
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  background: var(--fond-3);
  color: var(--texte);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.bouton:active { filter: brightness(1.25); }
.bouton.principal { background: var(--accent); }
.bouton.principal:active { background: var(--accent-2); }
.bouton.danger { background: var(--danger); }
.bouton.discret { background: transparent; color: var(--texte-2); }
.bouton.large { width: 100%; margin-top: 6px; }
.bouton.icone { font-size: 20px; padding: 6px 10px; }
.bouton.actif { background: var(--accent); color: #fff; }
.bouton[disabled] { opacity: 0.5; }

.actions-secondaires { margin-top: 16px; text-align: center; }
.aide-installation { text-align: center; margin: 16px 0 0; }
.aide-installation a { color: var(--texte-2); }

.compte-a-rebours {
  font-size: 56px;
  font-weight: 700;
  text-align: center;
  margin: 10px 0;
  font-variant-numeric: tabular-nums;
}

/* Barre de session */
.barre {
  flex: 0 0 var(--barre);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 0 8px;
  background: var(--fond-2);
  border-bottom: 1px solid #0a0d10;
}
.barre-groupe { display: flex; align-items: center; gap: 6px; min-width: 0; }
.indicateur { font-size: 14px; color: var(--texte-2); }
.indicateur.ok { color: var(--ok); }
.indicateur.moyen { color: var(--moyen); }
.indicateur.mauvais { color: var(--mauvais); }
.latence { font-size: 13px; color: var(--texte-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.machine { font-size: 13px; color: var(--texte-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 28vw; }
.temps { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; margin-right: 4px; }
.temps.alerte { color: var(--moyen); }

/* Session */
.ecran-session { padding: 0; flex-direction: column; align-items: stretch; justify-content: flex-start; overflow: hidden; }
.zone-ecran {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #000;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#canevas { display: block; width: 100%; height: 100%; }
.message-zone {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(16, 20, 24, 0.9);
  color: var(--texte);
  padding: 14px 18px;
  border-radius: 10px;
  text-align: center;
  max-width: 80%;
  line-height: 1.4;
}

.barre-touches {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 6px 8px calc(6px + var(--sab));
  background: var(--fond-2);
  border-top: 1px solid #0a0d10;
  -webkit-overflow-scrolling: touch;
}
.touche {
  flex: 0 0 auto;
  min-width: 48px;
  min-height: 42px;
  padding: 6px 10px;
  border: none;
  border-radius: 8px;
  background: var(--fond-3);
  color: var(--texte);
  font-size: 15px;
  font-weight: 600;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.touche:active { filter: brightness(1.3); }
.touche.actif { background: var(--accent); color: #fff; }

.saisie {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 2px;
  height: 2px;
  opacity: 0.01;
  resize: none;
  border: none;
  padding: 0;
  font-size: 16px; /* évite le zoom automatique d'iOS sur focus */
  z-index: -1;
}

/* Pied */
.pied {
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--texte-2);
  text-align: center;
  padding: 6px 8px calc(6px + var(--sab));
}
.pied.compact { display: none; }

/* Menu */
.menu {
  position: fixed;
  right: calc(8px + var(--sar));
  top: calc(var(--sat) + var(--barre) + 4px);
  width: 260px;
  background: var(--fond-2);
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  padding: 6px;
  z-index: 20;
}
.element-menu {
  display: block;
  width: 100%;
  text-align: left;
  min-height: 44px;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--texte);
  font-size: 16px;
}
.element-menu:active { background: var(--fond-3); }
.element-menu.inactif { color: var(--texte-2); }
.element-menu.choisi { background: var(--fond-3); }
.separateur { height: 1px; background: #0a0d10; margin: 4px 0; }

/* Dialogue */
.voile {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 30;
}
.dialogue {
  width: 100%;
  max-width: 400px;
  background: var(--fond-2);
  border-radius: var(--rayon);
  padding: 20px;
}
.dialogue h2 { margin: 0 0 8px; font-size: 19px; }
.dialogue p { margin: 0 0 16px; color: var(--texte-2); line-height: 1.4; }
.dialogue-actions { display: flex; justify-content: flex-end; gap: 8px; }
.liste-aide { color: var(--texte-2); line-height: 1.5; padding-left: 20px; margin: 0 0 16px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--sab));
  transform: translateX(-50%);
  background: rgba(36, 44, 53, 0.97);
  color: var(--texte);
  padding: 12px 16px;
  border-radius: 10px;
  max-width: 90%;
  text-align: center;
  z-index: 40;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  line-height: 1.4;
}

/* Portrait : écran distant ajusté en largeur (le canevas garde les proportions), commandes accessibles */
@media (orientation: portrait) {
  .machine { max-width: 20vw; }
  .temps { font-size: 14px; }
}

@media (max-width: 420px) {
  .bouton.danger { padding: 10px 10px; font-size: 14px; }
  .bouton.icone { padding: 6px 8px; }
}

/* Écrans étroits (iPhone en portrait) : la barre tient sur une ligne, Terminer reste visible */
@media (max-width: 560px) {
  .latence, .machine { display: none; }
  .temps { font-size: 14px; margin-right: 2px; }
  .barre { gap: 4px; padding: 0 6px; }
  .barre-groupe { gap: 4px; }
  .bouton.icone { min-width: 40px; padding: 6px 6px; font-size: 18px; }
  .bouton.danger { padding: 8px 10px; font-size: 14px; }
}
