* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: system-ui, "Segoe UI", sans-serif; }
body { display: flex; flex-direction: column; color: #1a1a2e; }

header {
  background: #16213e; color: #fff; padding: 12px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
header h1 { font-size: 18px; margin: 0; }
.conn { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.conn label { font-size: 13px; display: flex; flex-direction: column; gap: 2px; }
.conn input {
  padding: 6px 8px; border-radius: 6px; border: 1px solid #44507a;
  background: #0f1629; color: #fff; width: 120px; font-size: 14px;
}
.conn button {
  padding: 8px 14px; border: 0; border-radius: 6px; cursor: pointer;
  background: #4ade80; color: #072b16; font-weight: 600;
}
.badge { font-size: 12px; padding: 4px 10px; border-radius: 999px; font-weight: 600; }
.badge.off { background: #4b2033; color: #ff9db1; }
.badge.on  { background: #0f3d26; color: #6ee7a0; }

main { flex: 1; display: flex; min-height: 0; }
#lista { width: 240px; background: #f3f4f8; padding: 14px; overflow-y: auto; border-right: 1px solid #dde; }
#lista h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .5px; color: #555; }
#hijos { list-style: none; padding: 0; margin: 0; }
#hijos li {
  background: #fff; border: 1px solid #e2e4ef; border-radius: 10px;
  padding: 10px 12px; margin-bottom: 10px; cursor: pointer;
}
#hijos li.sel { border-color: #4ade80; box-shadow: 0 0 0 2px #4ade8055; }
#hijos .nombre { font-weight: 600; }
#hijos .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
#hijos .dot.on { background: #22c55e; } #hijos .dot.off { background: #9aa; }
#hijos .meta { font-size: 12px; color: #667; margin-top: 4px; }
#mapa { flex: 1; min-height: 0; }

@media (max-width: 640px) {
  main { flex-direction: column; }
  #lista { width: 100%; max-height: 150px; }
}

/* Boton y texto de direccion en cada hijo */
.btn-dir {
  margin-top: 8px; padding: 5px 10px; font-size: 12px; cursor: pointer;
  border: 1px solid #c7d2fe; background: #eef2ff; color: #3730a3;
  border-radius: 6px;
}
.btn-dir:hover { background: #e0e7ff; }
.dir { font-size: 12px; color: #444; margin-top: 6px; line-height: 1.35; }

/* Pantalla en vivo */
.btn-pantalla {
  margin-top: 8px; margin-left: 6px; padding: 5px 10px; font-size: 12px; cursor: pointer;
  border: 1px solid #bbf7d0; background: #f0fdf4; color: #166534; border-radius: 6px;
}
.btn-pantalla:disabled { opacity: .45; cursor: not-allowed; }
.visor {
  position: fixed; inset: 0; background: rgba(10, 14, 30, .78); z-index: 2000;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.visor[hidden] { display: none; }
.visor-caja {
  background: #0f1629; border-radius: 14px; padding: 12px; max-height: 100%;
  display: flex; flex-direction: column; gap: 10px; max-width: 100%;
}
.visor-cab { display: flex; align-items: center; gap: 10px; color: #fff; font-size: 14px; }
.visor-estado { font-size: 12px; color: #9aa6c7; flex: 1; }
.visor-cab button {
  padding: 6px 12px; border: 0; border-radius: 6px; cursor: pointer;
  background: #ff9db1; color: #4b2033; font-weight: 600;
}
#visorImg {
  display: block; max-height: calc(100vh - 110px); max-width: 100%;
  border-radius: 8px; background: #000; min-width: 200px; min-height: 300px; object-fit: contain;
}
